001: package com.triactive.jdo.test;
002:
003: import junit.framework.Assert;
004: import javax.jdo.JDOHelper;
005:
006: public class Person implements Cloneable {
007: // persistent member variables
008: private long personNum;
009: private String firstName;
010: private String lastName;
011: private String emailAddress;
012:
013: public Person() {
014: }
015:
016: public Person(long num, String first, String last, String email) {
017: personNum = num;
018: firstName = first;
019: lastName = last;
020: emailAddress = email;
021: }
022:
023: public Object clone() {
024: Object o = null;
025:
026: try {
027: o = super .clone();
028: } catch (CloneNotSupportedException e) { /* can't happen */
029: }
030:
031: return o;
032: }
033:
034: public long getPersonNum() {
035: return personNum;
036: }
037:
038: public void setPersonNum(long num) {
039: personNum = num;
040: }
041:
042: public String getFirstName() {
043: return firstName;
044: }
045:
046: public void setFirstName(String s) {
047: firstName = s;
048: }
049:
050: public String getLastName() {
051: return lastName;
052: }
053:
054: public void setLastName(String s) {
055: lastName = s;
056: }
057:
058: public String getEmailAddress() {
059: return emailAddress;
060: }
061:
062: public void setEmailAddress(String s) {
063: emailAddress = s;
064: }
065:
066: public void assertEquals(Person p) {
067: Assert.assertEquals(lastName, p.lastName);
068: Assert.assertEquals(firstName, p.firstName);
069: Assert.assertEquals(emailAddress, p.emailAddress);
070: Assert.assertEquals(personNum, p.personNum);
071: }
072:
073: public int hashCode() {
074: Object id = JDOHelper.getObjectId(this );
075:
076: return id == null ? super .hashCode() : id.hashCode();
077: }
078:
079: public boolean equals(Object o) {
080: if (o == this )
081: return true;
082:
083: Object id = JDOHelper.getObjectId(this );
084:
085: return id == null ? super .equals(o) : id.equals(JDOHelper
086: .getObjectId(o));
087: }
088:
089: public String toString() {
090: Object id = JDOHelper.getObjectId(this );
091:
092: if (id == null)
093: id = "<not persistent>";
094:
095: String str = "ID: " + id + "\n" + "PersonNum: "
096: + getPersonNum() + "\n" + "Lastname: " + getLastName()
097: + "\n" + "Firstname: " + getFirstName() + "\n"
098: + "Email: " + getEmailAddress() + "\n";
099: return str;
100: }
101: }
|