KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > jdo > cache > Key


1 /*
2  * Created on Jul 24, 2005
3  */

4 package com.nightlabs.ipanema.jdo.cache;
5
6 import java.util.Set JavaDoc;
7
8 import org.apache.log4j.Logger;
9
10 import com.nightlabs.jdo.ObjectID;
11
12 /**
13  * @author Marco Schulze - marco at nightlabs dot de
14  */

15 public class Key
16 {
17     private String JavaDoc scope;
18     private Object JavaDoc objectID;
19     private Set JavaDoc fetchGroups;
20
21     /**
22      * @param scope Can be <tt>null</tt> (the default) or a <tt>String</tt> specifying a different
23      * namespace (e.g. if the method with which the data has been fetched does some special
24      * manipulation with the object and it therefore differs even though the fetchGroups
25      * are the same as with the normal fetch-method).
26      * @param objectID A JDO object ID - must not be <tt>null</tt>. Note, that you MUST NOT change
27      * the objectID after you called this constructor!
28      * @param fetchGroups Can be <tt>null</tt> or must be a <tt>Set</tt> of <tt>String</tt>.
29      * Note, that you MUST NOT change the set after you called this constructor!
30      */

31     public Key(String JavaDoc scope, Object JavaDoc objectID, Set JavaDoc fetchGroups)
32     {
33         this.scope = scope;
34
35         if (objectID == null)
36             throw new NullPointerException JavaDoc("objectID");
37
38         this.objectID = objectID;
39         if (!(objectID instanceof ObjectID)) {
40             Logger.getLogger(Key.class).warn(
41                     "objectID (class " + objectID.getClass().getName() + ") does not implement " + ObjectID.class.getName() + "!");
42         }
43
44         this.fetchGroups = fetchGroups;
45     }
46
47     private int _hashCode = 0;
48
49     /**
50      * @see java.lang.Object#hashCode()
51      */

52     public int hashCode()
53     {
54         if (_hashCode == 0) {
55             _hashCode =
56                 (scope == null ? 0 : scope.hashCode()) ^
57                 (objectID == null ? 0 : objectID.hashCode()) ^
58                 (fetchGroups == null ? 0 : fetchGroups.hashCode());
59         }
60
61         return _hashCode;
62     }
63
64     /**
65      * @see java.lang.Object#equals(java.lang.Object)
66      */

67     public boolean equals(Object JavaDoc obj)
68     {
69         if (obj == this)
70             return true;
71
72         if (obj.hashCode() != this.hashCode())
73             return false;
74
75         if (!(obj instanceof Key))
76             return false;
77
78         Key other = (Key)obj;
79
80         return
81                 (this.scope == null ? other.scope == null : this.scope.equals(other.scope))
82                 &&
83                 (this.objectID == null ? other.objectID == null : this.objectID.equals(other.objectID))
84                 &&
85                 (this.fetchGroups == null ? other.fetchGroups == null : this.fetchGroups.equals(other.fetchGroups));
86     }
87
88     private transient String JavaDoc thisString = null;
89
90     /**
91      * @see java.lang.Object#toString()
92      */

93     public String JavaDoc toString()
94     {
95         if (thisString == null) {
96             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
97             sb.append(this.getClass().getName());
98             sb.append('{');
99             sb.append("scope=");
100             sb.append(scope);
101             sb.append(';');
102             sb.append("objectID=");
103             sb.append(objectID);
104             sb.append(';');
105             sb.append("fetchGroups=");
106             sb.append(fetchGroups);
107             sb.append('}');
108             thisString = sb.toString();
109         }
110         return thisString;
111     }
112
113     /**
114      * Note, that you MUST NOT change the returned <tt>Set</tt>!
115      *
116      * @return Returns the fetchGroups.
117      */

118     public Set JavaDoc getFetchGroups()
119     {
120         return fetchGroups;
121     }
122     /**
123      * @return Returns the objectID.
124      */

125     public Object JavaDoc getObjectID()
126     {
127         return objectID;
128     }
129     /**
130      * @return Returns the scope.
131      */

132     public String JavaDoc getScope()
133     {
134         return scope;
135     }
136 }
137
Popular Tags