package brs.visitor; import brs.*; import utils.fp.*; public class InOrder implements IVisitor { /** * Object -> (Object -> (Object -> Object)) */ private ILambda _combine; public InOrder(ILambda process) { _combine = process; } /** * @param inp an ILambda to process the data Objects in host. * inp.apply(null) must be defined. */ public Object emptyCase(BiTree host, Object inp) { return ((ILambda)inp).apply(null); } /** * Processes the left subtree, the root and the right subtree. Combines the * results. See S02 code for BSTDictionary for an example of printing the * the tree in order by usign a lambda that concatenates the 3 results. * @param inp an ILambda to process the data Objects in host. * inp.apply(null) must be defined. */ public Object nonEmptyCase(BiTree host, Object inp) { ILambda f = (ILambda)inp; return ((ILambda)((ILambda)_combine.apply( host.getLeftSubTree().execute(this, inp))).apply( f.apply(host.getRootDat()))).apply( host.getRightSubTree().execute(this, inp)); } }