package modules.broadcast;

import simulator.*;

// the areaquery counts each node as 1 and returns the total
public class AreaQuery implements ConvergeCast {
  int area=1;

  public Integer getArea() { return new Integer(area); }
  public void addToArea(Object input) {
    if(input instanceof Number) {
      area+=((Number)input).intValue();
    }
  }

  // interface functions
  public Object getLeafValue(PortedProcessor pp) { return getArea(); }
  public Object deliverLeaf(PortedProcessor pp) { return getArea(); }
  public Object getBranchValue(PortedProcessor pp) { return getArea(); }
  public Object deliverBranch(PortedProcessor pp) { return getArea(); }
  public Object deliverRoot(PortedProcessor pp) { return getArea(); }

  public void putBranchValue(PortedProcessor pp, Object input) 
  { addToArea(input); }
  public void putRootValue(PortedProcessor pp, Object input)
  { addToArea(input); }

  public Object fail(PortedProcessor pp) { return null; }

  public ConvergeCast getChild() { return new AreaQuery(); }
  public String toString() { return "Area="+area; }
}
