Class Iterables
Note: This class includes codes copied from Apache Commons Lang, Google Guava and other open source projects under the Apache License 2.0. The methods copied from other libraries/frameworks/projects may be modified in this class.
This is a utility class for iterable data structures, including Collection/Array/Iterator
.
The methods in this class should only read the input Collection/Array/Iterator
parameters, not modify them.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic u.Optional<BigDecimal>
averageBigDecimal
(Iterable<? extends BigDecimal> c) static <T,
E extends Exception>
u.Optional<BigDecimal>averageBigDecimal
(Iterable<? extends T> c, Throwables.Function<? super T, BigDecimal, E> func) static u.Optional<BigDecimal>
averageBigInteger
(Iterable<? extends BigInteger> c) static <T,
E extends Exception>
u.Optional<BigDecimal>averageBigInteger
(Iterable<? extends T> c, Throwables.Function<? super T, BigInteger, E> func) static <T extends Number>
u.OptionalDoubleaverageDouble
(Iterable<? extends T> c) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageDouble
(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageDouble
(Collection<? extends T> c, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageDouble
(Collection<? extends T> c, int fromIndex, int toIndex, Throwables.ToDoubleFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageDouble
(T[] a) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageDouble
(T[] a, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageDouble
(T[] a, int fromIndex, int toIndex, Throwables.ToDoubleFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageDouble
(T[] a, Throwables.ToDoubleFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageInt
(Iterable<? extends T> c) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageInt
(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageInt
(Collection<? extends T> c, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageInt
(Collection<? extends T> c, int fromIndex, int toIndex, Throwables.ToIntFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageInt
(T[] a) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageInt
(T[] a, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageInt
(T[] a, int fromIndex, int toIndex, Throwables.ToIntFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageInt
(T[] a, Throwables.ToIntFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageLong
(Iterable<? extends T> c) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageLong
(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageLong
(Collection<? extends T> c, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageLong
(Collection<? extends T> c, int fromIndex, int toIndex, Throwables.ToLongFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageLong
(T[] a) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalDoubleaverageLong
(T[] a, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageLong
(T[] a, int fromIndex, int toIndex, Throwables.ToLongFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoubleaverageLong
(T[] a, Throwables.ToLongFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.cartesianProduct
(Collection<? extends E>... cs) Note: copy from Google Guava under Apache License v2.cartesianProduct
(Collection<? extends Collection<? extends E>> cs) Note: copy from Google Guava under Apache License v2.static <E> Iterables.SetView<E>
difference
(Set<E> set1, Set<?> set2) Returns an unmodifiable view of the difference of two sets.static <T,
E extends Exception>
Pair<u.Nullable<T>,u.Nullable<T>> findFirstAndLast
(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicate) Find first and last.static <T,
E extends Exception, E2 extends Exception>
Pair<u.Nullable<T>,u.Nullable<T>> findFirstAndLast
(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) Find first and last.static <T,
E extends Exception>
Pair<u.Nullable<T>,u.Nullable<T>> findFirstAndLast
(T[] a, Throwables.Predicate<? super T, E> predicate) Find first and last.static <T,
E extends Exception, E2 extends Exception>
Pair<u.Nullable<T>,u.Nullable<T>> findFirstAndLast
(T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) Find first and last.static <T,
E extends Exception>
Pair<u.OptionalInt,u.OptionalInt> findFirstAndLastIndex
(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicate) Find first and last index.static <T,
E extends Exception, E2 extends Exception>
Pair<u.OptionalInt,u.OptionalInt> findFirstAndLastIndex
(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) Find first and last index.static <T,
E extends Exception>
Pair<u.OptionalInt,u.OptionalInt> findFirstAndLastIndex
(T[] a, Throwables.Predicate<? super T, E> predicate) Find first and last index.static <T,
E extends Exception, E2 extends Exception>
Pair<u.OptionalInt,u.OptionalInt> findFirstAndLastIndex
(T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) Find first and last index.static <T,
E extends Exception, E2 extends Exception>
u.Nullable<T>findFirstOrLast
(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) Find first or last.static <T,
E extends Exception, E2 extends Exception>
u.Nullable<T>findFirstOrLast
(T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) Find first or last.static <T,
E extends Exception, E2 extends Exception>
u.OptionalIntfindFirstOrLastIndex
(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) static <T,
E extends Exception, E2 extends Exception>
u.OptionalIntfindFirstOrLastIndex
(T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, E2> predicateForLast) Find first or last index.static u.OptionalInt
static u.OptionalInt
indexOf
(Collection<?> c, Object objToFind) static <E> Iterables.SetView<E>
intersection
(Set<E> set1, Set<?> set2) Returns an unmodifiable view of the intersection of two sets.static <T extends Comparable<? super T>>
u.Nullable<T>kthLargest
(Collection<? extends T> c, int k) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.static <T> u.Nullable<T>
kthLargest
(Collection<? extends T> c, int k, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.static <T extends Comparable<? super T>>
u.Nullable<T>kthLargest
(T[] a, int k) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.static <T> u.Nullable<T>
kthLargest
(T[] a, int k, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.static u.OptionalInt
lastIndexOf
(Object[] a, Object objToFind) static u.OptionalInt
lastIndexOf
(Collection<?> c, Object objToFind) static u.OptionalByte
max
(byte... a) ReturnsOptionalByte.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalChar
max
(char... a) ReturnsOptionalChar.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalDouble
max
(double... a) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalFloat
max
(float... a) ReturnsOptionalFloat.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalInt
max
(int... a) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalLong
max
(long... a) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalShort
max
(short... a) ReturnsOptionalShort.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
max
(Iterable<? extends T> c, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
max
(Iterator<? extends T> iter, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>max
(T[] a) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
max
(T[] a, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
maxBy
(Iterable<? extends T> c, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
maxBy
(Iterator<? extends T> iter, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
maxBy
(T[] a, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalDoublemaxDouble
(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> valueExtractor) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalDoublemaxDouble
(Iterator<? extends T> iter, Throwables.ToDoubleFunction<? super T, E> valueExtractor) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalDoublemaxDouble
(T[] a, Throwables.ToDoubleFunction<? super T, E> valueExtractor) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalIntmaxInt
(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> valueExtractor) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalIntmaxInt
(Iterator<? extends T> iter, Throwables.ToIntFunction<? super T, E> valueExtractor) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalIntmaxInt
(T[] a, Throwables.ToIntFunction<? super T, E> valueExtractor) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalLongmaxLong
(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> valueExtractor) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalLongmaxLong
(Iterator<? extends T> iter, Throwables.ToLongFunction<? super T, E> valueExtractor) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalLongmaxLong
(T[] a, Throwables.ToLongFunction<? super T, E> valueExtractor) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>median
(Collection<? extends T> c) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
median
(Collection<? extends T> c, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>median
(T[] a) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
median
(T[] a, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
medianBy
(Collection<? extends T> c, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
medianBy
(T[] a, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalByte
min
(byte... a) ReturnsOptionalByte.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalChar
min
(char... a) ReturnsOptionalChar.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalDouble
min
(double... a) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalFloat
min
(float... a) ReturnsOptionalFloat.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalInt
min
(int... a) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalLong
min
(long... a) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static u.OptionalShort
min
(short... a) ReturnsOptionalShort.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
min
(Iterable<? extends T> c, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
min
(Iterator<? extends T> iter, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Nullable<T>min
(T[] a) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
min
(T[] a, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
minBy
(Iterable<? extends T> c, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
minBy
(Iterator<? extends T> iter, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T> u.Nullable<T>
minBy
(T[] a, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalDoubleminDouble
(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> valueExtractor) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalDoubleminDouble
(Iterator<? extends T> iter, Throwables.ToDoubleFunction<? super T, E> valueExtractor) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalDoubleminDouble
(T[] a, Throwables.ToDoubleFunction<? super T, E> valueExtractor) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalIntminInt
(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> valueExtractor) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalIntminInt
(Iterator<? extends T> iter, Throwables.ToIntFunction<? super T, E> valueExtractor) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalIntminInt
(T[] a, Throwables.ToIntFunction<? super T, E> valueExtractor) ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalLongminLong
(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> valueExtractor) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalLongminLong
(Iterator<? extends T> iter, Throwables.ToLongFunction<? super T, E> valueExtractor) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static <T,
E extends Exception>
u.OptionalLongminLong
(T[] a, Throwables.ToLongFunction<? super T, E> valueExtractor) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.static <T extends Comparable<? super T>>
u.Optional<Pair<T,T>> static <T> u.Optional<Pair<T,
T>> minMax
(Iterable<? extends T> c, Comparator<? super T> cmp) static <T extends Comparable<? super T>>
u.Optional<Pair<T,T>> static <T> u.Optional<Pair<T,
T>> minMax
(Iterator<? extends T> iter, Comparator<? super T> cmp) static <T extends Comparable<? super T>>
u.Optional<Pair<T,T>> minMax
(T[] a) static <T> u.Optional<Pair<T,
T>> minMax
(T[] a, Comparator<? super T> cmp) static <E extends Comparable<? super E>>
Collection<List<E>>orderedPermutations
(Collection<E> elements) Note: copy from Google Guava under Apache License v2.static <E> Collection<List<E>>
orderedPermutations
(Collection<E> elements, Comparator<? super E> comparator) Note: copy from Google Guava under Apache License v2.static <E> Collection<List<E>>
permutations
(Collection<E> elements) Note: copy from Google Guava under Apache License v2.Note: copy from Google Guava under Apache License v2.rollup
(Collection<? extends T> c) static <K extends Comparable<? super K>>
NavigableSet<K>subSet
(NavigableSet<K> set, Range<K> range) static u.Optional<BigDecimal>
sumBigDecimal
(Iterable<? extends BigDecimal> c) static <T,
E extends Exception>
u.Optional<BigDecimal>sumBigDecimal
(Iterable<? extends T> c, Throwables.Function<? super T, BigDecimal, E> func) static u.Optional<BigInteger>
sumBigInteger
(Iterable<? extends BigInteger> c) static <T,
E extends Exception>
u.Optional<BigInteger>sumBigInteger
(Iterable<? extends T> c, Throwables.Function<? super T, BigInteger, E> func) static <T extends Number>
u.OptionalDoubleReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalDoublesumDouble
(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> func) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalIntReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalIntsumInt
(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> func) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalLongsumIntToLong
(Iterable<? extends T> c) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalLongsumIntToLong
(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> func) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T extends Number>
u.OptionalLongReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <T,
E extends Exception>
u.OptionalLongsumLong
(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> func) ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.static <E> Iterables.SetView<E>
symmetricDifference
(Set<? extends E> set1, Set<? extends E> set2) Returns an unmodifiable view of the symmetric difference of two sets.static <E> Iterables.SetView<E>
Returns an unmodifiable view of the union of two sets.
-
Method Details
-
min
ReturnsOptionalChar.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
min
ReturnsOptionalByte.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
min
ReturnsOptionalShort.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
min
ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
min
ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
min
ReturnsOptionalFloat.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
min
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
min
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
min
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-cmp
-- Returns:
-
min
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
min
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-cmp
-- Returns:
-
min
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
min
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
iter
-cmp
-- Returns:
-
minBy
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-keyMapper
-- Returns:
-
minBy
public static <T> u.Nullable<T> minBy(Iterable<? extends T> c, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-keyMapper
-- Returns:
-
minBy
public static <T> u.Nullable<T> minBy(Iterator<? extends T> iter, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
iter
-keyMapper
-- Returns:
-
minInt
@Beta public static <T,E extends Exception> u.OptionalInt minInt(T[] a, Throwables.ToIntFunction<? super T, E> valueExtractor) throws EReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
a
-valueExtractor
-- Returns:
- Throws:
E
-
minInt
@Beta public static <T,E extends Exception> u.OptionalInt minInt(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> valueExtractor) throws EReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
c
-valueExtractor
-- Returns:
- Throws:
E
-
minInt
@Beta public static <T,E extends Exception> u.OptionalInt minInt(Iterator<? extends T> iter, Throwables.ToIntFunction<? super T, E> valueExtractor) throws EReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
iter
-valueExtractor
-- Returns:
- Throws:
E
-
minLong
@Beta public static <T,E extends Exception> u.OptionalLong minLong(T[] a, Throwables.ToLongFunction<? super T, E> valueExtractor) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
a
-valueExtractor
-- Returns:
- Throws:
E
-
minLong
@Beta public static <T,E extends Exception> u.OptionalLong minLong(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> valueExtractor) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
c
-valueExtractor
-- Returns:
- Throws:
E
-
minLong
@Beta public static <T,E extends Exception> u.OptionalLong minLong(Iterator<? extends T> iter, Throwables.ToLongFunction<? super T, E> valueExtractor) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
iter
-valueExtractor
-- Returns:
- Throws:
E
-
minDouble
@Beta public static <T,E extends Exception> u.OptionalDouble minDouble(T[] a, Throwables.ToDoubleFunction<? super T, E> valueExtractor) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
a
-valueExtractor
-- Returns:
- Throws:
E
-
minDouble
@Beta public static <T,E extends Exception> u.OptionalDouble minDouble(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> valueExtractor) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
c
-valueExtractor
-- Returns:
- Throws:
E
-
minDouble
@Beta public static <T,E extends Exception> u.OptionalDouble minDouble(Iterator<? extends T> iter, Throwables.ToDoubleFunction<? super T, E> valueExtractor) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
iter
-valueExtractor
-- Returns:
- Throws:
E
-
max
ReturnsOptionalChar.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
max
ReturnsOptionalByte.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
max
ReturnsOptionalShort.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
max
ReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
max
ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
max
ReturnsOptionalFloat.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
max
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Parameters:
a
-- Returns:
-
max
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
max
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-cmp
-- Returns:
-
max
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
max
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-cmp
-- Returns:
-
max
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
iter
-- Returns:
-
max
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
iter
-cmp
-- Returns:
-
maxBy
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-keyMapper
-- Returns:
-
maxBy
public static <T> u.Nullable<T> maxBy(Iterable<? extends T> c, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-keyMapper
-- Returns:
-
maxBy
public static <T> u.Nullable<T> maxBy(Iterator<? extends T> iter, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
iter
-keyMapper
-- Returns:
-
maxInt
@Beta public static <T,E extends Exception> u.OptionalInt maxInt(T[] a, Throwables.ToIntFunction<? super T, E> valueExtractor) throws EReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
a
-valueExtractor
-- Returns:
- Throws:
E
-
maxInt
@Beta public static <T,E extends Exception> u.OptionalInt maxInt(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> valueExtractor) throws EReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
c
-valueExtractor
-- Returns:
- Throws:
E
-
maxInt
@Beta public static <T,E extends Exception> u.OptionalInt maxInt(Iterator<? extends T> iter, Throwables.ToIntFunction<? super T, E> valueExtractor) throws EReturnsOptionalInt.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
iter
-valueExtractor
-- Returns:
- Throws:
E
-
maxLong
@Beta public static <T,E extends Exception> u.OptionalLong maxLong(T[] a, Throwables.ToLongFunction<? super T, E> valueExtractor) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
a
-valueExtractor
-- Returns:
- Throws:
E
-
maxLong
@Beta public static <T,E extends Exception> u.OptionalLong maxLong(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> valueExtractor) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
c
-valueExtractor
-- Returns:
- Throws:
E
-
maxLong
@Beta public static <T,E extends Exception> u.OptionalLong maxLong(Iterator<? extends T> iter, Throwables.ToLongFunction<? super T, E> valueExtractor) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
iter
-valueExtractor
-- Returns:
- Throws:
E
-
maxDouble
@Beta public static <T,E extends Exception> u.OptionalDouble maxDouble(T[] a, Throwables.ToDoubleFunction<? super T, E> valueExtractor) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
a
-valueExtractor
-- Returns:
- Throws:
E
-
maxDouble
@Beta public static <T,E extends Exception> u.OptionalDouble maxDouble(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> valueExtractor) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
c
-valueExtractor
-- Returns:
- Throws:
E
-
maxDouble
@Beta public static <T,E extends Exception> u.OptionalDouble maxDouble(Iterator<? extends T> iter, Throwables.ToDoubleFunction<? super T, E> valueExtractor) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-E
-- Parameters:
iter
-valueExtractor
-- Returns:
- Throws:
E
-
minMax
- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
minMax
- Type Parameters:
T
-- Parameters:
a
-cmp
-- Returns:
-
minMax
public static <T extends Comparable<? super T>> u.Optional<Pair<T,T>> minMax(Iterable<? extends T> c) - Type Parameters:
T
-- Parameters:
c
-- Returns:
-
minMax
- Type Parameters:
T
-- Parameters:
c
-cmp
-- Returns:
-
minMax
public static <T extends Comparable<? super T>> u.Optional<Pair<T,T>> minMax(Iterator<? extends T> iter) - Type Parameters:
T
-- Parameters:
iter
-- Returns:
- See Also:
-
minMax
public static <T> u.Optional<Pair<T,T>> minMax(Iterator<? extends T> iter, Comparator<? super T> cmp) - Type Parameters:
T
-- Parameters:
iter
-cmp
-- Returns:
- See Also:
-
median
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
median
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-cmp
-- Returns:
-
median
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
median
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-cmp
-- Returns:
-
medianBy
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
a
-keyMapper
-- Returns:
-
medianBy
public static <T> u.Nullable<T> medianBy(Collection<? extends T> c, Function<? super T, ? extends Comparable> keyMapper) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty.- Type Parameters:
T
-- Parameters:
c
-keyMapper
-- Returns:
-
kthLargest
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.- Type Parameters:
T
-- Parameters:
a
-k
-- Returns:
-
kthLargest
ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.- Type Parameters:
T
-- Parameters:
a
-k
-cmp
-- Returns:
-
kthLargest
public static <T extends Comparable<? super T>> u.Nullable<T> kthLargest(Collection<? extends T> c, int k) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.- Type Parameters:
T
-- Parameters:
c
-k
-- Returns:
-
kthLargest
public static <T> u.Nullable<T> kthLargest(Collection<? extends T> c, int k, Comparator<? super T> cmp) ReturnsNullable.empty()
if the specifiedArray/Collection
isnull
or empty, or its length/size is less thank
.- Type Parameters:
T
-- Parameters:
c
-k
-cmp
-- Returns:
-
sumInt
ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
sumInt
public static <T,E extends Exception> u.OptionalInt sumInt(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> func) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
sumIntToLong
ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
sumIntToLong
public static <T,E extends Exception> u.OptionalLong sumIntToLong(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> func) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
sumLong
ReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
sumLong
public static <T,E extends Exception> u.OptionalLong sumLong(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> func) throws EReturnsOptionalLong.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
sumDouble
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
sumDouble
public static <T,E extends Exception> u.OptionalDouble sumDouble(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
sumBigInteger
- Parameters:
c
-- Returns:
-
sumBigInteger
public static <T,E extends Exception> u.Optional<BigInteger> sumBigInteger(Iterable<? extends T> c, Throwables.Function<? super T, BigInteger, throws EE> func) - Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
sumBigDecimal
- Parameters:
c
-- Returns:
-
sumBigDecimal
public static <T,E extends Exception> u.Optional<BigDecimal> sumBigDecimal(Iterable<? extends T> c, Throwables.Function<? super T, BigDecimal, throws EE> func) - Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
averageInt
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
averageInt
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
averageInt
public static <T,E extends Exception> u.OptionalDouble averageInt(T[] a, Throwables.ToIntFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
a
-func
-- Returns:
- Throws:
E
- the e
-
averageInt
public static <T,E extends Exception> u.OptionalDouble averageInt(T[] a, int fromIndex, int toIndex, Throwables.ToIntFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
a
-fromIndex
-toIndex
-func
-- Returns:
- Throws:
E
- the e
-
averageInt
public static <T extends Number> u.OptionalDouble averageInt(Collection<? extends T> c, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
averageInt
public static <T,E extends Exception> u.OptionalDouble averageInt(Collection<? extends T> c, int fromIndex, int toIndex, Throwables.ToIntFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-fromIndex
-toIndex
-func
-- Returns:
- Throws:
E
- the e
-
averageInt
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
averageInt
public static <T,E extends Exception> u.OptionalDouble averageInt(Iterable<? extends T> c, Throwables.ToIntFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
averageLong
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
averageLong
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
averageLong
public static <T,E extends Exception> u.OptionalDouble averageLong(T[] a, Throwables.ToLongFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
a
-func
-- Returns:
- Throws:
E
- the e
-
averageLong
public static <T,E extends Exception> u.OptionalDouble averageLong(T[] a, int fromIndex, int toIndex, Throwables.ToLongFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
a
-fromIndex
-toIndex
-func
-- Returns:
- Throws:
E
- the e
-
averageLong
public static <T extends Number> u.OptionalDouble averageLong(Collection<? extends T> c, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
averageLong
public static <T,E extends Exception> u.OptionalDouble averageLong(Collection<? extends T> c, int fromIndex, int toIndex, Throwables.ToLongFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-fromIndex
-toIndex
-func
-- Returns:
- Throws:
E
- the e
-
averageLong
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
averageLong
public static <T,E extends Exception> u.OptionalDouble averageLong(Iterable<? extends T> c, Throwables.ToLongFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
averageDouble
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
a
-- Returns:
-
averageDouble
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
a
-fromIndex
-toIndex
-- Returns:
-
averageDouble
public static <T,E extends Exception> u.OptionalDouble averageDouble(T[] a, Throwables.ToDoubleFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
a
-func
-- Returns:
- Throws:
E
- the e
-
averageDouble
public static <T,E extends Exception> u.OptionalDouble averageDouble(T[] a, int fromIndex, int toIndex, Throwables.ToDoubleFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
a
-fromIndex
-toIndex
-func
-- Returns:
- Throws:
E
- the e
-
averageDouble
public static <T extends Number> u.OptionalDouble averageDouble(Collection<? extends T> c, int fromIndex, int toIndex) ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-fromIndex
-toIndex
-- Returns:
-
averageDouble
public static <T,E extends Exception> u.OptionalDouble averageDouble(Collection<? extends T> c, int fromIndex, int toIndex, Throwables.ToDoubleFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-fromIndex
-toIndex
-func
-- Returns:
- Throws:
E
- the e
-
averageDouble
ReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-- Parameters:
c
-- Returns:
-
averageDouble
public static <T,E extends Exception> u.OptionalDouble averageDouble(Iterable<? extends T> c, Throwables.ToDoubleFunction<? super T, E> func) throws EReturnsOptionalDouble.empty()
if the specifiedArray/Collection
isnull
or empty, orfromIndex == toIndex
.- Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
averageBigInteger
- Parameters:
c
-- Returns:
-
averageBigInteger
public static <T,E extends Exception> u.Optional<BigDecimal> averageBigInteger(Iterable<? extends T> c, Throwables.Function<? super T, BigInteger, throws EE> func) - Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
averageBigDecimal
- Parameters:
c
-- Returns:
-
averageBigDecimal
public static <T,E extends Exception> u.Optional<BigDecimal> averageBigDecimal(Iterable<? extends T> c, Throwables.Function<? super T, BigDecimal, throws EE> func) - Type Parameters:
T
-E
-- Parameters:
c
-func
-- Returns:
- Throws:
E
- the e
-
indexOf
- Parameters:
a
-objToFind
-- Returns:
- See Also:
-
indexOf
- Parameters:
c
-objToFind
-- Returns:
- See Also:
-
lastIndexOf
- Parameters:
a
-objToFind
-- Returns:
- See Also:
-
lastIndexOf
- Parameters:
c
-objToFind
-- Returns:
- See Also:
-
findFirstOrLast
public static <T,E extends Exception, u.Nullable<T> findFirstOrLastE2 extends Exception> (T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) Find first or last.- Type Parameters:
T
-E
-E2
-- Parameters:
a
-predicateForFirst
-predicateForLast
-- Returns:
- the nullable
- Throws:
E
- the eE2
- the e2
-
findFirstOrLast
public static <T,E extends Exception, u.Nullable<T> findFirstOrLastE2 extends Exception> (Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) Find first or last.- Type Parameters:
T
-E
-E2
-- Parameters:
c
-predicateForFirst
-predicateForLast
-- Returns:
- the nullable
- Throws:
E
- the eE2
- the e2
-
findFirstOrLastIndex
public static <T,E extends Exception, u.OptionalInt findFirstOrLastIndexE2 extends Exception> (T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) Find first or last index.- Type Parameters:
T
-E
-E2
-- Parameters:
a
-predicateForFirst
-predicateForLast
-- Returns:
- the optional int
- Throws:
E
- the eE2
- the e2
-
findFirstOrLastIndex
public static <T,E extends Exception, u.OptionalInt findFirstOrLastIndexE2 extends Exception> (Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) - Type Parameters:
T
-E
-E2
-- Parameters:
c
-predicateForFirst
-predicateForLast
-- Returns:
- Throws:
E
E2
-
findFirstAndLast
public static <T,E extends Exception> Pair<u.Nullable<T>,u.Nullable<T>> findFirstAndLast(T[] a, Throwables.Predicate<? super T, E> predicate) throws EFind first and last.- Type Parameters:
T
-E
-- Parameters:
a
-predicate
-- Returns:
- the pair
- Throws:
E
- the e
-
findFirstAndLast
public static <T,E extends Exception, Pair<u.Nullable<T>,E2 extends Exception> u.Nullable<T>> findFirstAndLast(T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) Find first and last.- Type Parameters:
T
-E
-E2
-- Parameters:
a
-predicateForFirst
-predicateForLast
-- Returns:
- the pair
- Throws:
E
- the eE2
- the e2
-
findFirstAndLast
public static <T,E extends Exception> Pair<u.Nullable<T>,u.Nullable<T>> findFirstAndLast(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicate) throws EFind first and last.- Type Parameters:
T
-E
-- Parameters:
c
-predicate
-- Returns:
- the pair
- Throws:
E
- the e
-
findFirstAndLast
public static <T,E extends Exception, Pair<u.Nullable<T>,E2 extends Exception> u.Nullable<T>> findFirstAndLast(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) Find first and last.- Type Parameters:
T
-E
-E2
-- Parameters:
c
-predicateForFirst
-predicateForLast
-- Returns:
- the pair
- Throws:
E
- the eE2
- the e2
-
findFirstAndLastIndex
public static <T,E extends Exception> Pair<u.OptionalInt,u.OptionalInt> findFirstAndLastIndex(T[] a, Throwables.Predicate<? super T, E> predicate) throws EFind first and last index.- Type Parameters:
T
-E
-- Parameters:
a
-predicate
-- Returns:
- the pair
- Throws:
E
- the e
-
findFirstAndLastIndex
public static <T,E extends Exception, Pair<u.OptionalInt,E2 extends Exception> u.OptionalInt> findFirstAndLastIndex(T[] a, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) Find first and last index.- Type Parameters:
T
-E
-E2
-- Parameters:
a
-predicateForFirst
-predicateForLast
-- Returns:
- the pair
- Throws:
E
- the eE2
- the e2
-
findFirstAndLastIndex
public static <T,E extends Exception> Pair<u.OptionalInt,u.OptionalInt> findFirstAndLastIndex(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicate) throws EFind first and last index.- Type Parameters:
T
-E
-- Parameters:
c
-predicate
-- Returns:
- the pair
- Throws:
E
- the e
-
findFirstAndLastIndex
public static <T,E extends Exception, Pair<u.OptionalInt,E2 extends Exception> u.OptionalInt> findFirstAndLastIndex(Collection<? extends T> c, Throwables.Predicate<? super T, E> predicateForFirst, Throwables.Predicate<? super T, throws E, E2E2> predicateForLast) Find first and last index.- Type Parameters:
T
-E
-E2
-- Parameters:
c
-predicateForFirst
-predicateForLast
-- Returns:
- the pair
- Throws:
E
- the eE2
- the e2
-
union
Returns an unmodifiable view of the union of two sets. The returned set contains all elements that are contained in either backing set. Iterating over the returned set iterates first over all the elements ofset1
, then over each element ofset2
, in order, that is not contained inset1
.Results are undefined if
set1
andset2
are sets based on different equivalence relations (asHashSet
,TreeSet
, and theMap.keySet()
of anIdentityHashMap
all are).- Type Parameters:
E
-- Parameters:
set1
-set2
-- Returns:
-
intersection
Returns an unmodifiable view of the intersection of two sets. The returned set contains all elements that are contained by both backing sets. The iteration order of the returned set matches that ofset1
.Results are undefined if
set1
andset2
are sets based on different equivalence relations (asHashSet
,TreeSet
, and the keySet of anIdentityHashMap
all are).Note: The returned view performs slightly better when
set1
is the smaller of the two sets. If you have reason to believe one of your sets will generally be smaller than the other, pass it first. Unfortunately, since this method sets the generic type of the returned set based on the type of the first set passed, this could in rare cases force you to make a cast, for example:Set<Object> aFewBadObjects = ... Set<String> manyBadStrings = ... // impossible for a non-String to be in the intersection SuppressWarnings("unchecked") Set<String> badStrings = (Set) Sets.intersection( aFewBadObjects, manyBadStrings);
This is unfortunate, but should come up only very rarely.
- Type Parameters:
E
-- Parameters:
set1
-set2
-- Returns:
-
difference
Returns an unmodifiable view of the difference of two sets. The returned set contains all elements that are contained byset1
and not contained byset2
.set2
may also contain elements not present inset1
; these are simply ignored. The iteration order of the returned set matches that ofset1
.Results are undefined if
set1
andset2
are sets based on different equivalence relations (asHashSet
,TreeSet
, and the keySet of anIdentityHashMap
all are).- Type Parameters:
E
-- Parameters:
set1
-set2
-- Returns:
-
symmetricDifference
public static <E> Iterables.SetView<E> symmetricDifference(Set<? extends E> set1, Set<? extends E> set2) Returns an unmodifiable view of the symmetric difference of two sets. The returned set contains all elements that are contained in eitherset1
orset2
but not in both. The iteration order of the returned set is undefined.Results are undefined if
set1
andset2
are sets based on different equivalence relations (asHashSet
,TreeSet
, and the keySet of anIdentityHashMap
all are).- Type Parameters:
E
-- Parameters:
set1
-set2
-- Returns:
- Since:
- 3.0
-
powerSet
Note: copy from Google Guava under Apache License v2.
Returns the set of all possible subsets ofset
. 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 size2^n
, its memory usage is onlyO(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.- Type Parameters:
E
-- Parameters:
set
- the set of elements to construct a power set from- Returns:
- the sets the
- Throws:
IllegalArgumentException
- ifset
has more than 30 unique elements (causing the power set size to exceed theint
range)NullPointerException
- ifset
is or containsnull
- See Also:
-
rollup
- Type Parameters:
T
-- Parameters:
c
-- Returns:
- the list
-
permutations
Note: copy from Google Guava under Apache License v2.
Returns aCollection
of all the permutations of the specifiedCollection
.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.
- Type Parameters:
E
-- Parameters:
elements
- the original collection whose elements have to be permuted.- Returns:
- an immutable
Collection
containing all the different permutations of the original collection. - Throws:
NullPointerException
- if the specified collection is null or has any null elements.
-
orderedPermutations
public static <E extends Comparable<? super E>> Collection<List<E>> orderedPermutations(Collection<E> elements) Note: copy from Google Guava under Apache License v2.
Returns aCollection
of all the permutations of the specifiedIterable
.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())
.- Type Parameters:
E
-- Parameters:
elements
- the original iterable whose elements have to be permuted.- Returns:
- an immutable
Collection
containing all the different permutations of the original iterable. - Throws:
NullPointerException
- if the specified iterable is null or has any null elements.
-
orderedPermutations
public static <E> Collection<List<E>> orderedPermutations(Collection<E> elements, Comparator<? super E> comparator) Note: copy from Google Guava under Apache License v2.
Returns aCollection
of all the permutations of the specifiedIterable
using the specifiedComparator
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.
- Type Parameters:
E
-- Parameters:
elements
- the original iterable whose elements have to be permuted.comparator
- a comparator for the iterable's elements.- Returns:
- an immutable
Collection
containing all the different permutations of the original iterable. - Throws:
NullPointerException
- If the specified iterable is null, has any null elements, or if the specified comparator is null.
-
cartesianProduct
Note: copy from Google Guava under Apache License v2.
Returns every possible list that can be formed by choosing one element from each of the given lists in order; the "n-ary Cartesian product" of the lists. For example: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 sizem 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.- Type Parameters:
E
- any common base class shared by all axes (often justObject
)- Parameters:
cs
- the lists to choose elements from, in the order that the elements chosen from those lists should appear in the resulting lists- Returns:
- lists
- Throws:
IllegalArgumentException
- if the size of the cartesian product would be greater thanInteger.MAX_VALUE
NullPointerException
- iflists
, any one of thelists
, or any element of a provided list is null
-
cartesianProduct
Note: copy from Google Guava under Apache License v2.
Returns every possible list that can be formed by choosing one element from each of the given lists in order; the "n-ary Cartesian product" of the lists. For example: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 sizem 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.- Type Parameters:
E
- any common base class shared by all axes (often justObject
)- Parameters:
cs
- the lists to choose elements from, in the order that the elements chosen from those lists should appear in the resulting lists- Returns:
- lists
- Throws:
IllegalArgumentException
- if the size of the cartesian product would be greater thanInteger.MAX_VALUE
NullPointerException
- iflists
, any one of thelists
, or any element of a provided list is null
-