Universität Paderborn - Home Universität Paderborn
Die Universität der Informationsgesellschaft

Parallel Programming WS 2014/2015 - File Node.java

import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

public class Node
{
   private int id;            // unique number of this node
   private int value;         // the value stored at this node
   private Channel input;     // the input port of this node
   private Set<Node> neighbours;    // nodes adjacent to this node
   
   // construct a node with given id number and value
   public Node (int id, int value)
   {
      this.id = id; this.value = value;
      this.input = new Channel();
      this.neighbours = new HashSet<Node>();
   }
   
   // get the numeric unique id of this node
   public int getNodeID ()
   { return id; }

   // get the input port of this node
   public Channel getInputChannel ()
   { return input; }

   // how many neighbours does this node have?
   public int getNumberOfNeighbours ()
   { return neighbours.size(); }

   // iterate over all nodes adjacent to this node
   // returns an iterator over Node instances
   public Iterator getNeighbours ()
   { return neighbours.iterator(); }

   // retrieve the value stored at this node
   public int getValue ()
   { return value; }

   // add an undirected edge between two nodes
   public static void connect (Node a, Node b)
   {
      if (a.equals(b)) return;   // no self-loops please
      a.neighbours.add(b);
      b.neighbours.add(a);
   }
}

Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 02.02.2015