View Javadoc
1   package ejava.examples.txhotel.bo;
2   
3   import java.io.Serializable;
4   import java.util.Date;
5   
6   @SuppressWarnings("serial")
7   public class Person implements Serializable {
8       private long id;
9       private long version;
10      private String firstName;
11      private String lastName;
12      private Date creationDate=new Date();
13      
14      public Person() {}
15      public Person(long id, long version, String firstName, String lastName) { 
16          setId(id);
17          setVersion(version);
18          setFirstName(firstName);
19          setLastName(lastName);
20      }
21      
22      public long getId() {
23          return id;
24      }
25      private void setId(long id) {
26          this.id = id;
27      }
28      public String getFirstName() {
29          return firstName;
30      }
31      public void setFirstName(String firstName) {
32          this.firstName = firstName;
33      }
34      public String getLastName() {
35          return lastName;
36      }
37      public void setLastName(String lastName) {
38          this.lastName = lastName;
39      }    
40      public long getVersion() {
41          return version;
42      }
43      public void setVersion(long version) {
44          this.version = version;
45      }
46      
47      @Override
48  	public boolean equals(Object obj) {
49      	try {
50      		if (this==obj) return true;
51      		Person rhs = (Person)obj;
52      		return creationDate.getTime()==rhs.creationDate.getTime() &&
53      				firstName.equals(rhs.firstName) &&
54      				lastName.equals(rhs.lastName);
55      	} catch (Exception ex) {
56      		return false;
57      	}
58  	}
59  	@Override
60  	public int hashCode() {
61  		return creationDate.hashCode();
62  	}
63  	
64  	public String toString() {
65          StringBuilder text = new StringBuilder();
66          text.append("id=" + id);
67          text.append(", version=" + version);
68          text.append(", firstName=" + firstName);
69          text.append(", lastName=" + lastName);
70          return text.toString();
71      }
72  }