package t234; /** * Represents the empty state of a 2-3-4 tree. EmptyNode is an example of the * Null object pattern.
Since there is conceptually only one empty state for all the 2-3-4 trees,
EmptyNode is implemented with the Singleton pattern.
* @since 11/13/01 * @author Dung X. Nguyen, Copyright 2001 - All Rights Reserved. */ class EmptyNode extends ANode234 { final public static EmptyNode Singleton = new EmptyNode (); private EmptyNode (){ } final boolean isEmpty (Tree234 owner) { return true; } /** * Inserts an Integer into the owner tree without duplication. * This is the EmptyNode: just asks the owner to change its state to a Node2. * @param n * @param owner the owner of this EmptyNode. */ final void insert (Tree234 owner, Integer n) { owner.changeRoot (new Node2 (n)); } final void insertHelper (Tree234 ownerPo, Tree234 owner, Integer n) { owner.insert (n); // can call insert (owner, n) instead. } /** * @throw IllegalStateException ("Empty tree cannot be a parent!"). */ final void attach (Tree234 owner, Tree234 lTree, Integer n, Tree234 rTree) { throw new IllegalStateException ("Empty tree cannot be a parent!"); } final void drawRootAndSubtrees (int level) { System.out.print ("{}"); } }