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 newSortedIterablecontaining 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 aOrderedIterableformed from thisOrderedIterableand anotherIterableby combining corresponding elements in pairs.Zips thisRichIterablewith its indices.Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWithMethods inherited from interface java.lang.Iterable
iterator, spliteratorMethods 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, zipWithIndexMethods 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: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()));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:
tapin interfaceOrderedIterable<T>- Specified by:
tapin 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:
takeWhilein 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:
dropWhilein 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:
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
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"));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:
selectin interfaceOrderedIterable<T>- Specified by:
selectin interfaceRichIterable<T>
-
selectWith
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));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:
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:
-
reject
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"));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:
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
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));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:
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:
-
partition
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"));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:
partitionin interfaceOrderedIterable<T>- Specified by:
partitionin interfaceRichIterable<T>
-
selectInstancesOf
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
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);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:
groupByin interfaceOrderedIterable<T>- Specified by:
groupByin interfaceRichIterable<T>
-
groupByEach
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
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:
-