Advertisement
Guest User

GraphNode

a guest
Dec 11th, 2013
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class GraphNode<E> {
  2.     private int index; // index of vertex
  3.     private E info;
  4.     private LinkedList<GraphNode<E>> neighbors;
  5.  
  6.     public GraphNode(int index, E info) {
  7.         this.index = index;
  8.         this.info = info;
  9.         neighbors = new LinkedList<GraphNode<E>>();
  10.     }
  11.  
  12.     boolean containsNeighbor(GraphNode<E> o) {
  13.         return neighbors.contains(o);
  14.     }
  15.  
  16.     void addNeighbor(GraphNode<E> o) {
  17.         neighbors.add(o);
  18.     }
  19.  
  20.     void removeNeighbor(GraphNode<E> o) {
  21.         if (neighbors.contains(o))
  22.             neighbors.remove(o);
  23.     }
  24.  
  25.     @Override
  26.     public String toString() {
  27.         String ret = "INFO:" + info + " Neighbors:";
  28.         for (int i = 0; i < neighbors.size(); i++)
  29.             ret += neighbors.get(i).info + "
  30.         return ret;
  31.     }
  32.  
  33.     @Override
  34.     public boolean equals(Object obj)
  35.         GraphNode<E> pom = (GraphNode<E>) obj;
  36.         return (pom.info.equals(this.info));
  37.     }
  38.     public int getIndex() {
  39.         return index;
  40.     }
  41.     public void setIndex(int index) {
  42.         this.index = index;
  43.     }
  44.  
  45.     public E getInfo() {
  46.         return info;
  47.     }
  48.  
  49.     public void setInfo(E info) {
  50.         this.info = info;
  51.     }
  52.  
  53.     public LinkedList<GraphNode<E>> getNeighbors() {
  54.         return neighbors;
  55.     }
  56.  
  57.     public void setNeighbors(LinkedList<GraphNode<E>> neighbors) {
  58.         this.neighbors = neighbors;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement