001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.module.purap.util;
017    
018    import org.apache.commons.lang.builder.CompareToBuilder;
019    import org.apache.commons.lang.builder.EqualsBuilder;
020    import org.apache.commons.lang.builder.HashCodeBuilder;
021    import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
022    
023    public class VendorGroupingHelper implements Comparable {
024        private Integer vendorHeaderGeneratedIdentifier;
025        private Integer vendorDetailAssignedIdentifier;
026        private String vendorCountry;
027        private String vendorPostalCode;
028        
029        public VendorGroupingHelper( PurchasingAccountsPayableDocument doc ) {
030            vendorHeaderGeneratedIdentifier = doc.getVendorHeaderGeneratedIdentifier();
031            vendorDetailAssignedIdentifier = doc.getVendorDetailAssignedIdentifier();
032            vendorCountry = doc.getVendorCountryCode();
033            vendorPostalCode = doc.getVendorPostalCode();
034            if ( vendorPostalCode != null && vendorPostalCode.length() > 5 ) {
035                vendorPostalCode = vendorPostalCode.substring(0, 5);
036            }
037        }
038        
039        public Integer getVendorHeaderGeneratedIdentifier() {
040            return vendorHeaderGeneratedIdentifier;
041        }
042    
043        public Integer getVendorDetailAssignedIdentifier() {
044            return vendorDetailAssignedIdentifier;
045        }
046    
047        public String getVendorCountry() {
048            return vendorCountry;
049        }
050    
051        public String getVendorPostalCode() {
052            return vendorPostalCode;
053        }
054    
055        /**
056         * @see java.lang.Object#toString()
057         */
058        public String toString() {
059            return vendorHeaderGeneratedIdentifier + "-" + vendorDetailAssignedIdentifier + "-" + vendorCountry + "-" + vendorPostalCode;
060        }
061    
062        /**
063         * @see java.lang.Object#equals(Object)
064         */
065        public boolean equals(Object object) {
066            if ( !(object instanceof VendorGroupingHelper) ) {
067                    return false;
068            }
069            VendorGroupingHelper rhs = (VendorGroupingHelper)object;
070            return new EqualsBuilder().append(
071                            this.vendorPostalCode, rhs.vendorPostalCode ).append(
072                            this.vendorHeaderGeneratedIdentifier, rhs.vendorHeaderGeneratedIdentifier ).append(
073                            this.vendorDetailAssignedIdentifier, rhs.vendorDetailAssignedIdentifier ).append(
074                            this.vendorCountry, rhs.vendorCountry ).isEquals();
075        }
076    
077        /**
078         * @see java.lang.Object#hashCode()
079         */
080        public int hashCode() {
081            return new HashCodeBuilder( -999235111, -1951404497 ).append( this.vendorPostalCode )
082                    .append( this.vendorHeaderGeneratedIdentifier )
083                            .append( this.vendorDetailAssignedIdentifier ).append( this.vendorCountry )
084                            .toHashCode();
085        }
086    
087        /**
088         * @see java.lang.Comparable#compareTo(Object)
089         */
090        public int compareTo(Object object) {
091            VendorGroupingHelper myClass = (VendorGroupingHelper)object;
092            return new CompareToBuilder().append( this.vendorPostalCode, myClass.vendorPostalCode )
093                            .append( this.vendorHeaderGeneratedIdentifier,
094                                            myClass.vendorHeaderGeneratedIdentifier )
095                            .append( this.vendorDetailAssignedIdentifier,
096                                            myClass.vendorDetailAssignedIdentifier ).append( this.vendorCountry,
097                                            myClass.vendorCountry ).toComparison();
098        }
099    
100        
101        
102    }