SinkTime.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.stream.sync;
33
34
import java.security.AccessControlException;
35
import java.util.HashMap;
36
37
public class SinkTime {
38
	/**
39
	 * Key used to disable synchro. Just run : java -DSYNC_DISABLE_KEY ...
40
	 */
41
	public static final String SYNC_DISABLE_KEY = "org.graphstream.stream.sync.disable";
42
	/**
43
	 * Flag used to disable sync.
44
	 */
45
	protected static final boolean disableSync;
46
47
	/*
48
	 * The following code is used to prevent AccessControlException to be thrown
49
	 * when trying to get the value of the property (in applets for example).
50
	 */
51
	static {
52
		boolean off;
53
54
		try {
55
			off = System.getProperty(SYNC_DISABLE_KEY) != null;
56
		} catch (AccessControlException ex) {
57
			off = false;
58
		}
59
60
		disableSync = off;
61
	}
62
63
	/**
64
	 * Map storing times of sources.
65
	 */
66
	protected HashMap<String, Long> times = new HashMap<String, Long>();
67
68
	/**
69
	 * Update timeId for a source.
70
	 * 
71
	 * @param sourceId
72
	 * @param timeId
73
	 * @return true if time has been updated
74
	 */
75
	protected boolean setTimeFor(String sourceId, long timeId) {
76
		Long knownTimeId = times.get(sourceId);
77
78 1 1. setTimeFor : negated conditional → KILLED
		if (knownTimeId == null) {
79
			times.put(sourceId, timeId);
80 1 1. setTimeFor : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
			return true;
81 2 1. setTimeFor : changed conditional boundary → SURVIVED
2. setTimeFor : negated conditional → KILLED
		} else if (timeId > knownTimeId) {
82
			times.put(sourceId, timeId);
83 1 1. setTimeFor : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
			return true;
84
		}
85
86 1 1. setTimeFor : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED
		return false;
87
	}
88
89
	/**
90
	 * Allow to know if event is new for this source. This updates the timeId
91
	 * mapped to the source.
92
	 * 
93
	 * @param sourceId
94
	 * @param timeId
95
	 * @return true if event is new for the source
96
	 */
97
	public boolean isNewEvent(String sourceId, long timeId) {
98 4 1. isNewEvent : negated conditional → SURVIVED
2. isNewEvent : replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED
3. isNewEvent : negated conditional → KILLED
4. isNewEvent : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
		return disableSync || setTimeFor(sourceId, timeId);
99
	}
100
}

Mutations

78

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

80

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

81

1.1
Location : setTimeFor
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : setTimeFor
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.graphAttributeChangedTest(org.graphstream.graph.implementations.AbstractGraphTest)
negated conditional → KILLED

83

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

86

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

98

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

2.2
Location : isNewEvent
Killed by : org.graphstream.graph.implementations.AbstractGraphTest.graphAttributeAddedTest(org.graphstream.graph.implementations.AbstractGraphTest)
negated conditional → KILLED

3.3
Location : isNewEvent
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED

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

Active mutators

Tests examined


Report generated by PIT 0.33