1 2 3 package org.quilt.graph; 4 5 10 public class Vertex { 11 12 13 protected int index = -1; 14 15 protected Directed graph = null; 16 17 protected Connector connector = null; 18 19 protected String label_ = null; 20 21 22 protected Vertex () { 23 } 24 29 public Vertex (Directed g) { 30 checkForNull(g, "graph"); 31 graph = g; 32 index = g.anotherVertex(this); 33 } 34 public Connector getConnector () { 36 return connector; 37 } 38 public void setConnector (Connector c) { 39 checkForNull (c, "connector"); 40 connector = c; 41 } 42 public Edge getEdge () { 43 if (connector == null) { 44 return null; 45 } else { 46 return connector.getEdge(); 47 } 48 } 49 public Vertex getTarget() { 50 if (connector == null) { 51 return null; 52 } else { 53 return connector.getTarget(); 54 } 55 } 56 57 public Directed getGraph() { 58 return graph; 59 } 60 61 62 public int getIndex() { 63 return index; 64 } 65 66 public String getLabel() { 67 return label_; 68 } 69 70 public void setLabel (String s) { 71 label_ = s; 72 } 73 79 public Edge makeBinary() { 80 Edge otherEdge = new Edge(this, graph.getExit()); 81 connector = new BinaryConnector( connector, otherEdge ); 82 return otherEdge; 83 } 84 88 public ComplexConnector makeComplex(int n) { 89 connector = new ComplexConnector ( connector, n); 91 return (ComplexConnector) connector; 92 } 93 94 98 public MultiConnector makeMulti(int n) { 99 connector = new MultiConnector ( connector, n); 101 return (MultiConnector) connector; 102 } 103 104 106 112 public boolean above (final Directed g) { 113 System.out.println("above: checking whether graph " + g.getIndex() 115 + " is above vertex " + toString () 116 + " whose parent is graph " + getGraph().getParent().getIndex() 117 ); 118 if (g == null || g == graph) { 120 return false; 121 } 122 123 for ( Directed pop = graph.getParent(); pop != null; 125 pop = pop.getParent() ) { 126 System.out.println(" checking whether graph " + g.getIndex() 128 + " is the same as graph " + pop.getIndex()); 129 if ( pop == g ) { 131 return true; 132 } 133 } 134 return false; 135 } 136 142 public static void checkForNull( Object o, String what) { 143 if (o == null) { 144 throw new IllegalArgumentException ("null " + what); 145 } 146 } 147 150 public String toString () { 151 StringBuffer sb = new StringBuffer () 152 .append(graph.getIndex()) 153 .append(":") 154 .append(index); 155 return sb.toString(); 156 } 157 } 158 | Popular Tags |