KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > jbas1361 > BPK


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.jbas1361;
23
24 public class BPK
25    extends Object JavaDoc
26    implements java.io.Serializable JavaDoc
27 {
28    private int _hashCode = 0;
29    private StringBuffer JavaDoc _toStringValue = null;
30
31    public Integer JavaDoc id;
32    public String JavaDoc name;
33
34    public BPK()
35    {
36    }
37
38    public BPK( Integer JavaDoc id,String JavaDoc name )
39    {
40       this.id = id;
41       this.name = name;
42    }
43
44    public Integer JavaDoc getId()
45    {
46       return id;
47    }
48    public String JavaDoc getName()
49    {
50       return name;
51    }
52
53    public void setId(Integer JavaDoc id)
54    {
55       this.id = id;
56       _hashCode = 0;
57    }
58    public void setName(String JavaDoc name)
59    {
60       this.name = name;
61       _hashCode = 0;
62    }
63
64    public int hashCode()
65    {
66       if( _hashCode == 0 )
67       {
68          if (this.id != null) _hashCode += this.id.hashCode();
69          if (this.name != null) _hashCode += this.name.hashCode();
70       }
71
72       return _hashCode;
73    }
74
75    public boolean equals(Object JavaDoc obj)
76    {
77       if( !(obj instanceof org.jboss.test.cmp2.jbas1361.BPK) )
78          return false;
79
80       org.jboss.test.cmp2.jbas1361.BPK pk = (org.jboss.test.cmp2.jbas1361.BPK)obj;
81       boolean eq = true;
82
83       if( obj == null )
84       {
85          eq = false;
86       }
87       else
88       {
89          if( this.id == null && ((org.jboss.test.cmp2.jbas1361.BPK)obj).getId() == null )
90          {
91             eq = true;
92          }
93          else
94          {
95             if( this.id == null || ((org.jboss.test.cmp2.jbas1361.BPK)obj).getId() == null )
96             {
97                eq = false;
98             }
99             else
100             {
101                eq = eq && this.id.equals( pk.id );
102             }
103          }
104          if( this.name == null && ((org.jboss.test.cmp2.jbas1361.BPK)obj).getName() == null )
105          {
106             eq = true;
107          }
108          else
109          {
110             if( this.name == null || ((org.jboss.test.cmp2.jbas1361.BPK)obj).getName() == null )
111             {
112                eq = false;
113             }
114             else
115             {
116                eq = eq && this.name.equals( pk.name );
117             }
118          }
119       }
120
121       return eq;
122    }
123
124    /** @return String representation of this pk in the form of [.field1.field2.field3]. */
125    public String JavaDoc toString()
126    {
127       if( _toStringValue == null )
128       {
129          _toStringValue = new StringBuffer JavaDoc("[.");
130          _toStringValue.append(this.id).append('.');
131          _toStringValue.append(this.name).append('.');
132          _toStringValue.append(']');
133       }
134
135       return _toStringValue.toString();
136    }
137 }
138
Popular Tags