
/**
 * sizeVisitor.java
 *
 *
 * Created: Tue Oct 15 22:12:08 2002
 *
 * @author <a href="mailto:bina@cse.buffalo.edu "</a>
 * @version
 */

public class SBSizeVisitor implements SBVisitor{
   // default constructor is automatically available
   
   public Object operationOnEmpty(Object obt, Object inp)
   {  
          return (new Integer(0));
   }
    
   public Object operationOnNonEmpty(Object obt, Object inp)
   {
      SBTree bt = (SBTree)obt;

       // I don't have to do the empty case since it will be polymorphically
      // dispatched to the empty case; don't have to do the leaf case
      // since we have null object instead of nullpointer

       // recursive step for left and right subtrees
      Integer lSize = (Integer)(bt.getLeft().acceptVisitor(this, null));
      Integer rSize = (Integer)(bt.getRight().acceptVisitor(this,null));
      
      return new Integer( lSize.intValue() + rSize.intValue());
   }
}// sizeVisitor
