1 25 package classycle.graph; 26 27 import java.util.Vector ; 28 29 46 public class Vertex implements Comparable 47 { 48 private final Vector _heads = new Vector (); 49 private final Vector _tails = new Vector (); 50 private final Attributes _attributes; 51 private boolean _visited; 52 53 54 public Vertex(Attributes attributes) 55 { 56 _attributes = attributes; 57 } 58 59 60 public Attributes getAttributes() 61 { 62 return _attributes; 63 } 64 65 69 public int getNumberOfOutgoingArcs() 70 { 71 return _heads.size(); 72 } 73 74 75 public Vertex getHeadVertex(int index) 76 { 77 return (Vertex) _heads.elementAt(index); 78 } 79 80 88 public void addOutgoingArcTo(Vertex headVertex) 89 { 90 if (!_heads.contains(headVertex)) 91 { 92 _heads.addElement(headVertex); 93 headVertex.addIncomingArcTo(this); 94 } 95 } 96 97 101 public int getNumberOfIncomingArcs() 102 { 103 return _tails.size(); 104 } 105 106 107 public Vertex getTailVertex(int index) 108 { 109 return (Vertex) _tails.elementAt(index); 110 } 111 112 120 public void addIncomingArcTo(Vertex tailVertex) 121 { 122 if (!_tails.contains(tailVertex)) 123 { 124 _tails.addElement(tailVertex); 125 tailVertex.addOutgoingArcTo(this); 126 } 127 } 128 129 130 public void reset() 131 { 132 _visited = false; 133 } 134 135 139 public void visit() 140 { 141 _visited = true; 142 } 143 144 145 public boolean isVisited() 146 { 147 return _visited; 148 } 149 150 154 public String toString() 155 { 156 StringBuffer result = new StringBuffer (); 157 result.append(getAttributes() == null ? super.toString() 158 : getAttributes().toString()) 159 .append(": ").append(getNumberOfIncomingArcs()) 160 .append(" incoming arc(s), ").append(getNumberOfOutgoingArcs()) 161 .append(" outgoing arc(s)."); 162 return new String (result); 163 } 164 165 public int compareTo(Object object) 166 { 167 int result = 1; 168 if (object instanceof Vertex && _attributes != null) 169 { 170 result = _attributes.compareTo(((Vertex) object)._attributes); 171 } 172 return result; 173 } 174 175 } | Popular Tags |