public final class Seq<T>
extends java.util.AbstractCollection<E>
Collection
to support more daily used/functional methods.
All the operations are null safety. And an empty String
/Array
/Collection
/Optional
/Nullable
will be returned if possible, instead of null.
Seq
should not be passed as a parameter or returned as a result because it's a pure utility class for the operations/calculation based on Collection/ArrayModifier and Type | Method and Description |
---|---|
<E extends java.lang.Exception> |
accept(Try.Consumer<? super Seq<T>,E> action) |
boolean |
add(E e)
Deprecated.
Unsupported operation.
|
boolean |
addAll(java.util.Collection<? extends E> newElements)
Deprecated.
Unsupported operation.
|
<E extends java.lang.Exception> |
allMatch(Try.Predicate<? super T,E> filter) |
<E extends java.lang.Exception> |
anyMatch(Try.Predicate<? super T,E> filter) |
java.util.List<T> |
append(java.util.Collection<? extends T> c) |
java.util.List<T> |
append(T... a) |
<R,E extends java.lang.Exception> |
apply(Try.Function<? super Seq<T>,R,E> func) |
OptionalDouble |
averageDouble() |
<E extends java.lang.Exception> |
averageDouble(Try.ToDoubleFunction<? super T,E> mapper) |
OptionalDouble |
averageInt() |
<E extends java.lang.Exception> |
averageInt(Try.ToIntFunction<? super T,E> mapper) |
OptionalDouble |
averageLong() |
<E extends java.lang.Exception> |
averageLong(Try.ToLongFunction<? super T,E> mapper) |
static <E> java.util.List<java.util.List<E>> |
cartesianProduct(java.util.Collection<? extends java.util.Collection<? extends E>> cs)
Note: copy from Google Guava under Apache License v2.
|
static <E> java.util.List<java.util.List<E>> |
cartesianProduct(java.util.Collection<? extends E>... cs)
Note: copy from Google Guava under Apache License v2.
|
void |
clear()
Deprecated.
Unsupported operation.
|
<R,A,E extends java.lang.Exception> |
collapse(Try.BiPredicate<? super T,? super T,E> collapsible,
Collector<? super T,A,R> collector)
Merge series of adjacent elements which satisfy the given predicate using
the merger function and return a new stream.
|
<E extends java.lang.Exception,E2 extends java.lang.Exception> |
collapse(Try.BiPredicate<? super T,? super T,E> collapsible,
Try.BiFunction<? super T,? super T,T,E2> mergeFunction)
Merge series of adjacent elements which satisfy the given predicate using
the merger function and return a new stream.
|
<R,A> R |
collect(Collector<? super T,A,R> collector) |
<R,E extends java.lang.Exception> |
collect(Supplier<R> supplier,
Try.BiConsumer<R,? super T,E> accumulator) |
<R,A,RR,E extends java.lang.Exception> |
collectAndThen(Collector<T,A,R> downstream,
Try.Function<R,RR,E> finisher) |
static <T> java.util.List<T> |
concat(java.util.Collection<? extends java.util.Collection<? extends T>> c) |
static <T> java.util.List<T> |
concat(java.util.Collection<? extends T>... a) |
static <T> java.util.List<T> |
concat(java.util.Collection<? extends T> a,
java.util.Collection<? extends T> b) |
static <T> java.util.List<T> |
concat(T[]... a) |
static <T> java.util.List<T> |
concat(T[] a,
T[] b) |
boolean |
contains(java.lang.Object e) |
boolean |
containsAll(java.util.Collection<?> c) |
boolean |
containsAll(java.lang.Object[] a) |
boolean |
containsAny(java.util.Collection<?> c) |
boolean |
containsAny(java.lang.Object[] a) |
<E extends java.lang.Exception> |
count(Try.Predicate<? super T,E> filter) |
java.util.List<T> |
difference(java.util.Collection<?> b) |
java.util.List<T> |
difference(java.lang.Object[] a) |
boolean |
disjoint(java.util.Collection<?> c) |
static boolean |
disjoint(java.util.Collection<?> c1,
java.util.Collection<?> c2)
Returns
true if the two specified arrays have no elements in common. |
boolean |
disjoint(java.lang.Object[] a) |
static boolean |
disjoint(java.lang.Object[] a,
java.lang.Object[] b) |
java.util.List<T> |
distinct() |
<E extends java.lang.Exception> |
distinctBy(Try.Function<? super T,?,E> keyExtractor) |
<E extends java.lang.Exception> |
dropWhile(Try.Predicate<? super T,E> filter) |
<U,E extends java.lang.Exception> |
dropWhile(U seed,
Try.BiPredicate<? super T,? super U,E> predicate) |
boolean |
equals(java.lang.Object obj) |
<E extends java.lang.Exception> |
filter(Try.Predicate<? super T,E> filter) |
<E extends java.lang.Exception> |
filter(Try.Predicate<? super T,E> filter,
int max) |
<U,E extends java.lang.Exception> |
filter(U seed,
Try.BiPredicate<? super T,? super U,E> predicate) |
<E extends java.lang.Exception> |
findFirst(Try.Predicate<? super T,E> predicate) |
<E extends java.lang.Exception> |
findFirstAndLast(Try.Predicate<? super T,E> predicate) |
<E extends java.lang.Exception,E2 extends java.lang.Exception> |
findFirstAndLast(Try.Predicate<? super T,E> predicateForFirst,
Try.Predicate<? super T,E2> predicateForLast) |
<E extends java.lang.Exception> |
findFirstAndLastIndex(Try.Predicate<? super T,E> predicate) |
<E extends java.lang.Exception,E2 extends java.lang.Exception> |
findFirstAndLastIndex(Try.Predicate<? super T,E> predicateForFirst,
Try.Predicate<? super T,E2> predicateForLast) |
<E extends java.lang.Exception> |
findFirstIndex(Try.Predicate<? super T,E> predicate) |
<E extends java.lang.Exception,E2 extends java.lang.Exception> |
findFirstOrLast(Try.Predicate<? super T,E> predicateForFirst,
Try.Predicate<? super T,E2> predicateForLast) |
<E extends java.lang.Exception,E2 extends java.lang.Exception> |
findFirstOrLastIndex(Try.Predicate<? super T,E> predicateForFirst,
Try.Predicate<? super T,E2> predicateForLast) |
<E extends java.lang.Exception> |
findLast(Try.Predicate<? super T,E> predicate) |
<E extends java.lang.Exception> |
findLastIndex(Try.Predicate<? super T,E> predicate) |
Nullable<T> |
first() |
java.util.List<T> |
first(int n)
Return at most first
n elements. |
<R,E extends java.lang.Exception> |
flatMap(Try.Function<? super T,? extends java.util.Collection<R>,E> func) |
<T2,T3,R,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> |
flatMap(Try.Function<? super T,? extends java.util.Collection<T2>,E> mapper2,
Try.Function<? super T2,? extends java.util.Collection<T3>,E2> mapper3,
Try.TriFunction<? super T,? super T2,? super T3,R,E3> func) |
<U,R,E extends java.lang.Exception,E2 extends java.lang.Exception> |
flatMap(Try.Function<? super T,? extends java.util.Collection<U>,E> mapper,
Try.BiFunction<? super T,? super U,? extends R,E2> func) |
<E extends java.lang.Exception> |
flatMapToBoolean(Try.Function<? super T,? extends java.util.Collection<java.lang.Boolean>,E> func) |
<E extends java.lang.Exception> |
flatMapToByte(Try.Function<? super T,? extends java.util.Collection<java.lang.Byte>,E> func) |
<E extends java.lang.Exception> |
flatMapToChar(Try.Function<? super T,? extends java.util.Collection<java.lang.Character>,E> func) |
<E extends java.lang.Exception> |
flatMapToDouble(Try.Function<? super T,? extends java.util.Collection<java.lang.Double>,E> func) |
<E extends java.lang.Exception> |
flatMapToFloat(Try.Function<? super T,? extends java.util.Collection<java.lang.Float>,E> func) |
<E extends java.lang.Exception> |
flatMapToInt(Try.Function<? super T,? extends java.util.Collection<java.lang.Integer>,E> func) |
<E extends java.lang.Exception> |
flatMapToLong(Try.Function<? super T,? extends java.util.Collection<java.lang.Long>,E> func) |
<E extends java.lang.Exception> |
flatMapToShort(Try.Function<? super T,? extends java.util.Collection<java.lang.Short>,E> func) |
<R,E extends java.lang.Exception> |
flattMap(Try.Function<? super T,? extends R[],E> func) |
<E extends java.lang.Exception> |
flattMapToBoolean(Try.Function<? super T,boolean[],E> func) |
<E extends java.lang.Exception> |
flattMapToByte(Try.Function<? super T,byte[],E> func) |
<E extends java.lang.Exception> |
flattMapToChar(Try.Function<? super T,char[],E> func) |
<E extends java.lang.Exception> |
flattMapToDouble(Try.Function<? super T,double[],E> func) |
<E extends java.lang.Exception> |
flattMapToFloat(Try.Function<? super T,float[],E> func) |
<E extends java.lang.Exception> |
flattMapToInt(Try.Function<? super T,int[],E> func) |
<E extends java.lang.Exception> |
flattMapToLong(Try.Function<? super T,long[],E> func) |
<E extends java.lang.Exception> |
flattMapToShort(Try.Function<? super T,short[],E> func) |
<R,E extends java.lang.Exception,E2 extends java.lang.Exception> |
forEach(R seed,
Try.BiFunction<R,? super T,R,E> accumulator,
Try.BiPredicate<? super R,? super T,E2> conditionToBreak) |
<R,E extends java.lang.Exception,E2 extends java.lang.Exception> |
forEach(R seed,
Try.IndexedBiFunction<R,? super T,R,E> accumulator,
Try.BiPredicate<? super R,? super T,E2> conditionToBreak)
Execute
accumulator on each element till true is returned by conditionToBreak |
<E extends java.lang.Exception> |
foreach(Try.Consumer<? super T,E> action) |
<T2,T3,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> |
forEach(Try.Function<? super T,? extends java.util.Collection<T2>,E> flatMapper,
Try.Function<? super T2,? extends java.util.Collection<T3>,E2> flatMapper2,
Try.TriConsumer<? super T,? super T2,? super T3,E3> action) |
<U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
forEach(Try.Function<? super T,? extends java.util.Collection<U>,E> flatMapper,
Try.BiConsumer<? super T,? super U,E2> action) |
<E extends java.lang.Exception> |
forEach(Try.IndexedConsumer<? super T,E> action) |
<T2,T3,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> |
forEachNonNull(Try.Function<? super T,? extends java.util.Collection<T2>,E> flatMapper,
Try.Function<? super T2,? extends java.util.Collection<T3>,E2> flatMapper2,
Try.TriConsumer<? super T,? super T2,? super T3,E3> action) |
<U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
forEachNonNull(Try.Function<? super T,? extends java.util.Collection<U>,E> flatMapper,
Try.BiConsumer<? super T,? super U,E2> action) |
<E extends java.lang.Exception> |
forEachPair(Try.BiConsumer<? super T,? super T,E> action) |
<E extends java.lang.Exception> |
forEachPair(Try.BiConsumer<? super T,? super T,E> action,
int increment) |
<E extends java.lang.Exception> |
forEachTriple(Try.TriConsumer<? super T,? super T,? super T,E> action) |
<E extends java.lang.Exception> |
forEachTriple(Try.TriConsumer<? super T,? super T,? super T,E> action,
int increment) |
<U,E extends java.lang.Exception> |
fullJoin(java.util.Collection<U> b,
Try.BiPredicate<? super T,? super U,E> predicate)
The time complexity is O(n * m) : n is the size of this
Seq and m is the size of specified collection b . |
<U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
fullJoin(java.util.Collection<U> b,
Try.Function<? super T,?,E> leftKeyMapper,
Try.Function<? super U,?,E2> rightKeyMapper)
The time complexity is O(n + m) : n is the size of this
Seq and m is the size of specified collection b . |
<K,E extends java.lang.Exception> |
groupTo(Try.Function<? super T,? extends K,E> classifier) |
<K,M extends java.util.Map<K,java.util.List<T>>,E extends java.lang.Exception> |
groupTo(Try.Function<? super T,? extends K,E> classifier,
Supplier<M> mapFactory) |
<K,U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
groupTo(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends U,E2> valueMapper) |
<K,U,M extends java.util.Map<K,java.util.List<U>>,E extends java.lang.Exception,E2 extends java.lang.Exception> |
groupTo(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends U,E2> valueMapper,
Supplier<M> mapFactory) |
boolean |
hasDuplicates() |
int |
hashCode() |
java.util.List<com.landawn.abacus.util.Indexed<T>> |
indexed() |
<U,E extends java.lang.Exception> |
innerJoin(java.util.Collection<U> b,
Try.BiPredicate<? super T,? super U,E> predicate)
The time complexity is O(n * m) : n is the size of this
Seq and m is the size of specified collection b . |
<U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
innerJoin(java.util.Collection<U> b,
Try.Function<? super T,?,E> leftKeyMapper,
Try.Function<? super U,?,E2> rightKeyMapper)
The time complexity is O(n + m) : n is the size of this
Seq and m is the size of specified collection b . |
java.util.List<T> |
intersection(java.util.Collection<?> b) |
java.util.List<T> |
intersection(java.lang.Object[] a) |
java.util.List<T> |
intersperse(T value) |
boolean |
isEmpty() |
static <T> ObjIterator<T> |
iterate(java.util.Collection<? extends java.util.Collection<? extends T>> c) |
static <T> ObjIterator<T> |
iterate(java.util.Collection<? extends T>... a) |
static <T> ObjIterator<T> |
iterate(T[]... a) |
java.util.Iterator<T> |
iterator() |
java.lang.String |
join() |
java.lang.String |
join(char delimiter) |
java.lang.String |
join(java.lang.String delimiter) |
static <T> Seq<T> |
just(T t) |
Nullable<T> |
kthLargest(int k) |
Nullable<T> |
kthLargest(int k,
java.util.Comparator<? super T> cmp) |
Nullable<T> |
last() |
java.util.List<T> |
last(int n)
Return at most last
n elements. |
<U,E extends java.lang.Exception> |
leftJoin(java.util.Collection<U> b,
Try.BiPredicate<? super T,? super U,E> predicate)
The time complexity is O(n * m) : n is the size of this
Seq and m is the size of specified collection b . |
<U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
leftJoin(java.util.Collection<U> b,
Try.Function<? super T,?,E> leftKeyMapper,
Try.Function<? super U,?,E2> rightKeyMapper)
The time complexity is O(n + m) : n is the size of this
Seq and m is the size of specified collection b . |
<R,E extends java.lang.Exception> |
map(Try.Function<? super T,? extends R,E> func) |
<E extends java.lang.Exception> |
mapToBoolean(Try.ToBooleanFunction<? super T,E> func) |
<E extends java.lang.Exception> |
mapToByte(Try.ToByteFunction<? super T,E> func) |
<E extends java.lang.Exception> |
mapToChar(Try.ToCharFunction<? super T,E> func) |
<E extends java.lang.Exception> |
mapToDouble(Try.ToDoubleFunction<? super T,E> func) |
<E extends java.lang.Exception> |
mapToFloat(Try.ToFloatFunction<? super T,E> func) |
<E extends java.lang.Exception> |
mapToInt(Try.ToIntFunction<? super T,E> func) |
<E extends java.lang.Exception> |
mapToLong(Try.ToLongFunction<? super T,E> func) |
<E extends java.lang.Exception> |
mapToShort(Try.ToShortFunction<? super T,E> func) |
Nullable<T> |
max() |
Nullable<T> |
max(java.util.Comparator<? super T> cmp) |
Nullable<T> |
maxBy(Function<? super T,? extends java.lang.Comparable> keyExtractor) |
Nullable<T> |
median() |
Nullable<T> |
median(java.util.Comparator<? super T> cmp) |
static <T,E extends java.lang.Exception> |
merge(java.util.Collection<? extends T> a,
java.util.Collection<? extends T> b,
Try.BiFunction<? super T,? super T,com.landawn.abacus.util.Nth,E> nextSelector) |
<E extends java.lang.Exception> |
merge(java.util.Collection<? extends T> b,
Try.BiFunction<? super T,? super T,com.landawn.abacus.util.Nth,E> nextSelector) |
static <T,E extends java.lang.Exception> |
merge(T[] a,
T[] b,
Try.BiFunction<? super T,? super T,com.landawn.abacus.util.Nth,E> nextSelector) |
Nullable<T> |
min() |
Nullable<T> |
min(java.util.Comparator<? super T> cmp) |
Nullable<T> |
minBy(Function<? super T,? extends java.lang.Comparable> keyExtractor) |
<E extends java.lang.Exception> |
noneMatch(Try.Predicate<? super T,E> filter) |
static <T> java.util.List<T> |
nRepeat(java.util.Collection<T> c,
int n)
Repeats the elements in the specified Collection one by one.
|
static <T> java.util.List<T> |
nRepeatToSize(java.util.Collection<T> c,
int size)
Repeats the elements in the specified Collection one by one till reach the specified size.
|
int |
occurrencesOf(java.lang.Object objectToFind) |
static <T> Seq<T> |
of(java.util.Collection<T> c)
The returned
Seq and the specified Collection are backed by the same data. |
static <K,V> Seq<java.util.Map.Entry<K,V>> |
of(java.util.Map<K,V> map) |
static <T> Seq<T> |
of(T... a) |
static <E extends java.lang.Comparable<? super E>> |
orderedPermutations(java.util.Collection<E> elements)
Note: copy from Google Guava under Apache License v2.
|
static <E> java.util.Collection<java.util.List<E>> |
orderedPermutations(java.util.Collection<E> elements,
java.util.Comparator<? super E> comparator)
Note: copy from Google Guava under Apache License v2.
|
static <E> java.util.Collection<java.util.List<E>> |
permutations(java.util.Collection<E> elements)
Note: copy from Google Guava under Apache License v2.
|
static <E> java.util.Set<java.util.Set<E>> |
powerSet(java.util.Set<E> set)
Note: copy from Google Guava under Apache License v2.
|
java.util.List<T> |
prepend(java.util.Collection<? extends T> c) |
java.util.List<T> |
prepend(T... a) |
void |
println() |
<E extends java.lang.Exception> |
reduce(Try.BinaryOperator<T,E> accumulator)
This is equivalent to:
|
<U,E extends java.lang.Exception> |
reduce(U identity,
Try.BiFunction<U,? super T,U,E> accumulator)
This is equivalent to:
|
boolean |
remove(java.lang.Object object)
Deprecated.
Unsupported operation.
|
boolean |
removeAll(java.util.Collection<?> oldElements)
Deprecated.
Unsupported operation.
|
boolean |
removeIf(java.util.function.Predicate<? super E> filter)
Deprecated.
Unsupported operation.
|
static <T> java.util.List<T> |
repeat(T value,
int n) |
static <T> java.util.List<T> |
repeatt(java.util.Collection<T> c,
int n)
Seq.repeat(N.asList(1, 2, 3), 2) => [1, 2, 3, 1, 2, 3]
|
static <T> java.util.List<T> |
repeatToSize(java.util.Collection<T> c,
int size)
Seq.repeatToSize(N.asList(1, 2, 3), 5) => [1, 2, 3, 1, 2]
|
boolean |
retainAll(java.util.Collection<?> elementsToKeep)
Deprecated.
Unsupported operation.
|
static <T> void |
reverse(java.util.Collection<T> c) |
<U,E extends java.lang.Exception> |
rightJoin(java.util.Collection<U> b,
Try.BiPredicate<? super T,? super U,E> predicate)
The time complexity is O(n * m) : n is the size of this
Seq and m is the size of specified collection b . |
<U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
rightJoin(java.util.Collection<U> b,
Try.Function<? super T,?,E> leftKeyMapper,
Try.Function<? super U,?,E2> rightKeyMapper)
The time complexity is O(n + m) : n is the size of this
Seq and m is the size of specified collection b . |
static <T> java.util.List<java.util.List<T>> |
rollup(java.util.Collection<? extends T> c) |
static <T> void |
rotate(java.util.Collection<T> c,
int distance) |
<R,E extends java.lang.Exception> |
scan(R seed,
Try.BiFunction<? super R,? super T,R,E> accumulator)
Returns a
Stream produced by iterative application of a accumulation function
to an initial element identity and next element of the current stream. |
<E extends java.lang.Exception> |
scan(Try.BiFunction<? super T,? super T,T,E> accumulator)
Returns a
Stream produced by iterative application of a accumulation function
to an initial element identity and next element of the current stream. |
static <T> void |
shuffle(java.util.Collection<T> c) |
static <T> void |
shuffle(java.util.Collection<T> c,
java.util.Random rnd) |
int |
size() |
<E extends java.lang.Exception> |
skipUntil(Try.Predicate<? super T,E> filter) |
<U,E extends java.lang.Exception> |
skipUntil(U seed,
Try.BiPredicate<? super T,? super U,E> predicate) |
Seq<T> |
slice(int fromIndex,
int toIndex)
Returns a read-only
Seq . |
java.util.List<java.util.List<T>> |
sliding(int windowSize) |
java.util.List<java.util.List<T>> |
sliding(int windowSize,
int increment) |
java.util.List<java.util.List<T>> |
split(int size)
Returns consecutive sub lists of this list, each of the same size (the final list may be smaller),
or an empty List if the specified list is null or empty.
|
<U,E extends java.lang.Exception> |
split(Try.Predicate<? super T,E> predicate) |
<U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
split(U identity,
Try.BiPredicate<? super T,? super U,E> predicate,
Try.Consumer<? super U,E2> identityUpdate) |
Pair<java.util.List<T>,java.util.List<T>> |
splitAt(int n) |
<E extends java.lang.Exception> |
splitBy(Try.Predicate<? super T,E> predicate) |
double |
sumDouble() |
<E extends java.lang.Exception> |
sumDouble(Try.ToDoubleFunction<? super T,E> mapper) |
int |
sumInt() |
<E extends java.lang.Exception> |
sumInt(Try.ToIntFunction<? super T,E> mapper) |
long |
sumLong() |
<E extends java.lang.Exception> |
sumLong(Try.ToLongFunction<? super T,E> mapper) |
java.util.List<T> |
symmetricDifference(java.util.Collection<T> b) |
java.util.List<T> |
symmetricDifference(T[] a) |
<E extends java.lang.Exception> |
takeWhile(Try.Predicate<? super T,E> filter) |
<U,E extends java.lang.Exception> |
takeWhile(U seed,
Try.BiPredicate<? super T,? super U,E> predicate) |
<E extends java.lang.Exception> |
takeWhileInclusive(Try.Predicate<? super T,E> filter) |
<U,E extends java.lang.Exception> |
takeWhileInclusive(U seed,
Try.BiPredicate<? super T,? super U,E> predicate) |
java.lang.Object[] |
toArray() |
<A> A[] |
toArray(A[] a) |
java.util.List<T> |
toList() |
<R extends java.util.List<T>> |
toList(IntFunction<R> supplier) |
<K,A,D,E extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> classifier,
Collector<? super T,A,D> downstream) |
<K,A,D,M extends java.util.Map<K,D>,E extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> classifier,
Collector<? super T,A,D> downstream,
Supplier<M> mapFactory) |
<K,U,E extends java.lang.Exception,E2 extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends U,E2> valueMapper) |
<K,U,A,D,E extends java.lang.Exception,E2 extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> classifier,
Try.Function<? super T,? extends U,E2> valueMapper,
Collector<? super U,A,D> downstream) |
<K,U,A,D,M extends java.util.Map<K,D>,E extends java.lang.Exception,E2 extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> classifier,
Try.Function<? super T,? extends U,E2> valueMapper,
Collector<? super U,A,D> downstream,
Supplier<M> mapFactory) |
<K,U,M extends java.util.Map<K,U>,E extends java.lang.Exception,E2 extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends U,E2> valueMapper,
Supplier<M> mapFactory) |
<K,U,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends U,E2> valueMapper,
Try.BinaryOperator<U,E3> mergeFunction) |
<K,U,M extends java.util.Map<K,U>,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> |
toMap(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends U,E2> valueMapper,
Try.BinaryOperator<U,E3> mergeFunction,
Supplier<M> mapFactory) |
<K,E extends java.lang.Exception> |
toMultimap(Try.Function<? super T,? extends K,E> keyExtractor) |
<K,V extends java.util.Collection<T>,M extends Multimap<K,T,V>,E extends java.lang.Exception> |
toMultimap(Try.Function<? super T,? extends K,E> keyExtractor,
Supplier<M> mapFactory) |
<K,U,V extends java.util.Collection<U>,M extends Multimap<K,U,V>,E extends java.lang.Exception,E2 extends java.lang.Exception> |
toMultimap(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends U,E2> valueMapper,
Supplier<M> mapFactory) |
<K,V,E extends java.lang.Exception,E2 extends java.lang.Exception> |
toMultimap(Try.Function<? super T,? extends K,E> keyExtractor,
Try.Function<? super T,? extends V,E2> valueMapper) |
Multiset<T> |
toMultiset() |
Multiset<T> |
toMultiset(IntFunction<Multiset<T>> supplier) |
java.util.List<T> |
top(int n) |
java.util.List<T> |
top(int n,
java.util.Comparator<? super T> cmp) |
java.util.Set<T> |
toSet() |
<R extends java.util.Set<T>> |
toSet(IntFunction<R> supplier) |
java.lang.String |
toString() |
static <T,L,R,E extends java.lang.Exception> |
unzip(java.util.Collection<? extends T> c,
Try.BiConsumer<? super T,Pair<L,R>,E> unzip) |
static <T,L,R,LC extends java.util.Collection<L>,RC extends java.util.Collection<R>,E extends java.lang.Exception> |
unzip(java.util.Collection<? extends T> c,
Try.BiConsumer<? super T,Pair<L,R>,E> unzip,
IntFunction<? extends java.util.Collection<?>> supplier) |
static <T,L,M,R,E extends java.lang.Exception> |
unzipp(java.util.Collection<? extends T> c,
Try.BiConsumer<? super T,Triple<L,M,R>,E> unzip) |
static <T,L,M,R,LC extends java.util.Collection<L>,MC extends java.util.Collection<M>,RC extends java.util.Collection<R>,E extends java.lang.Exception> |
unzipp(java.util.Collection<? extends T> c,
Try.BiConsumer<? super T,Triple<L,M,R>,E> unzip,
IntFunction<? extends java.util.Collection<?>> supplier) |
static <A,B,R,E extends java.lang.Exception> |
zip(A[] a,
B[] b,
A valueForNoneA,
B valueForNoneB,
Try.BiFunction<? super A,? super B,R,E> zipFunction) |
static <A,B,C,R,E extends java.lang.Exception> |
zip(A[] a,
B[] b,
C[] c,
A valueForNoneA,
B valueForNoneB,
C valueForNoneC,
Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) |
static <A,B,C,R,E extends java.lang.Exception> |
zip(A[] a,
B[] b,
C[] c,
Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) |
static <A,B,R,E extends java.lang.Exception> |
zip(A[] a,
B[] b,
Try.BiFunction<? super A,? super B,R,E> zipFunction) |
static <A,B,R,E extends java.lang.Exception> |
zip(java.util.Collection<A> a,
java.util.Collection<B> b,
A valueForNoneA,
B valueForNoneB,
Try.BiFunction<? super A,? super B,R,E> zipFunction) |
static <A,B,C,R,E extends java.lang.Exception> |
zip(java.util.Collection<A> a,
java.util.Collection<B> b,
java.util.Collection<C> c,
A valueForNoneA,
B valueForNoneB,
C valueForNoneC,
Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) |
static <A,B,C,R,E extends java.lang.Exception> |
zip(java.util.Collection<A> a,
java.util.Collection<B> b,
java.util.Collection<C> c,
Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) |
static <A,B,R,E extends java.lang.Exception> |
zip(java.util.Collection<A> a,
java.util.Collection<B> b,
Try.BiFunction<? super A,? super B,R,E> zipFunction) |
<B,C,R,E extends java.lang.Exception> |
zipWith(java.util.Collection<B> b,
java.util.Collection<C> c,
T valueForNoneA,
B valueForNoneB,
C valueForNoneC,
Try.TriFunction<? super T,? super B,? super C,R,E> zipFunction) |
<B,C,R,E extends java.lang.Exception> |
zipWith(java.util.Collection<B> b,
java.util.Collection<C> c,
Try.TriFunction<? super T,? super B,? super C,R,E> zipFunction) |
<B,R,E extends java.lang.Exception> |
zipWith(java.util.Collection<B> b,
T valueForNoneA,
B valueForNoneB,
Try.BiFunction<? super T,? super B,R,E> zipFunction) |
<B,R,E extends java.lang.Exception> |
zipWith(java.util.Collection<B> b,
Try.BiFunction<? super T,? super B,R,E> zipFunction) |
public static <T> Seq<T> just(T t)
@SafeVarargs public static <T> Seq<T> of(T... a)
public static <T> Seq<T> of(java.util.Collection<T> c)
Seq
and the specified Collection
are backed by the same data.
Any changes to one will appear in the other.c
- public static <K,V> Seq<java.util.Map.Entry<K,V>> of(java.util.Map<K,V> map)
map
- public boolean contains(java.lang.Object e)
contains
in interface java.util.Collection<T>
public boolean containsAll(java.util.Collection<?> c)
public boolean containsAll(java.lang.Object[] a)
public boolean containsAny(java.util.Collection<?> c)
public boolean containsAny(java.lang.Object[] a)
public boolean disjoint(java.util.Collection<?> c)
public boolean disjoint(java.lang.Object[] a)
public java.util.List<T> intersection(java.util.Collection<?> b)
b
- IntList.intersection(IntList)
public java.util.List<T> intersection(java.lang.Object[] a)
public java.util.List<T> difference(java.util.Collection<?> b)
b
- IntList.difference(IntList)
public java.util.List<T> difference(java.lang.Object[] a)
public java.util.List<T> symmetricDifference(java.util.Collection<T> b)
b
- IntList.symmetricDifference(IntList)
public int occurrencesOf(java.lang.Object objectToFind)
public int sumInt()
public <E extends java.lang.Exception> int sumInt(Try.ToIntFunction<? super T,E> mapper) throws E extends java.lang.Exception
E extends java.lang.Exception
public long sumLong()
public <E extends java.lang.Exception> long sumLong(Try.ToLongFunction<? super T,E> mapper) throws E extends java.lang.Exception
E extends java.lang.Exception
public double sumDouble()
public <E extends java.lang.Exception> double sumDouble(Try.ToDoubleFunction<? super T,E> mapper) throws E extends java.lang.Exception
E extends java.lang.Exception
public OptionalDouble averageInt()
public <E extends java.lang.Exception> OptionalDouble averageInt(Try.ToIntFunction<? super T,E> mapper) throws E extends java.lang.Exception
E extends java.lang.Exception
public OptionalDouble averageLong()
public <E extends java.lang.Exception> OptionalDouble averageLong(Try.ToLongFunction<? super T,E> mapper) throws E extends java.lang.Exception
E extends java.lang.Exception
public OptionalDouble averageDouble()
public <E extends java.lang.Exception> OptionalDouble averageDouble(Try.ToDoubleFunction<? super T,E> mapper) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void foreach(Try.Consumer<? super T,E> action) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void forEach(Try.IndexedConsumer<? super T,E> action) throws E extends java.lang.Exception
E extends java.lang.Exception
public <R,E extends java.lang.Exception,E2 extends java.lang.Exception> R forEach(R seed, Try.BiFunction<R,? super T,R,E> accumulator, Try.BiPredicate<? super R,? super T,E2> conditionToBreak) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <R,E extends java.lang.Exception,E2 extends java.lang.Exception> R forEach(R seed, Try.IndexedBiFunction<R,? super T,R,E> accumulator, Try.BiPredicate<? super R,? super T,E2> conditionToBreak) throws E extends java.lang.Exception, E2 extends java.lang.Exception
accumulator
on each element till true
is returned by conditionToBreak
seed
- The seed element is both the initial value of the reduction and the default result if there are no elements.accumulator
- conditionToBreak
- break if true
is return.E extends java.lang.Exception
public <U,E extends java.lang.Exception,E2 extends java.lang.Exception> void forEach(Try.Function<? super T,? extends java.util.Collection<U>,E> flatMapper, Try.BiConsumer<? super T,? super U,E2> action) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <T2,T3,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> void forEach(Try.Function<? super T,? extends java.util.Collection<T2>,E> flatMapper, Try.Function<? super T2,? extends java.util.Collection<T3>,E2> flatMapper2, Try.TriConsumer<? super T,? super T2,? super T3,E3> action) throws E extends java.lang.Exception, E2 extends java.lang.Exception, E3 extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception,E2 extends java.lang.Exception> void forEachNonNull(Try.Function<? super T,? extends java.util.Collection<U>,E> flatMapper, Try.BiConsumer<? super T,? super U,E2> action) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <T2,T3,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> void forEachNonNull(Try.Function<? super T,? extends java.util.Collection<T2>,E> flatMapper, Try.Function<? super T2,? extends java.util.Collection<T3>,E2> flatMapper2, Try.TriConsumer<? super T,? super T2,? super T3,E3> action) throws E extends java.lang.Exception, E2 extends java.lang.Exception, E3 extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void forEachPair(Try.BiConsumer<? super T,? super T,E> action) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void forEachPair(Try.BiConsumer<? super T,? super T,E> action, int increment) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void forEachTriple(Try.TriConsumer<? super T,? super T,? super T,E> action) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void forEachTriple(Try.TriConsumer<? super T,? super T,? super T,E> action, int increment) throws E extends java.lang.Exception
E extends java.lang.Exception
public java.util.List<T> first(int n)
n
elements.n
- public java.util.List<T> last(int n)
n
elements.n
- public <E extends java.lang.Exception> Nullable<T> findFirst(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> Nullable<T> findLast(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> OptionalInt findFirstIndex(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> OptionalInt findLastIndex(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception,E2 extends java.lang.Exception> Nullable<T> findFirstOrLast(Try.Predicate<? super T,E> predicateForFirst, Try.Predicate<? super T,E2> predicateForLast) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception,E2 extends java.lang.Exception> OptionalInt findFirstOrLastIndex(Try.Predicate<? super T,E> predicateForFirst, Try.Predicate<? super T,E2> predicateForLast) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> Pair<Nullable<T>,Nullable<T>> findFirstAndLast(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception,E2 extends java.lang.Exception> Pair<Nullable<T>,Nullable<T>> findFirstAndLast(Try.Predicate<? super T,E> predicateForFirst, Try.Predicate<? super T,E2> predicateForLast) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> Pair<OptionalInt,OptionalInt> findFirstAndLastIndex(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception,E2 extends java.lang.Exception> Pair<OptionalInt,OptionalInt> findFirstAndLastIndex(Try.Predicate<? super T,E> predicateForFirst, Try.Predicate<? super T,E2> predicateForLast) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> boolean allMatch(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> boolean anyMatch(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> boolean noneMatch(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public boolean hasDuplicates()
public <E extends java.lang.Exception> int count(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> filter(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> filter(Try.Predicate<? super T,E> filter, int max) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<T> filter(U seed, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> takeWhile(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<T> takeWhile(U seed, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> takeWhileInclusive(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<T> takeWhileInclusive(U seed, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> dropWhile(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<T> dropWhile(U seed, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> skipUntil(Try.Predicate<? super T,E> filter) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<T> skipUntil(U seed, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <R,E extends java.lang.Exception> java.util.List<R> map(Try.Function<? super T,? extends R,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> BooleanList mapToBoolean(Try.ToBooleanFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> CharList mapToChar(Try.ToCharFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> ByteList mapToByte(Try.ToByteFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> ShortList mapToShort(Try.ToShortFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> IntList mapToInt(Try.ToIntFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> LongList mapToLong(Try.ToLongFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> FloatList mapToFloat(Try.ToFloatFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> DoubleList mapToDouble(Try.ToDoubleFunction<? super T,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <R,E extends java.lang.Exception> java.util.List<R> flatMap(Try.Function<? super T,? extends java.util.Collection<R>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <R,E extends java.lang.Exception> java.util.List<R> flattMap(Try.Function<? super T,? extends R[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> BooleanList flatMapToBoolean(Try.Function<? super T,? extends java.util.Collection<java.lang.Boolean>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> BooleanList flattMapToBoolean(Try.Function<? super T,boolean[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> CharList flatMapToChar(Try.Function<? super T,? extends java.util.Collection<java.lang.Character>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> CharList flattMapToChar(Try.Function<? super T,char[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> ByteList flatMapToByte(Try.Function<? super T,? extends java.util.Collection<java.lang.Byte>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> ByteList flattMapToByte(Try.Function<? super T,byte[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> ShortList flatMapToShort(Try.Function<? super T,? extends java.util.Collection<java.lang.Short>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> ShortList flattMapToShort(Try.Function<? super T,short[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> IntList flatMapToInt(Try.Function<? super T,? extends java.util.Collection<java.lang.Integer>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> IntList flattMapToInt(Try.Function<? super T,int[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> LongList flatMapToLong(Try.Function<? super T,? extends java.util.Collection<java.lang.Long>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> LongList flattMapToLong(Try.Function<? super T,long[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> FloatList flatMapToFloat(Try.Function<? super T,? extends java.util.Collection<java.lang.Float>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> FloatList flattMapToFloat(Try.Function<? super T,float[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> DoubleList flatMapToDouble(Try.Function<? super T,? extends java.util.Collection<java.lang.Double>,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> DoubleList flattMapToDouble(Try.Function<? super T,double[],E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,R,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.List<R> flatMap(Try.Function<? super T,? extends java.util.Collection<U>,E> mapper, Try.BiFunction<? super T,? super U,? extends R,E2> func) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <T2,T3,R,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> java.util.List<R> flatMap(Try.Function<? super T,? extends java.util.Collection<T2>,E> mapper2, Try.Function<? super T2,? extends java.util.Collection<T3>,E2> mapper3, Try.TriFunction<? super T,? super T2,? super T3,R,E3> func) throws E extends java.lang.Exception, E2 extends java.lang.Exception, E3 extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.List<T> collapse(Try.BiPredicate<? super T,? super T,E> collapsible, Try.BiFunction<? super T,? super T,T,E2> mergeFunction) throws E extends java.lang.Exception, E2 extends java.lang.Exception
collapsible
- mergeFunction
- E extends java.lang.Exception
public <R,A,E extends java.lang.Exception> java.util.List<R> collapse(Try.BiPredicate<? super T,? super T,E> collapsible, Collector<? super T,A,R> collector) throws E extends java.lang.Exception
collapsible
- collector
- E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> scan(Try.BiFunction<? super T,? super T,T,E> accumulator) throws E extends java.lang.Exception
Stream
produced by iterative application of a accumulation function
to an initial element identity
and next element of the current stream.
Produces a Stream
consisting of identity
, acc(identity, value1)
,
acc(acc(identity, value1), value2)
, etc.
This is an intermediate operation.
Example:
accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: [1, 3, 6, 10, 15]
accumulator
- the accumulation functionE extends java.lang.Exception
public <R,E extends java.lang.Exception> java.util.List<R> scan(R seed, Try.BiFunction<? super R,? super T,R,E> accumulator) throws E extends java.lang.Exception
Stream
produced by iterative application of a accumulation function
to an initial element identity
and next element of the current stream.
Produces a Stream
consisting of identity
, acc(identity, value1)
,
acc(acc(identity, value1), value2)
, etc.
This is an intermediate operation.
Example:
seed:10 accumulator: (a, b) -> a + b stream: [1, 2, 3, 4, 5] result: [11, 13, 16, 20, 25]
seed
- the initial value. it's only used once by accumulator
to calculate the fist element in the returned stream.
It will be ignored if this stream is empty and won't be the first element of the returned stream.accumulator
- the accumulation functionE extends java.lang.Exception
public <E extends java.lang.Exception> Nullable<T> reduce(Try.BinaryOperator<T,E> accumulator) throws E extends java.lang.Exception
if (isEmpty()) {
return Nullable.empty();
}
final Iterator iter = iterator();
T result = iter.next();
while (iter.hasNext()) {
result = accumulator.apply(result, iter.next());
}
return Nullable.of(result);
accumulator
- E extends java.lang.Exception
public <U,E extends java.lang.Exception> U reduce(U identity, Try.BiFunction<U,? super T,U,E> accumulator) throws E extends java.lang.Exception
if (isEmpty()) {
return identity;
}
final Iterator iter = iterator();
U result = identity;
while (iter.hasNext()) {
result = accumulator.apply(result, iter.next());
}
return result;
identity
- accumulator
- E extends java.lang.Exception
public <R,E extends java.lang.Exception> R collect(Supplier<R> supplier, Try.BiConsumer<R,? super T,E> accumulator) throws E extends java.lang.Exception
E extends java.lang.Exception
public <R,A,RR,E extends java.lang.Exception> RR collectAndThen(Collector<T,A,R> downstream, Try.Function<R,RR,E> finisher) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> java.util.List<T> merge(java.util.Collection<? extends T> b, Try.BiFunction<? super T,? super T,com.landawn.abacus.util.Nth,E> nextSelector) throws E extends java.lang.Exception
E extends java.lang.Exception
public <B,R,E extends java.lang.Exception> java.util.List<R> zipWith(java.util.Collection<B> b, Try.BiFunction<? super T,? super B,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public <B,R,E extends java.lang.Exception> java.util.List<R> zipWith(java.util.Collection<B> b, T valueForNoneA, B valueForNoneB, Try.BiFunction<? super T,? super B,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public <B,C,R,E extends java.lang.Exception> java.util.List<R> zipWith(java.util.Collection<B> b, java.util.Collection<C> c, Try.TriFunction<? super T,? super B,? super C,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public <B,C,R,E extends java.lang.Exception> java.util.List<R> zipWith(java.util.Collection<B> b, java.util.Collection<C> c, T valueForNoneA, B valueForNoneB, C valueForNoneC, Try.TriFunction<? super T,? super B,? super C,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public java.util.List<com.landawn.abacus.util.Indexed<T>> indexed()
public java.util.List<T> distinct()
public <E extends java.lang.Exception> java.util.List<T> distinctBy(Try.Function<? super T,?,E> keyExtractor) throws E extends java.lang.Exception
keyExtractor
- don't change value of the input parameter.E extends java.lang.Exception
public java.util.List<T> top(int n)
public java.util.List<java.util.List<T>> split(int size)
public <U,E extends java.lang.Exception> java.util.List<java.util.List<T>> split(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.List<java.util.List<T>> split(U identity, Try.BiPredicate<? super T,? super U,E> predicate, Try.Consumer<? super U,E2> identityUpdate) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> Pair<java.util.List<T>,java.util.List<T>> splitBy(Try.Predicate<? super T,E> predicate) throws E extends java.lang.Exception
E extends java.lang.Exception
public java.util.List<java.util.List<T>> sliding(int windowSize)
public java.util.List<java.util.List<T>> sliding(int windowSize, int increment)
public java.lang.String join()
public java.lang.String join(char delimiter)
public java.lang.String join(java.lang.String delimiter)
public boolean isEmpty()
public int size()
size
in interface java.util.Collection<T>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<T>
public <A> A[] toArray(A[] a)
toArray
in interface java.util.Collection<T>
public java.util.List<T> toList()
public <R extends java.util.List<T>> R toList(IntFunction<R> supplier)
public java.util.Set<T> toSet()
public <R extends java.util.Set<T>> R toSet(IntFunction<R> supplier)
public Multiset<T> toMultiset(IntFunction<Multiset<T>> supplier)
public <K,U,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.Map<K,U> toMap(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends U,E2> valueMapper) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <K,U,M extends java.util.Map<K,U>,E extends java.lang.Exception,E2 extends java.lang.Exception> M toMap(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends U,E2> valueMapper, Supplier<M> mapFactory) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <K,U,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> java.util.Map<K,U> toMap(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends U,E2> valueMapper, Try.BinaryOperator<U,E3> mergeFunction) throws E extends java.lang.Exception, E2 extends java.lang.Exception, E3 extends java.lang.Exception
E extends java.lang.Exception
public <K,U,M extends java.util.Map<K,U>,E extends java.lang.Exception,E2 extends java.lang.Exception,E3 extends java.lang.Exception> M toMap(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends U,E2> valueMapper, Try.BinaryOperator<U,E3> mergeFunction, Supplier<M> mapFactory) throws E extends java.lang.Exception, E2 extends java.lang.Exception, E3 extends java.lang.Exception
E extends java.lang.Exception
public <K,A,D,E extends java.lang.Exception> java.util.Map<K,D> toMap(Try.Function<? super T,? extends K,E> classifier, Collector<? super T,A,D> downstream) throws E extends java.lang.Exception
E extends java.lang.Exception
public <K,A,D,M extends java.util.Map<K,D>,E extends java.lang.Exception> M toMap(Try.Function<? super T,? extends K,E> classifier, Collector<? super T,A,D> downstream, Supplier<M> mapFactory) throws E extends java.lang.Exception
E extends java.lang.Exception
public <K,U,A,D,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.Map<K,D> toMap(Try.Function<? super T,? extends K,E> classifier, Try.Function<? super T,? extends U,E2> valueMapper, Collector<? super U,A,D> downstream) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <K,U,A,D,M extends java.util.Map<K,D>,E extends java.lang.Exception,E2 extends java.lang.Exception> M toMap(Try.Function<? super T,? extends K,E> classifier, Try.Function<? super T,? extends U,E2> valueMapper, Collector<? super U,A,D> downstream, Supplier<M> mapFactory) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <K,E extends java.lang.Exception> java.util.Map<K,java.util.List<T>> groupTo(Try.Function<? super T,? extends K,E> classifier) throws E extends java.lang.Exception
E extends java.lang.Exception
public <K,M extends java.util.Map<K,java.util.List<T>>,E extends java.lang.Exception> M groupTo(Try.Function<? super T,? extends K,E> classifier, Supplier<M> mapFactory) throws E extends java.lang.Exception
E extends java.lang.Exception
public <K,U,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.Map<K,java.util.List<U>> groupTo(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends U,E2> valueMapper) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <K,U,M extends java.util.Map<K,java.util.List<U>>,E extends java.lang.Exception,E2 extends java.lang.Exception> M groupTo(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends U,E2> valueMapper, Supplier<M> mapFactory) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <K,E extends java.lang.Exception> ListMultimap<K,T> toMultimap(Try.Function<? super T,? extends K,E> keyExtractor) throws E extends java.lang.Exception
keyExtractor
- E extends java.lang.Exception
public <K,V extends java.util.Collection<T>,M extends Multimap<K,T,V>,E extends java.lang.Exception> M toMultimap(Try.Function<? super T,? extends K,E> keyExtractor, Supplier<M> mapFactory) throws E extends java.lang.Exception
E extends java.lang.Exception
public <K,V,E extends java.lang.Exception,E2 extends java.lang.Exception> ListMultimap<K,V> toMultimap(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends V,E2> valueMapper) throws E extends java.lang.Exception, E2 extends java.lang.Exception
keyExtractor
- valueMapper
- E extends java.lang.Exception
public <K,U,V extends java.util.Collection<U>,M extends Multimap<K,U,V>,E extends java.lang.Exception,E2 extends java.lang.Exception> M toMultimap(Try.Function<? super T,? extends K,E> keyExtractor, Try.Function<? super T,? extends U,E2> valueMapper, Supplier<M> mapFactory) throws E extends java.lang.Exception, E2 extends java.lang.Exception
E extends java.lang.Exception
public <U,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.List<Pair<T,U>> innerJoin(java.util.Collection<U> b, Try.Function<? super T,?,E> leftKeyMapper, Try.Function<? super U,?,E2> rightKeyMapper) throws E extends java.lang.Exception, E2 extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- leftKeyMapper
- rightKeyMapper
- E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<Pair<T,U>> innerJoin(java.util.Collection<U> b, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- predicate
- E extends java.lang.Exception
public <U,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.List<Pair<T,U>> fullJoin(java.util.Collection<U> b, Try.Function<? super T,?,E> leftKeyMapper, Try.Function<? super U,?,E2> rightKeyMapper) throws E extends java.lang.Exception, E2 extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- leftKeyMapper
- rightKeyMapper
- E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<Pair<T,U>> fullJoin(java.util.Collection<U> b, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- predicate
- E extends java.lang.Exception
public <U,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.List<Pair<T,U>> leftJoin(java.util.Collection<U> b, Try.Function<? super T,?,E> leftKeyMapper, Try.Function<? super U,?,E2> rightKeyMapper) throws E extends java.lang.Exception, E2 extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- leftKeyMapper
- rightKeyMapper
- E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<Pair<T,U>> leftJoin(java.util.Collection<U> b, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- predicate
- E extends java.lang.Exception
public <U,E extends java.lang.Exception,E2 extends java.lang.Exception> java.util.List<Pair<T,U>> rightJoin(java.util.Collection<U> b, Try.Function<? super T,?,E> leftKeyMapper, Try.Function<? super U,?,E2> rightKeyMapper) throws E extends java.lang.Exception, E2 extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- leftKeyMapper
- rightKeyMapper
- E extends java.lang.Exception
public <U,E extends java.lang.Exception> java.util.List<Pair<T,U>> rightJoin(java.util.Collection<U> b, Try.BiPredicate<? super T,? super U,E> predicate) throws E extends java.lang.Exception
Seq
and m is the size of specified collection b
.b
- predicate
- E extends java.lang.Exception
public Seq<T> slice(int fromIndex, int toIndex)
Seq
.fromIndex
- toIndex
- public java.util.Iterator<T> iterator()
public <R,E extends java.lang.Exception> R apply(Try.Function<? super Seq<T>,R,E> func) throws E extends java.lang.Exception
E extends java.lang.Exception
public <E extends java.lang.Exception> void accept(Try.Consumer<? super Seq<T>,E> action) throws E extends java.lang.Exception
E extends java.lang.Exception
public void println()
public int hashCode()
hashCode
in interface java.util.Collection<T>
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Collection<T>
public java.lang.String toString()
public static <T> java.util.List<T> repeat(T value, int n)
public static <T> java.util.List<T> repeatt(java.util.Collection<T> c, int n)
Seq.repeat(N.asList(1, 2, 3), 2) => [1, 2, 3, 1, 2, 3]
c
- n
- public static <T> java.util.List<T> nRepeat(java.util.Collection<T> c, int n)
Seq.nRepeat(N.asList(1, 2, 3), 2) => [1, 1, 2, 2, 3, 3]
c
- n
- public static <T> java.util.List<T> repeatToSize(java.util.Collection<T> c, int size)
Seq.repeatToSize(N.asList(1, 2, 3), 5) => [1, 2, 3, 1, 2]
c
- size
- public static <T> java.util.List<T> nRepeatToSize(java.util.Collection<T> c, int size)
Seq.nRepeatToSize(N.asList(1, 2, 3), 5) => [1, 1, 2, 2, 3]
c
- size
- public static <T> void reverse(java.util.Collection<T> c)
public static <T> void rotate(java.util.Collection<T> c, int distance)
public static <T> void shuffle(java.util.Collection<T> c)
public static <T> void shuffle(java.util.Collection<T> c, java.util.Random rnd)
public static boolean disjoint(java.lang.Object[] a, java.lang.Object[] b)
public static boolean disjoint(java.util.Collection<?> c1, java.util.Collection<?> c2)
true
if the two specified arrays have no elements in common.a
- b
- true
if the two specified arrays have no elements in common.Collections.disjoint(Collection, Collection)
public static <T> java.util.List<T> concat(T[] a, T[] b)
@SafeVarargs public static <T> java.util.List<T> concat(T[]... a)
public static <T> java.util.List<T> concat(java.util.Collection<? extends T> a, java.util.Collection<? extends T> b)
@SafeVarargs public static <T> java.util.List<T> concat(java.util.Collection<? extends T>... a)
public static <T> java.util.List<T> concat(java.util.Collection<? extends java.util.Collection<? extends T>> c)
@SafeVarargs public static <T> ObjIterator<T> iterate(T[]... a)
@SafeVarargs public static <T> ObjIterator<T> iterate(java.util.Collection<? extends T>... a)
public static <T> ObjIterator<T> iterate(java.util.Collection<? extends java.util.Collection<? extends T>> c)
public static <T,E extends java.lang.Exception> java.util.List<T> merge(T[] a, T[] b, Try.BiFunction<? super T,? super T,com.landawn.abacus.util.Nth,E> nextSelector) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <T,E extends java.lang.Exception> java.util.List<T> merge(java.util.Collection<? extends T> a, java.util.Collection<? extends T> b, Try.BiFunction<? super T,? super T,com.landawn.abacus.util.Nth,E> nextSelector) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,R,E extends java.lang.Exception> java.util.List<R> zip(A[] a, B[] b, Try.BiFunction<? super A,? super B,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,R,E extends java.lang.Exception> java.util.List<R> zip(java.util.Collection<A> a, java.util.Collection<B> b, Try.BiFunction<? super A,? super B,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,C,R,E extends java.lang.Exception> java.util.List<R> zip(A[] a, B[] b, C[] c, Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,C,R,E extends java.lang.Exception> java.util.List<R> zip(java.util.Collection<A> a, java.util.Collection<B> b, java.util.Collection<C> c, Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,R,E extends java.lang.Exception> java.util.List<R> zip(A[] a, B[] b, A valueForNoneA, B valueForNoneB, Try.BiFunction<? super A,? super B,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,R,E extends java.lang.Exception> java.util.List<R> zip(java.util.Collection<A> a, java.util.Collection<B> b, A valueForNoneA, B valueForNoneB, Try.BiFunction<? super A,? super B,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,C,R,E extends java.lang.Exception> java.util.List<R> zip(A[] a, B[] b, C[] c, A valueForNoneA, B valueForNoneB, C valueForNoneC, Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <A,B,C,R,E extends java.lang.Exception> java.util.List<R> zip(java.util.Collection<A> a, java.util.Collection<B> b, java.util.Collection<C> c, A valueForNoneA, B valueForNoneB, C valueForNoneC, Try.TriFunction<? super A,? super B,? super C,R,E> zipFunction) throws E extends java.lang.Exception
E extends java.lang.Exception
public static <T,L,R,E extends java.lang.Exception> Pair<java.util.List<L>,java.util.List<R>> unzip(java.util.Collection<? extends T> c, Try.BiConsumer<? super T,Pair<L,R>,E> unzip) throws E extends java.lang.Exception
c
- unzip
- the second parameter is an output parameter.E extends java.lang.Exception
public static <T,L,R,LC extends java.util.Collection<L>,RC extends java.util.Collection<R>,E extends java.lang.Exception> Pair<LC,RC> unzip(java.util.Collection<? extends T> c, Try.BiConsumer<? super T,Pair<L,R>,E> unzip, IntFunction<? extends java.util.Collection<?>> supplier) throws E extends java.lang.Exception
c
- unzip
- the second parameter is an output parameter.supplier
- E extends java.lang.Exception
public static <T,L,M,R,E extends java.lang.Exception> Triple<java.util.List<L>,java.util.List<M>,java.util.List<R>> unzipp(java.util.Collection<? extends T> c, Try.BiConsumer<? super T,Triple<L,M,R>,E> unzip) throws E extends java.lang.Exception
c
- unzip
- the second parameter is an output parameter.E extends java.lang.Exception
public static <T,L,M,R,LC extends java.util.Collection<L>,MC extends java.util.Collection<M>,RC extends java.util.Collection<R>,E extends java.lang.Exception> Triple<LC,MC,RC> unzipp(java.util.Collection<? extends T> c, Try.BiConsumer<? super T,Triple<L,M,R>,E> unzip, IntFunction<? extends java.util.Collection<?>> supplier) throws E extends java.lang.Exception
c
- unzip
- the second parameter is an output parameter.supplier
- E extends java.lang.Exception
public static <T> java.util.List<java.util.List<T>> rollup(java.util.Collection<? extends T> c)
public static <E> java.util.Set<java.util.Set<E>> powerSet(java.util.Set<E> set)
set
. For example,
powerSet(ImmutableSet.of(1, 2))
returns the set {{},
{1}, {2}, {1, 2}}
.
Elements appear in these subsets in the same iteration order as they appeared in the input set. The order in which these subsets appear in the outer set is undefined. Note that the power set of the empty set is not the empty set, but a one-element set containing the empty set.
The returned set and its constituent sets use equals
to decide
whether two elements are identical, even if the input set uses a different
concept of equivalence.
Performance notes: while the power set of a set with size n
is of size 2^n
, its memory usage is only O(n)
. When the
power set is constructed, the input set is merely copied. Only as the
power set is iterated are the individual subsets created, and these subsets
themselves occupy only a small constant amount of memory.
set
- the set of elements to construct a power set fromjava.lang.IllegalArgumentException
- if set
has more than 30 unique
elements (causing the power set size to exceed the int
range)java.lang.NullPointerException
- if set
is or contains null
public static <E> java.util.Collection<java.util.List<E>> permutations(java.util.Collection<E> elements)
Collection
of all the permutations of the specified
Collection
.
Notes: This is an implementation of the Plain Changes algorithm for permutations generation, described in Knuth's "The Art of Computer Programming", Volume 4, Chapter 7, Section 7.2.1.2.
If the input list contains equal elements, some of the generated permutations will be equal.
An empty collection has only one permutation, which is an empty list.
elements
- the original collection whose elements have to be permuted.Collection
containing all the different
permutations of the original collection.java.lang.NullPointerException
- if the specified collection is null or has any
null elements.public static <E extends java.lang.Comparable<? super E>> java.util.Collection<java.util.List<E>> orderedPermutations(java.util.Collection<E> elements)
Collection
of all the permutations of the specified
Iterable
.
Notes: This is an implementation of the algorithm for Lexicographical Permutations Generation, described in Knuth's "The Art of Computer Programming", Volume 4, Chapter 7, Section 7.2.1.2. The iteration order follows the lexicographical order. This means that the first permutation will be in ascending order, and the last will be in descending order.
Duplicate elements are considered equal. For example, the list [1, 1]
will have only one permutation, instead of two. This is why the elements
have to implement Comparable
.
An empty iterable has only one permutation, which is an empty list.
This method is equivalent to
Collections2.orderedPermutations(list, Ordering.natural())
.
elements
- the original iterable whose elements have to be permuted.Collection
containing all the different
permutations of the original iterable.java.lang.NullPointerException
- if the specified iterable is null or has any
null elements.public static <E> java.util.Collection<java.util.List<E>> orderedPermutations(java.util.Collection<E> elements, java.util.Comparator<? super E> comparator)
Collection
of all the permutations of the specified
Iterable
using the specified Comparator
for establishing
the lexicographical ordering.
Examples:
for (List<String> perm : orderedPermutations(asList("b", "c", "a"))) {
println(perm);
}
// -> ["a", "b", "c"]
// -> ["a", "c", "b"]
// -> ["b", "a", "c"]
// -> ["b", "c", "a"]
// -> ["c", "a", "b"]
// -> ["c", "b", "a"]
for (List<Integer> perm : orderedPermutations(asList(1, 2, 2, 1))) {
println(perm);
}
// -> [1, 1, 2, 2]
// -> [1, 2, 1, 2]
// -> [1, 2, 2, 1]
// -> [2, 1, 1, 2]
// -> [2, 1, 2, 1]
// -> [2, 2, 1, 1]
Notes: This is an implementation of the algorithm for Lexicographical Permutations Generation, described in Knuth's "The Art of Computer Programming", Volume 4, Chapter 7, Section 7.2.1.2. The iteration order follows the lexicographical order. This means that the first permutation will be in ascending order, and the last will be in descending order.
Elements that compare equal are considered equal and no new permutations are created by swapping them.
An empty iterable has only one permutation, which is an empty list.
elements
- the original iterable whose elements have to be permuted.comparator
- a comparator for the iterable's elements.Collection
containing all the different
permutations of the original iterable.java.lang.NullPointerException
- If the specified iterable is null, has any
null elements, or if the specified comparator is null.@SafeVarargs public static <E> java.util.List<java.util.List<E>> cartesianProduct(java.util.Collection<? extends E>... cs)
Lists.cartesianProduct(ImmutableList.of(
ImmutableList.of(1, 2),
ImmutableList.of("A", "B", "C")))
returns a list containing six lists in the following order:
ImmutableList.of(1, "A")
ImmutableList.of(1, "B")
ImmutableList.of(1, "C")
ImmutableList.of(2, "A")
ImmutableList.of(2, "B")
ImmutableList.of(2, "C")
The result is guaranteed to be in the "traditional", lexicographical order for Cartesian products that you would get from nesting for loops:
for (B b0 : lists.get(0)) {
for (B b1 : lists.get(1)) {
...
ImmutableList<B> tuple = ImmutableList.of(b0, b1, ...);
// operate on tuple
}
}
Note that if any input list is empty, the Cartesian product will also be empty. If no lists at all are provided (an empty list), the resulting Cartesian product has one element, an empty list (counter-intuitive, but mathematically consistent).
Performance notes: while the cartesian product of lists of size
m, n, p
is a list of size m x n x p
, its actual memory
consumption is much smaller. When the cartesian product is constructed, the
input lists are merely copied. Only as the resulting list is iterated are
the individual lists created, and these are not retained after iteration.
E
- any common base class shared by all axes (often just Object
)cs
- the lists to choose elements from, in the order that
the elements chosen from those lists should appear in the resulting
listsjava.lang.IllegalArgumentException
- if the size of the cartesian product would
be greater than Integer.MAX_VALUE
java.lang.NullPointerException
- if lists
, any one of the
lists
, or any element of a provided list is nullpublic static <E> java.util.List<java.util.List<E>> cartesianProduct(java.util.Collection<? extends java.util.Collection<? extends E>> cs)
Lists.cartesianProduct(ImmutableList.of(
ImmutableList.of(1, 2),
ImmutableList.of("A", "B", "C")))
returns a list containing six lists in the following order:
ImmutableList.of(1, "A")
ImmutableList.of(1, "B")
ImmutableList.of(1, "C")
ImmutableList.of(2, "A")
ImmutableList.of(2, "B")
ImmutableList.of(2, "C")
The result is guaranteed to be in the "traditional", lexicographical order for Cartesian products that you would get from nesting for loops:
for (B b0 : lists.get(0)) {
for (B b1 : lists.get(1)) {
...
ImmutableList<B> tuple = ImmutableList.of(b0, b1, ...);
// operate on tuple
}
}
Note that if any input list is empty, the Cartesian product will also be empty. If no lists at all are provided (an empty list), the resulting Cartesian product has one element, an empty list (counter-intuitive, but mathematically consistent).
Performance notes: while the cartesian product of lists of size
m, n, p
is a list of size m x n x p
, its actual memory
consumption is much smaller. When the cartesian product is constructed, the
input lists are merely copied. Only as the resulting list is iterated are
the individual lists created, and these are not retained after iteration.
E
- any common base class shared by all axes (often just Object
)cs
- the lists to choose elements from, in the order that
the elements chosen from those lists should appear in the resulting
listsjava.lang.IllegalArgumentException
- if the size of the cartesian product would
be greater than Integer.MAX_VALUE
java.lang.NullPointerException
- if lists
, any one of the lists
,
or any element of a provided list is null@Deprecated public final boolean add(E e)
add
in interface java.util.Collection<E>
add
in class java.util.AbstractCollection<E>
@Deprecated public final boolean addAll(java.util.Collection<? extends E> newElements)
addAll
in interface java.util.Collection<E>
addAll
in class java.util.AbstractCollection<E>
@Deprecated public final boolean remove(java.lang.Object object)
remove
in interface java.util.Collection<E>
remove
in class java.util.AbstractCollection<E>
@Deprecated public boolean removeIf(java.util.function.Predicate<? super E> filter)
@Deprecated public final boolean removeAll(java.util.Collection<?> oldElements)
removeAll
in interface java.util.Collection<E>
removeAll
in class java.util.AbstractCollection<E>
@Deprecated public final boolean retainAll(java.util.Collection<?> elementsToKeep)
retainAll
in interface java.util.Collection<E>
retainAll
in class java.util.AbstractCollection<E>
@Deprecated public final void clear()
clear
in interface java.util.Collection<E>
clear
in class java.util.AbstractCollection<E>