1 | /*- | |
2 | * #%L | |
3 | * io.earcam.instrumental.io | |
4 | * %% | |
5 | * Copyright (C) 2018 earcam | |
6 | * %% | |
7 | * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT) | |
8 | * | |
9 | * You <b>must</b> choose to accept, in full - any individual or combination of | |
10 | * the following licenses: | |
11 | * <ul> | |
12 | * <li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li> | |
13 | * <li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li> | |
14 | * <li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li> | |
15 | * <li><a href="https://opensource.org/licenses/MIT">MIT</a></li> | |
16 | * </ul> | |
17 | * #L% | |
18 | */ | |
19 | package io.earcam.utilitarian.io; | |
20 | ||
21 | import java.util.Collections; | |
22 | import java.util.Iterator; | |
23 | import java.util.NoSuchElementException; | |
24 | import java.util.Set; | |
25 | ||
26 | class Filterator<E> implements Iterator<E> { | |
27 | ||
28 | private Iterator<E> iterator; | |
29 | private Set<E> excludes; | |
30 | private E next; | |
31 | private boolean checked; | |
32 | ||
33 | ||
34 | Filterator(Iterator<E> iterator, E exclude) | |
35 | { | |
36 | this(iterator, Collections.singleton(exclude)); | |
37 | } | |
38 | ||
39 | ||
40 | Filterator(Iterator<E> iterator, Set<E> excludes) | |
41 | { | |
42 | this.iterator = iterator; | |
43 | this.excludes = excludes; | |
44 | } | |
45 | ||
46 | ||
47 | @Override | |
48 | public boolean hasNext() | |
49 | { | |
50 |
4
1. hasNext : negated conditional → KILLED 2. hasNext : negated conditional → KILLED 3. hasNext : negated conditional → KILLED 4. hasNext : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return checked || (iterator.hasNext() && checkNext()); |
51 | } | |
52 | ||
53 | ||
54 | private boolean checkNext() | |
55 | { | |
56 | next = iterator.next(); | |
57 |
1
1. checkNext : negated conditional → KILLED |
if(excludes.contains(next)) { |
58 |
1
1. checkNext : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return hasNext(); |
59 | } | |
60 | checked = true; | |
61 |
1
1. checkNext : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED |
return true; |
62 | } | |
63 | ||
64 | ||
65 | @Override | |
66 | public E next() | |
67 | { | |
68 |
2
1. next : negated conditional → KILLED 2. next : negated conditional → KILLED |
if(!(checked || hasNext())) { |
69 | throw new NoSuchElementException(); | |
70 | } | |
71 | checked = false; | |
72 |
1
1. next : mutated return of Object value for io/earcam/utilitarian/io/Filterator::next to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return next; |
73 | } | |
74 | } | |
Mutations | ||
50 |
1.1 2.2 3.3 4.4 |
|
57 |
1.1 |
|
58 |
1.1 |
|
61 |
1.1 |
|
68 |
1.1 2.2 |
|
72 |
1.1 |