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.Iterator; | |
36 | import java.util.Map; | |
37 | ||
38 | import org.graphstream.graph.Element; | |
39 | ||
40 | /** | |
41 | * An implementation of an {@link org.graphstream.graph.Element}. | |
42 | * | |
43 | * <p> | |
44 | * It allows only one attribute and has no internal map structure. <b>It is not | |
45 | * used and may be removed.</b> | |
46 | * </p> | |
47 | * | |
48 | */ | |
49 | public abstract class OneAttributeElement implements Element { | |
50 | // Constants | |
51 | ||
52 | // Attributes | |
53 | ||
54 | /** | |
55 | * Tag of this element. | |
56 | */ | |
57 | protected String id; | |
58 | ||
59 | /** | |
60 | * The only one attribute | |
61 | */ | |
62 | Object attribute = null; | |
63 | ||
64 | // Constructors | |
65 | ||
66 | /** | |
67 | * New element. | |
68 | * | |
69 | * @param id | |
70 | * The unique identifier of this element. | |
71 | */ | |
72 | public OneAttributeElement(String id) { | |
73 | assert id != null : "Graph elements cannot have a null identifier"; | |
74 | this.id = id; | |
75 | } | |
76 | ||
77 | // Accessors | |
78 | ||
79 | public String getId() { | |
80 |
1
1. getId : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return id; |
81 | } | |
82 | ||
83 | @SuppressWarnings("all") | |
84 | public <T> T getAttribute(String key) { | |
85 |
1
1. getAttribute : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getAttribute to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) attribute; |
86 | } | |
87 | ||
88 | @SuppressWarnings("all") | |
89 | public <T> T getFirstAttributeOf(String... keys) { | |
90 |
1
1. getFirstAttributeOf : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getFirstAttributeOf to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) attribute; |
91 | } | |
92 | ||
93 | @SuppressWarnings("all") | |
94 | public <T> T getAttribute(String key, Class<T> clazz) { | |
95 |
1
1. getAttribute : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getAttribute to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) attribute; |
96 | } | |
97 | ||
98 | @SuppressWarnings("all") | |
99 | public <T> T getFirstAttributeOf(Class<T> clazz, String... keys) { | |
100 |
1
1. getFirstAttributeOf : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getFirstAttributeOf to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) attribute; |
101 | } | |
102 | ||
103 | public CharSequence getLabel(String key) { | |
104 |
2
1. getLabel : negated conditional → NO_COVERAGE 2. getLabel : negated conditional → NO_COVERAGE |
if (attribute != null && attribute instanceof CharSequence) |
105 |
1
1. getLabel : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getLabel to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (CharSequence) attribute; |
106 |
1
1. getLabel : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getLabel to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
107 | } | |
108 | ||
109 | public double getNumber(String key) { | |
110 |
2
1. getNumber : negated conditional → NO_COVERAGE 2. getNumber : negated conditional → NO_COVERAGE |
if (attribute != null && attribute instanceof Number) |
111 |
1
1. getNumber : replaced return of double value with -(x + 1) for org/graphstream/graph/implementations/OneAttributeElement::getNumber → NO_COVERAGE |
return ((Number) attribute).doubleValue(); |
112 | ||
113 |
1
1. getNumber : replaced return of double value with -(x + 1) for org/graphstream/graph/implementations/OneAttributeElement::getNumber → NO_COVERAGE |
return Double.NaN; |
114 | } | |
115 | ||
116 | @SuppressWarnings("unchecked") | |
117 | public ArrayList<? extends Number> getVector(String key) { | |
118 |
2
1. getVector : negated conditional → NO_COVERAGE 2. getVector : negated conditional → NO_COVERAGE |
if (attribute != null && attribute instanceof ArrayList) |
119 |
1
1. getVector : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getVector to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ((ArrayList<? extends Number>) attribute); |
120 | ||
121 |
1
1. getVector : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getVector to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
122 | } | |
123 | ||
124 | public boolean hasAttribute(String key) { | |
125 | ||
126 |
1
1. hasAttribute : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
127 | } | |
128 | ||
129 | public boolean hasAttribute(String key, Class<?> clazz) { | |
130 |
1
1. hasAttribute : negated conditional → NO_COVERAGE |
if (attribute != null) |
131 |
1
1. hasAttribute : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (clazz.isInstance(attribute)); |
132 |
1
1. hasAttribute : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
133 | } | |
134 | ||
135 | public boolean hasLabel(String key) { | |
136 |
1
1. hasLabel : negated conditional → NO_COVERAGE |
if (attribute != null) |
137 |
1
1. hasLabel : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (attribute instanceof CharSequence); |
138 | ||
139 |
1
1. hasLabel : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
140 | } | |
141 | ||
142 | public boolean hasNumber(String key) { | |
143 |
1
1. hasNumber : negated conditional → NO_COVERAGE |
if (attribute != null) |
144 |
1
1. hasNumber : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (attribute instanceof Number); |
145 | ||
146 |
1
1. hasNumber : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
147 | } | |
148 | ||
149 | public boolean hasVector(String key) { | |
150 |
2
1. hasVector : negated conditional → NO_COVERAGE 2. hasVector : negated conditional → NO_COVERAGE |
if (attribute != null && attribute instanceof ArrayList<?>) |
151 |
1
1. hasVector : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
152 | ||
153 |
1
1. hasVector : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
154 | } | |
155 | ||
156 | public Iterator<String> getAttributeKeyIterator() { | |
157 |
1
1. getAttributeKeyIterator : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getAttributeKeyIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
158 | } | |
159 | ||
160 | public Map<String, Object> getAttributeMap() { | |
161 |
1
1. getAttributeMap : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::getAttributeMap to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
162 | } | |
163 | ||
164 | /** | |
165 | * Override the Object method | |
166 | */ | |
167 | @Override | |
168 | public String toString() { | |
169 |
1
1. toString : mutated return of Object value for org/graphstream/graph/implementations/OneAttributeElement::toString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return id; |
170 | } | |
171 | ||
172 | // Commands | |
173 | ||
174 | public void clearAttributes() { | |
175 | attribute = null; | |
176 | } | |
177 | ||
178 | public void addAttribute(String attribute, Object value) { | |
179 | this.attribute = value; | |
180 | // System.out.println(attribute+" = "+value.toString()); | |
181 | } | |
182 | ||
183 | public void changeAttribute(String attribute, Object value) { | |
184 |
1
1. changeAttribute : removed call to org/graphstream/graph/implementations/OneAttributeElement::addAttribute → NO_COVERAGE |
addAttribute(attribute, value); |
185 | // System.out.println(attribute+" = "+value.toString()); | |
186 | ||
187 | } | |
188 | ||
189 | public void addAttributes(Map<String, Object> attributes) { | |
190 | // System.out.println(attributes.toString()); | |
191 |
2
1. addAttributes : changed conditional boundary → NO_COVERAGE 2. addAttributes : negated conditional → NO_COVERAGE |
if (attributes.size() >= 0) |
192 |
1
1. addAttributes : removed call to org/graphstream/graph/implementations/OneAttributeElement::addAttribute → NO_COVERAGE |
addAttribute("", attributes.get((attributes.keySet().toArray()[0]))); |
193 | ||
194 | } | |
195 | ||
196 | public void removeAttribute(String attribute) { | |
197 | this.attribute = null; | |
198 | } | |
199 | ||
200 | public static enum AttributeChangeEvent { | |
201 | ADD, CHANGE, REMOVE | |
202 | }; | |
203 | ||
204 | /** | |
205 | * Called for each change in the attribute set. This method must be | |
206 | * implemented by sub-elements in order to send events to the graph | |
207 | * listeners. | |
208 | * | |
209 | * @param sourceId | |
210 | * The source of the change. | |
211 | * @param timeId | |
212 | * The source time of the change, for synchronization. | |
213 | * @param attribute | |
214 | * The attribute name that changed. | |
215 | * @param event | |
216 | * The type of event among ADD, CHANGE and REMOVE. | |
217 | * @param oldValue | |
218 | * The old value of the attribute, null if the attribute was | |
219 | * added. | |
220 | * @param newValue | |
221 | * The new value of the attribute, null if the attribute is about | |
222 | * to be removed. | |
223 | */ | |
224 | protected abstract void attributeChanged(String sourceId, long timeId, | |
225 | String attribute, AttributeChangeEvent event, Object oldValue, | |
226 | Object newValue); | |
227 | } | |
Mutations | ||
80 |
1.1 |
|
85 |
1.1 |
|
90 |
1.1 |
|
95 |
1.1 |
|
100 |
1.1 |
|
104 |
1.1 2.2 |
|
105 |
1.1 |
|
106 |
1.1 |
|
110 |
1.1 2.2 |
|
111 |
1.1 |
|
113 |
1.1 |
|
118 |
1.1 2.2 |
|
119 |
1.1 |
|
121 |
1.1 |
|
126 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
136 |
1.1 |
|
137 |
1.1 |
|
139 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
146 |
1.1 |
|
150 |
1.1 2.2 |
|
151 |
1.1 |
|
153 |
1.1 |
|
157 |
1.1 |
|
161 |
1.1 |
|
169 |
1.1 |
|
184 |
1.1 |
|
191 |
1.1 2.2 |
|
192 |
1.1 |