AttributePipe.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;
33
34
/**
35
 * Allows to filter the attribute event stream.
36
 * 
37
 * <p>
38
 * The filtering is based on attribute predicates. An attribute predicate is an
39
 * object that you provide and that only defines one method
40
 * {@link AttributePredicate#matches(String, Object)}. If the "matches()" method
41
 * return false, the attribute is discarded from the event stream, else it is
42
 * passed to the listeners of this filter.
43
 * </p>
44
 * 
45
 * <p>
46
 * You can setup a predicate from all attributes (graph, node and edge
47
 * attributes) and specific predicates for graph, node and edge attributes.
48
 * </p>
49
 */
50
public class AttributePipe extends PipeBase {
51
	protected AttributePredicate globalPredicate = new FalsePredicate();
52
53
	protected AttributePredicate graphPredicate = new FalsePredicate();
54
55
	protected AttributePredicate nodePredicate = new FalsePredicate();
56
57
	protected AttributePredicate edgePredicate = new FalsePredicate();
58
59
	/**
60
	 * Set an attribute filter for graph, node and edge attributes. If the
61
	 * filter is null, attributes will not be filtered globally.
62
	 * 
63
	 * @param filter
64
	 *            The filter to use, it can be null to disable global attribute
65
	 *            filtering.
66
	 */
67
	public void setGlobalAttributeFilter(AttributePredicate filter) {
68 1 1. setGlobalAttributeFilter : negated conditional → NO_COVERAGE
		if (filter == null)
69
			globalPredicate = new FalsePredicate();
70
		else
71
			globalPredicate = filter;
72
	}
73
74
	/**
75
	 * Set an attribute filter for graph attributes only (node an edge
76
	 * attributes are not filtered by this filter). If the filter is null, graph
77
	 * attributes will not be filtered.
78
	 * 
79
	 * @param filter
80
	 *            The filter to use, it can be null to disable graph attribute
81
	 *            filtering.
82
	 */
83
	public void setGraphAttributeFilter(AttributePredicate filter) {
84 1 1. setGraphAttributeFilter : negated conditional → NO_COVERAGE
		if (filter == null)
85
			graphPredicate = new FalsePredicate();
86
		else
87
			graphPredicate = filter;
88
	}
89
90
	/**
91
	 * Set an attribute filter for node attributes only (graph an edge
92
	 * attributes are not filtered by this filter). If the filter is null, node
93
	 * attributes will not be filtered.
94
	 * 
95
	 * @param filter
96
	 *            The filter to use, it can be null to disable node attribute
97
	 *            filtering.
98
	 */
99
	public void setNodeAttributeFilter(AttributePredicate filter) {
100 1 1. setNodeAttributeFilter : negated conditional → NO_COVERAGE
		if (filter == null)
101
			nodePredicate = new FalsePredicate();
102
		else
103
			nodePredicate = filter;
104
	}
105
106
	/**
107
	 * Set an attribute filter for edge attributes only (graph an node
108
	 * attributes are not filtered by this filter). If the filter is null, edge
109
	 * attributes will not be filtered.
110
	 * 
111
	 * @param filter
112
	 *            The filter to use, it can be null to disable edge attribute
113
	 *            filtering.
114
	 */
115
	public void setEdgeAttributeFilter(AttributePredicate filter) {
116 1 1. setEdgeAttributeFilter : negated conditional → NO_COVERAGE
		if (filter == null)
117
			edgePredicate = new FalsePredicate();
118
		else
119
			edgePredicate = filter;
120
	}
121
122
	/**
123
	 * The filter for all graph, node and edge attributes. This filter can be
124
	 * null.
125
	 * 
126
	 * @return The global attribute filter or null if there is no global filter.
127
	 */
128
	public AttributePredicate getGlobalAttributeFilter() {
129 1 1. getGlobalAttributeFilter : mutated return of Object value for org/graphstream/stream/AttributePipe::getGlobalAttributeFilter to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return globalPredicate;
130
	}
131
132
	/**
133
	 * The filter for all graph attributes. This filter can be null.
134
	 * 
135
	 * @return The graph attribute filter or null if there is no graph filter.
136
	 */
137
	public AttributePredicate getGraphAttributeFilter() {
138 1 1. getGraphAttributeFilter : mutated return of Object value for org/graphstream/stream/AttributePipe::getGraphAttributeFilter to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return graphPredicate;
139
	}
140
141
	/**
142
	 * The filter for all node attributes. This filter can be null.
143
	 * 
144
	 * @return The node global attribute filter or null if there is no node
145
	 *         filter.
146
	 */
147
	public AttributePredicate getNodeAttributeFilter() {
148 1 1. getNodeAttributeFilter : mutated return of Object value for org/graphstream/stream/AttributePipe::getNodeAttributeFilter to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return nodePredicate;
149
	}
150
151
	/**
152
	 * The filter for all edge attributes. This filter can be null.
153
	 * 
154
	 * @return The edge attribute filter or null of there is no edge filter.
155
	 */
156
	public AttributePredicate getEdgeAttributeFilter() {
157 1 1. getEdgeAttributeFilter : mutated return of Object value for org/graphstream/stream/AttributePipe::getEdgeAttributeFilter to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return edgePredicate;
158
	}
159
160
	// GraphListener
161
162
	@Override
163
	public void edgeAttributeAdded(String graphId, long timeId, String edgeId,
164
			String attribute, Object value) {
165 1 1. edgeAttributeAdded : negated conditional → NO_COVERAGE
		if (!edgePredicate.matches(attribute, value)) {
166 1 1. edgeAttributeAdded : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, value)) {
167 1 1. edgeAttributeAdded : removed call to org/graphstream/stream/AttributePipe::sendEdgeAttributeAdded → NO_COVERAGE
				sendEdgeAttributeAdded(graphId, timeId, edgeId, attribute,
168
						value);
169
			}
170
		}
171
	}
172
173
	@Override
174
	public void edgeAttributeChanged(String graphId, long timeId,
175
			String edgeId, String attribute, Object oldValue, Object newValue) {
176 1 1. edgeAttributeChanged : negated conditional → NO_COVERAGE
		if (!edgePredicate.matches(attribute, newValue)) {
177 1 1. edgeAttributeChanged : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, newValue)) {
178 1 1. edgeAttributeChanged : removed call to org/graphstream/stream/AttributePipe::sendEdgeAttributeChanged → NO_COVERAGE
				sendEdgeAttributeChanged(graphId, timeId, edgeId, attribute,
179
						oldValue, newValue);
180
			}
181
		}
182
	}
183
184
	@Override
185
	public void edgeAttributeRemoved(String graphId, long timeId,
186
			String edgeId, String attribute) {
187 1 1. edgeAttributeRemoved : negated conditional → NO_COVERAGE
		if (!edgePredicate.matches(attribute, null)) {
188 1 1. edgeAttributeRemoved : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, null)) {
189 1 1. edgeAttributeRemoved : removed call to org/graphstream/stream/AttributePipe::sendEdgeAttributeRemoved → NO_COVERAGE
				sendEdgeAttributeRemoved(graphId, timeId, edgeId, attribute);
190
			}
191
		}
192
	}
193
194
	@Override
195
	public void graphAttributeAdded(String graphId, long timeId,
196
			String attribute, Object value) {
197 1 1. graphAttributeAdded : negated conditional → NO_COVERAGE
		if (!graphPredicate.matches(attribute, value)) {
198 1 1. graphAttributeAdded : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, value)) {
199 1 1. graphAttributeAdded : removed call to org/graphstream/stream/AttributePipe::sendGraphAttributeAdded → NO_COVERAGE
				sendGraphAttributeAdded(graphId, timeId, attribute, value);
200
			}
201
		}
202
	}
203
204
	@Override
205
	public void graphAttributeChanged(String graphId, long timeId,
206
			String attribute, Object oldValue, Object newValue) {
207 1 1. graphAttributeChanged : negated conditional → NO_COVERAGE
		if (!graphPredicate.matches(attribute, newValue)) {
208 1 1. graphAttributeChanged : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, newValue)) {
209 1 1. graphAttributeChanged : removed call to org/graphstream/stream/AttributePipe::sendGraphAttributeChanged → NO_COVERAGE
				sendGraphAttributeChanged(graphId, timeId, attribute, oldValue,
210
						newValue);
211
			}
212
		}
213
	}
214
215
	@Override
216
	public void graphAttributeRemoved(String graphId, long timeId,
217
			String attribute) {
218 1 1. graphAttributeRemoved : negated conditional → NO_COVERAGE
		if (!graphPredicate.matches(attribute, null)) {
219 1 1. graphAttributeRemoved : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, null)) {
220 1 1. graphAttributeRemoved : removed call to org/graphstream/stream/AttributePipe::sendGraphAttributeRemoved → NO_COVERAGE
				sendGraphAttributeRemoved(graphId, timeId, attribute);
221
			}
222
		}
223
	}
224
225
	@Override
226
	public void nodeAttributeAdded(String graphId, long timeId, String nodeId,
227
			String attribute, Object value) {
228 1 1. nodeAttributeAdded : negated conditional → NO_COVERAGE
		if (!nodePredicate.matches(attribute, value)) {
229 1 1. nodeAttributeAdded : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, value)) {
230 1 1. nodeAttributeAdded : removed call to org/graphstream/stream/AttributePipe::sendNodeAttributeAdded → NO_COVERAGE
				sendNodeAttributeAdded(graphId, timeId, nodeId, attribute,
231
						value);
232
			}
233
		}
234
	}
235
236
	@Override
237
	public void nodeAttributeChanged(String graphId, long timeId,
238
			String nodeId, String attribute, Object oldValue, Object newValue) {
239 1 1. nodeAttributeChanged : negated conditional → NO_COVERAGE
		if (!nodePredicate.matches(attribute, newValue)) {
240 1 1. nodeAttributeChanged : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, newValue)) {
241 1 1. nodeAttributeChanged : removed call to org/graphstream/stream/AttributePipe::sendNodeAttributeChanged → NO_COVERAGE
				sendNodeAttributeChanged(graphId, timeId, nodeId, attribute,
242
						oldValue, newValue);
243
			}
244
		}
245
	}
246
247
	@Override
248
	public void nodeAttributeRemoved(String graphId, long timeId,
249
			String nodeId, String attribute) {
250 1 1. nodeAttributeRemoved : negated conditional → NO_COVERAGE
		if (!nodePredicate.matches(attribute, null)) {
251 1 1. nodeAttributeRemoved : negated conditional → NO_COVERAGE
			if (!globalPredicate.matches(attribute, null)) {
252 1 1. nodeAttributeRemoved : removed call to org/graphstream/stream/AttributePipe::sendNodeAttributeRemoved → NO_COVERAGE
				sendNodeAttributeRemoved(graphId, timeId, nodeId, attribute);
253
			}
254
		}
255
	}
256
257
	protected class FalsePredicate implements AttributePredicate {
258
		public boolean matches(String attributeName, Object attributeValue) {
259 1 1. matches : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
			return false;
260
		}
261
262
	}
263
}

Mutations

68

1.1
Location : setGlobalAttributeFilter
Killed by : none
negated conditional → NO_COVERAGE

84

1.1
Location : setGraphAttributeFilter
Killed by : none
negated conditional → NO_COVERAGE

100

1.1
Location : setNodeAttributeFilter
Killed by : none
negated conditional → NO_COVERAGE

116

1.1
Location : setEdgeAttributeFilter
Killed by : none
negated conditional → NO_COVERAGE

129

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

138

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

148

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

157

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

165

1.1
Location : edgeAttributeAdded
Killed by : none
negated conditional → NO_COVERAGE

166

1.1
Location : edgeAttributeAdded
Killed by : none
negated conditional → NO_COVERAGE

167

1.1
Location : edgeAttributeAdded
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendEdgeAttributeAdded → NO_COVERAGE

176

1.1
Location : edgeAttributeChanged
Killed by : none
negated conditional → NO_COVERAGE

177

1.1
Location : edgeAttributeChanged
Killed by : none
negated conditional → NO_COVERAGE

178

1.1
Location : edgeAttributeChanged
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendEdgeAttributeChanged → NO_COVERAGE

187

1.1
Location : edgeAttributeRemoved
Killed by : none
negated conditional → NO_COVERAGE

188

1.1
Location : edgeAttributeRemoved
Killed by : none
negated conditional → NO_COVERAGE

189

1.1
Location : edgeAttributeRemoved
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendEdgeAttributeRemoved → NO_COVERAGE

197

1.1
Location : graphAttributeAdded
Killed by : none
negated conditional → NO_COVERAGE

198

1.1
Location : graphAttributeAdded
Killed by : none
negated conditional → NO_COVERAGE

199

1.1
Location : graphAttributeAdded
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendGraphAttributeAdded → NO_COVERAGE

207

1.1
Location : graphAttributeChanged
Killed by : none
negated conditional → NO_COVERAGE

208

1.1
Location : graphAttributeChanged
Killed by : none
negated conditional → NO_COVERAGE

209

1.1
Location : graphAttributeChanged
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendGraphAttributeChanged → NO_COVERAGE

218

1.1
Location : graphAttributeRemoved
Killed by : none
negated conditional → NO_COVERAGE

219

1.1
Location : graphAttributeRemoved
Killed by : none
negated conditional → NO_COVERAGE

220

1.1
Location : graphAttributeRemoved
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendGraphAttributeRemoved → NO_COVERAGE

228

1.1
Location : nodeAttributeAdded
Killed by : none
negated conditional → NO_COVERAGE

229

1.1
Location : nodeAttributeAdded
Killed by : none
negated conditional → NO_COVERAGE

230

1.1
Location : nodeAttributeAdded
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendNodeAttributeAdded → NO_COVERAGE

239

1.1
Location : nodeAttributeChanged
Killed by : none
negated conditional → NO_COVERAGE

240

1.1
Location : nodeAttributeChanged
Killed by : none
negated conditional → NO_COVERAGE

241

1.1
Location : nodeAttributeChanged
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendNodeAttributeChanged → NO_COVERAGE

250

1.1
Location : nodeAttributeRemoved
Killed by : none
negated conditional → NO_COVERAGE

251

1.1
Location : nodeAttributeRemoved
Killed by : none
negated conditional → NO_COVERAGE

252

1.1
Location : nodeAttributeRemoved
Killed by : none
removed call to org/graphstream/stream/AttributePipe::sendNodeAttributeRemoved → NO_COVERAGE

259

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

Active mutators

Tests examined


Report generated by PIT 0.33