package commons.graph.model;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
 * A list of nodes. Nodes are unique.
 * @author ks
 */
public class Nodes
{

Map<String, Node> data = new HashMap<String, Node>();

public void clear ()
{
   data.clear();
}

public boolean contain (String label)
{
   return data.containsKey(label);
}

public boolean contain (Node node)
{
   return data.containsKey(node.label);
}

public Node getNode (String label)
{
   return data.get(label);
}

public Iterator<Node> nodeIterator ()
{
   final Iterator<String> iter = labelIterator();
   return new Iterator<Node>()
   {

      public boolean hasNext ()
      {
         return iter.hasNext();
      }

      public Node next ()
      {
         return data.get(iter.next());
      }

      public void remove ()
      {}
   };
}

public Iterator<String> labelIterator ()
{
   final Iterator<String> iter = data.keySet().iterator();
   return new Iterator<String>()
   {
      public boolean hasNext ()
      {
         return iter.hasNext();
      }

      public String next ()
      {
         return iter.next();
      }

      public void remove ()
      {}
   };
}

public void add (Node node)
{
   data.put(node.label, node);
}

public int size ()
{
   return data.size();
}
}
