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 Parent.
026: */
027: public class ParentPK extends Object implements java.io.Serializable {
028: private int _hashCode = 0;
029: private StringBuffer _toStringValue = null;
030:
031: public Long id;
032: public String firstName;
033:
034: public ParentPK() {
035: }
036:
037: public ParentPK(Long id, String firstName) {
038: this .id = id;
039: this .firstName = firstName;
040: }
041:
042: public Long getId() {
043: return id;
044: }
045:
046: public String getFirstName() {
047: return firstName;
048: }
049:
050: public void setId(Long id) {
051: this .id = id;
052: _hashCode = 0;
053: }
054:
055: public void setFirstName(String firstName) {
056: this .firstName = firstName;
057: _hashCode = 0;
058: }
059:
060: public int hashCode() {
061: if (_hashCode == 0) {
062: if (this .id != null)
063: _hashCode += this .id.hashCode();
064: if (this .firstName != null)
065: _hashCode += this .firstName.hashCode();
066: }
067:
068: return _hashCode;
069: }
070:
071: public boolean equals(Object obj) {
072: if (!(obj instanceof ParentPK))
073: return false;
074:
075: ParentPK pk = (ParentPK) obj;
076: boolean eq = true;
077:
078: if (obj == null) {
079: eq = false;
080: } else {
081: if (this .id == null && ((ParentPK) obj).getId() == null) {
082: eq = true;
083: } else {
084: if (this .id == null || ((ParentPK) obj).getId() == null) {
085: eq = false;
086: } else {
087: eq = eq && this .id.equals(pk.id);
088: }
089: }
090: if (this .firstName == null
091: && ((ParentPK) obj).getFirstName() == null) {
092: eq = true;
093: } else {
094: if (this .firstName == null
095: || ((ParentPK) obj).getFirstName() == null) {
096: eq = false;
097: } else {
098: eq = eq && this .firstName.equals(pk.firstName);
099: }
100: }
101: }
102:
103: return eq;
104: }
105:
106: /** @return String representation of this pk in the form of [.field1.field2.field3]. */
107: public String toString() {
108: if (_toStringValue == null) {
109: _toStringValue = new StringBuffer("[.");
110: _toStringValue.append(this .id).append('.');
111: _toStringValue.append(this .firstName).append('.');
112: _toStringValue.append(']');
113: }
114:
115: return _toStringValue.toString();
116: }
117:
118: }
|