- All Superinterfaces:
Iterable<T>
- All Known Subinterfaces:
MutableCollection<T>
- All Known Implementing Classes:
Collection,List,MutableList,MutableSet,Opt,Set
Collection of elements that may be traversed in sequence.
This interface adds transformation and reduction methods
to the
Iterable. The transformations return traversable
views of the collection indicating that their result should only
be used for reduction or iteration. Traversables can be chained
avoiding iteration until the reduction is performed.-
Method Summary
Modifier and TypeMethodDescriptiondefault Traversable<?> chain(Traversable<?> other) Traversable that iterates over elements of both traversables.default <R> Traversable<R> chainMap(Function<? super @Out T, ? extends Traversable<R>> mapping) Appliesmappingto the elements and chains the resulting traversables together.default intcount()Counts number of elements in this collection.default intCounts number of elements that satisfy givencondition.default booleanTests whether any element in this traversable matches givencondition.default Traversable<T> Returns traversable that only traverses elements satisfying givencondition.Returns element that satisfiesconditionor empty optional if there is no such element.default Tfirst()Returns the first element produced by the iterator of this traversable.default <R> Rfold(R first, BiFunction<? super R, ? super @Out T, ? extends R> combine) Starting from thefirst, appliescombineto elements of the collection returning result.default booleanTests whether all elements in this traversable match givencondition.Deprecated.default <K> ListMultimap<K, T> groupedIntoLists(Function<? super @Out T, ? extends K> classifier) Collects elements of this traversable into sets grouped by given classifier.default <K> SetMultimap<K, T> groupedIntoSets(Function<? super @Out T, ? extends K> classifier) Collects elements of this traversable into sets grouped by given classifier.default booleanisEmpty()Whether this collection has no elements.default StringJoins elements of the traversable into a string.default StringJoins elements of the traversable into a string.default <R> Traversable<R> Returns traversable with givenmappingapplied to all elements.default <U> Traversable<U> Returns traversable that only traverses subclasses ofclazz.default booleannonEmpty()Whether this collection contains elements.sortedBy(Comparator<? super @Out T> comparing) Returns list of elements of this traversable sorted by given comparator.default Traversable<T> take(int limit) Traverses no more thanlimitelements of this traversable.default Traversable<T> Iterates through elements of this traversable until given condition fails.toList()Collects elements of this traversable into an immutable list.toSet()Collects elements of this traversable into an immutable set.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
takeWhile
Iterates through elements of this traversable until given condition fails. The returned traversable is a view of this object.- See Also:
-
take
Traverses no more thanlimitelements of this traversable. The returned traversable is a view of this object.- See Also:
-
filter
Returns traversable that only traverses elements satisfying givencondition. The returned traversable is a view of this object.- See Also:
-
narrow
Returns traversable that only traverses subclasses ofclazz. The returned traversable is a view of this object. -
map
Returns traversable with givenmappingapplied to all elements. The returned traversable is a view of this traversable that lazily appliesmappingto elements returned by iterator.- See Also:
-
chain
Traversable that iterates over elements of both traversables. The iterator of the result first returns elements of this traverable, and once it is exhausted elements of the other traversable.- See Also:
-
chainMap
Appliesmappingto the elements and chains the resulting traversables together. -
first
Returns the first element produced by the iterator of this traversable. May produce different results each time it is called if the traversable has no defined order of its elements.- Throws:
NoSuchElementException- if the traversable is empty.
-
exists
Tests whether any element in this traversable matches givencondition. -
forall
Tests whether all elements in this traversable match givencondition. -
fold
Starting from thefirst, appliescombineto elements of the collection returning result. The order of elements is determined by the iterator. -
find
Returns element that satisfiesconditionor empty optional if there is no such element. -
join
Joins elements of the traversable into a string. -
join
Joins elements of the traversable into a string. -
count
Counts number of elements that satisfy givencondition. If the traversable has more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE.- Since:
- 4.1
-
count
default int count()Counts number of elements in this collection. As opposed toCollection.size()this method may need to perform computations to count the number of elements. If the traversable has more thanInteger.MAX_VALUEelements, returnsInteger.MAX_VALUE. -
isEmpty
default boolean isEmpty()Whether this collection has no elements. -
nonEmpty
default boolean nonEmpty()Whether this collection contains elements. -
groupedBy
@Deprecated(since="4.1") default <K> Map<K,? extends List<T>> groupedBy(Function<? super @Out T, ? extends K> classifier) Deprecated.Collects elements of this traversable into lists grouped by given classifier. The resulting collection is immutable and is not affected by changes to this traversable.- Type Parameters:
K- type of the classifier key.- Parameters:
classifier- function that assigns keys to elements of this traversable.
-
groupedIntoSets
Collects elements of this traversable into sets grouped by given classifier. The resulting collection is immutable and is not affected by changes to this traversable.- Type Parameters:
K- type of the classifier key.- Parameters:
classifier- function that assigns keys to elements of this traversable.- Since:
- 4.1
-
groupedIntoLists
Collects elements of this traversable into sets grouped by given classifier. The resulting collection is immutable and is not affected by changes to this traversable.- Type Parameters:
K- type of the classifier key.- Parameters:
classifier- function that assigns keys to elements of this traversable.- Since:
- 4.1
-
sortedBy
Returns list of elements of this traversable sorted by given comparator.- Parameters:
comparing- comparator for elements of this traversable.
-
toList
Collects elements of this traversable into an immutable list. -
toSet
Collects elements of this traversable into an immutable set.
-
groupedIntoSets(java.util.function.Function)orgroupedIntoLists(java.util.function.Function)instead.