SingleNode.java

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.Collections;
35
import java.util.HashMap;
36
import java.util.Iterator;
37
38
import org.graphstream.graph.Edge;
39
import org.graphstream.graph.Node;
40
41
/**
42
 * Nodes used with {@link SingleGraph}
43
 *
44
 */
45
46
public class SingleNode extends AdjacencyListNode {
47
	protected static class TwoEdges {
48
		AbstractEdge in, out;
49
	}
50
	
51
	protected HashMap<AbstractNode, TwoEdges> neighborMap;
52
53
	// *** Constructor ***
54
55
	protected SingleNode(AbstractGraph graph, String id) {
56
		super(graph, id);
57
		neighborMap = new HashMap<AbstractNode, TwoEdges>(
58 3 1. : Replaced integer multiplication with division → SURVIVED
2. : Replaced integer division with multiplication → SURVIVED
3. : Replaced integer addition with subtraction → SURVIVED
				4 * INITIAL_EDGE_CAPACITY / 3 + 1);
59
	}
60
61
	// *** Helpers ***
62
63
	@SuppressWarnings("unchecked")
64
	@Override
65
	protected <T extends Edge> T locateEdge(Node opposite, char type) {
66
		TwoEdges ee = neighborMap.get(opposite);
67 1 1. locateEdge : negated conditional → KILLED
		if (ee == null)
68 1 1. locateEdge : mutated return of Object value for org/graphstream/graph/implementations/SingleNode::locateEdge to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return null;
69 2 1. locateEdge : negated conditional → SURVIVED
2. locateEdge : mutated return of Object value for org/graphstream/graph/implementations/SingleNode::locateEdge to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return (T)(type == I_EDGE ? ee.in : ee.out);
70
	}
71
72
	@Override
73
	protected void removeEdge(int i) {
74
		AbstractNode opposite = edges[i].getOpposite(this);
75
		TwoEdges ee = neighborMap.get(opposite);
76
		char type = edgeType(edges[i]);
77 1 1. removeEdge : negated conditional → SURVIVED
		if (type != O_EDGE)
78
			ee.in = null;
79 1 1. removeEdge : negated conditional → SURVIVED
		if (type != I_EDGE)
80
			ee.out = null;
81 2 1. removeEdge : negated conditional → SURVIVED
2. removeEdge : negated conditional → SURVIVED
		if (ee.in == null && ee.out == null)
82
			neighborMap.remove(opposite);
83 1 1. removeEdge : removed call to org/graphstream/graph/implementations/AdjacencyListNode::removeEdge → SURVIVED
		super.removeEdge(i);
84
	}
85
86
	// *** Callbacks ***
87
88
	@Override
89
	protected boolean addEdgeCallback(AbstractEdge edge) {
90
		AbstractNode opposite = edge.getOpposite(this);
91
		TwoEdges ee = neighborMap.get(opposite);
92 1 1. addEdgeCallback : negated conditional → KILLED
		if (ee == null)
93
			ee = new TwoEdges();
94
		char type = edgeType(edge);
95 1 1. addEdgeCallback : negated conditional → SURVIVED
		if (type != O_EDGE) {
96 1 1. addEdgeCallback : negated conditional → KILLED
			if (ee.in != null)
97 1 1. addEdgeCallback : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
				return false;
98
			ee.in = edge;
99
		}
100 1 1. addEdgeCallback : negated conditional → KILLED
		if (type != I_EDGE) {
101 1 1. addEdgeCallback : negated conditional → KILLED
			if (ee.out != null)
102 1 1. addEdgeCallback : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
				return false;
103
			ee.out = edge;
104
		}
105
		neighborMap.put(opposite, ee);
106 1 1. addEdgeCallback : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return super.addEdgeCallback(edge);
107
	}
108
109
	@Override
110
	protected void clearCallback() {
111 1 1. clearCallback : removed call to java/util/HashMap::clear → SURVIVED
		neighborMap.clear();
112 1 1. clearCallback : removed call to org/graphstream/graph/implementations/AdjacencyListNode::clearCallback → SURVIVED
		super.clearCallback();
113
	}
114
115
	// *** Others ***
116
117
	@SuppressWarnings("unchecked")
118
	@Override
119
	public <T extends Node> Iterator<T> getNeighborNodeIterator() {
120 1 1. getNeighborNodeIterator : mutated return of Object value for org/graphstream/graph/implementations/SingleNode::getNeighborNodeIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return (Iterator<T>) Collections.unmodifiableSet(neighborMap.keySet())
121
				.iterator();
122
	}
123
}

Mutations

58

1.1
Location :
Killed by : none
Replaced integer multiplication with division → SURVIVED

2.2
Location :
Killed by : none
Replaced integer division with multiplication → SURVIVED

3.3
Location :
Killed by : none
Replaced integer addition with subtraction → SURVIVED

67

1.1
Location : locateEdge
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.removeEdgeTestFromToNodeNullNoStrictChecking(org.graphstream.graph.implementations.AbstractGraphTest)
negated conditional → KILLED

68

1.1
Location : locateEdge
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.removeEdgeTestFromToNodeNullNoStrictChecking(org.graphstream.graph.implementations.AbstractGraphTest)
mutated return of Object value for org/graphstream/graph/implementations/SingleNode::locateEdge to ( if (x != null) null else throw new RuntimeException ) → KILLED

69

1.1
Location : locateEdge
Killed by : none
negated conditional → SURVIVED

2.2
Location : locateEdge
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.removeEdgeTestFromToString(org.graphstream.graph.implementations.AbstractGraphTest)
mutated return of Object value for org/graphstream/graph/implementations/SingleNode::locateEdge to ( if (x != null) null else throw new RuntimeException ) → KILLED

77

1.1
Location : removeEdge
Killed by : none
negated conditional → SURVIVED

79

1.1
Location : removeEdge
Killed by : none
negated conditional → SURVIVED

81

1.1
Location : removeEdge
Killed by : none
negated conditional → SURVIVED

2.2
Location : removeEdge
Killed by : none
negated conditional → SURVIVED

83

1.1
Location : removeEdge
Killed by : none
removed call to org/graphstream/graph/implementations/AdjacencyListNode::removeEdge → SURVIVED

92

1.1
Location : addEdgeCallback
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.addEdgeTestNoExistenceNoStrictCheckingAutoDstMissing(org.graphstream.graph.implementations.AbstractGraphTest)
negated conditional → KILLED

95

1.1
Location : addEdgeCallback
Killed by : none
negated conditional → SURVIVED

96

1.1
Location : addEdgeCallback
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.twoSingleGraphTest(org.graphstream.graph.implementations.AbstractGraphTest)
negated conditional → KILLED

97

1.1
Location : addEdgeCallback
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.addEdgeTestNoExistenceStrictChecking(org.graphstream.graph.implementations.AbstractGraphTest)
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

100

1.1
Location : addEdgeCallback
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.removeEdgeTestFromToString(org.graphstream.graph.implementations.AbstractGraphTest)
negated conditional → KILLED

101

1.1
Location : addEdgeCallback
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.twoSingleGraphTest(org.graphstream.graph.implementations.AbstractGraphTest)
negated conditional → KILLED

102

1.1
Location : addEdgeCallback
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

106

1.1
Location : addEdgeCallback
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.removeEdgeTestFromToString(org.graphstream.graph.implementations.AbstractGraphTest)
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

111

1.1
Location : clearCallback
Killed by : none
removed call to java/util/HashMap::clear → SURVIVED

112

1.1
Location : clearCallback
Killed by : none
removed call to org/graphstream/graph/implementations/AdjacencyListNode::clearCallback → SURVIVED

120

1.1
Location : getNeighborNodeIterator
Killed by : none
mutated return of Object value for org/graphstream/graph/implementations/SingleNode::getNeighborNodeIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 0.33