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>
public interface SortedIterable<T> extends OrderedIterable<T>
A SortedIterable is an ordered iterable where the elements are stored in sorted order defined by a non-strict partial order relation. The sort order is determined by the Comparator returned bycomparator()or is the natural ordering ifcomparator()returnsnull. Operations that would sort the collection can be faster than O(n log n). For exampleRichIterable.toSortedList()takes O(n) time.- Since:
- 5.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods 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 newSortedIterablecontaining 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 toRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys for each value.Tmax()Returns the maximum element out of this container based on the natural order, not the order of this container.Tmin()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 toRichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.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 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.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 returnsthis.<S> ListIterable<Pair<T,S>>zip(Iterable<S> that)Returns aOrderedIterableformed from thisOrderedIterableand anotherIterableby combining corresponding elements in pairs.SortedIterable<Pair<T,Integer>>zipWithIndex()Zips thisRichIterablewith 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 Detail
-
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
SortedIterable<T> tap(Procedure<? super T> procedure)
Description copied from interface:RichIterableExecutes 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()));- Specified by:
tapin interfaceOrderedIterable<T>- Specified by:
tapin interfaceRichIterable<T>- See Also:
RichIterable.each(Procedure),RichIterable.forEach(Procedure)
-
takeWhile
SortedIterable<T> takeWhile(Predicate<? super T> predicate)
Returns the initial elements that satisfy the Predicate. Short circuits at the first element which does not satisfy the Predicate.- Specified by:
takeWhilein interfaceOrderedIterable<T>
-
dropWhile
SortedIterable<T> dropWhile(Predicate<? super T> predicate)
Returns the final elements that do not satisfy the Predicate. Short circuits at the first element which does satisfy the Predicate.- Specified by:
dropWhilein interfaceOrderedIterable<T>
-
partitionWhile
PartitionSortedIterable<T> partitionWhile(Predicate<? super T> predicate)
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:
partitionWhilein interfaceOrderedIterable<T>
-
distinct
SortedIterable<T> distinct()
Returns a newSortedIterablecontaining 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:
distinctin interfaceOrderedIterable<T>- Returns:
SortedIterableof 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:
minin interfaceOrderedIterable<T>- Specified by:
minin interfaceRichIterable<T>- Throws:
ClassCastException- if the elements are notComparableNoSuchElementException- 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:
maxin interfaceOrderedIterable<T>- Specified by:
maxin interfaceRichIterable<T>- Throws:
ClassCastException- if the elements are notComparableNoSuchElementException- if the SortedIterable is empty
-
select
SortedIterable<T> select(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns 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"));- Specified by:
selectin interfaceOrderedIterable<T>- Specified by:
selectin interfaceRichIterable<T>
-
selectWith
<P> SortedIterable<T> selectWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableSimilar toRichIterable.select(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.E.g. return a
Collectionof 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));- Specified by:
selectWithin interfaceOrderedIterable<T>- Specified by:
selectWithin interfaceRichIterable<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- See Also:
RichIterable.select(Predicate)
-
reject
SortedIterable<T> reject(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns 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"));- Specified by:
rejectin interfaceOrderedIterable<T>- Specified by:
rejectin interfaceRichIterable<T>- Parameters:
predicate- aPredicateto use as the reject criteria- Returns:
- a RichIterable that contains elements that cause
Predicate.accept(Object)method to evaluate to false
-
rejectWith
<P> SortedIterable<T> rejectWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableSimilar toRichIterable.reject(Predicate), except with an evaluation parameter for the second generic argument inPredicate2.E.g. return a
Collectionof 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));- Specified by:
rejectWithin interfaceOrderedIterable<T>- Specified by:
rejectWithin interfaceRichIterable<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- See Also:
RichIterable.select(Predicate)
-
partition
PartitionSortedIterable<T> partition(Predicate<? super T> predicate)
Description copied from interface:RichIterableFilters 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"));- Specified by:
partitionin interfaceOrderedIterable<T>- Specified by:
partitionin interfaceRichIterable<T>
-
selectInstancesOf
<S> SortedIterable<S> selectInstancesOf(Class<S> clazz)
Description copied from interface:RichIterableReturns 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:
selectInstancesOfin interfaceOrderedIterable<T>- Specified by:
selectInstancesOfin interfaceRichIterable<T>
-
groupBy
<V> SortedIterableMultimap<V,T> groupBy(Function<? super T,? extends V> function)
Description copied from interface:RichIterableFor 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);- Specified by:
groupByin interfaceOrderedIterable<T>- Specified by:
groupByin interfaceRichIterable<T>
-
groupByEach
<V> SortedIterableMultimap<V,T> groupByEach(Function<? super T,? extends Iterable<V>> function)
Description copied from interface:RichIterableSimilar toRichIterable.groupBy(Function), except the result of evaluating function will return a collection of keys for each value.- Specified by:
groupByEachin interfaceOrderedIterable<T>- Specified by:
groupByEachin interfaceRichIterable<T>
-
zip
<S> ListIterable<Pair<T,S>> zip(Iterable<S> that)
Description copied from interface:OrderedIterableReturns aOrderedIterableformed from thisOrderedIterableand anotherIterableby combining corresponding elements in pairs. The secondIterableshould also be ordered. If one of the twoIterables is longer than the other, its remaining elements are ignored.- Specified by:
zipin interfaceOrderedIterable<T>- Specified by:
zipin interfaceRichIterable<T>- Type Parameters:
S- the type of the second half of the returned pairs- Parameters:
that- TheIterableproviding the second half of each result pair- Returns:
- A new
OrderedIterablecontaining pairs consisting of corresponding elements of thisOrderedIterableand that. The length of the returnedOrderedIterableis the minimum of the lengths of thisOrderedIterableand that.
-
zipWithIndex
SortedIterable<Pair<T,Integer>> zipWithIndex()
Description copied from interface:RichIterableZips thisRichIterablewith its indices.- Specified by:
zipWithIndexin interfaceOrderedIterable<T>- Specified by:
zipWithIndexin interfaceRichIterable<T>- Returns:
- A new
RichIterablecontaining pairs consisting of all elements of thisRichIterablepaired with their index. Indices start at 0. - See Also:
RichIterable.zip(Iterable)
-
-