View Javadoc

1   package net.ramapuram.thomas.model;
2   
3   import org.apache.commons.lang.builder.ToStringBuilder;
4   import org.apache.commons.lang.builder.ToStringStyle;
5   import org.compass.annotations.Searchable;
6   import org.compass.annotations.SearchableProperty;
7   
8   import javax.persistence.Column;
9   import javax.persistence.Embeddable;
10  import java.io.Serializable;
11  
12  /**
13   * This class is used to represent an address with address,
14   * city, province and postal-code information.
15   *
16   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
17   */
18  @Embeddable
19  @Searchable(root = false)
20  public class Address extends BaseObject implements Serializable {
21      private static final long serialVersionUID = 3617859655330969141L;
22      private String address;
23      private String city;
24      private String province;
25      private String country;
26      private String postalCode;
27  
28      @Column(length = 150)
29      @SearchableProperty
30      public String getAddress() {
31          return address;
32      }
33  
34      @Column(length = 50)
35      @SearchableProperty
36      public String getCity() {
37          return city;
38      }
39  
40      @Column(length = 100)
41      @SearchableProperty
42      public String getProvince() {
43          return province;
44      }
45  
46      @Column(length = 100)
47      @SearchableProperty
48      public String getCountry() {
49          return country;
50      }
51  
52      @Column(name = "postal_code", length = 15)
53      @SearchableProperty
54      public String getPostalCode() {
55          return postalCode;
56      }
57  
58      public void setAddress(String address) {
59          this.address = address;
60      }
61  
62      public void setCity(String city) {
63          this.city = city;
64      }
65  
66      public void setCountry(String country) {
67          this.country = country;
68      }
69  
70      public void setPostalCode(String postalCode) {
71          this.postalCode = postalCode;
72      }
73  
74      public void setProvince(String province) {
75          this.province = province;
76      }
77  
78      /**
79       * Overridden equals method for object comparison. Compares based on hashCode.
80       *
81       * @param o Object to compare
82       * @return true/false based on hashCode
83       */
84      public boolean equals(Object o) {
85          if (this == o) {
86              return true;
87          }
88          if (!(o instanceof Address)) {
89              return false;
90          }
91  
92          final Address address1 = (Address) o;
93  
94          return this.hashCode() == address1.hashCode();
95      }
96  
97      /**
98       * Overridden hashCode method - compares on address, city, province, country and postal code.
99       *
100      * @return hashCode
101      */
102     public int hashCode() {
103         int result;
104         result = (address != null ? address.hashCode() : 0);
105         result = 29 * result + (city != null ? city.hashCode() : 0);
106         result = 29 * result + (province != null ? province.hashCode() : 0);
107         result = 29 * result + (country != null ? country.hashCode() : 0);
108         result = 29 * result + (postalCode != null ? postalCode.hashCode() : 0);
109         return result;
110     }
111 
112     /**
113      * Returns a multi-line String with key=value pairs.
114      *
115      * @return a String representation of this class.
116      */
117     public String toString() {
118         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
119                 .append("country", this.country)
120                 .append("address", this.address)
121                 .append("province", this.province)
122                 .append("postalCode", this.postalCode)
123                 .append("city", this.city).toString();
124     }
125 }