package binaryTree.visitor; import binaryTree.*; import ordering.*; public class BSTFinder implements IVisitor { /** @SBGen Singleton Variable */ public final static BSTFinder Singleton = new BSTFinder (); /** @SBGen Constructor */ private BSTFinder() { } /** * Returns null. * @param host satisfies Binary Search Tree Property (BSTP). * @param input an IOrdered. */ public Object emptyCase(BiTree host, Object input) { return null; } /** * Returns the object associated with the input key if host has it, otherwise returns null. * @param host satisfies BSTP. * @param input an IOrdered. * @return */ public Object nonEmptyCase(BiTree host, Object input) { IOrdered root = (IOrdered)host.getRootDat(); IOrdered inp = (IOrdered)input; int inpCompRoot = inp.compare (root); return inpCompRoot == IOrdered.LESS? host.getLeftSubTree().execute(this, input): inpCompRoot == IOrdered.GREATER? host.getRightSubTree().execute (this, input): root; } }