KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * IndexKey.java
3  *
4  * Created on 09 May 2003, 15:07
5  */

6
7 package com.jofti.btree;
8
9 /**
10  *
11  * An entry for the internal node structures.<p>
12  *
13  * @author Steve Woodcock<br>
14  * @version 1.0<br>
15  */

16 class IndexNodeEntry implements NodeEntry {
17     
18     /**
19      *
20      */

21     private static final long serialVersionUID = 6905415196213618087L;
22     
23     private Node childNode = null;
24     private Node containingNode = null;
25     Comparable JavaDoc value=null;
26     
27     private volatile int hashCode =0;
28     
29     
30     /** Creates a new instance of IndexNodeEntry */
31     IndexNodeEntry() {
32     }
33     
34
35     
36    void updateValue(){
37         this.value = childNode.getRightValue();
38    }
39    
40     
41     /** Getter for property childNode.
42      * @return Value of property childNode.
43      *
44      */

45     Node getChildNode() {
46         return childNode;
47     }
48     
49     /** Setter for property childNode.
50      * @param childNode New value of property childNode.
51      *
52      */

53     void setChildNode(Node childNode) {
54         this.childNode = childNode;
55     }
56     
57     
58     /** Getter for property containingNode.
59      * @return Value of property containingNode.
60      *
61      */

62     Node getContainingNode() {
63         return containingNode;
64     }
65     
66     /** Setter for property containingNode.
67      * @param containingNode New value of property containingNode.
68      *
69      */

70     void setContainingNode(Node containingNode) {
71         this.containingNode = containingNode;
72     }
73     
74     /** Compares this object with the specified object for order. Returns a
75      * negative integer, zero, or a positive integer as this object is less
76      * than, equal to, or greater than the specified object.<p>
77      *
78      * In the foregoing description, the notation
79      * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
80      * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
81      * <tt>0</tt>, or <tt>1</tt> according to whether the value of <i>expression</i>
82      * is negative, zero or positive.
83      *
84      * The implementor must ensure <tt>sgn(x.compareTo(y)) ==
85      * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
86      * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
87      * <tt>y.compareTo(x)</tt> throws an exception.)<p>
88      *
89      * The implementor must also ensure that the relation is transitive:
90      * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
91      * <tt>x.compareTo(z)&gt;0</tt>.<p>
92      *
93      * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
94      * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
95      * all <tt>z</tt>.<p>
96      *
97      * It is strongly recommended, but <i>not</i> strictly required that
98      * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
99      * class that implements the <tt>Comparable</tt> interface and violates
100      * this condition should clearly indicate this fact. The recommended
101      * language is "Note: this class has a natural ordering that is
102      * inconsistent with equals."
103      *
104      * @param o the Object to be compared.
105      * @return a negative integer, zero, or a positive integer as this object
106      * is less than, equal to, or greater than the specified object.
107      *
108      * @throws ClassCastException if the specified object's type prevents it
109      * from being compared to this Object.
110      *
111      */

112     public int compareTo(Object JavaDoc o)
113     {
114
115         return value.compareTo(((IndexNodeEntry)o).value);
116
117     }
118     
119     /* (non-Javadoc)
120      * @see java.lang.Object#equals(java.lang.Object)
121      */

122     public boolean equals(Object JavaDoc o)
123     {
124         if (o instanceof IndexNodeEntry)
125         {
126              return compareTo((IndexNodeEntry)o) == 0;
127         } else {
128             return false;
129         }
130     }
131  
132     
133     /* (non-Javadoc)
134      * @see java.lang.Object#hashCode()
135      */

136     public int hashCode(){
137         if (hashCode ==0){
138             int result = 17;
139             result = 37*result + value.hashCode();
140             hashCode = result;
141         }
142         return hashCode;
143     }
144     
145     /* (non-Javadoc)
146      * @see java.lang.Object#toString()
147      */

148     public String JavaDoc toString() {
149         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
150         buf.append(" Value:" + value);
151         buf.append(" ChildNode:" + childNode);
152         return buf.toString();
153     }
154
155
156
157
158
159
160
161     /* (non-Javadoc)
162      * @see com.jofti.btree.NodeEntry#getValue()
163      */

164     public Comparable JavaDoc getValue()
165     {
166         return value;
167     }
168
169
170
171
172
173
174
175     /* (non-Javadoc)
176      * @see com.jofti.btree.NodeEntry#setValue(java.lang.Comparable)
177      */

178     public void setValue(Comparable JavaDoc value)
179     {
180         this.value = value;
181         
182     }
183     
184 }
185
Popular Tags