001: package auction.model;
002:
003: import auction.exceptions.BusinessException;
004:
005: import java.io.Serializable;
006: import java.util.*;
007:
008: /**
009: * A user of the CaveatEmptor auction application.
010: *
011: * @author Christian Bauer
012: */
013: public class User implements Serializable, Comparable {
014:
015: private Long id = null;
016: private int version = 0;
017:
018: private String firstname;
019: private String lastname;
020: private String username; // Unique and immutable
021: private String password;
022: private String email;
023: private String phoneNumber;
024:
025: private Address homeAddress;
026:
027: private Collection<Book> booksForSale = new ArrayList<Book>();
028:
029: private Date created = new Date();
030:
031: /**
032: * No-arg constructor for JavaBean tools
033: */
034: public User() {
035: }
036:
037: /**
038: * Simple constructor.
039: */
040: public User(String firstname, String lastname, String username,
041: String password, String email, String phoneNumber) {
042: this .firstname = firstname;
043: this .lastname = lastname;
044: this .username = username;
045: this .password = password;
046: this .email = email;
047: this .phoneNumber = phoneNumber;
048: }
049:
050: // ********************** Accessor Methods ********************** //
051:
052: public String getName() {
053: return (firstname + " " + lastname);
054: }
055:
056: public Long getId() {
057: return id;
058: }
059:
060: public int getVersion() {
061: return version;
062: }
063:
064: public String getFirstname() {
065: return firstname;
066: }
067:
068: public void setFirstname(String firstname) {
069: this .firstname = firstname;
070: }
071:
072: public String getLastname() {
073: return lastname;
074: }
075:
076: public void setLastname(String lastname) {
077: this .lastname = lastname;
078: }
079:
080: public String getUsername() {
081: return username;
082: }
083:
084: public void setUsername(String username) {
085: this .username = username;
086: }
087:
088: public String getPassword() {
089: return password;
090: }
091:
092: public void setPassword(String password) {
093: this .password = password;
094: }
095:
096: public String getEmail() {
097: return email;
098: }
099:
100: public void setEmail(String email) {
101: this .email = email;
102: }
103:
104: public String getPhoneNumber() {
105: return phoneNumber;
106: }
107:
108: public void setPhoneNumber(String phoneNumber) {
109: this .phoneNumber = phoneNumber;
110: }
111:
112: public Address getHomeAddress() {
113: return homeAddress;
114: }
115:
116: public void setHomeAddress(Address homeAddress) {
117: this .homeAddress = homeAddress;
118: }
119:
120: public Collection<Book> getBooksForSale() {
121: return booksForSale;
122: }
123:
124: public void setBooksForSale(Collection<Book> booksForSale) {
125: this .booksForSale = booksForSale;
126: }
127:
128: public void removeBookForSale(Book book) {
129: if (book == null)
130: throw (new IllegalArgumentException("Null Book"));
131: booksForSale.remove(book);
132: }
133:
134: public Date getCreated() {
135: return created;
136: }
137:
138: // ********************** Common Methods ********************** //
139:
140: public boolean equals(Object o) {
141: if (this == o)
142: return true;
143: if (!(o instanceof User))
144: return false;
145: final User user = (User) o;
146: return getUsername().equals(user.getUsername());
147: }
148:
149: public int hashCode() {
150: return getUsername().hashCode();
151: }
152:
153: public String toString() {
154: return "User ('" + getId() + "'), " + "Username: '"
155: + getUsername() + "'";
156: }
157:
158: public int compareTo(Object o) {
159: if (o instanceof User)
160: // Don't compare Date objects! Use the time in milliseconds!
161: return Long.valueOf(this .getCreated().getTime()).compareTo(
162: Long.valueOf(((User) o).getCreated().getTime()));
163: return 0;
164: }
165:
166: // ********************** Business Methods ********************** //
167:
168: }
|