KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > btree > LeafNodeEntry


1 /*
2  * NodeEntry.java
3  *
4  * Created on 25 May 2003, 09:36
5  */

6
7 package com.jofti.btree;
8
9
10
11 import java.util.Set JavaDoc;
12
13 import com.jofti.util.FastSet;
14
15
16
17 /**
18  * The leaf node entry contains a value, qand a set of uniqueIds that are the ids passed into the node for that value. <br>
19  * Adding a new id,value pair will result in the id being added to the set and the value remaining unchanged.<p>
20  *
21  *
22  * @author Steve Woodcock
23  * @version 1.14<br>
24  */

25 public class LeafNodeEntry implements NodeEntry{
26     
27     
28     /**
29      *
30      */

31     private static final long serialVersionUID = -181573341072167495L;
32
33     public Set JavaDoc uniqueIdSet = null;
34     
35     public Comparable JavaDoc value = null;
36     
37     protected volatile int hashCode =0;
38     
39     /** Creates a new instance of NodeEntry */
40     public LeafNodeEntry() {
41     }
42     
43     public LeafNodeEntry(Object JavaDoc uniqueId, Comparable JavaDoc value){
44         uniqueIdSet = new FastSet();
45         uniqueIdSet.add(uniqueId);
46         this.value =value;
47     }
48     
49     /** Getter for property uniqueIdList.
50      * @return Value of property uniqueIdList.
51      *
52      */

53     Set JavaDoc getUniqueIdSet() {
54         if (uniqueIdSet == null){
55             return new FastSet();
56         }
57         return uniqueIdSet;
58     }
59     
60     /**
61      * Return the size of the Set.
62      * @return
63      */

64     public int getUniqueIdSize(){
65         if (uniqueIdSet == null){
66             return 0;
67         }
68             return uniqueIdSet.size();
69     }
70     
71     /** Setter for property uniqueIdList.
72      * @param uniqueIdList New value of property uniqueIdList.
73      *
74      */

75     void setUniqueIdSet(Set JavaDoc uniqueIdList) {
76         if (uniqueIdSet == null){
77             uniqueIdSet = new FastSet();
78         }
79         this.uniqueIdSet.clear();
80         this.uniqueIdSet.addAll(uniqueIdList);
81     }
82     
83     
84     /**
85      * Adds an object to the existing Set.
86      * @param uniqueId
87      */

88     public void addUniqueId(Object JavaDoc uniqueId) {
89         if (uniqueIdSet == null){
90             uniqueIdSet = new FastSet();
91         }
92         uniqueIdSet.add(uniqueId);
93     }
94     
95      /**
96       * Adds the elements of a set to the existing set.
97      * @param uniqueIdList
98      */

99     void addUniqueIdSet(Set JavaDoc uniqueIdList) {
100         this.uniqueIdSet.addAll(uniqueIdList);
101     }
102     
103     void removeUniqueId(Object JavaDoc Id) {
104         if (uniqueIdSet == null){
105             return;
106         }
107         uniqueIdSet.remove(Id);
108     }
109     
110     void removeAllIds(Set JavaDoc idSet){
111         if (uniqueIdSet == null){
112             return;
113         }
114         uniqueIdSet.removeAll(idSet);
115     }
116     /** Getter for property value.
117      * @return Value of property value.
118      *
119      */

120     public Comparable JavaDoc getValue() {
121         return value;
122     }
123     
124     /** Setter for property value.
125      * @param value New value of property value.
126      *
127      */

128     
129     public void setValue(Comparable JavaDoc value) {
130         this.value = value;
131     }
132     
133     public String JavaDoc toString(){
134         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
135         buf.append("value:"+value);
136         buf.append(",");
137         buf.append("uniqueIds:" +uniqueIdSet);
138         
139         return buf.toString();
140     }
141     
142     /** Compares this object with the specified object for order. Returns a
143      * negative integer, zero, or a positive integer as this object is less
144      * than, equal to, or greater than the specified object.<p>
145      *
146      * In the foregoing description, the notation
147      * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
148      * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
149      * <tt>0</tt>, or <tt>1</tt> according to whether the value of <i>expression</i>
150      * is negative, zero or positive.
151      *
152      * The implementor must ensure <tt>sgn(x.compareTo(y)) ==
153      * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
154      * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
155      * <tt>y.compareTo(x)</tt> throws an exception.)<p>
156      *
157      * The implementor must also ensure that the relation is transitive:
158      * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
159      * <tt>x.compareTo(z)&gt;0</tt>.<p>
160      *
161      * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
162      * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
163      * all <tt>z</tt>.<p>
164      *
165      * It is strongly recommended, but <i>not</i> strictly required that
166      * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
167      * class that implements the <tt>Comparable</tt> interface and violates
168      * this condition should clearly indicate this fact. The recommended
169      * language is "Note: this class has a natural ordering that is
170      * inconsistent with equals."
171      *
172      * @param o the Object to be compared.
173      * @return a negative integer, zero, or a positive integer as this object
174      * is less than, equal to, or greater than the specified object.
175      *
176      * @throws ClassCastException if the specified object's type prevents it
177      * from being compared to this Object.
178      *
179      */

180     public int compareTo(Object JavaDoc o) {
181
182         if (o instanceof LeafNodeEntry)
183         {
184             return value.compareTo(((LeafNodeEntry)o).value);
185         }
186         throw new IllegalArgumentException JavaDoc("Cannot compare with a non leafnode");
187         
188     }
189     
190     /* (non-Javadoc)
191      * @see java.lang.Object#equals(java.lang.Object)
192      */

193     public boolean equals(Object JavaDoc o) {
194
195         if (o instanceof LeafNodeEntry)
196         {
197             return value.compareTo(((LeafNodeEntry)o).value) == 0;
198         } else {
199             return false;
200         }
201     }
202     
203     /* (non-Javadoc)
204      * @see java.lang.Object#hashCode()
205      */

206     public int hashCode(){
207         if (hashCode ==0){
208             int result = 17;
209             result = 37*result + value.hashCode();
210             hashCode = result;
211         }
212         return hashCode;
213     }
214
215     
216 }
217
Popular Tags