View Javadoc
1 /* BinaryConnector.java */ 2 3 package org.quilt.graph; 4 5 /*** 6 * A Connector holding two edges. Implementation detail: we assume 7 * that in laying out bytecode the 'else' code appears immediately 8 * after the if but the 'then' code is accessed using a goto. 9 * 10 * @author <a href="mailto:jddixon@users.sourceforge.net">Jim Dixon</a> 11 */ 12 public class BinaryConnector extends Connector { 13 /*** The preferred edge, the 'else' edge. */ 14 private Edge edge; 15 /*** The other edge, the 'then' edge. */ 16 private Edge otherEdge; 17 /*** Source of both edges. */ 18 private Vertex source = null; 19 20 private void doSetUp(Edge e, Edge otherE) { 21 if (e == null || otherE == null) { 22 throw new IllegalArgumentException ("arguments cannot be null"); 23 } 24 edge = e; 25 source = edge.getSource(); 26 otherEdge = otherE; 27 if ( source != otherEdge.getSource() ) { 28 throw new IllegalArgumentException ( 29 "edges in a BinaryConnector must have the same source"); 30 } 31 } 32 public BinaryConnector (Edge e, Edge otherE) { 33 doSetUp(e, otherE); 34 } 35 public BinaryConnector (Connector conn, Edge otherE) { 36 if (conn == null) { 37 throw new IllegalArgumentException("connector cannot be null"); 38 } 39 doSetUp(conn.getEdge(), otherE); 40 } 41 // INTERFACE CONNECTOR ////////////////////////////////////////// 42 /*** Get the preferred edge. */ 43 public Edge getEdge() { 44 return edge; 45 } 46 /*** Get the target of the preferred edge. */ 47 public Vertex getTarget() { 48 return edge.getTarget(); 49 } 50 /*** Change the target of the preferred edge. */ 51 public void setTarget (Vertex v) { 52 checkTarget(v); 53 edge.setTarget(v); 54 } 55 public int size () { 56 return 2; 57 } 58 // OTHER METHODS //////////////////////////////////////////////// 59 private void checkTarget (final Vertex target) { 60 if (target == null) { 61 throw new IllegalArgumentException("target may not be null"); 62 } 63 // DEBUG 64 if (source == null) 65 System.out.println("BinaryConnector.checkTarget INTERNAL ERROR: " 66 + " source is null"); 67 else if (source.getGraph() == null) 68 System.out.println( 69 "BinaryConnector.checkTarget: source has no graph!"); 70 if (target.getGraph() == null) 71 System.out.println( 72 "BinaryConnector.checkTarget: target has no graph!"); 73 // END 74 if ( target.getGraph() != source.getGraph() ) { 75 throw new IllegalArgumentException( 76 "new target must be in same graph"); 77 } 78 } 79 /*** Get the other edge. */ 80 public Edge getOtherEdge() { 81 return otherEdge; 82 } 83 /*** Get the target of the other edge */ 84 public Vertex getOtherTarget() { 85 return otherEdge.getTarget(); 86 } 87 /*** Set the target of the other edge. */ 88 public void setOtherTarget (Vertex v) { 89 checkTarget(v); 90 otherEdge.setTarget (v); 91 } 92 }

This page was automatically generated by Maven