package t234;
/**
* Represents the abstract state of a 2-3-4 tree.
* @since 11/13/01
* @author Dung X. Nguyen, Copyright 2001 - All Rights Reserved.
*/
abstract class ANode234 {
/**
* Checks the owner tree for emptiness.
EXERCISE: Remove this isEmpty method and rewrite the insertion algorithm
without checking for emptiness.
*/
abstract boolean isEmpty (Tree234 owner);
/**
* Inserts an Integer into the owner without duplication.
* @param owner the owner of this ANode234.
* @param n != null Integer object to be inserted.
*/
abstract void insert (Tree234 owner, Integer n);
/**
* Help insert an Integer into the owner, reconnecting the owner's parent
* subtrees if needed.
* Called from insert.
* @param ownerPo the parent tree of the owner tree.
* @param owner the owner of this ANode234.
* @param n != null Integer object to be inserted.
*/
abstract void insertHelper (Tree234 ownerPo, Tree234 owner, Integer n);
/**
* Adds a data element with its left and right subtrees to this ANode234
* and re-attaches it to the owner tree.
* @param owner the owner of this ANode234.
* @param lTree a Tree234 whose elmements are less than n.
* @param n != null Integer object to be inserted.
* @param rTree a Tree234 whose elements are greater than n.
*/
abstract void attach (Tree234 owner, Tree234 lTree, Integer n, Tree234 rTree);
/**
* Draws the root and subtrees at a given level >= 0.
*/
abstract void drawRootAndSubtrees(int level);
/**
* Template method pattern: Invariant behavior.
*/
final void drawAtLevel (int level) {
drawSpaces(level);
drawRootAndSubtrees(level);
}
/**
* Invariant behavior
*/
final void drawSpaces (int n) {
for (int i = 0; i < n; i++) {
System.out.print (" ");
}
}
}