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 Group.
026: */
027: public class GroupPK 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 long groupNumber;
034:
035: public GroupPK() {
036: }
037:
038: public GroupPK(String departmentCode, String departmentCode2,
039: long groupNumber) {
040: this .departmentCode = departmentCode;
041: this .departmentCode2 = departmentCode2;
042: this .groupNumber = groupNumber;
043: }
044:
045: public String getDepartmentCode() {
046: return departmentCode;
047: }
048:
049: public String getDepartmentCode2() {
050: return departmentCode2;
051: }
052:
053: public long getGroupNumber() {
054: return groupNumber;
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 setGroupNumber(long groupNumber) {
068: this .groupNumber = groupNumber;
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: _hashCode += (int) this .groupNumber;
079: }
080:
081: return _hashCode;
082: }
083:
084: public boolean equals(Object obj) {
085: if (!(obj instanceof GroupPK))
086: return false;
087:
088: GroupPK pk = (GroupPK) obj;
089: boolean eq = true;
090:
091: if (obj == null) {
092: eq = false;
093: } else {
094: if (this .departmentCode == null
095: && ((GroupPK) obj).getDepartmentCode() == null) {
096: eq = true;
097: } else {
098: if (this .departmentCode == null
099: || ((GroupPK) obj).getDepartmentCode() == null) {
100: eq = false;
101: } else {
102: eq = eq
103: && this .departmentCode
104: .equals(pk.departmentCode);
105: }
106: }
107: if (this .departmentCode2 == null
108: && ((GroupPK) obj).getDepartmentCode2() == null) {
109: eq = true;
110: } else {
111: if (this .departmentCode2 == null
112: || ((GroupPK) obj).getDepartmentCode2() == null) {
113: eq = false;
114: } else {
115: eq = eq
116: && this .departmentCode2
117: .equals(pk.departmentCode2);
118: }
119: }
120: eq = eq && this .groupNumber == pk.groupNumber;
121: }
122:
123: return eq;
124: }
125:
126: /** @return String representation of this pk in the form of [.field1.field2.field3]. */
127: public String toString() {
128: if (_toStringValue == null) {
129: _toStringValue = new StringBuffer("[.");
130: _toStringValue.append(this .departmentCode).append('.');
131: _toStringValue.append(this .departmentCode2).append('.');
132: _toStringValue.append(this .groupNumber).append('.');
133: _toStringValue.append(']');
134: }
135:
136: return _toStringValue.toString();
137: }
138:
139: }
|