001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.entity.interfaces;
023:
024: /**
025: * Value object for TestEntity.
026: *
027: */
028: public class TestEntityValue extends Object implements
029: java.io.Serializable {
030: private String entityID;
031: private boolean entityIDHasBeenSet = false;
032: private String value1;
033: private boolean value1HasBeenSet = false;
034:
035: private String pk;
036:
037: public TestEntityValue() {
038: }
039:
040: public TestEntityValue(String entityID, String value1) {
041: this .entityID = entityID;
042: entityIDHasBeenSet = true;
043: this .value1 = value1;
044: value1HasBeenSet = true;
045: pk = this .getEntityID();
046: }
047:
048: //TODO Cloneable is better than this !
049: public TestEntityValue(TestEntityValue otherValue) {
050: this .entityID = otherValue.entityID;
051: entityIDHasBeenSet = true;
052: this .value1 = otherValue.value1;
053: value1HasBeenSet = true;
054:
055: pk = this .getEntityID();
056: }
057:
058: public String getPrimaryKey() {
059: return pk;
060: }
061:
062: public void setPrimaryKey(String pk) {
063: // it's also nice to update PK object - just in case
064: // somebody would ask for it later...
065: this .pk = pk;
066: setEntityID(pk);
067: }
068:
069: public String getEntityID() {
070: return this .entityID;
071: }
072:
073: public void setEntityID(String entityID) {
074: this .entityID = entityID;
075: entityIDHasBeenSet = true;
076:
077: pk = entityID;
078: }
079:
080: public boolean entityIDHasBeenSet() {
081: return entityIDHasBeenSet;
082: }
083:
084: public String getValue1() {
085: return this .value1;
086: }
087:
088: public void setValue1(String value1) {
089: this .value1 = value1;
090: value1HasBeenSet = true;
091:
092: }
093:
094: public boolean value1HasBeenSet() {
095: return value1HasBeenSet;
096: }
097:
098: public String toString() {
099: StringBuffer str = new StringBuffer("{");
100:
101: str.append("entityID=" + getEntityID() + " " + "value1="
102: + getValue1());
103: str.append('}');
104:
105: return (str.toString());
106: }
107:
108: /**
109: * A Value Object has an identity if the attributes making its Primary Key have all been set. An object without identity is never equal to any other object.
110: *
111: * @return true if this instance has an identity.
112: */
113: protected boolean hasIdentity() {
114: return entityIDHasBeenSet;
115: }
116:
117: public boolean equals(Object other) {
118: if (this == other)
119: return true;
120: if (!hasIdentity())
121: return false;
122: if (other instanceof TestEntityValue) {
123: TestEntityValue that = (TestEntityValue) other;
124: if (!that.hasIdentity())
125: return false;
126: boolean lEquals = true;
127:
128: lEquals = lEquals && isIdentical(that);
129:
130: return lEquals;
131: } else {
132: return false;
133: }
134: }
135:
136: public boolean isIdentical(Object other) {
137: if (other instanceof TestEntityValue) {
138: TestEntityValue that = (TestEntityValue) other;
139: boolean lEquals = true;
140: if (this .entityID == null) {
141: lEquals = lEquals && (that.entityID == null);
142: } else {
143: lEquals = lEquals
144: && this .entityID.equals(that.entityID);
145: }
146: if (this .value1 == null) {
147: lEquals = lEquals && (that.value1 == null);
148: } else {
149: lEquals = lEquals && this .value1.equals(that.value1);
150: }
151:
152: return lEquals;
153: } else {
154: return false;
155: }
156: }
157:
158: public int hashCode() {
159: int result = 17;
160: result = 37
161: * result
162: + ((this .entityID != null) ? this .entityID.hashCode()
163: : 0);
164:
165: result = 37 * result
166: + ((this .value1 != null) ? this .value1.hashCode() : 0);
167:
168: return result;
169: }
170:
171: }
|