View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.purap.util;
20  
21  import org.apache.commons.lang.builder.CompareToBuilder;
22  import org.apache.commons.lang.builder.EqualsBuilder;
23  import org.apache.commons.lang.builder.HashCodeBuilder;
24  import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
25  
26  public class VendorGroupingHelper implements Comparable {
27      private Integer vendorHeaderGeneratedIdentifier;
28      private Integer vendorDetailAssignedIdentifier;
29      private String vendorCountry;
30      private String vendorPostalCode;
31      
32      public VendorGroupingHelper( PurchasingAccountsPayableDocument doc ) {
33          vendorHeaderGeneratedIdentifier = doc.getVendorHeaderGeneratedIdentifier();
34          vendorDetailAssignedIdentifier = doc.getVendorDetailAssignedIdentifier();
35          vendorCountry = doc.getVendorCountryCode();
36          vendorPostalCode = doc.getVendorPostalCode();
37          if ( vendorPostalCode != null && vendorPostalCode.length() > 5 ) {
38              vendorPostalCode = vendorPostalCode.substring(0, 5);
39          }
40      }
41      
42      public Integer getVendorHeaderGeneratedIdentifier() {
43          return vendorHeaderGeneratedIdentifier;
44      }
45  
46      public Integer getVendorDetailAssignedIdentifier() {
47          return vendorDetailAssignedIdentifier;
48      }
49  
50      public String getVendorCountry() {
51          return vendorCountry;
52      }
53  
54      public String getVendorPostalCode() {
55          return vendorPostalCode;
56      }
57  
58      /**
59       * @see java.lang.Object#toString()
60       */
61      public String toString() {
62      	return vendorHeaderGeneratedIdentifier + "-" + vendorDetailAssignedIdentifier + "-" + vendorCountry + "-" + vendorPostalCode;
63      }
64  
65      /**
66       * @see java.lang.Object#equals(Object)
67       */
68      public boolean equals(Object object) {
69      	if ( !(object instanceof VendorGroupingHelper) ) {
70      		return false;
71      	}
72      	VendorGroupingHelper rhs = (VendorGroupingHelper)object;
73      	return new EqualsBuilder().append(
74      			this.vendorPostalCode, rhs.vendorPostalCode ).append(
75      			this.vendorHeaderGeneratedIdentifier, rhs.vendorHeaderGeneratedIdentifier ).append(
76      			this.vendorDetailAssignedIdentifier, rhs.vendorDetailAssignedIdentifier ).append(
77      			this.vendorCountry, rhs.vendorCountry ).isEquals();
78      }
79  
80      /**
81       * @see java.lang.Object#hashCode()
82       */
83      public int hashCode() {
84      	return new HashCodeBuilder( -999235111, -1951404497 ).append( this.vendorPostalCode )
85      	        .append( this.vendorHeaderGeneratedIdentifier )
86      			.append( this.vendorDetailAssignedIdentifier ).append( this.vendorCountry )
87      			.toHashCode();
88      }
89  
90      /**
91       * @see java.lang.Comparable#compareTo(Object)
92       */
93      public int compareTo(Object object) {
94      	VendorGroupingHelper myClass = (VendorGroupingHelper)object;
95      	return new CompareToBuilder().append( this.vendorPostalCode, myClass.vendorPostalCode )
96      			.append( this.vendorHeaderGeneratedIdentifier,
97      					myClass.vendorHeaderGeneratedIdentifier )
98      			.append( this.vendorDetailAssignedIdentifier,
99      					myClass.vendorDetailAssignedIdentifier ).append( this.vendorCountry,
100     					myClass.vendorCountry ).toComparison();
101     }
102 
103     
104     
105 }