View Javadoc

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