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.file; | |
33 | ||
34 | import java.io.FileNotFoundException; | |
35 | import java.io.IOException; | |
36 | import java.io.OutputStream; | |
37 | import java.io.RandomAccessFile; | |
38 | import java.io.Writer; | |
39 | import java.nio.ByteBuffer; | |
40 | import java.nio.ByteOrder; | |
41 | import java.nio.channels.FileChannel; | |
42 | ||
43 | import org.graphstream.graph.Graph; | |
44 | ||
45 | /** | |
46 | * This class intends to output a dynamic graph into a Flash animation. | |
47 | * | |
48 | * <p> | |
49 | * <b>This work may never to any usable feature. Please do not try to use it or | |
50 | * ask for help about it.</b> | |
51 | * </p> | |
52 | */ | |
53 | public class FileSinkSWF implements FileSink { | |
54 | private static class BitString { | |
55 | /** | |
56 | * Bit 0 mask. | |
57 | **/ | |
58 | protected static final byte BIT_0 = (byte) Integer.parseInt("10000000", | |
59 | 2); | |
60 | /** | |
61 | * Bit 1 mask. | |
62 | **/ | |
63 | protected static final byte BIT_1 = (byte) Integer.parseInt("01000000", | |
64 | 2); | |
65 | /** | |
66 | * Bit 2 mask. | |
67 | **/ | |
68 | protected static final byte BIT_2 = (byte) Integer.parseInt("00100000", | |
69 | 2); | |
70 | /** | |
71 | * Bit 3 mask. | |
72 | **/ | |
73 | protected static final byte BIT_3 = (byte) Integer.parseInt("00010000", | |
74 | 2); | |
75 | /** | |
76 | * Bit 4 mask. | |
77 | **/ | |
78 | protected static final byte BIT_4 = (byte) Integer.parseInt("00001000", | |
79 | 2); | |
80 | /** | |
81 | * Bit 5 mask. | |
82 | **/ | |
83 | protected static final byte BIT_5 = (byte) Integer.parseInt("00000100", | |
84 | 2); | |
85 | /** | |
86 | * Bit 6 mask. | |
87 | **/ | |
88 | protected static final byte BIT_6 = (byte) Integer.parseInt("00000010", | |
89 | 2); | |
90 | /** | |
91 | * Bit 7 mask. | |
92 | **/ | |
93 | protected static final byte BIT_7 = (byte) Integer.parseInt("00000001", | |
94 | 2); | |
95 | /** | |
96 | * Set of all masks. | |
97 | **/ | |
98 | protected static final byte[] BITS = { BIT_0, BIT_1, BIT_2, BIT_3, | |
99 | BIT_4, BIT_5, BIT_6, BIT_7 }; | |
100 | ||
101 | /** | |
102 | * Buffer storing data. | |
103 | * | |
104 | * @see java.nio.ByteBuffer | |
105 | **/ | |
106 | protected ByteBuffer buffer; | |
107 | /** | |
108 | * Size of the buffer, current pointers. | |
109 | **/ | |
110 | private int size, curseur, bitCurseur; | |
111 | ||
112 | BitString(int... values) { | |
113 | this.size = this.curseur = this.bitCurseur = 0; | |
114 | ||
115 | int bitsize = 0; | |
116 | ||
117 |
3
1. 2. 3. |
for (int i = 0; i < values.length; i++) |
118 | bitsize = Math.max(bitsize, | |
119 | Integer.toBinaryString(Math.abs(values[i])).length()); | |
120 | ||
121 |
3
1. 2. 3. |
int totalbits = 5 + values.length * (bitsize + 1); |
122 | ||
123 |
5
1. 2. 3. 4. 5. |
__resize(totalbits / 8 + (totalbits % 8 == 0 ? 0 : 1)); |
124 |
1
1. |
fill(false); |
125 | ||
126 |
1
1. |
String sizeBinary = Integer.toBinaryString(bitsize + 1); |
127 |
3
1. 2. 3. |
for (int i = sizeBinary.length() - 1; i > Math.max(0, |
128 |
2
1. 2. |
sizeBinary.length() - 6); i--) |
129 |
2
1. 2. |
add(sizeBinary.charAt(i) != '0'); |
130 |
3
1. 2. 3. |
for (int i = sizeBinary.length(); i < 5; i++) |
131 |
1
1. |
add(false); |
132 | ||
133 | String valueBinary; | |
134 |
3
1. 2. 3. |
for (int i = 0; i < values.length; i++) { |
135 |
3
1. 2. 3. |
add(values[i] < 0); |
136 | valueBinary = Integer.toBinaryString(Math.abs(values[i])); | |
137 | ||
138 |
3
1. 2. 3. |
for (int j = 0; j < bitsize; j++) { |
139 |
2
1. 2. |
if (j < valueBinary.length()) |
140 |
4
1. 2. 3. 4. |
add(valueBinary.charAt(bitsize - 1 - j) != '0'); |
141 | else | |
142 |
3
1. 2. 3. |
add(values[i] < 0); |
143 | } | |
144 | } | |
145 | } | |
146 | ||
147 | /** | |
148 | * Resize the string. | |
149 | * | |
150 | * @param size | |
151 | * in bytes new size | |
152 | **/ | |
153 | private void __resize(int size) { | |
154 | ByteBuffer nBuffer = ByteBuffer.allocate(size); | |
155 | ||
156 |
3
1. __resize : changed conditional boundary → NO_COVERAGE 2. __resize : Changed increment from 1 to -1 → NO_COVERAGE 3. __resize : negated conditional → NO_COVERAGE |
for (int i = 0; i < Math.min(this.size, size); i++) |
157 | nBuffer.put(buffer.get(i)); | |
158 | ||
159 | this.buffer = nBuffer; | |
160 | this.size = size; | |
161 | } | |
162 | ||
163 | /** | |
164 | * Bit value at the given index. | |
165 | * | |
166 | * @param index | |
167 | * bit index | |
168 | **/ | |
169 | public boolean valueAt(int index) { | |
170 |
6
1. valueAt : Replaced integer division with multiplication → NO_COVERAGE 2. valueAt : Replaced integer modulus with multiplication → NO_COVERAGE 3. valueAt : Replaced bitwise AND with OR → NO_COVERAGE 4. valueAt : negated conditional → NO_COVERAGE 5. valueAt : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE 6. valueAt : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (buffer.get(index / 8) & BITS[index % 8]) != 0; |
171 | } | |
172 | ||
173 | /** | |
174 | * Add a bit. | |
175 | * | |
176 | * @param value | |
177 | * bit value | |
178 | **/ | |
179 | public void add(boolean value) { | |
180 |
2
1. add : changed conditional boundary → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE |
if (curseur >= size) { |
181 |
2
1. add : Replaced integer addition with subtraction → NO_COVERAGE 2. add : removed call to org/graphstream/stream/file/FileSinkSWF$BitString::__resize → NO_COVERAGE |
__resize(size + 1); |
182 | } | |
183 | ||
184 |
1
1. add : negated conditional → NO_COVERAGE |
if (value) { |
185 | byte val = buffer.get(curseur); | |
186 |
3
1. add : Replaced integer subtraction with addition → NO_COVERAGE 2. add : Replaced Shift Left with Shift Right → NO_COVERAGE 3. add : Replaced bitwise OR with AND → NO_COVERAGE |
val = (byte) (val | (1 << (7 - bitCurseur))); |
187 | buffer.put(curseur, val); | |
188 | } | |
189 | ||
190 |
1
1. add : Replaced integer addition with subtraction → NO_COVERAGE |
bitCurseur++; |
191 | ||
192 |
2
1. add : changed conditional boundary → NO_COVERAGE 2. add : negated conditional → NO_COVERAGE |
if (bitCurseur > 7) { |
193 | bitCurseur = 0; | |
194 |
1
1. add : Replaced integer addition with subtraction → NO_COVERAGE |
curseur++; |
195 | } | |
196 | } | |
197 | ||
198 | /** | |
199 | * Fill with the given value. | |
200 | */ | |
201 | public void fill(boolean v) { | |
202 |
2
1. fill : Replaced integer multiplication with division → NO_COVERAGE 2. fill : removed call to org/graphstream/stream/file/FileSinkSWF$BitString::fill → NO_COVERAGE |
fill(v, 0, size * 8); |
203 | } | |
204 | ||
205 | public void fill(boolean v, int offset, int size) { | |
206 |
4
1. fill : changed conditional boundary → NO_COVERAGE 2. fill : Changed increment from 1 to -1 → NO_COVERAGE 3. fill : Replaced integer addition with subtraction → NO_COVERAGE 4. fill : negated conditional → NO_COVERAGE |
for (int i = offset; i < offset + size; i++) { |
207 |
1
1. fill : removed call to org/graphstream/stream/file/FileSinkSWF$BitString::setValue → NO_COVERAGE |
setValue(i, v); |
208 | } | |
209 | } | |
210 | ||
211 | public void setValue(int id, boolean v) { | |
212 |
1
1. setValue : Replaced integer division with multiplication → NO_COVERAGE |
byte val = buffer.get(id / 8); |
213 | ||
214 |
1
1. setValue : negated conditional → NO_COVERAGE |
if (v) { |
215 |
4
1. setValue : Replaced integer modulus with multiplication → NO_COVERAGE 2. setValue : Replaced integer subtraction with addition → NO_COVERAGE 3. setValue : Replaced Shift Left with Shift Right → NO_COVERAGE 4. setValue : Replaced bitwise OR with AND → NO_COVERAGE |
val = (byte) (val | (1 << (7 - (id % 8)))); |
216 | } else { | |
217 |
5
1. setValue : Replaced integer modulus with multiplication → NO_COVERAGE 2. setValue : Replaced integer subtraction with addition → NO_COVERAGE 3. setValue : Replaced Shift Left with Shift Right → NO_COVERAGE 4. setValue : Replaced XOR with AND → NO_COVERAGE 5. setValue : Replaced bitwise AND with OR → NO_COVERAGE |
val = (byte) (val & (~(1 << (7 - (id % 8))))); |
218 | } | |
219 | ||
220 |
1
1. setValue : Replaced integer division with multiplication → NO_COVERAGE |
buffer.put(id / 8, val); |
221 | } | |
222 | ||
223 | /** | |
224 | * BitString to string. | |
225 | **/ | |
226 | @Override | |
227 | public String toString() { | |
228 | StringBuffer b = new StringBuffer(); | |
229 |
3
1. toString : changed conditional boundary → NO_COVERAGE 2. toString : Changed increment from 1 to -1 → NO_COVERAGE 3. toString : negated conditional → NO_COVERAGE |
for (int i = 0; i < curseur; i++) { |
230 |
3
1. toString : changed conditional boundary → NO_COVERAGE 2. toString : Changed increment from 1 to -1 → NO_COVERAGE 3. toString : negated conditional → NO_COVERAGE |
for (int j = 0; j < 8; j++) |
231 |
3
1. toString : Replaced integer multiplication with division → NO_COVERAGE 2. toString : Replaced integer addition with subtraction → NO_COVERAGE 3. toString : negated conditional → NO_COVERAGE |
b.append(valueAt(i * 8 + j) ? '1' : '0'); |
232 | } | |
233 |
3
1. toString : changed conditional boundary → NO_COVERAGE 2. toString : Changed increment from 1 to -1 → NO_COVERAGE 3. toString : negated conditional → NO_COVERAGE |
for (int i = 0; i < bitCurseur; i++) |
234 |
3
1. toString : Replaced integer multiplication with division → NO_COVERAGE 2. toString : Replaced integer addition with subtraction → NO_COVERAGE 3. toString : negated conditional → NO_COVERAGE |
b.append(valueAt(curseur * 8 + i) ? '1' : '0'); |
235 |
1
1. toString : mutated return of Object value for org/graphstream/stream/file/FileSinkSWF$BitString::toString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return b.toString(); |
236 | } | |
237 | } | |
238 | ||
239 | private final static int BUFFER_SIZE = 1024000; | |
240 | ||
241 | private final static byte F = 0x46; | |
242 | private final static byte W = 0x57; | |
243 | private final static byte S = 0x53; | |
244 | private final static byte VERSION = 0x0A; | |
245 | ||
246 | ByteBuffer buffer; | |
247 | FileChannel channel; | |
248 | ||
249 | long position; | |
250 | long currentSize; | |
251 | ||
252 | @SuppressWarnings("unused") | |
253 | private void initChannelAndBuffer(String path) { | |
254 |
1
1. initChannelAndBuffer : negated conditional → NO_COVERAGE |
if (channel != null) |
255 |
1
1. initChannelAndBuffer : removed call to org/graphstream/stream/file/FileSinkSWF::closeCurrentChannel → NO_COVERAGE |
closeCurrentChannel(); |
256 | ||
257 | try { | |
258 | RandomAccessFile file = new RandomAccessFile(path, "rw"); | |
259 | ||
260 | channel = file.getChannel(); | |
261 | buffer = ByteBuffer.allocateDirect(BUFFER_SIZE); | |
262 | buffer.order(ByteOrder.LITTLE_ENDIAN); | |
263 | ||
264 | position = 0; | |
265 | currentSize = 0; | |
266 | } catch (FileNotFoundException e) { | |
267 |
1
1. initChannelAndBuffer : removed call to java/io/FileNotFoundException::printStackTrace → NO_COVERAGE |
e.printStackTrace(); |
268 | } | |
269 | } | |
270 | ||
271 | private void closeCurrentChannel() { | |
272 | ||
273 | } | |
274 | ||
275 | @SuppressWarnings("unused") | |
276 | private void writeHeader() { | |
277 | buffer.put(F); | |
278 | buffer.put(W); | |
279 | buffer.put(S); | |
280 | buffer.put(VERSION); | |
281 | buffer.putInt(0); | |
282 |
1
1. writeHeader : removed call to org/graphstream/stream/file/FileSinkSWF::writeRECT → NO_COVERAGE |
writeRECT(buffer, 0, 0, 0, 0); |
283 | buffer.putShort((short) 0); | |
284 | } | |
285 | ||
286 | private static void writeRECT(ByteBuffer buffer, int xmin, int xmax, | |
287 | int ymin, int ymax) { | |
288 |
1
1. writeRECT : removed call to org/graphstream/stream/file/FileSinkSWF::writeSingleBits → NO_COVERAGE |
writeSingleBits(buffer, xmin, xmax, ymin, ymax); |
289 | } | |
290 | ||
291 | private static void writeSingleBits(ByteBuffer buffer, int... values) { | |
292 | int max = Integer.MIN_VALUE; | |
293 | ||
294 |
3
1. writeSingleBits : changed conditional boundary → NO_COVERAGE 2. writeSingleBits : Changed increment from 1 to -1 → NO_COVERAGE 3. writeSingleBits : negated conditional → NO_COVERAGE |
for (int i = 0; i < values.length; i++) |
295 | max = Math.max(max, Math.abs(values[i])); | |
296 | ||
297 | } | |
298 | ||
299 | public void begin(String fileName) throws IOException { | |
300 | // TODO Auto-generated method stub | |
301 | ||
302 | } | |
303 | ||
304 | public void begin(OutputStream stream) throws IOException { | |
305 | // TODO Auto-generated method stub | |
306 | ||
307 | } | |
308 | ||
309 | public void begin(Writer writer) throws IOException { | |
310 | | |
311 | } | |
312 | | |
313 | public void end() throws IOException { | |
314 | // TODO Auto-generated method stub | |
315 | ||
316 | } | |
317 | ||
318 | public void flush() throws IOException { | |
319 | // TODO Auto-generated method stub | |
320 | ||
321 | } | |
322 | ||
323 | public void writeAll(Graph graph, String fileName) throws IOException { | |
324 | // TODO Auto-generated method stub | |
325 | ||
326 | } | |
327 | ||
328 | public void writeAll(Graph graph, OutputStream stream) throws IOException { | |
329 | // TODO Auto-generated method stub | |
330 | ||
331 | } | |
332 | ||
333 | public void writeAll(Graph graph, Writer writer) throws IOException { | |
334 | | |
335 | } | |
336 | | |
337 | public void edgeAttributeAdded(String graphId, long timeId, String edgeId, | |
338 | String attribute, Object value) { | |
339 | // TODO Auto-generated method stub | |
340 | ||
341 | } | |
342 | ||
343 | public void edgeAttributeChanged(String graphId, long timeId, | |
344 | String edgeId, String attribute, Object oldValue, Object newValue) { | |
345 | // TODO Auto-generated method stub | |
346 | ||
347 | } | |
348 | ||
349 | public void edgeAttributeRemoved(String graphId, long timeId, | |
350 | String edgeId, String attribute) { | |
351 | // TODO Auto-generated method stub | |
352 | ||
353 | } | |
354 | ||
355 | public void graphAttributeAdded(String graphId, long timeId, | |
356 | String attribute, Object value) { | |
357 | // TODO Auto-generated method stub | |
358 | ||
359 | } | |
360 | ||
361 | public void graphAttributeChanged(String graphId, long timeId, | |
362 | String attribute, Object oldValue, Object newValue) { | |
363 | // TODO Auto-generated method stub | |
364 | ||
365 | } | |
366 | ||
367 | public void graphAttributeRemoved(String graphId, long timeId, | |
368 | String attribute) { | |
369 | // TODO Auto-generated method stub | |
370 | ||
371 | } | |
372 | ||
373 | public void nodeAttributeAdded(String graphId, long timeId, String nodeId, | |
374 | String attribute, Object value) { | |
375 | // TODO Auto-generated method stub | |
376 | ||
377 | } | |
378 | ||
379 | public void nodeAttributeChanged(String graphId, long timeId, | |
380 | String nodeId, String attribute, Object oldValue, Object newValue) { | |
381 | // TODO Auto-generated method stub | |
382 | ||
383 | } | |
384 | ||
385 | public void nodeAttributeRemoved(String graphId, long timeId, | |
386 | String nodeId, String attribute) { | |
387 | // TODO Auto-generated method stub | |
388 | ||
389 | } | |
390 | ||
391 | public void edgeAdded(String graphId, long timeId, String edgeId, | |
392 | String fromNodeId, String toNodeId, boolean directed) { | |
393 | // TODO Auto-generated method stub | |
394 | ||
395 | } | |
396 | ||
397 | public void edgeRemoved(String graphId, long timeId, String edgeId) { | |
398 | // TODO Auto-generated method stub | |
399 | ||
400 | } | |
401 | ||
402 | public void graphCleared(String graphId, long timeId) { | |
403 | // TODO Auto-generated method stub | |
404 | ||
405 | } | |
406 | ||
407 | public void nodeAdded(String graphId, long timeId, String nodeId) { | |
408 | // TODO Auto-generated method stub | |
409 | ||
410 | } | |
411 | ||
412 | public void nodeRemoved(String graphId, long timeId, String nodeId) { | |
413 | // TODO Auto-generated method stub | |
414 | ||
415 | } | |
416 | ||
417 | public void stepBegins(String graphId, long timeId, double time) { | |
418 | // TODO Auto-generated method stub | |
419 | ||
420 | } | |
421 | ||
422 | public static void main(String[] args) { | |
423 | BitString bs = new BitString(1024, -1024); | |
424 |
1
1. main : removed call to java/io/PrintStream::println → NO_COVERAGE |
System.out.println(bs); |
425 | } | |
426 | } | |
Mutations | ||
117 |
1.1 2.2 3.3 |
|
121 |
1.1 2.2 3.3 |
|
123 |
1.1 2.2 3.3 4.4 5.5 |
|
124 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 2.2 3.3 |
|
128 |
1.1 2.2 |
|
129 |
1.1 2.2 |
|
130 |
1.1 2.2 3.3 |
|
131 |
1.1 |
|
134 |
1.1 2.2 3.3 |
|
135 |
1.1 2.2 3.3 |
|
138 |
1.1 2.2 3.3 |
|
139 |
1.1 2.2 |
|
140 |
1.1 2.2 3.3 4.4 |
|
142 |
1.1 2.2 3.3 |
|
156 |
1.1 2.2 3.3 |
|
170 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
180 |
1.1 2.2 |
|
181 |
1.1 2.2 |
|
184 |
1.1 |
|
186 |
1.1 2.2 3.3 |
|
190 |
1.1 |
|
192 |
1.1 2.2 |
|
194 |
1.1 |
|
202 |
1.1 2.2 |
|
206 |
1.1 2.2 3.3 4.4 |
|
207 |
1.1 |
|
212 |
1.1 |
|
214 |
1.1 |
|
215 |
1.1 2.2 3.3 4.4 |
|
217 |
1.1 2.2 3.3 4.4 5.5 |
|
220 |
1.1 |
|
229 |
1.1 2.2 3.3 |
|
230 |
1.1 2.2 3.3 |
|
231 |
1.1 2.2 3.3 |
|
233 |
1.1 2.2 3.3 |
|
234 |
1.1 2.2 3.3 |
|
235 |
1.1 |
|
254 |
1.1 |
|
255 |
1.1 |
|
267 |
1.1 |
|
282 |
1.1 |
|
288 |
1.1 |
|
294 |
1.1 2.2 3.3 |
|
424 |
1.1 |