001: /*
002: * IndexKey.java
003: *
004: * Created on 09 May 2003, 15:07
005: */
006:
007: package com.jofti.btree;
008:
009: /**
010: *
011: * An entry for the internal node structures.<p>
012: *
013: * @author Steve Woodcock<br>
014: * @version 1.0<br>
015: */
016: class IndexNodeEntry implements NodeEntry {
017:
018: /**
019: *
020: */
021: private static final long serialVersionUID = 6905415196213618087L;
022:
023: private Node childNode = null;
024: private Node containingNode = null;
025: Comparable value = null;
026:
027: private volatile int hashCode = 0;
028:
029: /** Creates a new instance of IndexNodeEntry */
030: IndexNodeEntry() {
031: }
032:
033: void updateValue() {
034: this .value = childNode.getRightValue();
035: }
036:
037: /** Getter for property childNode.
038: * @return Value of property childNode.
039: *
040: */
041: Node getChildNode() {
042: return childNode;
043: }
044:
045: /** Setter for property childNode.
046: * @param childNode New value of property childNode.
047: *
048: */
049: void setChildNode(Node childNode) {
050: this .childNode = childNode;
051: }
052:
053: /** Getter for property containingNode.
054: * @return Value of property containingNode.
055: *
056: */
057: Node getContainingNode() {
058: return containingNode;
059: }
060:
061: /** Setter for property containingNode.
062: * @param containingNode New value of property containingNode.
063: *
064: */
065: void setContainingNode(Node containingNode) {
066: this .containingNode = containingNode;
067: }
068:
069: /** Compares this object with the specified object for order. Returns a
070: * negative integer, zero, or a positive integer as this object is less
071: * than, equal to, or greater than the specified object.<p>
072: *
073: * In the foregoing description, the notation
074: * <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
075: * <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
076: * <tt>0</tt>, or <tt>1</tt> according to whether the value of <i>expression</i>
077: * is negative, zero or positive.
078: *
079: * The implementor must ensure <tt>sgn(x.compareTo(y)) ==
080: * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
081: * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
082: * <tt>y.compareTo(x)</tt> throws an exception.)<p>
083: *
084: * The implementor must also ensure that the relation is transitive:
085: * <tt>(x.compareTo(y)>0 && y.compareTo(z)>0)</tt> implies
086: * <tt>x.compareTo(z)>0</tt>.<p>
087: *
088: * Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
089: * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
090: * all <tt>z</tt>.<p>
091: *
092: * It is strongly recommended, but <i>not</i> strictly required that
093: * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
094: * class that implements the <tt>Comparable</tt> interface and violates
095: * this condition should clearly indicate this fact. The recommended
096: * language is "Note: this class has a natural ordering that is
097: * inconsistent with equals."
098: *
099: * @param o the Object to be compared.
100: * @return a negative integer, zero, or a positive integer as this object
101: * is less than, equal to, or greater than the specified object.
102: *
103: * @throws ClassCastException if the specified object's type prevents it
104: * from being compared to this Object.
105: *
106: */
107: public int compareTo(Object o) {
108:
109: return value.compareTo(((IndexNodeEntry) o).value);
110:
111: }
112:
113: /* (non-Javadoc)
114: * @see java.lang.Object#equals(java.lang.Object)
115: */
116: public boolean equals(Object o) {
117: if (o instanceof IndexNodeEntry) {
118: return compareTo((IndexNodeEntry) o) == 0;
119: } else {
120: return false;
121: }
122: }
123:
124: /* (non-Javadoc)
125: * @see java.lang.Object#hashCode()
126: */
127: public int hashCode() {
128: if (hashCode == 0) {
129: int result = 17;
130: result = 37 * result + value.hashCode();
131: hashCode = result;
132: }
133: return hashCode;
134: }
135:
136: /* (non-Javadoc)
137: * @see java.lang.Object#toString()
138: */
139: public String toString() {
140: StringBuffer buf = new StringBuffer();
141: buf.append(" Value:" + value);
142: buf.append(" ChildNode:" + childNode);
143: return buf.toString();
144: }
145:
146: /* (non-Javadoc)
147: * @see com.jofti.btree.NodeEntry#getValue()
148: */
149: public Comparable getValue() {
150: return value;
151: }
152:
153: /* (non-Javadoc)
154: * @see com.jofti.btree.NodeEntry#setValue(java.lang.Comparable)
155: */
156: public void setValue(Comparable value) {
157: this.value = value;
158:
159: }
160:
161: }
|