001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.util;
017:
018: import org.apache.commons.lang.builder.EqualsBuilder;
019: import org.apache.commons.lang.builder.HashCodeBuilder;
020: import org.apache.commons.lang.builder.CompareToBuilder;
021: import org.apache.commons.lang.builder.ToStringBuilder;
022: import org.apache.commons.lang.builder.ToStringStyle;
023: import org.kuali.module.purap.document.PurchasingAccountsPayableDocument;
024:
025: public class VendorGroupingHelper implements Comparable {
026: private Integer vendorHeaderGeneratedIdentifier;
027: private Integer vendorDetailAssignedIdentifier;
028: private String vendorCountry;
029: private String vendorPostalCode;
030:
031: public VendorGroupingHelper(PurchasingAccountsPayableDocument doc) {
032: vendorHeaderGeneratedIdentifier = doc
033: .getVendorHeaderGeneratedIdentifier();
034: vendorDetailAssignedIdentifier = doc
035: .getVendorDetailAssignedIdentifier();
036: vendorCountry = doc.getVendorCountryCode();
037: vendorPostalCode = doc.getVendorPostalCode();
038: if (vendorPostalCode != null && vendorPostalCode.length() > 5) {
039: vendorPostalCode = vendorPostalCode.substring(0, 5);
040: }
041: }
042:
043: public Integer getVendorHeaderGeneratedIdentifier() {
044: return vendorHeaderGeneratedIdentifier;
045: }
046:
047: public Integer getVendorDetailAssignedIdentifier() {
048: return vendorDetailAssignedIdentifier;
049: }
050:
051: public String getVendorCountry() {
052: return vendorCountry;
053: }
054:
055: public String getVendorPostalCode() {
056: return vendorPostalCode;
057: }
058:
059: /**
060: * @see java.lang.Object#toString()
061: */
062: public String toString() {
063: return vendorHeaderGeneratedIdentifier + "-"
064: + vendorDetailAssignedIdentifier + "-" + vendorCountry
065: + "-" + vendorPostalCode;
066: }
067:
068: /**
069: * @see java.lang.Object#equals(Object)
070: */
071: public boolean equals(Object object) {
072: if (!(object instanceof VendorGroupingHelper)) {
073: return false;
074: }
075: VendorGroupingHelper rhs = (VendorGroupingHelper) object;
076: return new EqualsBuilder().append(this .vendorPostalCode,
077: rhs.vendorPostalCode).append(
078: this .vendorHeaderGeneratedIdentifier,
079: rhs.vendorHeaderGeneratedIdentifier).append(
080: this .vendorDetailAssignedIdentifier,
081: rhs.vendorDetailAssignedIdentifier).append(
082: this .vendorCountry, rhs.vendorCountry).isEquals();
083: }
084:
085: /**
086: * @see java.lang.Object#hashCode()
087: */
088: public int hashCode() {
089: return new HashCodeBuilder(-999235111, -1951404497).append(
090: this .vendorPostalCode).append(
091: this .vendorHeaderGeneratedIdentifier).append(
092: this .vendorDetailAssignedIdentifier).append(
093: this .vendorCountry).toHashCode();
094: }
095:
096: /**
097: * @see java.lang.Comparable#compareTo(Object)
098: */
099: public int compareTo(Object object) {
100: VendorGroupingHelper myClass = (VendorGroupingHelper) object;
101: return new CompareToBuilder().append(this.vendorPostalCode,
102: myClass.vendorPostalCode).append(
103: this.vendorHeaderGeneratedIdentifier,
104: myClass.vendorHeaderGeneratedIdentifier).append(
105: this.vendorDetailAssignedIdentifier,
106: myClass.vendorDetailAssignedIdentifier).append(
107: this.vendorCountry, myClass.vendorCountry)
108: .toComparison();
109: }
110:
111: }
|