/* ***************************************************************************** * File Name: LeafNode.java * Purpose: class representing a leaf in b+-tree * Authors: Han Don, Jeff Xing, Carol Cheung * Version: 1 * Last Date Updated: Feb. 27, 2001 ****************************************************************************/ /** * LeafNode holds a piece of string in a character * array, and a pointer to its younger sibling. * It provides the services that the the BTreeString requires. */ public class LeafNode { /** * The maximum length of string that I can hold. */ public final static int SMALL_STRING_LENGTH = 4096; /** * Pointer to my younger sibling. */ private LeafNode nextNode; /** * The char array in which I holds a piece of string. */ private char [] elements; /** * My key. */ private long key; /** * Construct a new leaf. * precondition: value.length <= SMALL_STRING_LENGTH. */ public LeafNode(char [] value, long k) { elements = value; nextNode = null; key = k; } /** * Return my younger sibling. */ public LeafNode getNext() { return nextNode; } /** * Link me and my younger sibling. */ public void setNext(LeafNode theNext){ nextNode = theNext; } /** * Return the character of the char array at index i. * Precondition: 0<= i < SMALL_STRING_LENGTH */ public char getElementAt(int i) { return elements[i]; } /** * Return a new string representing the value of elements. */ public String toString() { return (new String(elements)); } /** * Return a new string representing the value of elements * between the 'begin' and 'end' indice. * precondition: 0 <= begin <= end <= elements.length */ public String stringBetween(int begin, int end) { if(begin == end) return ""; else return (new String(elements, begin, end - begin)); } }