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 org.graphstream.graph.Edge; | |
35 | import org.graphstream.graph.Node; | |
36 | import org.graphstream.stream.SourceBase.ElementType; | |
37 | ||
38 | /** | |
39 | * <p> | |
40 | * This class provides a basic implementation of {@code Edge} interface, to | |
41 | * minimize the effort required to implement this interface. | |
42 | * </p> | |
43 | * | |
44 | * <p> | |
45 | * Although this class is abstract it implements all the methods of | |
46 | * {@link org.graphstream.graph.Edge} and | |
47 | * {@link org.graphstream.graph.implementations.AbstractElement}. It has a low | |
48 | * memory overhead (3 references and a boolean as fields). All {@code Edge} | |
49 | * methods are executed in O(1) time. | |
50 | * </p> | |
51 | */ | |
52 | public class AbstractEdge extends AbstractElement implements Edge { | |
53 | ||
54 | // *** Fields *** | |
55 | ||
56 | /** | |
57 | * The source node | |
58 | */ | |
59 | protected AbstractNode source; | |
60 | ||
61 | /** | |
62 | * The target node | |
63 | */ | |
64 | protected AbstractNode target; | |
65 | ||
66 | /** | |
67 | * Is this edge directed ? | |
68 | */ | |
69 | protected boolean directed; | |
70 | ||
71 | /** | |
72 | * The graph to which this edge belongs | |
73 | */ | |
74 | protected AbstractGraph graph; | |
75 | ||
76 | // *** Constructors *** | |
77 | ||
78 | /** | |
79 | * Constructs a new edge. This constructor copies the parameters into the | |
80 | * corresponding fields. | |
81 | * | |
82 | * @param id | |
83 | * Unique identifier of this edge. | |
84 | * @param source | |
85 | * Source node. | |
86 | * @param target | |
87 | * Target node. | |
88 | * @param directed | |
89 | * Indicates if the edge is directed. | |
90 | */ | |
91 | protected AbstractEdge(String id, AbstractNode source, AbstractNode target, | |
92 | boolean directed) { | |
93 | super(id); | |
94 | assert source != null && target != null : "An edge cannot have null endpoints"; | |
95 | this.source = source; | |
96 | this.target = target; | |
97 | this.directed = directed; | |
98 | this.graph = (AbstractGraph) source.getGraph(); | |
99 | } | |
100 | ||
101 | ||
102 | // *** Inherited from AbstractElement *** | |
103 | ||
104 | @Override | |
105 | protected void attributeChanged(String sourceId, long timeId, | |
106 | String attribute, AttributeChangeEvent event, Object oldValue, | |
107 | Object newValue) { | |
108 |
1
1. attributeChanged : removed call to org/graphstream/graph/implementations/AbstractGraph$GraphListeners::sendAttributeChangedEvent → SURVIVED |
graph.listeners.sendAttributeChangedEvent(sourceId, timeId, id, |
109 | ElementType.EDGE, attribute, event, oldValue, | |
110 | newValue); | |
111 | } | |
112 | ||
113 | /** | |
114 | * @return The id of the parent graph | |
115 | * @see org.graphstream.graph.implementations.AbstractElement#myGraphId() | |
116 | */ | |
117 | @Override | |
118 | protected String myGraphId() { | |
119 |
1
1. myGraphId : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::myGraphId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return graph.getId(); |
120 | } | |
121 | ||
122 | /** | |
123 | * This implementation calls the corresponding method of the parent graph | |
124 | * | |
125 | * @see org.graphstream.graph.implementations.AbstractElement#newEvent() | |
126 | */ | |
127 | @Override | |
128 | protected long newEvent() { | |
129 |
1
1. newEvent : replaced return of long value with value + 1 for org/graphstream/graph/implementations/AbstractEdge::newEvent → NO_COVERAGE |
return graph.newEvent(); |
130 | } | |
131 | ||
132 | /** | |
133 | * This implementation calls the corresponding method of the parent graph | |
134 | * | |
135 | * @see org.graphstream.graph.implementations.AbstractElement#nullAttributesAreErrors() | |
136 | */ | |
137 | @Override | |
138 | protected boolean nullAttributesAreErrors() { | |
139 |
1
1. nullAttributesAreErrors : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return graph.nullAttributesAreErrors(); |
140 | } | |
141 | | |
142 | @Override | |
143 | public String toString() { | |
144 |
2
1. toString : negated conditional → KILLED 2. toString : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::toString to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return String.format("%s[%s-%s%s]", getId(), source, directed ? ">" |
145 | : "-", target); | |
146 | } | |
147 | ||
148 | // *** Inherited from Edge *** | |
149 | ||
150 | @SuppressWarnings("unchecked") | |
151 | public <T extends Node> T getNode0() { | |
152 |
1
1. getNode0 : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::getNode0 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) source; |
153 | } | |
154 | ||
155 | @SuppressWarnings("unchecked") | |
156 | public <T extends Node> T getNode1() { | |
157 |
1
1. getNode1 : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::getNode1 to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (T) target; |
158 | } | |
159 | ||
160 | @SuppressWarnings("unchecked") | |
161 | public <T extends Node> T getOpposite(Node node) { | |
162 |
1
1. getOpposite : negated conditional → KILLED |
if (node == source) |
163 |
1
1. getOpposite : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::getOpposite to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (T) target; |
164 |
1
1. getOpposite : negated conditional → KILLED |
if (node == target) |
165 |
1
1. getOpposite : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::getOpposite to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (T) source; |
166 |
1
1. getOpposite : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::getOpposite to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
167 | } | |
168 | ||
169 | @SuppressWarnings("unchecked") | |
170 | public <T extends Node> T getSourceNode() { | |
171 |
1
1. getSourceNode : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::getSourceNode to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (T) source; |
172 | } | |
173 | ||
174 | @SuppressWarnings("unchecked") | |
175 | public <T extends Node> T getTargetNode() { | |
176 |
1
1. getTargetNode : mutated return of Object value for org/graphstream/graph/implementations/AbstractEdge::getTargetNode to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return (T) target; |
177 | } | |
178 | ||
179 | public boolean isDirected() { | |
180 |
1
1. isDirected : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return directed; |
181 | } | |
182 | ||
183 | public boolean isLoop() { | |
184 |
3
1. isLoop : negated conditional → NO_COVERAGE 2. isLoop : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE 3. isLoop : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return source == target; |
185 | } | |
186 | } | |
Mutations | ||
108 |
1.1 |
|
119 |
1.1 |
|
129 |
1.1 |
|
139 |
1.1 |
|
144 |
1.1 2.2 |
|
152 |
1.1 |
|
157 |
1.1 |
|
162 |
1.1 |
|
163 |
1.1 |
|
164 |
1.1 |
|
165 |
1.1 |
|
166 |
1.1 |
|
171 |
1.1 |
|
176 |
1.1 |
|
180 |
1.1 |
|
184 |
1.1 2.2 3.3 |