1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
| package java.util.stream;
import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.Objects;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.PrimitiveIterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntConsumer;
import java.util.function.IntFunction;
import java.util.function.IntPredicate;
import java.util.function.IntSupplier;
import java.util.function.IntToDoubleFunction;
import java.util.function.IntToLongFunction;
import java.util.function.IntUnaryOperator;
import java.util.function.ObjIntConsumer;
import java.util.function.Supplier;
public interface IntStream extends BaseStream<Integer, IntStream> {
IntStream filter(IntPredicate predicate);
IntStream map(IntUnaryOperator mapper);
<U> Stream<U> mapToObj(IntFunction<? extends U> mapper);
LongStream mapToLong(IntToLongFunction mapper);
DoubleStream mapToDouble(IntToDoubleFunction mapper);
IntStream flatMap(IntFunction<? extends IntStream> mapper);
IntStream distinct();
IntStream sorted();
IntStream peek(IntConsumer action);
IntStream limit(long maxSize);
IntStream skip(long n);
void forEach(IntConsumer action);
void forEachOrdered(IntConsumer action);
int[] toArray();
int reduce(int identity, IntBinaryOperator op);
OptionalInt reduce(IntBinaryOperator op);
<R> R collect(Supplier<R> supplier,
ObjIntConsumer<R> accumulator,
BiConsumer<R, R> combiner);
int sum();
OptionalInt min();
OptionalInt max();
long count();
OptionalDouble average();
IntSummaryStatistics summaryStatistics();
boolean anyMatch(IntPredicate predicate);
boolean allMatch(IntPredicate predicate);
boolean noneMatch(IntPredicate predicate);
OptionalInt findFirst();
OptionalInt findAny();
LongStream asLongStream();
DoubleStream asDoubleStream();
Stream<Integer> boxed();
@Override
IntStream sequential();
@Override
IntStream parallel();
@Override
PrimitiveIterator.OfInt iterator();
@Override
Spliterator.OfInt spliterator();
// Static factories
public static Builder builder() {
return new Streams.IntStreamBuilderImpl();
}
public static IntStream empty() {
return StreamSupport.intStream(Spliterators.emptyIntSpliterator(), false);
}
public static IntStream of(int t) {
return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t), false);
}
public static IntStream of(int... values) {
return Arrays.stream(values);
}
public static IntStream iterate(final int seed, final IntUnaryOperator f) {
Objects.requireNonNull(f);
final PrimitiveIterator.OfInt iterator = new PrimitiveIterator.OfInt() {
int t = seed;
@Override
public boolean hasNext() {
return true;
}
@Override
public int nextInt() {
int v = t;
t = f.applyAsInt(t);
return v;
}
};
return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(
iterator,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
public static IntStream generate(IntSupplier s) {
Objects.requireNonNull(s);
return StreamSupport.intStream(
new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s), false);
}
public static IntStream range(int startInclusive, int endExclusive) {
if (startInclusive >= endExclusive) {
return empty();
} else {
return StreamSupport.intStream(
new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false);
}
}
public static IntStream rangeClosed(int startInclusive, int endInclusive) {
if (startInclusive > endInclusive) {
return empty();
} else {
return StreamSupport.intStream(
new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false);
}
}
public static IntStream concat(IntStream a, IntStream b) {
Objects.requireNonNull(a);
Objects.requireNonNull(b);
Spliterator.OfInt split = new Streams.ConcatSpliterator.OfInt(
a.spliterator(), b.spliterator());
IntStream stream = StreamSupport.intStream(split, a.isParallel() || b.isParallel());
return stream.onClose(Streams.composedClose(a, b));
}
public interface Builder extends IntConsumer {
@Override
void accept(int t);
default Builder add(int t) {
accept(t);
return this;
}
IntStream build();
}
}
|