View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.util;
17  
18  import org.apache.commons.lang.builder.CompareToBuilder;
19  import org.apache.commons.lang.builder.EqualsBuilder;
20  import org.apache.commons.lang.builder.HashCodeBuilder;
21  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
22  
23  public class VendorGroupingHelper implements Comparable {
24      private Integer vendorHeaderGeneratedIdentifier;
25      private Integer vendorDetailAssignedIdentifier;
26      private String vendorCountry;
27      private String vendorPostalCode;
28  
29      public VendorGroupingHelper(PurchasingAccountsPayableDocument doc) {
30          vendorHeaderGeneratedIdentifier = doc.getVendorHeaderGeneratedIdentifier();
31          vendorDetailAssignedIdentifier = doc.getVendorDetailAssignedIdentifier();
32          vendorCountry = doc.getVendorCountryCode();
33          vendorPostalCode = doc.getVendorPostalCode();
34          if (vendorPostalCode != null && vendorPostalCode.length() > 5) {
35              vendorPostalCode = vendorPostalCode.substring(0, 5);
36          }
37      }
38  
39      public Integer getVendorHeaderGeneratedIdentifier() {
40          return vendorHeaderGeneratedIdentifier;
41      }
42  
43      public Integer getVendorDetailAssignedIdentifier() {
44          return vendorDetailAssignedIdentifier;
45      }
46  
47      public String getVendorCountry() {
48          return vendorCountry;
49      }
50  
51      public String getVendorPostalCode() {
52          return vendorPostalCode;
53      }
54  
55      /**
56       * @see java.lang.Object#toString()
57       */
58      public String toString() {
59          return vendorHeaderGeneratedIdentifier + "-" + vendorDetailAssignedIdentifier + "-" + vendorCountry + "-" + vendorPostalCode;
60      }
61  
62      /**
63       * @see java.lang.Object#equals(Object)
64       */
65      public boolean equals(Object object) {
66          if (!(object instanceof VendorGroupingHelper)) {
67              return false;
68          }
69          VendorGroupingHelper rhs = (VendorGroupingHelper) object;
70          return new EqualsBuilder().append(
71                  this.vendorPostalCode, rhs.vendorPostalCode).append(
72                  this.vendorHeaderGeneratedIdentifier, rhs.vendorHeaderGeneratedIdentifier).append(
73                  this.vendorDetailAssignedIdentifier, rhs.vendorDetailAssignedIdentifier).append(
74                  this.vendorCountry, rhs.vendorCountry).isEquals();
75      }
76  
77      /**
78       * @see java.lang.Object#hashCode()
79       */
80      public int hashCode() {
81          return new HashCodeBuilder(-999235111, -1951404497).append(this.vendorPostalCode)
82                  .append(this.vendorHeaderGeneratedIdentifier)
83                  .append(this.vendorDetailAssignedIdentifier).append(this.vendorCountry)
84                  .toHashCode();
85      }
86  
87      /**
88       * @see java.lang.Comparable#compareTo(Object)
89       */
90      public int compareTo(Object object) {
91          VendorGroupingHelper myClass = (VendorGroupingHelper) object;
92          return new CompareToBuilder().append(this.vendorPostalCode, myClass.vendorPostalCode)
93                  .append(this.vendorHeaderGeneratedIdentifier,
94                          myClass.vendorHeaderGeneratedIdentifier)
95                  .append(this.vendorDetailAssignedIdentifier,
96                          myClass.vendorDetailAssignedIdentifier).append(this.vendorCountry,
97                          myClass.vendorCountry).toComparison();
98      }
99  
100 
101 }