1 | /* | |
2 | * Copyright 2006 - 2013 | |
3 | * Stefan Balev <stefan.balev@graphstream-project.org> | |
4 | * Julien Baudry <julien.baudry@graphstream-project.org> | |
5 | * Antoine Dutot <antoine.dutot@graphstream-project.org> | |
6 | * Yoann Pign�� <yoann.pigne@graphstream-project.org> | |
7 | * Guilhelm Savin <guilhelm.savin@graphstream-project.org> | |
8 | * | |
9 | * This file is part of GraphStream <http://graphstream-project.org>. | |
10 | * | |
11 | * GraphStream is a library whose purpose is to handle static or dynamic | |
12 | * graph, create them from scratch, file or any source and display them. | |
13 | * | |
14 | * This program is free software distributed under the terms of two licenses, the | |
15 | * CeCILL-C license that fits European law, and the GNU Lesser General Public | |
16 | * License. You can use, modify and/ or redistribute the software under the terms | |
17 | * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following | |
18 | * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by | |
19 | * the Free Software Foundation, either version 3 of the License, or (at your | |
20 | * option) any later version. | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
23 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
24 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU Lesser General Public License | |
27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
28 | * | |
29 | * The fact that you are presently reading this means that you have had | |
30 | * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms. | |
31 | */ | |
32 | package org.graphstream.graph.implementations; | |
33 | ||
34 | import java.util.ArrayList; | |
35 | import java.util.Collection; | |
36 | import java.util.Collections; | |
37 | import java.util.HashMap; | |
38 | import java.util.Iterator; | |
39 | import java.util.Map; | |
40 | ||
41 | import org.graphstream.graph.CompoundAttribute; | |
42 | import org.graphstream.graph.Element; | |
43 | import org.graphstream.graph.NullAttributeException; | |
44 | ||
45 | /** | |
46 | * A base implementation of an element. | |
47 | * | |
48 | * <p> | |
49 | * This class is the Base class for {@link org.graphstream.graph.Node}, | |
50 | * {@link org.graphstream.graph.Edge} and {@link org.graphstream.graph.Graph}. | |
51 | * An element is made of an unique and arbitrary identifier that identifies it, | |
52 | * and a set of attributes. | |
53 | * </p> | |
54 | * | |
55 | * @since 20040910 | |
56 | */ | |
57 | public abstract class AbstractElement implements Element { | |
58 | // Attribute | |
59 | ||
60 | // protected static Set<String> emptySet = new HashSet<String>(); | |
61 | ||
62 | /** | |
63 | * Tag of this element. | |
64 | */ | |
65 | protected final String id; | |
66 | ||
67 | /** | |
68 | * The index of this element. | |
69 | */ | |
70 | private int index; | |
71 | ||
72 | /** | |
73 | * Attributes map. This map is created only when needed. It contains pairs | |
74 | * (key,value) where the key is the attribute name and the value an Object. | |
75 | */ | |
76 | protected HashMap<String, Object> attributes = null; | |
77 | ||
78 | /** | |
79 | * Vector used when removing attributes to avoid recursive removing. | |
80 | */ | |
81 | protected ArrayList<String> attributesBeingRemoved = null; | |
82 | ||
83 | // Construction | |
84 | ||
85 | /** | |
86 | * New element. | |
87 | * | |
88 | * @param id | |
89 | * The unique identifier of this element. | |
90 | */ | |
91 | public AbstractElement(String id) { | |
92 | assert id != null : "Graph elements cannot have a null identifier"; | |
93 | this.id = id; | |
94 | } | |
95 | ||
96 | // Access | |
97 | ||
98 | public String getId() { | |
99 |
1
1. getId : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getId to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return id; |
100 | } | |
101 | ||
102 | public int getIndex() { | |
103 |
1
1. getIndex : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED |
return index; |
104 | } | |
105 | ||
106 | /** | |
107 | * Used by subclasses to change the index of an element | |
108 | * | |
109 | * @param index | |
110 | * the new index | |
111 | */ | |
112 | protected void setIndex(int index) { | |
113 | this.index = index; | |
114 | } | |
115 | ||
116 | // XXX UGLY. how to create events in the abstract element ? | |
117 | // XXX The various methods that add and remove attributes will propagate an | |
118 | // event | |
119 | // XXX sometimes this is in response to another event and the | |
120 | // sourceId/timeId is given | |
121 | // XXX sometimes this comes from a direct call to | |
122 | // add/change/removeAttribute() methods | |
123 | // XXX in which case we need to generate a new event (sourceId/timeId) using | |
124 | // the graph | |
125 | // XXX id and a new time. These methods allow access to this. | |
126 | protected abstract String myGraphId(); // XXX | |
127 | ||
128 | protected abstract long newEvent(); // XXX | |
129 | ||
130 | protected abstract boolean nullAttributesAreErrors(); // XXX | |
131 | ||
132 | /** | |
133 | * @complexity O(log(n)) with n being the number of attributes of this | |
134 | * element. | |
135 | */ | |
136 | // public Object getAttribute( String key ) | |
137 | @SuppressWarnings("all") | |
138 | public <T> T getAttribute(String key) { | |
139 |
1
1. getAttribute : negated conditional → KILLED |
if (attributes != null) { |
140 | T value = (T) attributes.get(key); | |
141 | ||
142 |
1
1. getAttribute : negated conditional → KILLED |
if (value != null) |
143 |
1
1. getAttribute : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttribute to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return value; |
144 | } | |
145 | ||
146 |
1
1. getAttribute : negated conditional → KILLED |
if (nullAttributesAreErrors()) |
147 | throw new NullAttributeException(key); | |
148 | ||
149 |
1
1. getAttribute : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttribute to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return null; |
150 | } | |
151 | ||
152 | /** | |
153 | * @complexity O(log(n*m)) with n being the number of attributes of this | |
154 | * element and m the number of keys given. | |
155 | */ | |
156 | // public Object getFirstAttributeOf( String ... keys ) | |
157 | @SuppressWarnings("all") | |
158 | public <T> T getFirstAttributeOf(String... keys) { | |
159 | Object o = null; | |
160 | ||
161 |
1
1. getFirstAttributeOf : negated conditional → NO_COVERAGE |
if (attributes != null) { |
162 |
3
1. getFirstAttributeOf : changed conditional boundary → NO_COVERAGE 2. getFirstAttributeOf : Changed increment from 1 to -1 → NO_COVERAGE 3. getFirstAttributeOf : negated conditional → NO_COVERAGE |
for (String key : keys) { |
163 | o = attributes.get(key); | |
164 | ||
165 |
1
1. getFirstAttributeOf : negated conditional → NO_COVERAGE |
if (o != null) |
166 |
1
1. getFirstAttributeOf : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getFirstAttributeOf to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) o; |
167 | } | |
168 | } | |
169 | ||
170 |
2
1. getFirstAttributeOf : negated conditional → NO_COVERAGE 2. getFirstAttributeOf : negated conditional → NO_COVERAGE |
if (o == null && nullAttributesAreErrors()) |
171 | throw new NullAttributeException(); | |
172 | ||
173 |
1
1. getFirstAttributeOf : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getFirstAttributeOf to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) o; |
174 | } | |
175 | ||
176 | /** | |
177 | * @complexity O(log(n)) with n being the number of attributes of this | |
178 | * element. | |
179 | */ | |
180 | // public Object getAttribute( String key, Class<?> clazz ) | |
181 | @SuppressWarnings("all") | |
182 | public <T> T getAttribute(String key, Class<T> clazz) { | |
183 |
1
1. getAttribute : negated conditional → NO_COVERAGE |
if (attributes != null) { |
184 | Object o = attributes.get(key); | |
185 | ||
186 |
2
1. getAttribute : negated conditional → NO_COVERAGE 2. getAttribute : negated conditional → NO_COVERAGE |
if (o != null && clazz.isInstance(o)) |
187 |
1
1. getAttribute : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttribute to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) o; |
188 | } | |
189 | ||
190 |
1
1. getAttribute : negated conditional → NO_COVERAGE |
if (nullAttributesAreErrors()) |
191 | throw new NullAttributeException(key); | |
192 | ||
193 |
1
1. getAttribute : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttribute to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
194 | } | |
195 | ||
196 | /** | |
197 | * @complexity O(log(n*m)) with n being the number of attributes of this | |
198 | * element and m the number of keys given. | |
199 | */ | |
200 | // public Object getFirstAttributeOf( Class<?> clazz, String ... keys ) | |
201 | @SuppressWarnings("all") | |
202 | public <T> T getFirstAttributeOf(Class<T> clazz, String... keys) { | |
203 | Object o = null; | |
204 | ||
205 |
1
1. getFirstAttributeOf : negated conditional → NO_COVERAGE |
if (attributes == null) |
206 |
1
1. getFirstAttributeOf : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getFirstAttributeOf to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
207 | ||
208 |
3
1. getFirstAttributeOf : changed conditional boundary → NO_COVERAGE 2. getFirstAttributeOf : Changed increment from 1 to -1 → NO_COVERAGE 3. getFirstAttributeOf : negated conditional → NO_COVERAGE |
for (String key : keys) { |
209 | o = attributes.get(key); | |
210 | ||
211 |
2
1. getFirstAttributeOf : negated conditional → NO_COVERAGE 2. getFirstAttributeOf : negated conditional → NO_COVERAGE |
if (o != null && clazz.isInstance(o)) |
212 |
1
1. getFirstAttributeOf : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getFirstAttributeOf to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) o; |
213 | } | |
214 | ||
215 |
1
1. getFirstAttributeOf : negated conditional → NO_COVERAGE |
if (nullAttributesAreErrors()) |
216 | throw new NullAttributeException(); | |
217 | ||
218 |
1
1. getFirstAttributeOf : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getFirstAttributeOf to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
219 | } | |
220 | ||
221 | /** | |
222 | * @complexity O(log(n)) with n being the number of attributes of this | |
223 | * element. | |
224 | */ | |
225 | public CharSequence getLabel(String key) { | |
226 |
1
1. getLabel : negated conditional → NO_COVERAGE |
if (attributes != null) { |
227 | Object o = attributes.get(key); | |
228 | ||
229 |
2
1. getLabel : negated conditional → NO_COVERAGE 2. getLabel : negated conditional → NO_COVERAGE |
if (o != null && o instanceof CharSequence) |
230 |
1
1. getLabel : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getLabel to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (CharSequence) o; |
231 | } | |
232 | ||
233 |
1
1. getLabel : negated conditional → NO_COVERAGE |
if (nullAttributesAreErrors()) |
234 | throw new NullAttributeException(key); | |
235 | ||
236 |
1
1. getLabel : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getLabel to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
237 | } | |
238 | ||
239 | /** | |
240 | * @complexity O(log(n)) with n being the number of attributes of this | |
241 | * element. | |
242 | */ | |
243 | public double getNumber(String key) { | |
244 |
1
1. getNumber : negated conditional → NO_COVERAGE |
if (attributes != null) { |
245 | Object o = attributes.get(key); | |
246 | ||
247 |
1
1. getNumber : negated conditional → NO_COVERAGE |
if (o != null) { |
248 |
1
1. getNumber : negated conditional → NO_COVERAGE |
if (o instanceof Number) |
249 |
1
1. getNumber : replaced return of double value with -(x + 1) for org/graphstream/graph/implementations/AbstractElement::getNumber → NO_COVERAGE |
return ((Number) o).doubleValue(); |
250 | ||
251 |
1
1. getNumber : negated conditional → NO_COVERAGE |
if (o instanceof String) { |
252 | try { | |
253 |
1
1. getNumber : replaced return of double value with -(x + 1) for org/graphstream/graph/implementations/AbstractElement::getNumber → NO_COVERAGE |
return Double.parseDouble((String) o); |
254 | } catch (NumberFormatException e) {} | |
255 |
1
1. getNumber : negated conditional → NO_COVERAGE |
} else if(o instanceof CharSequence) { |
256 | try { | |
257 |
1
1. getNumber : replaced return of double value with -(x + 1) for org/graphstream/graph/implementations/AbstractElement::getNumber → NO_COVERAGE |
return Double.parseDouble(((CharSequence)o).toString()); |
258 | } catch (NumberFormatException e) {} | |
259 | } | |
260 | } | |
261 | } | |
262 | ||
263 |
1
1. getNumber : negated conditional → NO_COVERAGE |
if (nullAttributesAreErrors()) |
264 | throw new NullAttributeException(key); | |
265 | ||
266 |
1
1. getNumber : replaced return of double value with -(x + 1) for org/graphstream/graph/implementations/AbstractElement::getNumber → NO_COVERAGE |
return Double.NaN; |
267 | } | |
268 | ||
269 | /** | |
270 | * @complexity O(log(n)) with n being the number of attributes of this | |
271 | * element. | |
272 | */ | |
273 | @SuppressWarnings("unchecked") | |
274 | public ArrayList<? extends Number> getVector(String key) { | |
275 |
1
1. getVector : negated conditional → NO_COVERAGE |
if (attributes != null) { |
276 | Object o = attributes.get(key); | |
277 | ||
278 |
2
1. getVector : negated conditional → NO_COVERAGE 2. getVector : negated conditional → NO_COVERAGE |
if (o != null && o instanceof ArrayList) |
279 |
1
1. getVector : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getVector to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ((ArrayList<? extends Number>) o); |
280 | } | |
281 | ||
282 |
1
1. getVector : negated conditional → NO_COVERAGE |
if (nullAttributesAreErrors()) |
283 | throw new NullAttributeException(key); | |
284 | ||
285 |
1
1. getVector : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getVector to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
286 | } | |
287 | ||
288 | /** | |
289 | * @complexity O(log(n)) with n being the number of attributes of this | |
290 | * element. | |
291 | */ | |
292 | public Object[] getArray(String key) { | |
293 |
1
1. getArray : negated conditional → NO_COVERAGE |
if (attributes != null) { |
294 | Object o = attributes.get(key); | |
295 | ||
296 |
2
1. getArray : negated conditional → NO_COVERAGE 2. getArray : negated conditional → NO_COVERAGE |
if (o != null && o instanceof Object[]) |
297 |
1
1. getArray : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ((Object[]) o); |
298 | } | |
299 | ||
300 |
1
1. getArray : negated conditional → NO_COVERAGE |
if (nullAttributesAreErrors()) |
301 | throw new NullAttributeException(key); | |
302 | ||
303 |
1
1. getArray : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
304 | } | |
305 | ||
306 | /** | |
307 | * @complexity O(log(n)) with n being the number of attributes of this | |
308 | * element. | |
309 | */ | |
310 | public HashMap<?, ?> getHash(String key) { | |
311 |
1
1. getHash : negated conditional → NO_COVERAGE |
if (attributes != null) { |
312 | Object o = attributes.get(key); | |
313 | ||
314 |
1
1. getHash : negated conditional → NO_COVERAGE |
if (o != null) { |
315 |
1
1. getHash : negated conditional → NO_COVERAGE |
if (o instanceof HashMap<?, ?>) |
316 |
1
1. getHash : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getHash to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ((HashMap<?, ?>) o); |
317 |
1
1. getHash : negated conditional → NO_COVERAGE |
if (o instanceof CompoundAttribute) |
318 |
1
1. getHash : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getHash to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ((CompoundAttribute) o).toHashMap(); |
319 | } | |
320 | } | |
321 | ||
322 |
1
1. getHash : negated conditional → NO_COVERAGE |
if (nullAttributesAreErrors()) |
323 | throw new NullAttributeException(key); | |
324 | ||
325 |
1
1. getHash : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getHash to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
326 | } | |
327 | ||
328 | /** | |
329 | * @complexity O(log(n)) with n being the number of attributes of this | |
330 | * element. | |
331 | */ | |
332 | public boolean hasAttribute(String key) { | |
333 |
1
1. hasAttribute : negated conditional → NO_COVERAGE |
if (attributes != null) |
334 |
1
1. hasAttribute : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return attributes.containsKey(key); |
335 | ||
336 |
1
1. hasAttribute : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
337 | } | |
338 | ||
339 | /** | |
340 | * @complexity O(log(n)) with n being the number of attributes of this | |
341 | * element. | |
342 | */ | |
343 | public boolean hasAttribute(String key, Class<?> clazz) { | |
344 |
1
1. hasAttribute : negated conditional → NO_COVERAGE |
if (attributes != null) { |
345 | Object o = attributes.get(key); | |
346 | ||
347 |
1
1. hasAttribute : negated conditional → NO_COVERAGE |
if (o != null) |
348 |
1
1. hasAttribute : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (clazz.isInstance(o)); |
349 | } | |
350 | ||
351 |
1
1. hasAttribute : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
352 | } | |
353 | ||
354 | /** | |
355 | * @complexity O(log(n)) with n being the number of attributes of this | |
356 | * element. | |
357 | */ | |
358 | public boolean hasLabel(String key) { | |
359 |
1
1. hasLabel : negated conditional → NO_COVERAGE |
if (attributes != null) { |
360 | Object o = attributes.get(key); | |
361 | ||
362 |
1
1. hasLabel : negated conditional → NO_COVERAGE |
if (o != null) |
363 |
1
1. hasLabel : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (o instanceof CharSequence); |
364 | } | |
365 | ||
366 |
1
1. hasLabel : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
367 | } | |
368 | ||
369 | /** | |
370 | * @complexity O(log(n)) with n being the number of attributes of this | |
371 | * element. | |
372 | */ | |
373 | public boolean hasNumber(String key) { | |
374 |
1
1. hasNumber : negated conditional → NO_COVERAGE |
if (attributes != null) { |
375 | Object o = attributes.get(key); | |
376 | ||
377 |
1
1. hasNumber : negated conditional → NO_COVERAGE |
if (o != null) |
378 |
1
1. hasNumber : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (o instanceof Number); |
379 | } | |
380 | ||
381 |
1
1. hasNumber : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
382 | } | |
383 | ||
384 | /** | |
385 | * @complexity O(log(n)) with n being the number of attributes of this | |
386 | * element. | |
387 | */ | |
388 | public boolean hasVector(String key) { | |
389 |
1
1. hasVector : negated conditional → NO_COVERAGE |
if (attributes != null) { |
390 | Object o = attributes.get(key); | |
391 | ||
392 |
2
1. hasVector : negated conditional → NO_COVERAGE 2. hasVector : negated conditional → NO_COVERAGE |
if (o != null && o instanceof ArrayList<?>) |
393 |
1
1. hasVector : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
394 | } | |
395 | ||
396 |
1
1. hasVector : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
397 | } | |
398 | ||
399 | /** | |
400 | * @complexity O(log(n)) with n being the number of attributes of this | |
401 | * element. | |
402 | */ | |
403 | public boolean hasArray(String key) { | |
404 |
1
1. hasArray : negated conditional → NO_COVERAGE |
if (attributes != null) { |
405 | Object o = attributes.get(key); | |
406 | ||
407 |
2
1. hasArray : negated conditional → NO_COVERAGE 2. hasArray : negated conditional → NO_COVERAGE |
if (o != null && o instanceof Object[]) |
408 |
1
1. hasArray : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
409 | } | |
410 | ||
411 |
1
1. hasArray : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
412 | } | |
413 | ||
414 | /** | |
415 | * @complexity O(log(n)) with n being the number of attributes of this | |
416 | * element. | |
417 | */ | |
418 | public boolean hasHash(String key) { | |
419 |
1
1. hasHash : negated conditional → NO_COVERAGE |
if (attributes != null) { |
420 | Object o = attributes.get(key); | |
421 | ||
422 |
1
1. hasHash : negated conditional → NO_COVERAGE |
if (o != null |
423 |
2
1. hasHash : negated conditional → NO_COVERAGE 2. hasHash : negated conditional → NO_COVERAGE |
&& (o instanceof HashMap<?, ?> || o instanceof CompoundAttribute)) |
424 |
1
1. hasHash : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
425 | } | |
426 | ||
427 |
1
1. hasHash : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
428 | } | |
429 | ||
430 | public Iterator<String> getAttributeKeyIterator() { | |
431 |
1
1. getAttributeKeyIterator : negated conditional → NO_COVERAGE |
if (attributes != null) |
432 |
1
1. getAttributeKeyIterator : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttributeKeyIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return attributes.keySet().iterator(); |
433 | ||
434 |
1
1. getAttributeKeyIterator : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttributeKeyIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
435 | } | |
436 | ||
437 | public Iterable<String> getEachAttributeKey() { | |
438 |
1
1. getEachAttributeKey : negated conditional → NO_COVERAGE |
if (attributes != null) |
439 |
1
1. getEachAttributeKey : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getEachAttributeKey to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return attributes.keySet(); |
440 | ||
441 |
1
1. getEachAttributeKey : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getEachAttributeKey to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Collections.emptySet(); |
442 | } | |
443 | ||
444 | public Collection<String> getAttributeKeySet() { | |
445 |
1
1. getAttributeKeySet : negated conditional → NO_COVERAGE |
if (attributes != null) |
446 |
1
1. getAttributeKeySet : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttributeKeySet to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (Collection<String>) Collections |
447 | .unmodifiableCollection(attributes.keySet()); | |
448 | ||
449 |
1
1. getAttributeKeySet : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::getAttributeKeySet to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Collections.emptySet(); |
450 | } | |
451 | ||
452 | // public Map<String,Object> getAttributeMap() | |
453 | // { | |
454 | // if( attributes != null ) | |
455 | // { | |
456 | // if( constMap == null ) | |
457 | // constMap = new ConstMap<String,Object>( attributes ); | |
458 | // | |
459 | // return constMap; | |
460 | // } | |
461 | // | |
462 | // return null; | |
463 | // } | |
464 | ||
465 | /** | |
466 | * Override the Object method | |
467 | */ | |
468 | @Override | |
469 | public String toString() { | |
470 |
1
1. toString : mutated return of Object value for org/graphstream/graph/implementations/AbstractElement::toString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return id; |
471 | } | |
472 | ||
473 | public int getAttributeCount() { | |
474 |
1
1. getAttributeCount : negated conditional → NO_COVERAGE |
if (attributes != null) |
475 |
1
1. getAttributeCount : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return attributes.size(); |
476 | ||
477 |
1
1. getAttributeCount : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
478 | } | |
479 | ||
480 | // Command | |
481 | ||
482 | public void clearAttributes() { | |
483 |
1
1. clearAttributes : removed call to org/graphstream/graph/implementations/AbstractElement::clearAttributes_ → SURVIVED |
clearAttributes_(myGraphId(), newEvent()); |
484 | } | |
485 | ||
486 | protected void clearAttributes_(String sourceId, long timeId) { | |
487 |
1
1. clearAttributes_ : negated conditional → KILLED |
if (attributes != null) { |
488 | Iterator<String> keys = attributes.keySet().iterator(); | |
489 | Iterator<Object> vals = attributes.values().iterator(); | |
490 | ||
491 |
2
1. clearAttributes_ : negated conditional → NO_COVERAGE 2. clearAttributes_ : negated conditional → NO_COVERAGE |
while (keys.hasNext() && vals.hasNext()) { |
492 | String key = keys.next(); | |
493 | Object val = vals.next(); | |
494 | ||
495 |
1
1. clearAttributes_ : removed call to org/graphstream/graph/implementations/AbstractElement::attributeChanged → NO_COVERAGE |
attributeChanged(sourceId, timeId, key, |
496 | AttributeChangeEvent.REMOVE, val, null); | |
497 | } | |
498 | ||
499 |
1
1. clearAttributes_ : removed call to java/util/HashMap::clear → NO_COVERAGE |
attributes.clear(); |
500 | } | |
501 | } | |
502 | ||
503 | /** | |
504 | * @complexity O(log(n)) with n being the number of attributes of this | |
505 | * element. | |
506 | */ | |
507 | public void addAttribute(String attribute, Object... values) { | |
508 |
1
1. addAttribute : removed call to org/graphstream/graph/implementations/AbstractElement::addAttribute_ → NO_COVERAGE |
addAttribute_(myGraphId(), newEvent(), attribute, values); |
509 | } | |
510 | ||
511 | protected void addAttribute_(String sourceId, long timeId, | |
512 | String attribute, Object... values) { | |
513 |
1
1. addAttribute_ : negated conditional → KILLED |
if (attributes == null) |
514 | attributes = new HashMap<String, Object>(1); | |
515 | ||
516 | Object oldValue; | |
517 | Object value; | |
518 | ||
519 |
1
1. addAttribute_ : negated conditional → KILLED |
if (values.length == 0) |
520 | value = true; | |
521 |
1
1. addAttribute_ : negated conditional → KILLED |
else if (values.length == 1) |
522 | value = values[0]; | |
523 | else | |
524 | value = values; | |
525 | ||
526 | AttributeChangeEvent event = AttributeChangeEvent.ADD; | |
527 | ||
528 |
1
1. addAttribute_ : negated conditional → SURVIVED |
if (attributes.containsKey(attribute)) // In case the value is null, |
529 | event = AttributeChangeEvent.CHANGE; // but the attribute exists. | |
530 | ||
531 | oldValue = attributes.put(attribute, value); | |
532 |
1
1. addAttribute_ : removed call to org/graphstream/graph/implementations/AbstractElement::attributeChanged → SURVIVED |
attributeChanged(sourceId, timeId, attribute, event, oldValue, value); |
533 | } | |
534 | ||
535 | /** | |
536 | * @complexity O(log(n)) with n being the number of attributes of this | |
537 | * element. | |
538 | */ | |
539 | public void changeAttribute(String attribute, Object... values) { | |
540 |
1
1. changeAttribute : removed call to org/graphstream/graph/implementations/AbstractElement::changeAttribute_ → NO_COVERAGE |
changeAttribute_(myGraphId(), newEvent(), attribute, values); |
541 | } | |
542 | ||
543 | protected void changeAttribute_(String sourceId, long timeId, | |
544 | String attribute, Object... values) { | |
545 |
1
1. changeAttribute_ : removed call to org/graphstream/graph/implementations/AbstractElement::addAttribute_ → KILLED |
addAttribute_(sourceId, timeId, attribute, values); |
546 | } | |
547 | ||
548 | /** | |
549 | * @complexity O(log(n)) with n being the number of attributes of this | |
550 | * element. | |
551 | */ | |
552 | public void setAttribute(String attribute, Object... values) { | |
553 |
1
1. setAttribute : removed call to org/graphstream/graph/implementations/AbstractElement::setAttribute_ → NO_COVERAGE |
setAttribute_(myGraphId(), newEvent(), attribute, values); |
554 | } | |
555 | ||
556 | protected void setAttribute_(String sourceId, long timeId, | |
557 | String attribute, Object... values) { | |
558 |
1
1. setAttribute_ : removed call to org/graphstream/graph/implementations/AbstractElement::addAttribute_ → NO_COVERAGE |
addAttribute_(sourceId, timeId, attribute, values); |
559 | } | |
560 | ||
561 | /** | |
562 | * @complexity O(log(n)) with n being the number of attributes of this | |
563 | * element. | |
564 | */ | |
565 | public void addAttributes(Map<String, Object> attributes) { | |
566 |
1
1. addAttributes : removed call to org/graphstream/graph/implementations/AbstractElement::addAttributes_ → NO_COVERAGE |
addAttributes_(myGraphId(), newEvent(), attributes); |
567 | } | |
568 | ||
569 | protected void addAttributes_(String sourceId, long timeId, | |
570 | Map<String, Object> attributes) { | |
571 |
1
1. addAttributes_ : negated conditional → NO_COVERAGE |
if (this.attributes == null) |
572 | this.attributes = new HashMap<String, Object>(1); | |
573 | ||
574 | Iterator<String> i = attributes.keySet().iterator(); | |
575 | Iterator<Object> j = attributes.values().iterator(); | |
576 | ||
577 |
2
1. addAttributes_ : negated conditional → NO_COVERAGE 2. addAttributes_ : negated conditional → NO_COVERAGE |
while (i.hasNext() && j.hasNext()) |
578 |
1
1. addAttributes_ : removed call to org/graphstream/graph/implementations/AbstractElement::addAttribute_ → NO_COVERAGE |
addAttribute_(sourceId, timeId, i.next(), j.next()); |
579 | } | |
580 | ||
581 | /** | |
582 | * @complexity O(log(n)) with n being the number of attributes of this | |
583 | * element. | |
584 | */ | |
585 | public void removeAttribute(String attribute) { | |
586 |
1
1. removeAttribute : removed call to org/graphstream/graph/implementations/AbstractElement::removeAttribute_ → NO_COVERAGE |
removeAttribute_(myGraphId(), newEvent(), attribute); |
587 | } | |
588 | ||
589 | protected void removeAttribute_(String sourceId, long timeId, | |
590 | String attribute) { | |
591 |
1
1. removeAttribute_ : negated conditional → KILLED |
if (attributes != null) { |
592 | // | |
593 | // 'attributesBeingRemoved' is created only if this is required. | |
594 | // | |
595 |
1
1. removeAttribute_ : negated conditional → KILLED |
if (attributesBeingRemoved == null) |
596 | attributesBeingRemoved = new ArrayList<String>(); | |
597 | ||
598 | // | |
599 | // Avoid recursive calls when synchronising graphs. | |
600 | // | |
601 |
1
1. removeAttribute_ : negated conditional → KILLED |
if (attributes.containsKey(attribute) |
602 |
1
1. removeAttribute_ : negated conditional → KILLED |
&& !attributesBeingRemoved.contains(attribute)) { |
603 | attributesBeingRemoved.add(attribute); | |
604 | ||
605 |
1
1. removeAttribute_ : removed call to org/graphstream/graph/implementations/AbstractElement::attributeChanged → SURVIVED |
attributeChanged(sourceId, timeId, attribute, |
606 | AttributeChangeEvent.REMOVE, attributes.get(attribute), | |
607 | null); | |
608 | ||
609 | attributesBeingRemoved | |
610 |
1
1. removeAttribute_ : Replaced integer subtraction with addition → KILLED |
.remove(attributesBeingRemoved.size() - 1); |
611 | attributes.remove(attribute); | |
612 | } | |
613 | } | |
614 | } | |
615 | ||
616 | public static enum AttributeChangeEvent { | |
617 | ADD, CHANGE, REMOVE | |
618 | }; | |
619 | ||
620 | /** | |
621 | * Called for each change in the attribute set. This method must be | |
622 | * implemented by sub-elements in order to send events to the graph | |
623 | * listeners. | |
624 | * | |
625 | * @param sourceId | |
626 | * The source of the change. | |
627 | * @param timeId | |
628 | * The source time of the change, for synchronization. | |
629 | * @param attribute | |
630 | * The attribute name that changed. | |
631 | * @param event | |
632 | * The type of event among ADD, CHANGE and REMOVE. | |
633 | * @param oldValue | |
634 | * The old value of the attribute, null if the attribute was | |
635 | * added. | |
636 | * @param newValue | |
637 | * The new value of the attribute, null if the attribute is about | |
638 | * to be removed. | |
639 | */ | |
640 | protected abstract void attributeChanged(String sourceId, long timeId, | |
641 | String attribute, AttributeChangeEvent event, Object oldValue, | |
642 | Object newValue); | |
643 | } | |
Mutations | ||
99 |
1.1 |
|
103 |
1.1 |
|
139 |
1.1 |
|
142 |
1.1 |
|
143 |
1.1 |
|
146 |
1.1 |
|
149 |
1.1 |
|
161 |
1.1 |
|
162 |
1.1 2.2 3.3 |
|
165 |
1.1 |
|
166 |
1.1 |
|
170 |
1.1 2.2 |
|
173 |
1.1 |
|
183 |
1.1 |
|
186 |
1.1 2.2 |
|
187 |
1.1 |
|
190 |
1.1 |
|
193 |
1.1 |
|
205 |
1.1 |
|
206 |
1.1 |
|
208 |
1.1 2.2 3.3 |
|
211 |
1.1 2.2 |
|
212 |
1.1 |
|
215 |
1.1 |
|
218 |
1.1 |
|
226 |
1.1 |
|
229 |
1.1 2.2 |
|
230 |
1.1 |
|
233 |
1.1 |
|
236 |
1.1 |
|
244 |
1.1 |
|
247 |
1.1 |
|
248 |
1.1 |
|
249 |
1.1 |
|
251 |
1.1 |
|
253 |
1.1 |
|
255 |
1.1 |
|
257 |
1.1 |
|
263 |
1.1 |
|
266 |
1.1 |
|
275 |
1.1 |
|
278 |
1.1 2.2 |
|
279 |
1.1 |
|
282 |
1.1 |
|
285 |
1.1 |
|
293 |
1.1 |
|
296 |
1.1 2.2 |
|
297 |
1.1 |
|
300 |
1.1 |
|
303 |
1.1 |
|
311 |
1.1 |
|
314 |
1.1 |
|
315 |
1.1 |
|
316 |
1.1 |
|
317 |
1.1 |
|
318 |
1.1 |
|
322 |
1.1 |
|
325 |
1.1 |
|
333 |
1.1 |
|
334 |
1.1 |
|
336 |
1.1 |
|
344 |
1.1 |
|
347 |
1.1 |
|
348 |
1.1 |
|
351 |
1.1 |
|
359 |
1.1 |
|
362 |
1.1 |
|
363 |
1.1 |
|
366 |
1.1 |
|
374 |
1.1 |
|
377 |
1.1 |
|
378 |
1.1 |
|
381 |
1.1 |
|
389 |
1.1 |
|
392 |
1.1 2.2 |
|
393 |
1.1 |
|
396 |
1.1 |
|
404 |
1.1 |
|
407 |
1.1 2.2 |
|
408 |
1.1 |
|
411 |
1.1 |
|
419 |
1.1 |
|
422 |
1.1 |
|
423 |
1.1 2.2 |
|
424 |
1.1 |
|
427 |
1.1 |
|
431 |
1.1 |
|
432 |
1.1 |
|
434 |
1.1 |
|
438 |
1.1 |
|
439 |
1.1 |
|
441 |
1.1 |
|
445 |
1.1 |
|
446 |
1.1 |
|
449 |
1.1 |
|
470 |
1.1 |
|
474 |
1.1 |
|
475 |
1.1 |
|
477 |
1.1 |
|
483 |
1.1 |
|
487 |
1.1 |
|
491 |
1.1 2.2 |
|
495 |
1.1 |
|
499 |
1.1 |
|
508 |
1.1 |
|
513 |
1.1 |
|
519 |
1.1 |
|
521 |
1.1 |
|
528 |
1.1 |
|
532 |
1.1 |
|
540 |
1.1 |
|
545 |
1.1 |
|
553 |
1.1 |
|
558 |
1.1 |
|
566 |
1.1 |
|
571 |
1.1 |
|
577 |
1.1 2.2 |
|
578 |
1.1 |
|
586 |
1.1 |
|
591 |
1.1 |
|
595 |
1.1 |
|
601 |
1.1 |
|
602 |
1.1 |
|
605 |
1.1 |
|
610 |
1.1 |