Interface SortedIterable<T>
- All Superinterfaces:
InternalIterable<T>
,Iterable<T>
,OrderedIterable<T>
,RichIterable<T>
- All Known Subinterfaces:
ImmutableSortedBag<T>
,ImmutableSortedSet<T>
,MutableSortedBag<T>
,MutableSortedSet<T>
,SortedBag<T>
,SortedSetIterable<T>
- All Known Implementing Classes:
AbstractMutableSortedBag
,SortedSetAdapter
,SynchronizedSortedBag
,SynchronizedSortedSet
,TreeBag
,TreeSortedSet
,UnmodifiableSortedBag
,UnmodifiableSortedSet
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.- Since:
- 5.0
-
Method Summary
Modifier and TypeMethodDescriptionComparator<? super T>
Returns the comparator used to order the elements in this container, or null if this container uses the natural ordering of its elements.distinct()
Returns a newSortedIterable
containing the distinct elements in this iterable.Returns the final elements that do not satisfy the Predicate.<V> SortedIterableMultimap<V,
T> 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 toRichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys for each value.max()
Returns the maximum element out of this container based on the natural order, not the order of this container.min()
Returns the minimum element out of this container based on the natural order, not the order of this container.Filters a collection into a PartitionedIterable based on the evaluation of the predicate.partitionWhile
(Predicate<? super T> predicate) Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements.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 toRichIterable.reject(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.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 Classclazz
.<P> SortedIterable<T>
selectWith
(Predicate2<? super T, ? super P> predicate, P parameter) Similar toRichIterable.select(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.Returns the initial elements that satisfy the Predicate.Executes the Procedure for each element in the iterable and returnsthis
.<S> ListIterable<Pair<T,
S>> Returns aOrderedIterable
formed from thisOrderedIterable
and anotherIterable
by combining corresponding elements in pairs.Zips thisRichIterable
with its indices.Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith
Methods inherited from interface java.lang.Iterable
iterator, spliterator
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
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, rejectWithIndex, selectWithIndex, toStack, zip, zipWithIndex
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, 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, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countBy, countByEach, countByEach, countByWith, countByWith, countWith, detect, detectIfNone, detectOptional, detectWith, detectWithIfNone, detectWithOptional, each, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, 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, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
-
Method Details
-
comparator
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. -
tap
Description copied from interface:RichIterable
Executes the Procedure for each element in the iterable and returnsthis
.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()); } });
- Specified by:
tap
in interfaceOrderedIterable<T>
- Specified by:
tap
in interfaceRichIterable<T>
- See Also:
-
takeWhile
Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not satisfy the Predicate.- Specified by:
takeWhile
in interfaceOrderedIterable<T>
-
dropWhile
Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does satisfy the Predicate.- Specified by:
dropWhile
in interfaceOrderedIterable<T>
-
partitionWhile
Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements. Short circuits at the first element which does satisfy the Predicate.- Specified by:
partitionWhile
in interfaceOrderedIterable<T>
-
distinct
SortedIterable<T> distinct()Returns a newSortedIterable
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.- Specified by:
distinct
in interfaceOrderedIterable<T>
- Returns:
SortedIterable
of distinct elements
-
min
T min()Returns the minimum element out of this container based on the natural order, not the order of this container. If you want the minimum element based on the order of this container, useOrderedIterable.getFirst()
.- Specified by:
min
in interfaceOrderedIterable<T>
- Specified by:
min
in interfaceRichIterable<T>
- Throws:
ClassCastException
- if the elements are notComparable
NoSuchElementException
- if the SortedIterable is empty
-
max
T max()Returns the maximum element out of this container based on the natural order, not the order of this container. If you want the maximum element based on the order of this container, useOrderedIterable.getLast()
.- Specified by:
max
in interfaceOrderedIterable<T>
- Specified by:
max
in interfaceRichIterable<T>
- Throws:
ClassCastException
- if the elements are notComparable
NoSuchElementException
- if the SortedIterable is empty
-
select
Description copied from interface:RichIterable
Returns all elements of the source collection that return true when evaluating the predicate. This method is also commonly called filter.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"); } });
- Specified by:
select
in interfaceOrderedIterable<T>
- Specified by:
select
in interfaceRichIterable<T>
-
selectWith
Description copied from interface:RichIterable
Similar toRichIterable.select(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.E.g. return a
Collection
of Person elements where the person has an age greater than or equal to 18 yearsExample 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));
- Specified by:
selectWith
in interfaceOrderedIterable<T>
- Specified by:
selectWith
in interfaceRichIterable<T>
- Parameters:
predicate
- aPredicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
- See Also:
-
reject
Description copied from interface:RichIterable
Returns all elements of the source collection that return false when evaluating of the predicate. This method is also sometimes called filterNot and is the equivalent of calling iterable.select(Predicates.not(predicate)).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"); } });
- Specified by:
reject
in interfaceOrderedIterable<T>
- Specified by:
reject
in interfaceRichIterable<T>
- Parameters:
predicate
- aPredicate
to use as the reject criteria- Returns:
- a RichIterable that contains elements that cause
Predicate.accept(Object)
method to evaluate to false
-
rejectWith
Description copied from interface:RichIterable
Similar toRichIterable.reject(Predicate)
, except with an evaluation parameter for the second generic argument inPredicate2
.E.g. return a
Collection
of Person elements where the person has an age greater than or equal to 18 yearsExample 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));
- Specified by:
rejectWith
in interfaceOrderedIterable<T>
- Specified by:
rejectWith
in interfaceRichIterable<T>
- Parameters:
predicate
- aPredicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
- See Also:
-
partition
Description copied from interface:RichIterable
Filters a collection into a PartitionedIterable based on the evaluation of the predicate.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"); } });
- Specified by:
partition
in interfaceOrderedIterable<T>
- Specified by:
partition
in interfaceRichIterable<T>
-
selectInstancesOf
Description copied from interface:RichIterable
Returns all elements of the source collection that are instances of the Classclazz
.RichIterable<Integer> integers = List.mutable.with(new Integer(0), new Long(0L), new Double(0.0)).selectInstancesOf(Integer.class);
- Specified by:
selectInstancesOf
in interfaceOrderedIterable<T>
- Specified by:
selectInstancesOf
in interfaceRichIterable<T>
-
groupBy
Description copied from interface:RichIterable
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.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(); } });
- Specified by:
groupBy
in interfaceOrderedIterable<T>
- Specified by:
groupBy
in interfaceRichIterable<T>
-
groupByEach
Description copied from interface:RichIterable
Similar toRichIterable.groupBy(Function)
, except the result of evaluating function will return a collection of keys for each value.- Specified by:
groupByEach
in interfaceOrderedIterable<T>
- Specified by:
groupByEach
in interfaceRichIterable<T>
-
zip
Description copied from interface:OrderedIterable
Returns aOrderedIterable
formed from thisOrderedIterable
and anotherIterable
by combining corresponding elements in pairs. The secondIterable
should also be ordered. If one of the twoIterable
s is longer than the other, its remaining elements are ignored.- Specified by:
zip
in interfaceOrderedIterable<T>
- Specified by:
zip
in interfaceRichIterable<T>
- Type Parameters:
S
- the type of the second half of the returned pairs- Parameters:
that
- TheIterable
providing the second half of each result pair- Returns:
- A new
OrderedIterable
containing pairs consisting of corresponding elements of thisOrderedIterable
and that. The length of the returnedOrderedIterable
is the minimum of the lengths of thisOrderedIterable
and that.
-
zipWithIndex
SortedIterable<Pair<T,Integer>> zipWithIndex()Description copied from interface:RichIterable
Zips thisRichIterable
with its indices.- Specified by:
zipWithIndex
in interfaceOrderedIterable<T>
- Specified by:
zipWithIndex
in interfaceRichIterable<T>
- Returns:
- A new
RichIterable
containing pairs consisting of all elements of thisRichIterable
paired with their index. Indices start at 0. - See Also:
-