package modules.line;

import utils.*;
import simulator.*;
import modules.gradient.*;
import modules.node.*;
import modules.neighborset.*;
import java.util.*;

public class NodeAnchor implements LineAnchor {
  Object nid;
  public NodeAnchor(Object n) { nid=n; }

  // called on a processor, returns true if it's a part of the anchor
  public boolean member(PortedProcessor pp) {
    PersistentNodeB pn = (PersistentNodeB)pp.getModule("PersistentNode");
    NeighborSet ns = (NeighborSet)pp.getModule("NeighborSet");
    ActiveGradient ag = (ActiveGradient)pp.getModule("ActiveGradient");

    if(!pn.getNodes().contains(nid)) return false;
    Gradient g = ag.get(nid);
    if(g==null || g.getHopcount()>0) return false;
    return true;
  }

  public String toString() { return nid.toString(); }
  public boolean equals(Object o) { 
    if(o instanceof NodeAnchor)
      return nid.equals(((NodeAnchor)o).nid); 
    else return false;
  }
  public int hashCode() { return nid.hashCode(); }
}
