View Javadoc
1 /* ComplexConnector.java */ 2 3 package org.quilt.graph; 4 5 /*** 6 * A Connector holding a single edge plus a fixed size array of edges. 7 * This is a combination of the UnaryConnector and MultiConnector. 8 * 9 * @author <a href="jddixon@users.sourceforge.net">Jim Dixon</a> 10 */ 11 public class ComplexConnector extends Connector { 12 13 /*** The single edge */ 14 private Edge edge; 15 16 /*** The array of edges. */ 17 private Edge[] edges = null; 18 19 /*** Source of all edges in this connector. */ 20 private Vertex source = null; 21 22 /*** 23 * Constructor for a Connector with a single edge plus a fixed-size 24 * array of edges. The source of the single edge becomes the source 25 * of the array of edges. All edges in the array are set to point 26 * to the graph exit. 27 * 28 * @param e Becomes preferred edge of the connector. 29 * @param n Number of edges in the array 30 * @param graph Graph this appears in. 31 */ 32 public ComplexConnector (final Edge e, int n 33 //, final Exit exit 34 ) { 35 if ( e == null || n < 1 36 // || exit == null 37 ) { 38 throw new IllegalArgumentException ( 39 "constructor arguments must be in range and not null"); 40 } 41 edge = new Edge (e); // the preferred edge 42 edges = new Edge[n]; // fixed-size array of edges 43 source = edge.getSource(); 44 Vertex target = edge.getTarget(); 45 for (int i = 0; i < n; i++) { 46 edges[i] = new Edge (source, target); 47 } 48 } 49 public ComplexConnector (Connector conn, int n 50 //, final Exit exit 51 ) { 52 // will throw NPE if conn is null 53 this(conn.getEdge(), n 54 // , exit 55 ); 56 } 57 // INTERFACE CONNECTOR ////////////////////////////////////////// 58 /*** Get the single edge. */ 59 public Edge getEdge() { 60 return edge; 61 } 62 /*** Get the target of the single edge. */ 63 public Vertex getTarget() { 64 return edge.getTarget(); 65 } 66 /*** Change the target of the single edge. */ 67 public void setTarget(Vertex v) { 68 checkTarget(v); 69 edge.setTarget(v); 70 } 71 // OTHER METHODS //////////////////////////////////////////////// 72 private void checkTarget (final Vertex target) { 73 if (target == null) { 74 throw new IllegalArgumentException( 75 "target may not be null"); 76 } 77 if ( source.getGraph() != target.getGraph() ) { 78 throw new IllegalArgumentException( 79 "ComplexConnector's target must be in the same graph"); 80 } 81 } 82 private void rangeCheck(int n) { 83 if ( n < 0 || n >=edges.length) { 84 throw new IllegalArgumentException ( 85 "ComplexConnector index " + n 86 + " out of range 0.." + (edges.length - 1) ); 87 } 88 } 89 90 /*** Get the Nth edge from the array. */ 91 public Edge getEdge(int n) { 92 rangeCheck(n); 93 return edges[n]; 94 } 95 /*** Get the target of the Nth edge. */ 96 public Vertex getTarget(int n) { 97 rangeCheck(n); 98 return edges[n].getTarget(); 99 } 100 /*** Change the target of the Nth edge. */ 101 public void setTarget(Vertex v, int n) { 102 checkTarget(v); 103 rangeCheck(n); 104 edges[n].setTarget(v); 105 } 106 107 108 /*** 109 * Returns the number of edges in the connector EXCLUDING the 110 * preferred edge. This is the same number used in the 111 * constructor as the size of the connector. 112 * 113 * @return Total number of edges in the multiway part of the connector. 114 */ 115 public int size () { 116 return edges.length; 117 } 118 }

This page was automatically generated by Maven