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.cmp2.fkmapping.ejb;
023:
024: /**
025: * Primary key for Student.
026: */
027: public class StudentPK extends Object implements java.io.Serializable {
028: private int _hashCode = 0;
029: private StringBuffer _toStringValue = null;
030:
031: public String departmentCode;
032: public String departmentCode2;
033: public String lastName;
034:
035: public StudentPK() {
036: }
037:
038: public StudentPK(String departmentCode, String departmentCode2,
039: String lastName) {
040: this .departmentCode = departmentCode;
041: this .departmentCode2 = departmentCode2;
042: this .lastName = lastName;
043: }
044:
045: public String getDepartmentCode() {
046: return departmentCode;
047: }
048:
049: public String getDepartmentCode2() {
050: return departmentCode2;
051: }
052:
053: public String getLastName() {
054: return lastName;
055: }
056:
057: public void setDepartmentCode(String departmentCode) {
058: this .departmentCode = departmentCode;
059: _hashCode = 0;
060: }
061:
062: public void setDepartmentCode2(String departmentCode2) {
063: this .departmentCode2 = departmentCode2;
064: _hashCode = 0;
065: }
066:
067: public void setLastName(String lastName) {
068: this .lastName = lastName;
069: _hashCode = 0;
070: }
071:
072: public int hashCode() {
073: if (_hashCode == 0) {
074: if (this .departmentCode != null)
075: _hashCode += this .departmentCode.hashCode();
076: if (this .departmentCode2 != null)
077: _hashCode += this .departmentCode2.hashCode();
078: if (this .lastName != null)
079: _hashCode += this .lastName.hashCode();
080: }
081:
082: return _hashCode;
083: }
084:
085: public boolean equals(Object obj) {
086: if (!(obj instanceof StudentPK))
087: return false;
088:
089: StudentPK pk = (StudentPK) obj;
090: boolean eq = true;
091:
092: if (obj == null) {
093: eq = false;
094: } else {
095: if (this .departmentCode == null
096: && ((StudentPK) obj).getDepartmentCode() == null) {
097: eq = true;
098: } else {
099: if (this .departmentCode == null
100: || ((StudentPK) obj).getDepartmentCode() == null) {
101: eq = false;
102: } else {
103: eq = eq
104: && this .departmentCode
105: .equals(pk.departmentCode);
106: }
107: }
108: if (this .departmentCode2 == null
109: && ((StudentPK) obj).getDepartmentCode2() == null) {
110: eq = true;
111: } else {
112: if (this .departmentCode2 == null
113: || ((StudentPK) obj).getDepartmentCode2() == null) {
114: eq = false;
115: } else {
116: eq = eq
117: && this .departmentCode2
118: .equals(pk.departmentCode2);
119: }
120: }
121: if (this .lastName == null
122: && ((StudentPK) obj).getLastName() == null) {
123: eq = true;
124: } else {
125: if (this .lastName == null
126: || ((StudentPK) obj).getLastName() == null) {
127: eq = false;
128: } else {
129: eq = eq && this .lastName.equals(pk.lastName);
130: }
131: }
132: }
133:
134: return eq;
135: }
136:
137: /** @return String representation of this pk in the form of [.field1.field2.field3]. */
138: public String toString() {
139: if (_toStringValue == null) {
140: _toStringValue = new StringBuffer("[.");
141: _toStringValue.append(this .departmentCode).append('.');
142: _toStringValue.append(this .departmentCode2).append('.');
143: _toStringValue.append(this .lastName).append('.');
144: _toStringValue.append(']');
145: }
146:
147: return _toStringValue.toString();
148: }
149:
150: }
|