1 |
|
package io.sunshower.lambda.spliterators; |
2 |
|
|
3 |
|
import java.util.Comparator; |
4 |
|
import java.util.Spliterator; |
5 |
|
import java.util.function.Consumer; |
6 |
|
import java.util.function.Predicate; |
7 |
|
|
|
|
| 47.4% |
Uncovered Elements: 10 (19) |
Complexity: 8 |
Complexity Density: 0.89 |
|
8 |
|
public class TakeWhile<T> implements Spliterator<T> { |
9 |
|
|
10 |
|
private final Spliterator<T> source; |
11 |
|
private final Predicate<T> condition; |
12 |
|
private boolean conditionHolds = true; |
13 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
14 |
3 |
public TakeWhile(Spliterator<T> source, Predicate<T> condition) {... |
15 |
3 |
this.source = source; |
16 |
3 |
this.condition = condition; |
17 |
|
} |
18 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
19 |
25 |
@Override... |
20 |
|
public boolean tryAdvance(Consumer<? super T> action) { |
21 |
25 |
return conditionHolds |
22 |
|
&& source.tryAdvance( |
23 |
|
e -> { |
24 |
? |
if (conditionHolds = condition.test(e)) { |
25 |
20 |
action.accept(e); |
26 |
|
} |
27 |
|
}); |
28 |
|
} |
29 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
30 |
0 |
@Override... |
31 |
|
public Spliterator<T> trySplit() { |
32 |
0 |
return null; |
33 |
|
} |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
35 |
0 |
@Override... |
36 |
|
public long estimateSize() { |
37 |
0 |
return conditionHolds ? source.estimateSize() : 0; |
38 |
|
} |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
6 |
@Override... |
41 |
|
public int characteristics() { |
42 |
6 |
return source.characteristics() & ~Spliterator.SIZED; |
43 |
|
} |
44 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
0 |
@Override... |
46 |
|
public Comparator<? super T> getComparator() { |
47 |
0 |
return source.getComparator(); |
48 |
|
} |
49 |
|
} |