KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubis > beans > IDManagerPK


1 package edu.rice.rubis.beans;
2
3 /**
4  * IDManager Primary Key class
5  * We should have only one instance of the IDManager bean so the value
6  * of the primary key is 0.
7  * @author <a HREF="mailto:cecchet@rice.edu">Emmanuel Cecchet</a> and <a HREF="mailto:julie.marguerite@inrialpes.fr">Julie Marguerite</a>
8  * @version 1.0
9  */

10 public class IDManagerPK implements java.io.Serializable JavaDoc {
11   
12   public Integer JavaDoc id;
13
14   /**
15    * Creates a new <code>IDManagerPK</code> instance.
16    *
17    * @param uniqueId an <code>Integer</code> value
18    */

19   public IDManagerPK()
20   {
21     id = new Integer JavaDoc(0);
22   }
23
24   /**
25    * Creates a new <code>IDManagerPK</code> instance.
26    *
27    * @param uniqueId an <code>Integer</code> value
28    */

29   public IDManagerPK(Integer JavaDoc uniqueId)
30   {
31     id = uniqueId;
32   }
33
34   /**
35    * Specific <code>hashCode</code> just returning the id.
36    *
37    * @return the hash code
38    */

39   public int hashCode()
40   {
41     if (id == null)
42       return 0;
43     else
44       return id.intValue();
45   }
46   
47   /**
48    * Specific <code>equals</code> method.
49    *
50    * @param other the <code>Object</code> to compare with
51    * @return true if both objects have the same primary key
52    */

53   public boolean equals(Object JavaDoc other)
54   {
55     boolean isEqual = false;
56     if (other instanceof IDManagerPK)
57     {
58       if (id == null)
59         isEqual = (id == ((IDManagerPK)other).id);
60       else
61         isEqual = (id.intValue() == ((IDManagerPK)other).id.intValue());
62     }
63     return isEqual;
64   }
65
66 }
67
Popular Tags