1 package net.sf.crispy.util;
2
3 import java.util.HashMap;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Map;
7
8 public class Graph {
9
10 private static final long serialVersionUID = 7523758252776765521L;
11 private Map vertexs = new HashMap();
12 private Map edges = new HashMap();
13
14 /** All edges, map key is the from vertex */
15 private Map fromEdge = new Hashtable();
16 /** All edges, map key is the to vertex */
17 private Map toEdge = new Hashtable();
18
19
20 public Object put(Object pvKey, Object pvValue) {
21 Edge lvEdge = (Edge) pvKey;
22 fromEdge.put(lvEdge.getFrom(), lvEdge);
23 toEdge.put(lvEdge.getTo(), lvEdge);
24
25 return edges.put(pvKey, pvValue);
26 }
27 public void addVertex(Object pvVertexObj) {
28 vertexs.put(pvVertexObj, Integer.valueOf("1"));
29 }
30
31 public boolean getVertexCount(Object pvVertexObj) {
32 if (pvVertexObj == null) { return false; }
33 return (vertexs.get(pvVertexObj) == null ? false : true);
34 }
35
36 public Edge isToContains(Object pvObject) {
37 if (pvObject == null) { return null; }
38 return (Edge) toEdge.get(pvObject);
39 }
40
41 public Edge isFromContains(Object pvObject) {
42 if (pvObject == null) { return null; }
43
44
45
46
47
48
49 Edge lvFindEdgeFrom = (Edge) fromEdge.get(pvObject);
50
51
52 return lvFindEdgeFrom;
53 }
54
55 public Edge getProblemEdge(Object pvObject) {
56 if (pvObject == null) { return null; }
57
58 Iterator it = edges.keySet().iterator();
59
60 while (it.hasNext()) {
61
62 Edge lvEdge = (Edge) it.next();
63 if ((lvEdge.getTo() != null) && (lvEdge.getTo().equals(pvObject)) && (lvEdge.getMethodName() != null)) {
64 return lvEdge;
65 }
66 }
67 return null;
68 }
69
70 public synchronized boolean containsKey(Object pvKey) {
71
72 boolean b = edges.containsKey(pvKey);
73 return b;
74 }
75
76 }