# Coverage details for edu.uci.ics.jung.graph.event.GraphListenerHandler

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Copyright (c) 2003, the JUNG Project and the Regents of the University`
3 |  | `* of California`
4 |  | `* All rights reserved.`
5 |  | `*`
6 |  | `* This software is open-source under the BSD license; see either`
7 |  | `* "license.txt" or`
8 |  | `* http://jung.sourceforge.net/license.txt for a description.`
9 |  | `*`
10 |  | `* Created on Dec 29, 2003`
11 |  | `*/`
12 |  | `package edu.uci.ics.jung.graph.event;`
13 |  | ``
14 |  | `import java.util.*;`
15 |  | ``
16 |  | `import edu.uci.ics.jung.graph.*;`
17 |  | ``
18 |  | `/**`
19 |  | `* This utility class handles Graph listening and call dispatching. Use it in`
20 |  | `* the appropriate ways.`
21 |  | `*`
22 |  | `* @author danyelf`
23 |  | `*/`
24 |  | `public class GraphListenerHandler {`
25 |  | ``
26 |  | `private ArchetypeGraph mGraph;`
27 |  | ``
28 | 654 | `public GraphListenerHandler(ArchetypeGraph graph) {`
29 | 654 | `this.mGraphListenerMap = new HashMap();`
30 | 654 | `this.mGraph = graph;`
31 | 654 | `}`
32 |  | ``
33 |  | `Map mGraphListenerMap;`
34 |  | ``
35 |  | `/**`
36 |  | `* @param gel`
37 |  | `* @param get`
38 |  | `*/`
39 |  | `public void addListener(GraphEventListener gel, GraphEventType get) {`
40 | 28 | `if (get == GraphEventType.ALL_SINGLE_EVENTS) {`
41 | 21 | `addListener_internal(gel, GraphEventType.VERTEX_ADDITION);`
42 | 21 | `addListener_internal(gel, GraphEventType.VERTEX_REMOVAL);`
43 | 21 | `addListener_internal(gel, GraphEventType.EDGE_ADDITION);`
44 | 21 | `addListener_internal(gel, GraphEventType.EDGE_REMOVAL);`
45 |  | `} else {`
46 | 7 | `addListener_internal(gel, get);`
47 |  | `}`
48 | 28 | `}`
49 |  | ``
50 |  | `private void addListener_internal(`
51 |  | `GraphEventListener gel,`
52 |  | `GraphEventType get) {`
53 |  | ``
54 | 91 | `List listeners = (List) mGraphListenerMap.get(get);`
55 |  | ``
56 | 91 | `if (listeners == null) {`
57 | 80 | `listeners = new ArrayList();`
58 | 80 | `mGraphListenerMap.put(get, listeners);`
59 |  | `}`
60 |  | ``
61 | 91 | `listeners.add(gel);`
62 | 91 | `}`
63 |  | ``
64 |  | `/**`
65 |  | `* @param gel`
66 |  | `* @param get`
67 |  | `*/`
68 |  | `public void removeListener(GraphEventListener gel, GraphEventType get) {`
69 | 0 | `if (get == GraphEventType.ALL_SINGLE_EVENTS) {`
70 | 0 | `removeListener_internal(gel, GraphEventType.VERTEX_ADDITION);`
71 | 0 | `removeListener_internal(gel, GraphEventType.VERTEX_REMOVAL);`
72 | 0 | `removeListener_internal(gel, GraphEventType.EDGE_ADDITION);`
73 | 0 | `removeListener_internal(gel, GraphEventType.EDGE_REMOVAL);`
74 |  | `} else {`
75 | 0 | `removeListener_internal(gel, get);`
76 |  | `}`
77 | 0 | `}`
78 |  | ``
79 |  | `private void removeListener_internal(`
80 |  | `GraphEventListener gel,`
81 |  | `GraphEventType get) {`
82 | 0 | `List listeners = (List) mGraphListenerMap.get(get);`
83 | 0 | `if (listeners == null)`
84 | 0 | `return;`
85 |  | ``
86 | 0 | `listeners.remove(gel);`
87 | 0 | `}`
88 |  | ``
89 |  | `/**`
90 |  | `* @param type a GraphEventType`
91 |  | `* @return true if at least one listener is listening to this type`
92 |  | `*/`
93 |  | `public boolean listenersExist(GraphEventType type) {`
94 | 290244 | `List listeners = (List) mGraphListenerMap.get(type);`
95 | 290244 | `if ((listeners == null) || (listeners.size() == 0)) {`
96 | 290124 | `return false;`
97 |  | `}`
98 | 120 | `return true;`
99 |  | `}`
100 |  | ``
101 |  | `protected void notifyListenersVertexAdded(GraphEvent ge) {`
102 | 66 | `List listeners =`
103 |  | `(List) mGraphListenerMap.get(GraphEventType.VERTEX_ADDITION);`
104 | 66 | `for (Iterator lIt = listeners.iterator(); lIt.hasNext();) {`
105 | 75 | `GraphEventListener listener = (GraphEventListener) lIt.next();`
106 | 75 | `listener.vertexAdded(ge);`
107 |  | `}`
108 | 66 | `}`
109 |  | ``
110 |  | `protected void notifyListenersEdgeAdded(GraphEvent ge) {`
111 | 45 | `List listeners =`
112 |  | `(List) mGraphListenerMap.get(GraphEventType.EDGE_ADDITION);`
113 | 45 | `for (Iterator lIt = listeners.iterator(); lIt.hasNext();) {`
114 | 50 | `GraphEventListener listener = (GraphEventListener) lIt.next();`
115 | 50 | `listener.edgeAdded(ge);`
116 |  | `}`
117 | 45 | `}`
118 |  | ``
119 |  | `protected void notifyListenersVertexRemoved(GraphEvent ge) {`
120 | 5 | `List listeners =`
121 |  | `(List) mGraphListenerMap.get(GraphEventType.VERTEX_REMOVAL);`
122 | 5 | `for (Iterator lIt = listeners.iterator(); lIt.hasNext();) {`
123 | 10 | `GraphEventListener listener = (GraphEventListener) lIt.next();`
124 | 10 | `listener.vertexRemoved(ge);`
125 |  | `}`
126 | 5 | `}`
127 |  | ``
128 |  | `protected void notifyListenersEdgeRemoved(GraphEvent ge) {`
129 | 4 | `List listeners =`
130 |  | `(List) mGraphListenerMap.get(GraphEventType.EDGE_REMOVAL);`
131 | 4 | `for (Iterator lIt = listeners.iterator(); lIt.hasNext();) {`
132 | 8 | `GraphEventListener listener = (GraphEventListener) lIt.next();`
133 | 8 | `listener.edgeRemoved(ge);`
134 |  | `}`
135 | 4 | `}`
136 |  | ``
137 |  | `/**`
138 |  | `* @param e`
139 |  | `*/`
140 |  | `public void handleAdd(ArchetypeEdge e) {`
141 | 148067 | `if (listenersExist(GraphEventType.EDGE_ADDITION)) {`
142 | 45 | `notifyListenersEdgeAdded(new GraphEvent(mGraph, e));`
143 |  | `}`
144 | 148067 | `}`
145 |  | ``
146 |  | `/**`
147 |  | `* @param v`
148 |  | `*/`
149 |  | `public void handleAdd(ArchetypeVertex v) {`
150 | 32396 | `if (listenersExist(GraphEventType.VERTEX_ADDITION)) {`
151 | 66 | `notifyListenersVertexAdded(new GraphEvent(mGraph, v));`
152 |  | `}`
153 | 32396 | `}`
154 |  | ``
155 |  | `/**`
156 |  | `* @param v`
157 |  | `*/`
158 |  | `public void handleRemove(ArchetypeVertex v) {`
159 | 90 | `if (listenersExist(GraphEventType.VERTEX_REMOVAL)) {`
160 | 5 | `notifyListenersVertexRemoved(new GraphEvent(mGraph, v));`
161 |  | `}`
162 | 90 | `}`
163 |  | ``
164 |  | `/**`
165 |  | `* @param e`
166 |  | `*/`
167 |  | `public void handleRemove(ArchetypeEdge e) {`
168 | 109691 | `if (listenersExist(GraphEventType.EDGE_REMOVAL)) {`
169 | 4 | `notifyListenersEdgeRemoved(new GraphEvent(mGraph, e));`
170 |  | `}`
171 | 109691 | `}`
172 |  | ``
173 |  | `}`

this report was generated by version 1.0.5 of jcoverage. visit www.jcoverage.com for updates. | copyright © 2003, jcoverage ltd. all rights reserved. Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.