KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ce > auction > model > Address


1 package org.hibernate.ce.auction.model;
2
3 import javax.persistence.*;
4 import java.io.Serializable JavaDoc;
5
6 /**
7  * The address of a User.
8  *
9  * An instance of this class is always associated with only
10  * one <tt>User</tt> and depends on that parent objects lifecycle,
11  * it is a component.
12  *
13  * @see User
14  * @author Christian Bauer <christian@hibernate.org>
15  */

16 @Embeddable(access = AccessType.FIELD)
17 public class Address implements Serializable JavaDoc {
18
19     @Column(length = 255)
20     private String JavaDoc street;
21
22     @Column(length = 16)
23     private String JavaDoc zipcode;
24
25     @Column(length = 255)
26     private String JavaDoc city;
27
28     /**
29      * No-arg constructor for JavaBean tools.
30      */

31     Address() {}
32
33     /**
34      * Full constructor.
35      */

36     public Address(String JavaDoc street, String JavaDoc zipcode, String JavaDoc city) {
37         this.street = street;
38         this.zipcode = zipcode;
39         this.city = city;
40     }
41
42     // ********************** Accessor Methods ********************** //
43

44     public String JavaDoc getStreet() { return street; }
45     public void setStreet(String JavaDoc street) { this.street = street; }
46
47     public String JavaDoc getZipcode() { return zipcode; }
48     public void setZipcode(String JavaDoc zipcode) { this.zipcode = zipcode; }
49
50     public String JavaDoc getCity() { return city; }
51     public void setCity(String JavaDoc city) { this.city = city; }
52
53     // ********************** Common Methods ********************** //
54

55     public boolean equals(Object JavaDoc o) {
56         if (this == o) return true;
57         if (!(o instanceof Address)) return false;
58
59         final Address address = (Address) o;
60
61         if (!city.equals(address.city)) return false;
62         if (!street.equals(address.street)) return false;
63         if (!zipcode.equals(address.zipcode)) return false;
64
65         return true;
66     }
67
68     public int hashCode() {
69         int result;
70         result = street.hashCode();
71         result = 29 * result + zipcode.hashCode();
72         result = 29 * result + city.hashCode();
73         return result;
74     }
75
76     public String JavaDoc toString() {
77         return "Street: '" + getStreet() + "', " +
78                 "Zipcode: '" + getZipcode() + "', " +
79                 "City: '" + getCity() + "'";
80     }
81
82     // ********************** Business Methods ********************** //
83

84 }
85
Popular Tags