1 2 3 package org.quilt.graph; 4 5 12 public class BinaryConnector extends Connector { 13 14 private Edge edge; 15 16 private Edge otherEdge; 17 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 43 public Edge getEdge() { 44 return edge; 45 } 46 47 public Vertex getTarget() { 48 return edge.getTarget(); 49 } 50 51 public void setTarget (Vertex v) { 52 checkTarget(v); 53 edge.setTarget(v); 54 } 55 public int size () { 56 return 2; 57 } 58 private void checkTarget (final Vertex target) { 60 if (target == null) { 61 throw new IllegalArgumentException ("target may not be null"); 62 } 63 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 if ( target.getGraph() != source.getGraph() ) { 75 throw new IllegalArgumentException ( 76 "new target must be in same graph"); 77 } 78 } 79 80 public Edge getOtherEdge() { 81 return otherEdge; 82 } 83 84 public Vertex getOtherTarget() { 85 return otherEdge.getTarget(); 86 } 87 88 public void setOtherTarget (Vertex v) { 89 checkTarget(v); 90 otherEdge.setTarget (v); 91 } 92 } 93 | Popular Tags |