VisClient/org/dronus/graph/Node.java

Go to the documentation of this file.
00001 /*
00002  * Created on 05.03.2005
00003  *
00004  */
00005 package org.dronus.graph;
00006 
00007 import java.util.Collection;
00008 import java.util.LinkedList;
00009 import java.util.List;
00010 import java.util.Vector;
00011 
00016 public class Node  {
00017 
00018         public int id; 
00019         
00020         public List<Edge> edges= new LinkedList<Edge>();
00021         public String type="undefined",text;
00022         
00026         public Node(String id, String text, String type) {
00027                 this.id = id.hashCode();
00028                 this.text = text;
00029                 this.type = type;
00030         }
00031         
00035         public Node(int id, String text, String type) {
00036                 this.id = id;
00037                 this.text = text;
00038                 this.type = type;
00039         }
00040         
00045         public Node(String text) {
00046                 this.text=text;
00047         }
00048         
00049         public int edgeCount() {   return edges.size(); }
00050         public Collection<Edge> getEdges(){return edges;}
00051         public Collection<Node> getFromNodes(){
00052                 Vector<Node> nodes=new Vector<Node>();
00053                 for(Edge e: edges){
00054                         Node n=e.getFrom();
00055                         if (n!=this) nodes.add(n);
00056                 }
00057                 return nodes;
00058         }
00059         public Node getSubNode(String type){
00060                 for(Edge e: edges){
00061                         Node n=e.getFrom();
00062                         if (n!=this && n.type.equals(type)) 
00063                                 return n;
00064                 }
00065                 return null;
00066         }
00067         public String getSubNodeText(String type){
00068                 Node n=getSubNode(type);
00069                 if (n!=null) return n.text;
00070                 else return null;
00071         }
00072         //public Edge edgeAt( int index ) {  return (Edge)edges.elementAt(index);  }
00073         public void addEdge( Edge edge ) {   if ( edge != null )   edges.add(edge);  }
00074         public void removeEdge(Edge edge ) {   edges.remove(edge); }
00075         
00076         public boolean equals(Object other) {   return (other instanceof Node && ((Node)other).id==id); }
00077         
00078         public int hashCode() {return id;}
00079 }

Generated on Tue Apr 7 17:57:19 2009 for visclient by  doxygen 1.5.1