Class ImmutableSortedBagImpl<T>
- java.lang.Object
-
- org.eclipse.collections.impl.AbstractRichIterable<T>
-
- org.eclipse.collections.impl.bag.AbstractBag<T>
-
- org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable<T>
-
- org.eclipse.collections.impl.bag.sorted.immutable.AbstractImmutableSortedBag<T>
-
- org.eclipse.collections.impl.bag.sorted.immutable.ImmutableSortedBagImpl<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<SortedBag<T>>,java.lang.Iterable<T>,java.util.Collection<T>,Bag<T>,ImmutableBagIterable<T>,ImmutableSortedBag<T>,SortedBag<T>,ImmutableCollection<T>,InternalIterable<T>,OrderedIterable<T>,ReversibleIterable<T>,SortedIterable<T>,RichIterable<T>
class ImmutableSortedBagImpl<T> extends AbstractImmutableSortedBag<T> implements java.io.Serializable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classImmutableSortedBagImpl.InternalIterator
-
Field Summary
Fields Modifier and Type Field Description private java.util.Comparator<? super T>comparatorprivate T[]elementsprivate int[]occurrencesprivate static longserialVersionUIDprivate intsize
-
Constructor Summary
Constructors Modifier Constructor Description (package private)ImmutableSortedBagImpl(SortedBag<T> sortedBag)privateImmutableSortedBagImpl(T[] elements, int[] occurrences, java.util.Comparator<? super T> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallSatisfy(Predicate<? super T> predicate)Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty.<P> booleanallSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)Returns true if the predicate evaluates to true for every element of the collection, or returns false.booleanallSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)Returns true if the predicate evaluates to true for all elements of the Bag.booleananySatisfy(Predicate<? super T> predicate)Returns true if the predicate evaluates to true for any element of the iterable.<P> booleananySatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)Returns true if the predicate evaluates to true for any element of the collection, or return false.booleananySatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)Returns true if the predicate evaluates to true for any element of the Bag.<V> ImmutableList<V>collectWithIndex(ObjectIntToObjectFunction<? super T,? extends V> function)Returns a new OrderedIterable using results obtained by applying the specified function to each element and its corresponding index.<V,R extends java.util.Collection<V>>
RcollectWithIndex(ObjectIntToObjectFunction<? super T,? extends V> function, R target)Adds elements to the target Collection using results obtained by applying the specified function to each element and its corresponding index.java.util.Comparator<? super T>comparator()Returns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of its elements.intcompareTo(SortedBag<T> otherBag)booleancontains(java.lang.Object object)Returns true if the iterable has an element which responds true to element.equals(object).<S> booleancorresponds(OrderedIterable<S> other, Predicate2<? super T,? super S> predicate)Returns true if both OrderedIterables have the same length andpredicatereturns true for all corresponding elements e1 of thisOrderedIterableand e2 ofother.Tdetect(Predicate<? super T> predicate)Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true.intdetectIndex(Predicate<? super T> predicate)Returns the index of the first element of theOrderedIterablefor which thepredicateevaluates to true.private intdetectNotIndex(Predicate<? super T> predicate)java.util.Optional<T>detectOptional(Predicate<? super T> predicate)Returns the first element of the iterable for which the predicate evaluates to true as an Optional.TdetectWithOccurrences(ObjectIntPredicate<? super T> predicate)Returns an element of the Bag that satisfies the predicate or null if such an element does not existImmutableSortedSet<T>distinct()Returns a newSortedIterablecontaining the distinct elements in this iterable.RichIterable<T>distinctView()Returns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.ImmutableSortedBag<T>drop(int count)Returns an iterable after skipping the firstcountelements or an empty iterable if thecountis greater than the length of the iterable.ImmutableSortedBag<T>dropWhile(Predicate<? super T> predicate)Returns the final elements that do not satisfy the Predicate.voideach(Procedure<? super T> procedure)The procedure is executed for each element in the iterable.booleanequals(java.lang.Object other)Two bagsb1andb2are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).voidforEach(int fromIndex, int toIndex, Procedure<? super T> procedure)Iterates over the section of the iterable covered by the specified inclusive indexes.voidforEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure)Iterates over the section of the iterable covered by the specified inclusive indexes.voidforEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.voidforEachWithOccurrences(ObjectIntProcedure<? super T> procedure)For each distinct item, with the number of occurrences, execute the specified procedure.TgetFirst()Returns the first element of an iterable.TgetLast()Returns the last element of an iterable.inthashCode()Returns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount().hashCode().intindexOf(java.lang.Object object)Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.java.util.Iterator<T>iterator()Tmax()Returns the maximum element out of this container based on the natural order.Tmax(java.util.Comparator<? super T> comparator)Returns the maximum element out of this container based on the comparator.<V extends java.lang.Comparable<? super V>>
TmaxBy(Function<? super T,? extends V> function)Returns the maximum elements out of this container based on the natural order of the attribute returned by Function.Tmin()Returns the minimum element out of this container based on the natural order.Tmin(java.util.Comparator<? super T> comparator)Returns the minimum element out of this container based on the comparator.<V extends java.lang.Comparable<? super V>>
TminBy(Function<? super T,? extends V> function)Returns the minimum elements out of this container based on the natural order of the attribute returned by Function.ImmutableSortedBag<T>newWith(T element)This method is similar to thewithmethod inMutableCollectionwith the difference that a new copy of this collection with the element appended will be returned.ImmutableSortedBag<T>newWithAll(java.lang.Iterable<? extends T> elements)This method is similar to thewithAllmethod inMutableCollectionwith the difference that a new copy of this collection with the elements appended will be returned.ImmutableSortedBag<T>newWithout(T element)This method is similar to thewithoutmethod inMutableCollectionwith the difference that a new copy of this collection with the element removed will be returned.booleannoneSatisfy(Predicate<? super T> predicate)Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty.<P> booleannoneSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)Returns true if the predicate evaluates to false for every element of the collection, or return false.booleannoneSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)Returns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag.intoccurrencesOf(java.lang.Object item)The occurrences of a distinct item in the bag.PartitionImmutableSortedBag<T>partitionWhile(Predicate<? super T> predicate)Returns a Partition of the initial elements that satisfy the Predicate and the remaining elements.intsize()Returns the number of items in this iterable.intsizeDistinct()The size of the Bag when counting only distinct elements.ImmutableSortedBag<T>take(int count)Returns the firstcountelements of the iterable or all the elements in the iterable ifcountis greater than the length of the iterable.ImmutableSortedBag<T>takeWhile(Predicate<? super T> predicate)Returns the initial elements that satisfy the Predicate.java.lang.Object[]toArray()Converts this iterable to an array.<E> E[]toArray(E[] array)Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.MutableSortedMap<T,java.lang.Integer>toMapOfItemToCount()Converts the Bag to a Map of the Item type to its count as an Integer.MutableList<T>toSortedList()Converts the collection to a MutableList implementation and sorts it using the natural order of the elements.MutableSortedSet<T>toSortedSet()Converts the collection to a MutableSortedSet implementation and sorts it using the natural order of the elements.MutableSortedSet<T>toSortedSet(java.util.Comparator<? super T> comparator)Converts the collection to a MutableSortedSet implementation and sorts it using the specified comparator.-
Methods inherited from class org.eclipse.collections.impl.bag.sorted.immutable.AbstractImmutableSortedBag
bottomOccurrences, chunk, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, collectWithOccurrences, countBy, countByEach, countByWith, detectLastIndex, flatCollect, groupBy, groupByEach, groupByUniqueKey, newWithoutAll, partition, partitionWith, reject, rejectWith, select, selectByOccurrences, selectInstancesOf, selectWith, tap, toImmutable, topOccurrences, toReversed, writeReplace, zip, zip, zipWithIndex
-
Methods inherited from class org.eclipse.collections.impl.bag.immutable.AbstractImmutableBagIterable
add, addAll, castToCollection, clear, parallelStream, remove, removeAll, removeAllFrom, retainAll, shortCircuit, spliterator, stream, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from class org.eclipse.collections.impl.bag.AbstractBag
collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, count, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, groupBy, groupByEach, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoWith, occurrencesSortingBy, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toList, toListWithOccurrences, toSet, toSortedBag, toSortedBag, toSortedList, toStringOfItemToCount
-
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
appendString, appendString, asLazy, containsAll, containsAllArguments, containsAllIterable, countWith, detectWith, detectWithIfNone, detectWithOptional, forEach, forEachWith, groupByUniqueKey, into, isEmpty, toBiMap, toMap, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSetBy, toString, zipWithIndex
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.bag.Bag
aggregateBy, collectWithOccurrences, reduceBy, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toStringOfItemToCount
-
Methods inherited from interface org.eclipse.collections.api.collection.ImmutableCollection
aggregateBy, aggregateInPlaceBy, castToCollection, parallelStream, reduceBy, spliterator, stream, sumByDouble, sumByFloat, sumByInt, sumByLong
-
Methods inherited from interface org.eclipse.collections.api.bag.sorted.ImmutableSortedBag
flatCollectWith, selectDuplicates, selectUnique, toImmutableSortedBag
-
Methods inherited from interface org.eclipse.collections.api.InternalIterable
forEach, forEachWith
-
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
getFirstOptional, getLastOptional, rejectWithIndex, selectWithIndex, toStack, zipWithIndex
-
Methods inherited from interface org.eclipse.collections.api.ordered.ReversibleIterable
asReversed, reverseForEach, reverseForEachWithIndex
-
Methods inherited from interface org.eclipse.collections.api.RichIterable
appendString, appendString, appendString, asLazy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, collectWith, containsAll, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, count, countBy, countByEach, countByWith, countWith, detectIfNone, detectWith, detectWithIfNone, detectWithOptional, flatCollect, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, injectInto, injectInto, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, isEmpty, makeString, makeString, makeString, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, notEmpty, reduce, reject, rejectWith, select, selectWith, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, toBag, toBiMap, toImmutableBag, toImmutableBiMap, toImmutableList, toImmutableMap, toImmutableSet, toImmutableSortedBag, toImmutableSortedBagBy, toImmutableSortedList, toImmutableSortedList, toImmutableSortedListBy, toImmutableSortedSet, toImmutableSortedSet, toImmutableSortedSetBy, toList, toMap, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSetBy, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
elements
private final T[] elements
-
occurrences
private final int[] occurrences
-
comparator
private final java.util.Comparator<? super T> comparator
-
size
private final int size
-
-
Method Detail
-
newWith
public ImmutableSortedBag<T> newWith(T element)
Description copied from interface:ImmutableCollectionThis method is similar to thewithmethod inMutableCollectionwith the difference that a new copy of this collection with the element appended will be returned.- Specified by:
newWithin interfaceImmutableCollection<T>- Specified by:
newWithin interfaceImmutableSortedBag<T>
-
newWithout
public ImmutableSortedBag<T> newWithout(T element)
Description copied from interface:ImmutableCollectionThis method is similar to thewithoutmethod inMutableCollectionwith the difference that a new copy of this collection with the element removed will be returned.- Specified by:
newWithoutin interfaceImmutableCollection<T>- Specified by:
newWithoutin interfaceImmutableSortedBag<T>
-
newWithAll
public ImmutableSortedBag<T> newWithAll(java.lang.Iterable<? extends T> elements)
Description copied from interface:ImmutableCollectionThis method is similar to thewithAllmethod inMutableCollectionwith the difference that a new copy of this collection with the elements appended will be returned.- Specified by:
newWithAllin interfaceImmutableCollection<T>- Specified by:
newWithAllin interfaceImmutableSortedBag<T>
-
comparator
public java.util.Comparator<? super T> comparator()
Description copied from interface:SortedBagReturns the comparator used to order the elements in this bag, or null if this bag uses the natural ordering of its elements.- Specified by:
comparatorin interfaceSortedBag<T>- Specified by:
comparatorin interfaceSortedIterable<T>
-
min
public T min()
Description copied from interface:RichIterableReturns the minimum element out of this container based on the natural order.- Specified by:
minin interfaceOrderedIterable<T>- Specified by:
minin interfaceRichIterable<T>- Specified by:
minin interfaceSortedBag<T>- Specified by:
minin interfaceSortedIterable<T>- Overrides:
minin classAbstractRichIterable<T>
-
min
public T min(java.util.Comparator<? super T> comparator)
Description copied from interface:RichIterableReturns the minimum element out of this container based on the comparator.- Specified by:
minin interfaceRichIterable<T>- Overrides:
minin classAbstractRichIterable<T>
-
minBy
public <V extends java.lang.Comparable<? super V>> T minBy(Function<? super T,? extends V> function)
Description copied from interface:RichIterableReturns the minimum elements out of this container based on the natural order of the attribute returned by Function.- Specified by:
minByin interfaceRichIterable<T>- Overrides:
minByin classAbstractRichIterable<T>
-
max
public T max()
Description copied from interface:RichIterableReturns the maximum element out of this container based on the natural order.- Specified by:
maxin interfaceOrderedIterable<T>- Specified by:
maxin interfaceRichIterable<T>- Specified by:
maxin interfaceSortedBag<T>- Specified by:
maxin interfaceSortedIterable<T>- Overrides:
maxin classAbstractRichIterable<T>
-
max
public T max(java.util.Comparator<? super T> comparator)
Description copied from interface:RichIterableReturns the maximum element out of this container based on the comparator.- Specified by:
maxin interfaceRichIterable<T>- Overrides:
maxin classAbstractRichIterable<T>
-
maxBy
public <V extends java.lang.Comparable<? super V>> T maxBy(Function<? super T,? extends V> function)
Description copied from interface:RichIterableReturns the maximum elements out of this container based on the natural order of the attribute returned by Function.- Specified by:
maxByin interfaceRichIterable<T>- Overrides:
maxByin classAbstractRichIterable<T>
-
takeWhile
public ImmutableSortedBag<T> takeWhile(Predicate<? super T> predicate)
Description copied from interface:SortedIterableReturns the initial elements that satisfy the Predicate. Short circuits at the first element which does not satisfy the Predicate.- Specified by:
takeWhilein interfaceImmutableSortedBag<T>- Specified by:
takeWhilein interfaceOrderedIterable<T>- Specified by:
takeWhilein interfaceReversibleIterable<T>- Specified by:
takeWhilein interfaceSortedBag<T>- Specified by:
takeWhilein interfaceSortedIterable<T>
-
dropWhile
public ImmutableSortedBag<T> dropWhile(Predicate<? super T> predicate)
Description copied from interface:SortedIterableReturns the final elements that do not satisfy the Predicate. Short circuits at the first element which does satisfy the Predicate.- Specified by:
dropWhilein interfaceImmutableSortedBag<T>- Specified by:
dropWhilein interfaceOrderedIterable<T>- Specified by:
dropWhilein interfaceReversibleIterable<T>- Specified by:
dropWhilein interfaceSortedBag<T>- Specified by:
dropWhilein interfaceSortedIterable<T>
-
detectIndex
public int detectIndex(Predicate<? super T> predicate)
Description copied from interface:OrderedIterableReturns the index of the first element of theOrderedIterablefor which thepredicateevaluates to true. Returns -1 if no element evaluates true for thepredicate.- Specified by:
detectIndexin interfaceOrderedIterable<T>
-
partitionWhile
public PartitionImmutableSortedBag<T> partitionWhile(Predicate<? super T> predicate)
Description copied from interface:SortedIterableReturns 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>- Specified by:
partitionWhilein interfaceReversibleIterable<T>- Specified by:
partitionWhilein interfaceSortedBag<T>- Specified by:
partitionWhilein interfaceSortedIterable<T>
-
forEachWithOccurrences
public void forEachWithOccurrences(ObjectIntProcedure<? super T> procedure)
Description copied from interface:BagFor each distinct item, with the number of occurrences, execute the specified procedure.- Specified by:
forEachWithOccurrencesin interfaceBag<T>
-
anySatisfyWithOccurrences
public boolean anySatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)
Description copied from interface:BagReturns true if the predicate evaluates to true for any element of the Bag. Returns false if the Bag is empty or if no element returns true for the predicate.- Specified by:
anySatisfyWithOccurrencesin interfaceBag<T>
-
allSatisfyWithOccurrences
public boolean allSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)
Description copied from interface:BagReturns true if the predicate evaluates to true for all elements of the Bag. Returns false if the Bag is empty or if not all elements return true for the predicate.- Specified by:
allSatisfyWithOccurrencesin interfaceBag<T>
-
noneSatisfyWithOccurrences
public boolean noneSatisfyWithOccurrences(ObjectIntPredicate<? super T> predicate)
Description copied from interface:BagReturns true if the Bag is empty or if the predicate evaluates to false for all elements of the Bag. Returns false if the predicate evaluates to true for at least one element of the Bag.- Specified by:
noneSatisfyWithOccurrencesin interfaceBag<T>
-
detectWithOccurrences
public T detectWithOccurrences(ObjectIntPredicate<? super T> predicate)
Description copied from interface:BagReturns an element of the Bag that satisfies the predicate or null if such an element does not exist- Specified by:
detectWithOccurrencesin interfaceBag<T>
-
sizeDistinct
public int sizeDistinct()
Description copied from interface:BagThe size of the Bag when counting only distinct elements.- Specified by:
sizeDistinctin interfaceBag<T>
-
size
public int size()
Description copied from interface:RichIterableReturns the number of items in this iterable.- Specified by:
sizein interfacejava.util.Collection<T>- Specified by:
sizein interfaceRichIterable<T>
-
indexOf
public int indexOf(java.lang.Object object)
Description copied from interface:OrderedIterableReturns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.- Specified by:
indexOfin interfaceOrderedIterable<T>- See Also:
List.indexOf(Object)
-
getFirst
public T getFirst()
Description copied from interface:RichIterableReturns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.
- Specified by:
getFirstin interfaceOrderedIterable<T>- Specified by:
getFirstin interfaceRichIterable<T>
-
getLast
public T getLast()
Description copied from interface:RichIterableReturns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.
- Specified by:
getLastin interfaceOrderedIterable<T>- Specified by:
getLastin interfaceRichIterable<T>
-
forEach
public void forEach(int fromIndex, int toIndex, Procedure<? super T> procedure)Description copied from interface:OrderedIterableIterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.e.g. OrderedIterable<Person> people = FastList.newListWith(ted, mary, bob, sally) people.forEach(0, 1, person -> LOGGER.info(person.getName()));
This code would output ted and mary's names.
- Specified by:
forEachin interfaceOrderedIterable<T>
-
each
public void each(Procedure<? super T> procedure)
Description copied from interface:RichIterableThe procedure is executed for each element in the iterable.Example using a Java 8 lambda expression:
people.each(person -> LOGGER.info(person.getName()));
This method is a variant ofInternalIterable.forEach(Procedure)that has a signature conflict withIterable.forEach(java.util.function.Consumer).- Specified by:
eachin interfaceRichIterable<T>- See Also:
InternalIterable.forEach(Procedure),Iterable.forEach(java.util.function.Consumer)
-
forEachWithIndex
public void forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
Description copied from interface:InternalIterableIterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.Example using a Java 8 lambda:
people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));Example using an anonymous inner class:
people.forEachWithIndex(new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info("Index: " + index + " person: " + person.getName()); } });- Specified by:
forEachWithIndexin interfaceInternalIterable<T>- Specified by:
forEachWithIndexin interfaceOrderedIterable<T>- Overrides:
forEachWithIndexin classAbstractRichIterable<T>
-
collectWithIndex
public <V> ImmutableList<V> collectWithIndex(ObjectIntToObjectFunction<? super T,? extends V> function)
Description copied from interface:OrderedIterableReturns a new OrderedIterable using results obtained by applying the specified function to each element and its corresponding index.- Specified by:
collectWithIndexin interfaceImmutableSortedBag<T>- Specified by:
collectWithIndexin interfaceOrderedIterable<T>- Specified by:
collectWithIndexin interfaceReversibleIterable<T>- Specified by:
collectWithIndexin interfaceSortedBag<T>- Since:
- 9.1.
-
collectWithIndex
public <V,R extends java.util.Collection<V>> R collectWithIndex(ObjectIntToObjectFunction<? super T,? extends V> function, R target)
Description copied from interface:OrderedIterableAdds elements to the target Collection using results obtained by applying the specified function to each element and its corresponding index.- Specified by:
collectWithIndexin interfaceOrderedIterable<T>- Since:
- 9.1.
-
forEachWithIndex
public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure)Description copied from interface:OrderedIterableIterates over the section of the iterable covered by the specified inclusive indexes. The indexes are both inclusive.e.g. OrderedIterable<People> people = FastList.newListWith(ted, mary, bob, sally) people.forEachWithIndex(0, 1, (person, index) -> LOGGER.info(person.getName()));
This code would output ted and mary's names.
- Specified by:
forEachWithIndexin interfaceOrderedIterable<T>
-
occurrencesOf
public int occurrencesOf(java.lang.Object item)
Description copied from interface:BagThe occurrences of a distinct item in the bag.- Specified by:
occurrencesOfin interfaceBag<T>
-
distinct
public ImmutableSortedSet<T> distinct()
Description copied from interface:SortedIterableReturns 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 interfaceImmutableSortedBag<T>- Specified by:
distinctin interfaceOrderedIterable<T>- Specified by:
distinctin interfaceReversibleIterable<T>- Specified by:
distinctin interfaceSortedBag<T>- Specified by:
distinctin interfaceSortedIterable<T>- Returns:
SortedIterableof distinct elements
-
corresponds
public <S> boolean corresponds(OrderedIterable<S> other, Predicate2<? super T,? super S> predicate)
Description copied from interface:OrderedIterableReturns true if both OrderedIterables have the same length andpredicatereturns true for all corresponding elements e1 of thisOrderedIterableand e2 ofother. Thepredicateis evaluated for each element at the same position of eachOrderedIterablein a forward iteration order. This is a short circuit pattern.- Specified by:
correspondsin interfaceOrderedIterable<T>
-
toSortedList
public MutableList<T> toSortedList()
Description copied from interface:RichIterableConverts the collection to a MutableList implementation and sorts it using the natural order of the elements.- Specified by:
toSortedListin interfaceRichIterable<T>
-
toSortedSet
public MutableSortedSet<T> toSortedSet()
Description copied from interface:RichIterableConverts the collection to a MutableSortedSet implementation and sorts it using the natural order of the elements.- Specified by:
toSortedSetin interfaceRichIterable<T>- Overrides:
toSortedSetin classAbstractBag<T>
-
toSortedSet
public MutableSortedSet<T> toSortedSet(java.util.Comparator<? super T> comparator)
Description copied from interface:RichIterableConverts the collection to a MutableSortedSet implementation and sorts it using the specified comparator.- Specified by:
toSortedSetin interfaceRichIterable<T>- Overrides:
toSortedSetin classAbstractBag<T>
-
toArray
public java.lang.Object[] toArray()
Description copied from interface:RichIterableConverts this iterable to an array.- Specified by:
toArrayin interfacejava.util.Collection<T>- Specified by:
toArrayin interfaceRichIterable<T>- Overrides:
toArrayin classAbstractBag<T>- See Also:
Collection.toArray()
-
toArray
public <E> E[] toArray(E[] array)
Description copied from interface:RichIterableConverts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.- Specified by:
toArrayin interfacejava.util.Collection<T>- Specified by:
toArrayin interfaceRichIterable<T>- Overrides:
toArrayin classAbstractBag<T>- See Also:
Collection.toArray(Object[])
-
toMapOfItemToCount
public MutableSortedMap<T,java.lang.Integer> toMapOfItemToCount()
Description copied from interface:BagConverts the Bag to a Map of the Item type to its count as an Integer.- Specified by:
toMapOfItemToCountin interfaceBag<T>- Specified by:
toMapOfItemToCountin interfaceImmutableBagIterable<T>- Specified by:
toMapOfItemToCountin interfaceImmutableSortedBag<T>- Specified by:
toMapOfItemToCountin interfaceSortedBag<T>
-
compareTo
public int compareTo(SortedBag<T> otherBag)
- Specified by:
compareToin interfacejava.lang.Comparable<T>
-
allSatisfy
public boolean allSatisfy(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
allSatisfyin interfaceRichIterable<T>- Overrides:
allSatisfyin classAbstractRichIterable<T>
-
allSatisfyWith
public <P> boolean allSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for every element of the collection, or returns false.- Specified by:
allSatisfyWithin interfaceRichIterable<T>- Overrides:
allSatisfyWithin classAbstractRichIterable<T>
-
anySatisfy
public boolean anySatisfy(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.- Specified by:
anySatisfyin interfaceRichIterable<T>- Overrides:
anySatisfyin classAbstractRichIterable<T>
-
anySatisfyWith
public <P> boolean anySatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.- Specified by:
anySatisfyWithin interfaceRichIterable<T>- Overrides:
anySatisfyWithin classAbstractRichIterable<T>
-
noneSatisfy
public boolean noneSatisfy(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
noneSatisfyin interfaceRichIterable<T>- Overrides:
noneSatisfyin classAbstractRichIterable<T>
-
noneSatisfyWith
public <P> boolean noneSatisfyWith(Predicate2<? super T,? super P> predicate, P parameter)
Description copied from interface:RichIterableReturns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.- Specified by:
noneSatisfyWithin interfaceRichIterable<T>- Overrides:
noneSatisfyWithin classAbstractRichIterable<T>
-
detect
public T detect(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));- Specified by:
detectin interfaceRichIterable<T>- Overrides:
detectin classAbstractRichIterable<T>
-
detectOptional
public java.util.Optional<T> detectOptional(Predicate<? super T> predicate)
Description copied from interface:RichIterableReturns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.Example using a Java 8 lambda expression:
Person person = people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));- Specified by:
detectOptionalin interfaceRichIterable<T>- Overrides:
detectOptionalin classAbstractRichIterable<T>
-
contains
public boolean contains(java.lang.Object object)
Description copied from interface:RichIterableReturns true if the iterable has an element which responds true to element.equals(object).- Specified by:
containsin interfacejava.util.Collection<T>- Specified by:
containsin interfaceRichIterable<T>- Overrides:
containsin classAbstractRichIterable<T>
-
iterator
public java.util.Iterator<T> iterator()
-
take
public ImmutableSortedBag<T> take(int count)
Description copied from interface:ReversibleIterableReturns the firstcountelements of the iterable or all the elements in the iterable ifcountis greater than the length of the iterable.- Specified by:
takein interfaceImmutableSortedBag<T>- Specified by:
takein interfaceReversibleIterable<T>- Specified by:
takein interfaceSortedBag<T>- Parameters:
count- the number of items to take.
-
drop
public ImmutableSortedBag<T> drop(int count)
Description copied from interface:ReversibleIterableReturns an iterable after skipping the firstcountelements or an empty iterable if thecountis greater than the length of the iterable.- Specified by:
dropin interfaceImmutableSortedBag<T>- Specified by:
dropin interfaceReversibleIterable<T>- Specified by:
dropin interfaceSortedBag<T>- Parameters:
count- the number of items to drop.
-
equals
public boolean equals(java.lang.Object other)
Description copied from interface:BagTwo bagsb1andb2are equal ifm1.toMapOfItemToCount().equals(m2.toMapOfItemToCount()).
-
hashCode
public int hashCode()
Description copied from interface:BagReturns the hash code for this Bag, defined as this.Bag.toMapOfItemToCount().hashCode().
-
distinctView
public RichIterable<T> distinctView()
Description copied from interface:BagReturns an unmodifiable view on the distinct elements with the same complexity as the Bag implementation.- Specified by:
distinctViewin interfaceBag<T>- Returns:
- an unmodifiable view on the distinct elements of the Bag.
-
-