2
* Copyright 2014 Goldman Sachs.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package com.gs.collections.api;
19
import java.util.Comparator;
21
import com.gs.collections.api.annotation.Beta;
22
import com.gs.collections.api.bag.MutableBag;
23
import com.gs.collections.api.block.function.Function;
24
import com.gs.collections.api.block.function.Function0;
25
import com.gs.collections.api.block.function.Function2;
26
import com.gs.collections.api.block.function.primitive.DoubleFunction;
27
import com.gs.collections.api.block.function.primitive.FloatFunction;
28
import com.gs.collections.api.block.function.primitive.IntFunction;
29
import com.gs.collections.api.block.function.primitive.LongFunction;
30
import com.gs.collections.api.block.predicate.Predicate;
31
import com.gs.collections.api.block.predicate.Predicate2;
32
import com.gs.collections.api.block.procedure.Procedure;
33
import com.gs.collections.api.block.procedure.Procedure2;
34
import com.gs.collections.api.list.MutableList;
35
import com.gs.collections.api.map.MapIterable;
36
import com.gs.collections.api.map.MutableMap;
37
import com.gs.collections.api.map.sorted.MutableSortedMap;
38
import com.gs.collections.api.multimap.Multimap;
39
import com.gs.collections.api.set.MutableSet;
40
import com.gs.collections.api.set.sorted.MutableSortedSet;
43
* A ParallelIterable is RichIterable which will defer evaluation for certain methods like select, reject, collect, etc.
44
* Any methods that do not return a ParallelIterable when called will cause evaluation to be forced. Evaluation occurs
45
* in parallel. All code blocks passed in must be stateless or thread-safe.
50
public interface ParallelIterable<T>
52
ParallelIterable<T> asUnique();
55
* Creates a parallel iterable for selecting elements from the current iterable.
57
ParallelIterable<T> select(Predicate<? super T> predicate);
59
<P> ParallelIterable<T> selectWith(Predicate2<? super T, ? super P> predicate, P parameter);
61
<S> ParallelIterable<S> selectInstancesOf(Class<S> clazz);
64
* Creates a parallel iterable for rejecting elements from the current iterable.
66
ParallelIterable<T> reject(Predicate<? super T> predicate);
68
<P> ParallelIterable<T> rejectWith(Predicate2<? super T, ? super P> predicate, P parameter);
71
* Creates a parallel iterable for collecting elements from the current iterable.
73
<V> ParallelIterable<V> collect(Function<? super T, ? extends V> function);
75
<P, V> ParallelIterable<V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter);
78
* Creates a parallel iterable for selecting and collecting elements from the current iterable.
80
<V> ParallelIterable<V> collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function);
83
* Creates a parallel flattening iterable for the current iterable.
85
<V> ParallelIterable<V> flatCollect(Function<? super T, ? extends Iterable<V>> function);
88
// * Returns a parallel BooleanIterable which will transform the underlying iterable data to boolean values based on the booleanFunction.
90
// ParallelBooleanIterable collectBoolean(BooleanFunction<? super T> booleanFunction);
93
// * Returns a parallel ByteIterable which will transform the underlying iterable data to byte values based on the byteFunction.
95
// ParallelByteIterable collectByte(ByteFunction<? super T> byteFunction);
98
// * Returns a parallel CharIterable which will transform the underlying iterable data to char values based on the charFunction.
100
// ParallelCharIterable collectChar(CharFunction<? super T> charFunction);
103
// * Returns a parallel DoubleIterable which will transform the underlying iterable data to double values based on the doubleFunction.
105
// ParallelDoubleIterable collectDouble(DoubleFunction<? super T> doubleFunction);
108
// * Returns a parallel FloatIterable which will transform the underlying iterable data to float values based on the floatFunction.
110
// ParallelFloatIterable collectFloat(FloatFunction<? super T> floatFunction);
113
// * Returns a parallel IntIterable which will transform the underlying iterable data to int values based on the intFunction.
115
// ParallelIntIterable collectInt(IntFunction<? super T> intFunction);
118
// * Returns a parallel LongIterable which will transform the underlying iterable data to long values based on the longFunction.
120
// ParallelLongIterable collectLong(LongFunction<? super T> longFunction);
123
// * Returns a parallel ShortIterable which will transform the underlying iterable data to short values based on the shortFunction.
125
// ParallelShortIterable collectShort(ShortFunction<? super T> shortFunction);
127
void forEach(Procedure<? super T> procedure);
129
<P> void forEachWith(Procedure2<? super T, ? super P> procedure, P parameter);
131
T detect(Predicate<? super T> predicate);
133
<P> T detectWith(Predicate2<? super T, ? super P> predicate, P parameter);
135
T detectIfNone(Predicate<? super T> predicate, Function0<? extends T> function);
137
<P> T detectWithIfNone(Predicate2<? super T, ? super P> predicate, P parameter, Function0<? extends T> function);
139
int count(Predicate<? super T> predicate);
141
<P> int countWith(Predicate2<? super T, ? super P> predicate, P parameter);
143
boolean anySatisfy(Predicate<? super T> predicate);
145
<P> boolean anySatisfyWith(Predicate2<? super T, ? super P> predicate, P parameter);
147
boolean allSatisfy(Predicate<? super T> predicate);
149
<P> boolean allSatisfyWith(Predicate2<? super T, ? super P> predicate, P parameter);
151
boolean noneSatisfy(Predicate<? super T> predicate);
153
<P> boolean noneSatisfyWith(Predicate2<? super T, ? super P> predicate, P parameter);
155
MutableList<T> toList();
157
MutableList<T> toSortedList();
159
MutableList<T> toSortedList(Comparator<? super T> comparator);
161
<V extends Comparable<? super V>> MutableList<T> toSortedListBy(Function<? super T, ? extends V> function);
163
MutableSet<T> toSet();
165
MutableSortedSet<T> toSortedSet();
167
MutableSortedSet<T> toSortedSet(Comparator<? super T> comparator);
169
<V extends Comparable<? super V>> MutableSortedSet<T> toSortedSetBy(Function<? super T, ? extends V> function);
171
MutableBag<T> toBag();
173
<NK, NV> MutableMap<NK, NV> toMap(Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction);
175
<NK, NV> MutableSortedMap<NK, NV> toSortedMap(Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction);
177
<NK, NV> MutableSortedMap<NK, NV> toSortedMap(Comparator<? super NK> comparator, Function<? super T, ? extends NK> keyFunction, Function<? super T, ? extends NV> valueFunction);
181
<T1> T1[] toArray(T1[] target);
183
T min(Comparator<? super T> comparator);
185
T max(Comparator<? super T> comparator);
191
<V extends Comparable<? super V>> T minBy(Function<? super T, ? extends V> function);
193
<V extends Comparable<? super V>> T maxBy(Function<? super T, ? extends V> function);
195
long sumOfInt(IntFunction<? super T> function);
197
double sumOfFloat(FloatFunction<? super T> function);
199
long sumOfLong(LongFunction<? super T> function);
201
double sumOfDouble(DoubleFunction<? super T> function);
205
String makeString(String separator);
207
String makeString(String start, String separator, String end);
209
void appendString(Appendable appendable);
211
void appendString(Appendable appendable, String separator);
213
void appendString(Appendable appendable, String start, String separator, String end);
215
<V> Multimap<V, T> groupBy(Function<? super T, ? extends V> function);
217
<V> Multimap<V, T> groupByEach(Function<? super T, ? extends Iterable<V>> function);
219
<V> MapIterable<V, T> groupByUniqueKey(Function<? super T, ? extends V> function);
221
<K, V> MapIterable<K, V> aggregateInPlaceBy(Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator);
223
<K, V> MapIterable<K, V> aggregateBy(Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator);