/Users/lyon/j4p/src/graphics/graph/EdgesBean.java
|
1 package graphics.graph;
2
3 import java.util.Vector;
4
5 public class EdgesBean {
6 private static EdgesBean eb = new EdgesBean();
7 private Nodes nodes = GraphFactory.getNodes();
8
9 private EdgesBean() {
10 }
11
12 public static EdgesBean getEdgesBean() {
13 return eb;
14 }
15
16 private Vector edgeVector = new Vector();
17
18 public void addEdge(Edge e) {
19
20 if (containsEdge(e))
21 return;
22 System.out.println("adding edge:" + e);
23 edgeVector.addElement(e);
24 }
25
26 public boolean containsEdge(Edge e) {
27 if (e == null) return true;
28 for (int i = 0; i < edgeVector.size(); i++) {
29 Edge e1 = (Edge) edgeVector.elementAt(i);
30 if (e1.equals(e)) return true;
31 }
32 return false;
33 }
34
35 public int getNumberOfEdges() {
36 return edgeVector.size();
37 }
38
39 public void addEdge(String nodeName1, String nodeName2) {
40 addEdge(nodeName1, nodeName2, 40);
41 }
42
43 void addEdge(String from, String to, int len) {
44 Edge e = new Edge();
45 e.setFrom(nodes.findNode(from));
46 e.setTo(nodes.findNode(to));
47 e.setLen(len);
48 addEdge(e);
49 }
50
51 public Edge getEdge(int i) {
52 return (Edge) edgeVector.elementAt(i);
53 }
54 }