InternalIterable<T>
, Iterable<T>
, OrderedIterable<T>
, RichIterable<T>
ImmutableSortedBag<T>
, ImmutableSortedSet<T>
, MutableSortedBag<T>
, MutableSortedSet<T>
, SortedBag<T>
, SortedSetIterable<T>
AbstractMutableSortedBag
, SortedSetAdapter
, SynchronizedSortedBag
, SynchronizedSortedSet
, TreeBag
, TreeSortedSet
, UnmodifiableSortedBag
, UnmodifiableSortedSet
public interface SortedIterable<T> extends OrderedIterable<T>
comparator()
or is the natural
ordering if comparator()
returns null
. Operations that would sort the collection can be faster than
O(n log n). For example RichIterable.toSortedList()
takes O(n) time.Modifier and Type | Method | Description |
---|---|---|
Comparator<? super T> |
comparator() |
Returns the comparator used to order the elements in this container, or null if this container uses the natural
ordering of its elements.
|
SortedIterable<T> |
distinct() |
Returns a new
SortedIterable containing the distinct elements in this iterable. |
SortedIterable<T> |
dropWhile(Predicate<? super T> predicate) |
Returns the final elements that do not satisfy the Predicate.
|
<V> SortedIterableMultimap<V,T> |
groupBy(Function<? super T,? extends V> function) |
For each element of the iterable, the function is evaluated and the results of these evaluations are collected
into a new multimap, where the transformed value is the key and the original values are added to the same (or similar)
species of collection as the source iterable.
|
<V> SortedIterableMultimap<V,T> |
groupByEach(Function<? super T,? extends Iterable<V>> function) |
Similar to
RichIterable.groupBy(Function) , except the result of evaluating function will return a collection of keys
for each value. |
T |
max() |
Returns the maximum element out of this container based on the natural order, not the order of this container.
|
T |
min() |
Returns the minimum element out of this container based on the natural order, not the order of this container.
|
PartitionSortedIterable<T> |
partition(Predicate<? super T> predicate) |
Filters a collection into a PartitionedIterable based on the evaluation of the predicate.
|
PartitionSortedIterable<T> |
partitionWhile(Predicate<? super T> predicate) |
Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements.
|
SortedIterable<T> |
reject(Predicate<? super T> predicate) |
Returns all elements of the source collection that return false when evaluating of the predicate.
|
<P> SortedIterable<T> |
rejectWith(Predicate2<? super T,? super P> predicate,
P parameter) |
Similar to
RichIterable.reject(Predicate) , except with an evaluation parameter for the second generic argument in Predicate2 . |
SortedIterable<T> |
select(Predicate<? super T> predicate) |
Returns all elements of the source collection that return true when evaluating the predicate.
|
<S> SortedIterable<S> |
selectInstancesOf(Class<S> clazz) |
Returns all elements of the source collection that are instances of the Class
clazz . |
<P> SortedIterable<T> |
selectWith(Predicate2<? super T,? super P> predicate,
P parameter) |
Similar to
RichIterable.select(Predicate) , except with an evaluation parameter for the second generic argument in Predicate2 . |
SortedIterable<T> |
takeWhile(Predicate<? super T> predicate) |
Returns the initial elements that satisfy the Predicate.
|
SortedIterable<T> |
tap(Procedure<? super T> procedure) |
Executes the Procedure for each element in the iterable and returns
this . |
MutableStack<T> |
toStack() |
Converts the SortedIterable to a mutable MutableStack implementation.
|
<S> ListIterable<Pair<T,S>> |
zip(Iterable<S> that) |
Returns a
OrderedIterable formed from this OrderedIterable and another Iterable by
combining corresponding elements in pairs. |
SortedIterable<Pair<T,Integer>> |
zipWithIndex() |
Zips this
RichIterable with its indices. |
forEach, forEachWith
iterator, spliterator
collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, collectWithIndex, collectWithIndex, corresponds, detectIndex, flatCollect, flatCollectWith, forEach, forEachWithIndex, forEachWithIndex, getFirst, getFirstOptional, getLast, getLastOptional, indexOf, partitionWith, zip, zipWithIndex
aggregateBy, aggregateInPlaceBy, allSatisfy, allSatisfyWith, anySatisfy, anySatisfyWith, appendString, appendString, appendString, asLazy, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, contains, containsAll, containsAllArguments, containsAllIterable, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, into, isEmpty, makeString, makeString, makeString, max, maxBy, maxByOptional, maxOptional, maxOptional, min, minBy, minByOptional, minOptional, minOptional, noneSatisfy, noneSatisfyWith, notEmpty, reduce, reduceInPlace, reduceInPlace, reject, rejectWith, select, selectWith, size, sumByDouble, sumByFloat, sumByInt, sumByLong, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toArray, toArray, toBag, toBiMap, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
Comparator<? super T> comparator()
SortedIterable<T> tap(Procedure<? super T> procedure)
RichIterable
this
.
Example using a Java 8 lambda expression:
RichIterable<Person> tapped = people.tap(person -> LOGGER.info(person.getName()));
Example using an anonymous inner class:
RichIterable<Person> tapped = people.tap(new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
tap
in interface OrderedIterable<T>
tap
in interface RichIterable<T>
RichIterable.each(Procedure)
,
RichIterable.forEach(Procedure)
SortedIterable<T> takeWhile(Predicate<? super T> predicate)
takeWhile
in interface OrderedIterable<T>
SortedIterable<T> dropWhile(Predicate<? super T> predicate)
dropWhile
in interface OrderedIterable<T>
PartitionSortedIterable<T> partitionWhile(Predicate<? super T> predicate)
partitionWhile
in interface OrderedIterable<T>
SortedIterable<T> distinct()
SortedIterable
containing the distinct elements in this iterable.
Conceptually similar to RichIterable.toSet()
.RichIterable.toList()
but retains the original order. If an element appears
multiple times in this iterable, the first one will be copied into the result.
distinct
in interface OrderedIterable<T>
SortedIterable
of distinct elementsMutableStack<T> toStack()
toStack
in interface OrderedIterable<T>
T min()
OrderedIterable.getFirst()
.min
in interface OrderedIterable<T>
min
in interface RichIterable<T>
ClassCastException
- if the elements are not Comparable
NoSuchElementException
- if the SortedIterable is emptyT max()
OrderedIterable.getLast()
.max
in interface OrderedIterable<T>
max
in interface RichIterable<T>
ClassCastException
- if the elements are not Comparable
NoSuchElementException
- if the SortedIterable is emptySortedIterable<T> select(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<Person> selected = people.select(person -> person.getAddress().getCity().equals("London"));
Example using an anonymous inner class:
RichIterable<Person> selected = people.select(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getCity().equals("London"); } });
select
in interface OrderedIterable<T>
select
in interface RichIterable<T>
<P> SortedIterable<T> selectWith(Predicate2<? super T,? super P> predicate, P parameter)
RichIterable
RichIterable.select(Predicate)
, except with an evaluation parameter for the second generic argument in Predicate2
.
E.g. return a Collection
of Person elements where the person has an age greater than or equal to 18 years
Example using a Java 8 lambda expression:
RichIterable<Person> selected = people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18));
Example using an anonymous inner class:
RichIterable<Person> selected = people.selectWith(new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge()>= age; } }, Integer.valueOf(18));
selectWith
in interface OrderedIterable<T>
selectWith
in interface RichIterable<T>
predicate
- a Predicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argument P
in predicate
RichIterable.select(Predicate)
SortedIterable<T> reject(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
RichIterable<Person> rejected = people.reject(person -> person.person.getLastName().equals("Smith"));
Example using an anonymous inner class:
RichIterable<Person> rejected = people.reject(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } });
reject
in interface OrderedIterable<T>
reject
in interface RichIterable<T>
predicate
- a Predicate
to use as the reject criteriaPredicate.accept(Object)
method to evaluate to false<P> SortedIterable<T> rejectWith(Predicate2<? super T,? super P> predicate, P parameter)
RichIterable
RichIterable.reject(Predicate)
, except with an evaluation parameter for the second generic argument in Predicate2
.
E.g. return a Collection
of Person elements where the person has an age greater than or equal to 18 years
Example using a Java 8 lambda expression:
RichIterable<Person> rejected = people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18));
Example using an anonymous inner class:
MutableList<Person> rejected = people.rejectWith(new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge() < age; } }, Integer.valueOf(18));
rejectWith
in interface OrderedIterable<T>
rejectWith
in interface RichIterable<T>
predicate
- a Predicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argument P
in predicate
RichIterable.select(Predicate)
PartitionSortedIterable<T> partition(Predicate<? super T> predicate)
RichIterable
Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partition(person -> person.getAddress().getState().getName().equals("New York"));
Example using an anonymous inner class:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partition(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getState().getName().equals("New York"); } });
partition
in interface OrderedIterable<T>
partition
in interface RichIterable<T>
<S> SortedIterable<S> selectInstancesOf(Class<S> clazz)
RichIterable
clazz
.
RichIterable<Integer> integers = List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
selectInstancesOf
in interface OrderedIterable<T>
selectInstancesOf
in interface RichIterable<T>
<V> SortedIterableMultimap<V,T> groupBy(Function<? super T,? extends V> function)
RichIterable
Example using a Java 8 method reference:
Multimap<String, Person> peopleByLastName = people.groupBy(Person::getLastName);
Example using an anonymous inner class:
Multimap<String, Person> peopleByLastName = people.groupBy(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } });
groupBy
in interface OrderedIterable<T>
groupBy
in interface RichIterable<T>
<V> SortedIterableMultimap<V,T> groupByEach(Function<? super T,? extends Iterable<V>> function)
RichIterable
RichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys
for each value.groupByEach
in interface OrderedIterable<T>
groupByEach
in interface RichIterable<T>
<S> ListIterable<Pair<T,S>> zip(Iterable<S> that)
OrderedIterable
OrderedIterable
formed from this OrderedIterable
and another Iterable
by
combining corresponding elements in pairs. The second Iterable
should also be ordered.
If one of the two Iterable
s is longer than the other, its
remaining elements are ignored.zip
in interface OrderedIterable<T>
zip
in interface RichIterable<T>
S
- the type of the second half of the returned pairsthat
- The Iterable
providing the second half of each result pairOrderedIterable
containing pairs consisting of corresponding elements of this
OrderedIterable
and that. The length of the returned OrderedIterable
is the minimum of the lengths of
this OrderedIterable
and that.SortedIterable<Pair<T,Integer>> zipWithIndex()
RichIterable
RichIterable
with its indices.zipWithIndex
in interface OrderedIterable<T>
zipWithIndex
in interface RichIterable<T>
RichIterable
containing pairs consisting of all elements of this RichIterable
paired with their index. Indices start at 0.RichIterable.zip(Iterable)
Copyright © 2004–2019. All rights reserved.