Class ImmutableArrayList<T>
- All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>, List<T>, RandomAccess, SequencedCollection<T>, ImmutableCollection<T>, InternalIterable<T>, ImmutableList<T>, ListIterable<T>, OrderedIterable<T>, ReversibleIterable<T>, RichIterable<T>, BatchIterable<T>
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractImmutableList
AbstractImmutableList.ImmutableSubList<T> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanallSatisfy(Predicate<? super T> predicate) Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty.booleananySatisfy(Predicate<? super T> predicate) Returns true if the predicate evaluates to true for any element of the iterable.voidappendString(Appendable appendable, String start, String separator, String end) Prints a string representation of this collection onto the givenAppendable.voidbatchForEach(Procedure<? super T> procedure, int sectionIndex, int sectionCount) <V> ImmutableList<V> Returns a new collection with the results of applying the specified function on each element of the source collection.<V> ImmutableList<V> Returns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate.<P,V> ImmutableList <V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter) Same asRichIterable.collect(Function)with aFunction2and specified parameter which is passed to the block.<P, V, R extends Collection<V>>
RcollectWith(Function2<? super T, ? super P, ? extends V> function, P parameter, R target) Same as collectWith but with a targetCollection parameter to gather the results.<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 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.booleanReturns true if the iterable has an element which responds true to element.equals(object).booleancontainsAll(Collection<?> collection) Returns true if all elements in source are contained in this collection.<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.intReturn the total number of elements that answer true to the specified 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.private intdetectNotIndex(Predicate<? super T> predicate) detectOptional(Predicate<? super T> predicate) Returns the first element of the iterable for which the predicate evaluates to true as an Optional.<P> TdetectWith(Predicate2<? super T, ? super P> predicate, P parameter) Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.detectWithOptional(Predicate2<? super T, ? super P> predicate, P parameter) Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.drop(int count) Returns an iterable after skipping the firstcountelements or an empty iterable if thecountis greater than the length of the iterable.Returns the final elements that do not satisfy the Predicate.voidThe procedure is executed for each element in the iterable.booleanFollows the same general contract asList.equals(Object).<V> ImmutableList<V> flatCollect(Function<? super T, ? extends Iterable<V>> function) flatCollectis a special case ofRichIterable.collect(Function).<V, R extends Collection<V>>
RflatCollect(Function<? super T, ? extends Iterable<V>> function, R target) Same as flatCollect, only the results are collected into the target collection.voidforEachWithIndex(int from, int to, 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.get(int index) Returns the item at the specified position in this list iterable.intgetBatchCount(int batchSize) getFirst()Returns the first element of an iterable.getLast()Returns the last element of an iterable.inthashCode()Follows the same general contract asList.hashCode().booleanimmutableArrayListEquals(ImmutableArrayList<?> otherList) intReturns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.<IV> IVinjectInto(IV injectedValue, Function2<? super IV, ? super T, ? extends IV> function) Returns the final result of evaluating function using each element of the iterable and the previous evaluation result as the parameters.booleanisEmpty()Returns true if this iterable has zero items.iterator()intlastIndexOf(Object item) Returns the index of the last occurrence of the specified item in this list, or -1 if this list does not contain the item.<V extends Comparable<? super V>>
TReturns the maximum elements out of this container based on the natural order of the attribute returned by Function.<V extends Comparable<? super V>>
TReturns the minimum elements out of this container based on the natural order of the attribute returned by Function.static <E> ImmutableArrayList<E> static <E> ImmutableArrayList<E> newListWith(E... elements) This method is similar to thewithmethod inMutableCollectionwith the difference that a new copy of this collection with the element appended 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.booleannotEmpty()The English equivalent of !this.isEmpty()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.<P> PartitionImmutableList<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter) Filters a collection into a PartitionIterable based on the evaluation of the predicate.reduce(BinaryOperator<T> accumulator) This method produces the equivalent result asStream.reduce(BinaryOperator).<R> RreduceInPlace(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator) This method produces the equivalent result asStream.collect(Supplier, BiConsumer, BiConsumer).<R,A> R reduceInPlace(Collector<? super T, A, R> collector) This method produces the equivalent result asStream.collect(Collector).Returns all elements of the source collection that return false when evaluating of the predicate.<P> ImmutableList<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.<P, R extends Collection<T>>
RrejectWith(Predicate2<? super T, ? super P> predicate, P parameter, R target) Similar toRichIterable.reject(Predicate, Collection), except with an evaluation parameter for the second generic argument inPredicate2.rejectWithIndex(ObjectIntPredicate<? super T> predicate) Returns a new ImmutableList with all elements of the collection that return false when evaluating the specified predicate which is supplied each element and its relative index.<R extends Collection<T>>
RrejectWithIndex(ObjectIntPredicate<? super T> predicate, R target) Adds all elements to the target Collection that return false when evaluating the specified predicate which is supplied each element and its relative index.Returns all elements of the source collection that return true when evaluating the predicate.<S> ImmutableList<S> selectInstancesOf(Class<S> clazz) Returns all elements of the source collection that are instances of the Classclazz.<P> ImmutableList<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.<P, R extends Collection<T>>
RselectWith(Predicate2<? super T, ? super P> predicate, P parameter, R target) Similar toRichIterable.select(Predicate, Collection), except with an evaluation parameter for the second generic argument inPredicate2.selectWithIndex(ObjectIntPredicate<? super T> predicate) Returns a new ImmutableList with all elements of the collection that return true when evaluating the specified predicate which is supplied each element and its relative index.<R extends Collection<T>>
RselectWithIndex(ObjectIntPredicate<? super T> predicate, R target) Adds all elements to the target Collection that return true when evaluating the specified predicate which is supplied each element and its relative index.intsize()Returns the number of items in this iterable.summarizeDouble(DoubleFunction<? super T> function) Returns the result of summarizing the value returned from applying the DoubleFunction to each element of the iterable.summarizeFloat(FloatFunction<? super T> function) Returns the result of summarizing the value returned from applying the FloatFunction to each element of the iterable.summarizeInt(IntFunction<? super T> function) Returns the result of summarizing the value returned from applying the IntFunction to each element of the iterable.summarizeLong(LongFunction<? super T> function) Returns the result of summarizing the value returned from applying the LongFunction to each element of the iterable.doublesumOfDouble(DoubleFunction<? super T> function) Returns the final double result of evaluating function for each element of the iterable and adding the results together.doublesumOfFloat(FloatFunction<? super T> function) Returns the final double result of evaluating function for each element of the iterable and adding the results together.longsumOfInt(IntFunction<? super T> function) Returns the final long result of evaluating function for each element of the iterable and adding the results together.longsumOfLong(LongFunction<? super T> function) Returns the final long result of evaluating function for each element of the iterable and adding the results together.take(int count) Returns the firstcountelements of the iterable or all the elements in the iterable ifcountis greater than the length of the iterable.Returns the initial elements that satisfy the Predicate.Object[]toArray()Converts this iterable to an array.<E> E[]toArray(E[] a) Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.toString()Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Methods inherited from class AbstractImmutableList
add, addAll, asParallel, asReversed, castToList, chunk, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, detectIndex, detectLastIndex, distinct, distinct, distinctBy, forEach, forEachWith, groupBy, groupBy, groupByEach, groupByEach, injectInto, injectInto, injectInto, injectInto, listIterator, listIterator, max, max, min, min, newMutable, newWithAll, newWithout, newWithoutAll, regularListEquals, remove, replaceAll, set, sort, subList, tap, toImmutable, toReversed, zip, zipWithIndexMethods inherited from class AbstractImmutableCollection
add, addAll, castToCollection, clear, countBy, countByEach, countByWith, groupByUniqueKey, parallelStream, remove, removeAll, removeAllFrom, retainAll, stream, sumByDouble, sumByFloat, sumByInt, sumByLongMethods inherited from class AbstractRichIterable
allSatisfyWith, anySatisfyWith, appendString, asLazy, collect, collectIf, containsAllArguments, containsAllIterable, countWith, detectWithIfNone, forEach, groupByUniqueKey, into, noneSatisfyWith, reject, select, toBag, toBiMap, toList, toMap, toSet, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, zip, zipWithIndexMethods inherited from interface BatchIterable
forEachMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface ImmutableCollection
aggregateBy, aggregateInPlaceBy, castToCollection, countBy, countByEach, countByWith, groupByUniqueKey, parallelStream, reduceBy, stream, sumByDouble, sumByFloat, sumByInt, sumByLongMethods inherited from interface ImmutableList
flatCollectWith, toImmutableListMethods inherited from interface InternalIterable
forEachMethods inherited from interface List
add, addAll, addFirst, addLast, clear, remove, removeAll, removeFirst, removeLast, retainAll, reversedMethods inherited from interface ListIterable
binarySearch, binarySearch, forEachInBothMethods inherited from interface OrderedIterable
getFirstOptional, getLastOptional, toStack, zip, zipWithIndexMethods inherited from interface ReversibleIterable
reverseForEach, reverseForEachWithIndexMethods inherited from interface RichIterable
aggregateBy, allSatisfyWith, anySatisfyWith, appendString, appendString, asLazy, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectIf, collectInt, collectLong, collectShort, containsAllArguments, containsAllIterable, containsAny, containsAnyIterable, containsBy, containsNone, containsNoneIterable, countBy, countByEach, countByWith, countWith, detectIfNone, detectWithIfNone, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupByAndCollect, groupByUniqueKey, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, into, makeString, makeString, makeString, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, noneSatisfyWith, reduceBy, reject, select, toBag, toBiMap, toImmutableBag, toImmutableBiMap, 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
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
items
-
-
Constructor Details
-
ImmutableArrayList
ImmutableArrayList(T[] newElements)
-
-
Method Details
-
newList
-
newListWith
-
newWith
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 interfaceImmutableList<T>
-
hashCode
public int hashCode()Description copied from interface:ListIterableFollows the same general contract asList.hashCode().- Specified by:
hashCodein interfaceCollection<T>- Specified by:
hashCodein interfaceList<T>- Specified by:
hashCodein interfaceListIterable<T>- Overrides:
hashCodein classAbstractImmutableList<T>
-
equals
Description copied from interface:ListIterableFollows the same general contract asList.equals(Object).- Specified by:
equalsin interfaceCollection<T>- Specified by:
equalsin interfaceList<T>- Specified by:
equalsin interfaceListIterable<T>- Overrides:
equalsin classAbstractImmutableList<T>
-
immutableArrayListEquals
-
notEmpty
public boolean notEmpty()Description copied from interface:RichIterableThe English equivalent of !this.isEmpty()- Specified by:
notEmptyin interfaceRichIterable<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 interfaceList<T>- Specified by:
getFirstin interfaceListIterable<T>- Specified by:
getFirstin interfaceOrderedIterable<T>- Specified by:
getFirstin interfaceRichIterable<T>- Specified by:
getFirstin interfaceSequencedCollection<T>- Overrides:
getFirstin classAbstractImmutableList<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 interfaceList<T>- Specified by:
getLastin interfaceListIterable<T>- Specified by:
getLastin interfaceOrderedIterable<T>- Specified by:
getLastin interfaceRichIterable<T>- Specified by:
getLastin interfaceSequencedCollection<T>- Overrides:
getLastin classAbstractImmutableList<T>
-
each
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:
-
forEachWithIndex
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 classAbstractImmutableList<T>
-
batchForEach
- Specified by:
batchForEachin interfaceBatchIterable<T>
-
getBatchCount
public int getBatchCount(int batchSize) - Specified by:
getBatchCountin interfaceBatchIterable<T>
-
forEachWithIndex
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>- Overrides:
forEachWithIndexin classAbstractImmutableList<T>
-
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"));- Specified by:
selectin interfaceImmutableCollection<T>- Specified by:
selectin interfaceImmutableList<T>- Specified by:
selectin interfaceListIterable<T>- Specified by:
selectin interfaceOrderedIterable<T>- Specified by:
selectin interfaceReversibleIterable<T>- Specified by:
selectin interfaceRichIterable<T>- Overrides:
selectin classAbstractImmutableList<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));- Specified by:
selectWithin interfaceImmutableCollection<T>- Specified by:
selectWithin interfaceImmutableList<T>- Specified by:
selectWithin interfaceListIterable<T>- Specified by:
selectWithin interfaceOrderedIterable<T>- Specified by:
selectWithin interfaceReversibleIterable<T>- Specified by:
selectWithin interfaceRichIterable<T>- Overrides:
selectWithin classAbstractImmutableList<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- See Also:
-
selectWith
public <P, R extends Collection<T>> R selectWith(Predicate2<? super T, ? super P> predicate, P parameter, R target) Description copied from interface:RichIterableSimilar toRichIterable.select(Predicate, Collection), 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:
MutableList<Person> selected = people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18), Lists.mutable.empty());- Specified by:
selectWithin interfaceRichIterable<T>- Overrides:
selectWithin classAbstractImmutableList<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicatetarget- the Collection to append to for all elements in thisRichIterablethat meet select criteriapredicate- Returns:
targetCollection, which contains appended elements as a result of the select criteria- 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"));- Specified by:
rejectin interfaceImmutableCollection<T>- Specified by:
rejectin interfaceImmutableList<T>- Specified by:
rejectin interfaceListIterable<T>- Specified by:
rejectin interfaceOrderedIterable<T>- Specified by:
rejectin interfaceReversibleIterable<T>- Specified by:
rejectin interfaceRichIterable<T>- Overrides:
rejectin classAbstractImmutableList<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));- Specified by:
rejectWithin interfaceImmutableCollection<T>- Specified by:
rejectWithin interfaceImmutableList<T>- Specified by:
rejectWithin interfaceListIterable<T>- Specified by:
rejectWithin interfaceOrderedIterable<T>- Specified by:
rejectWithin interfaceReversibleIterable<T>- Specified by:
rejectWithin interfaceRichIterable<T>- Overrides:
rejectWithin classAbstractImmutableList<T>- Parameters:
predicate- aPredicate2to use as the select criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicate- See Also:
-
rejectWith
public <P, R extends Collection<T>> R rejectWith(Predicate2<? super T, ? super P> predicate, P parameter, R target) Description copied from interface:RichIterableSimilar toRichIterable.reject(Predicate, Collection), 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:
MutableList<Person> rejected = people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18), Lists.mutable.empty());- Specified by:
rejectWithin interfaceRichIterable<T>- Overrides:
rejectWithin classAbstractImmutableList<T>- Parameters:
predicate- aPredicate2to use as the reject criteriaparameter- a parameter to pass in for evaluation of the second argumentPinpredicatetarget- the Collection to append to for all elements in thisRichIterablethat causePredicate#accept(Object)method to evaluate to false- Returns:
targetCollection, which contains appended elements as a result of the reject criteria- 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"));- Specified by:
partitionin interfaceImmutableCollection<T>- Specified by:
partitionin interfaceImmutableList<T>- Specified by:
partitionin interfaceListIterable<T>- Specified by:
partitionin interfaceOrderedIterable<T>- Specified by:
partitionin interfaceReversibleIterable<T>- Specified by:
partitionin interfaceRichIterable<T>- Overrides:
partitionin classAbstractImmutableList<T>
-
partitionWith
public <P> PartitionImmutableList<T> partitionWith(Predicate2<? super T, ? super P> predicate, P parameter) Description copied from interface:RichIterableFilters a collection into a PartitionIterable based on the evaluation of the predicate.Example using a Java 8 lambda expression:
PartitionIterable<Person> newYorkersAndNonNewYorkers = people.partitionWith((Person person, String state) -> person.getAddress().getState().getName().equals(state), "New York");- Specified by:
partitionWithin interfaceImmutableCollection<T>- Specified by:
partitionWithin interfaceImmutableList<T>- Specified by:
partitionWithin interfaceListIterable<T>- Specified by:
partitionWithin interfaceOrderedIterable<T>- Specified by:
partitionWithin interfaceReversibleIterable<T>- Specified by:
partitionWithin interfaceRichIterable<T>- Overrides:
partitionWithin classAbstractImmutableList<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 interfaceImmutableCollection<T>- Specified by:
selectInstancesOfin interfaceImmutableList<T>- Specified by:
selectInstancesOfin interfaceListIterable<T>- Specified by:
selectInstancesOfin interfaceOrderedIterable<T>- Specified by:
selectInstancesOfin interfaceReversibleIterable<T>- Specified by:
selectInstancesOfin interfaceRichIterable<T>- Overrides:
selectInstancesOfin classAbstractImmutableList<T>
-
collect
Description copied from interface:RichIterableReturns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.Example using a Java 8 lambda expression:
RichIterable<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName());- Specified by:
collectin interfaceImmutableCollection<T>- Specified by:
collectin interfaceImmutableList<T>- Specified by:
collectin interfaceListIterable<T>- Specified by:
collectin interfaceOrderedIterable<T>- Specified by:
collectin interfaceReversibleIterable<T>- Specified by:
collectin interfaceRichIterable<T>- Overrides:
collectin classAbstractImmutableList<T>
-
collectWith
public <P,V> ImmutableList<V> collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter) Description copied from interface:RichIterableSame asRichIterable.collect(Function)with aFunction2and specified parameter which is passed to the block.Example using a Java 8 lambda expression:
RichIterable<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));- Specified by:
collectWithin interfaceImmutableCollection<T>- Specified by:
collectWithin interfaceImmutableList<T>- Specified by:
collectWithin interfaceListIterable<T>- Specified by:
collectWithin interfaceOrderedIterable<T>- Specified by:
collectWithin interfaceReversibleIterable<T>- Specified by:
collectWithin interfaceRichIterable<T>- Overrides:
collectWithin classAbstractImmutableList<T>- Parameters:
function- AFunction2to use as the collect transformation functionparameter- A parameter to pass in for evaluation of the second argumentPinfunction- Returns:
- A new
RichIterablethat contains the transformed elements returned byFunction2.value(Object, Object) - See Also:
-
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 interfaceImmutableList<T>- Specified by:
collectWithIndexin interfaceListIterable<T>- Specified by:
collectWithIndexin interfaceOrderedIterable<T>- Specified by:
collectWithIndexin interfaceReversibleIterable<T>- Since:
- 9.1.
-
collectWithIndex
public <V, R extends 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.
-
selectWithIndex
Description copied from interface:ImmutableListReturns a new ImmutableList with all elements of the collection that return true when evaluating the specified predicate which is supplied each element and its relative index.- Specified by:
selectWithIndexin interfaceImmutableList<T>- Specified by:
selectWithIndexin interfaceListIterable<T>- Since:
- 11.0
-
rejectWithIndex
Description copied from interface:ImmutableListReturns a new ImmutableList with all elements of the collection that return false when evaluating the specified predicate which is supplied each element and its relative index.- Specified by:
rejectWithIndexin interfaceImmutableList<T>- Specified by:
rejectWithIndexin interfaceListIterable<T>- Since:
- 11.0
-
selectWithIndex
public <R extends Collection<T>> R selectWithIndex(ObjectIntPredicate<? super T> predicate, R target) Description copied from interface:OrderedIterableAdds all elements to the target Collection that return true when evaluating the specified predicate which is supplied each element and its relative index.- Specified by:
selectWithIndexin interfaceOrderedIterable<T>- Since:
- 11.0
-
rejectWithIndex
public <R extends Collection<T>> R rejectWithIndex(ObjectIntPredicate<? super T> predicate, R target) Description copied from interface:OrderedIterableAdds all elements to the target Collection that return false when evaluating the specified predicate which is supplied each element and its relative index.- Specified by:
rejectWithIndexin interfaceOrderedIterable<T>- Since:
- 11.0
-
collectIf
public <V> ImmutableList<V> collectIf(Predicate<? super T> predicate, Function<? super T, ? extends V> function) Description copied from interface:RichIterableReturns a new collection with the results of applying the specified function on each element of the source collection, but only for those elements which return true upon evaluation of the predicate. This is the optimized equivalent of calling iterable.select(predicate).collect(function).Example using a Java 8 lambda and method reference:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(e -> e != null, Object::toString);
Example using Predicates factory:
RichIterable<String> strings = Lists.mutable.with(1, 2, 3).collectIf(Predicates.notNull(), Functions.getToString());
- Specified by:
collectIfin interfaceImmutableCollection<T>- Specified by:
collectIfin interfaceImmutableList<T>- Specified by:
collectIfin interfaceListIterable<T>- Specified by:
collectIfin interfaceOrderedIterable<T>- Specified by:
collectIfin interfaceReversibleIterable<T>- Specified by:
collectIfin interfaceRichIterable<T>- Overrides:
collectIfin classAbstractImmutableList<T>
-
collectWith
public <P, V, R extends Collection<V>> R collectWith(Function2<? super T, ? super P, ? extends V> function, P parameter, R target) Description copied from interface:RichIterableSame as collectWith but with a targetCollection parameter to gather the results.Example using a Java 8 lambda expression:
MutableSet<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1), Sets.mutable.empty());- Specified by:
collectWithin interfaceRichIterable<T>- Overrides:
collectWithin classAbstractImmutableList<T>- Parameters:
function- aFunction2to use as the collect transformation functionparameter- a parameter to pass in for evaluation of the second argumentPinfunctiontarget- the Collection to append to for all elements in thisRichIterablethat meet select criteriafunction- Returns:
targetCollection, which contains appended elements as a result of the collect transformation
-
flatCollect
Description copied from interface:RichIterableflatCollectis a special case ofRichIterable.collect(Function). Withcollect, when theFunctionreturns a collection, the result is a collection of collections.flatCollectoutputs a single "flattened" collection instead. This method is commonly called flatMap.Consider the following example where we have a
Personclass, and eachPersonhas a list ofAddressobjects. Take the followingFunction:Function<Person, List<Address>> addressFunction = Person::getAddresses; RichIterable<Person> people = ...;
Usingcollectreturns a collection of collections of addresses.RichIterable<List<Address>> addresses = people.collect(addressFunction);
UsingflatCollectreturns a single flattened list of addresses.RichIterable<Address> addresses = people.flatCollect(addressFunction);
- Specified by:
flatCollectin interfaceImmutableCollection<T>- Specified by:
flatCollectin interfaceImmutableList<T>- Specified by:
flatCollectin interfaceListIterable<T>- Specified by:
flatCollectin interfaceOrderedIterable<T>- Specified by:
flatCollectin interfaceReversibleIterable<T>- Specified by:
flatCollectin interfaceRichIterable<T>- Overrides:
flatCollectin classAbstractImmutableList<T>- Parameters:
function- TheFunctionto apply- Returns:
- a new flattened collection produced by applying the given
function
-
flatCollect
public <V, R extends Collection<V>> R flatCollect(Function<? super T, ? extends Iterable<V>> function, R target) Description copied from interface:RichIterableSame as flatCollect, only the results are collected into the target collection.- Specified by:
flatCollectin interfaceRichIterable<T>- Overrides:
flatCollectin classAbstractImmutableList<T>- Parameters:
function- TheFunctionto applytarget- The collection into which results should be added.- Returns:
target, which will contain a flattened collection of results produced by applying the givenfunction- See Also:
-
detect
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>
-
detectWith
Description copied from interface:RichIterableReturns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.Example using a Java 8 lambda expression:
Person person = people.detectWith((person, fullName) -> person.getFullName().equals(fullName), "John Smith");- Specified by:
detectWithin interfaceRichIterable<T>- Overrides:
detectWithin classAbstractRichIterable<T>
-
detectOptional
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>
-
detectWithOptional
Description copied from interface:RichIterableReturns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.Example using a Java 8 lambda expression:
Optional<Person> person = people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");- Specified by:
detectWithOptionalin interfaceRichIterable<T>- Overrides:
detectWithOptionalin classAbstractRichIterable<T>
-
count
Description copied from interface:RichIterableReturn the total number of elements that answer true to the specified predicate.Example using a Java 8 lambda expression:
int count = people.count(person -> person.getAddress().getState().getName().equals("New York"));- Specified by:
countin interfaceRichIterable<T>- Overrides:
countin classAbstractImmutableList<T>
-
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>- Overrides:
correspondsin classAbstractImmutableList<T>
-
anySatisfy
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>
-
allSatisfy
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>
-
noneSatisfy
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>
-
summarizeInt
Description copied from interface:RichIterableReturns the result of summarizing the value returned from applying the IntFunction to each element of the iterable.IntSummaryStatistics stats = Lists.mutable.with(1, 2, 3).summarizeInt(Integer::intValue);- Specified by:
summarizeIntin interfaceRichIterable<T>- Since:
- 8.0
-
summarizeFloat
Description copied from interface:RichIterableReturns the result of summarizing the value returned from applying the FloatFunction to each element of the iterable.DoubleSummaryStatistics stats = Lists.mutable.with(1, 2, 3).summarizeFloat(Integer::floatValue);- Specified by:
summarizeFloatin interfaceRichIterable<T>- Since:
- 8.0
-
summarizeLong
Description copied from interface:RichIterableReturns the result of summarizing the value returned from applying the LongFunction to each element of the iterable.LongSummaryStatistics stats = Lists.mutable.with(1, 2, 3).summarizeLong(Integer::longValue);- Specified by:
summarizeLongin interfaceRichIterable<T>- Since:
- 8.0
-
summarizeDouble
Description copied from interface:RichIterableReturns the result of summarizing the value returned from applying the DoubleFunction to each element of the iterable.DoubleSummaryStatistics stats = Lists.mutable.with(1, 2, 3).summarizeDouble(Integer::doubleValue);- Specified by:
summarizeDoublein interfaceRichIterable<T>- Since:
- 8.0
-
reduce
Description copied from interface:RichIterableThis method produces the equivalent result asStream.reduce(BinaryOperator).- Specified by:
reducein interfaceRichIterable<T>- Overrides:
reducein classAbstractImmutableCollection<T>- Since:
- 8.0
-
reduceInPlace
Description copied from interface:RichIterableThis method produces the equivalent result asStream.collect(Collector).MutableObjectLongMap<Integer> map2 = Lists.mutable.with(1, 2, 3, 4, 5).reduceInPlace(Collectors2.sumByInt(i -> Integer.valueOf(i % 2), Integer::intValue));- Specified by:
reduceInPlacein interfaceRichIterable<T>- Since:
- 8.0
-
reduceInPlace
Description copied from interface:RichIterableThis method produces the equivalent result asStream.collect(Supplier, BiConsumer, BiConsumer). The combiner used in collect is unnecessary in the serial case, so is not included in the API.- Specified by:
reduceInPlacein interfaceRichIterable<T>- Since:
- 8.0
-
sumOfInt
Description copied from interface:RichIterableReturns the final long result of evaluating function for each element of the iterable and adding the results together.- Specified by:
sumOfIntin interfaceRichIterable<T>- Overrides:
sumOfIntin classAbstractImmutableList<T>
-
sumOfLong
Description copied from interface:RichIterableReturns the final long result of evaluating function for each element of the iterable and adding the results together.- Specified by:
sumOfLongin interfaceRichIterable<T>- Overrides:
sumOfLongin classAbstractImmutableList<T>
-
sumOfFloat
Description copied from interface:RichIterableReturns the final double result of evaluating function for each element of the iterable and adding the results together. It uses Kahan summation algorithm to reduce numerical error.- Specified by:
sumOfFloatin interfaceRichIterable<T>- Overrides:
sumOfFloatin classAbstractImmutableList<T>
-
sumOfDouble
Description copied from interface:RichIterableReturns the final double result of evaluating function for each element of the iterable and adding the results together. It uses Kahan summation algorithm to reduce numerical error.- Specified by:
sumOfDoublein interfaceRichIterable<T>- Overrides:
sumOfDoublein classAbstractImmutableList<T>
-
injectInto
public <IV> IV injectInto(IV injectedValue, Function2<? super IV, ? super T, ? extends IV> function) Description copied from interface:RichIterableReturns the final result of evaluating function using each element of the iterable and the previous evaluation result as the parameters. The injected value is used for the first parameter of the first evaluation, and the current item in the iterable is used as the second parameter. This method is commonly called fold or sometimes reduce.- Specified by:
injectIntoin interfaceRichIterable<T>- Overrides:
injectIntoin classAbstractImmutableList<T>
-
size
public int size()Description copied from interface:RichIterableReturns the number of items in this iterable.- Specified by:
sizein interfaceBatchIterable<T>- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceList<T>- Specified by:
sizein interfaceRichIterable<T>
-
isEmpty
public boolean isEmpty()Description copied from interface:RichIterableReturns true if this iterable has zero items.- Specified by:
isEmptyin interfaceCollection<T>- Specified by:
isEmptyin interfaceList<T>- Specified by:
isEmptyin interfaceRichIterable<T>- Overrides:
isEmptyin classAbstractRichIterable<T>
-
contains
Description copied from interface:RichIterableReturns true if the iterable has an element which responds true to element.equals(object).- Specified by:
containsin interfaceCollection<T>- Specified by:
containsin interfaceList<T>- Specified by:
containsin interfaceRichIterable<T>- Overrides:
containsin classAbstractRichIterable<T>
-
iterator
-
toArray
Description copied from interface:RichIterableConverts this iterable to an array.- Specified by:
toArrayin interfaceCollection<T>- Specified by:
toArrayin interfaceList<T>- Specified by:
toArrayin interfaceRichIterable<T>- Overrides:
toArrayin classAbstractImmutableCollection<T>- See Also:
-
toArray
public <E> E[] toArray(E[] a) 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 interfaceCollection<T>- Specified by:
toArrayin interfaceList<T>- Specified by:
toArrayin interfaceRichIterable<T>- Overrides:
toArrayin classAbstractImmutableCollection<T>- See Also:
-
appendString
Description copied from interface:RichIterablePrints a string representation of this collection onto the givenAppendable. Prints the string returned byRichIterable.makeString(String, String, String).- Specified by:
appendStringin interfaceRichIterable<T>- Overrides:
appendStringin classAbstractImmutableList<T>
-
toString
Description copied from class:AbstractRichIterableReturns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.Assert.assertEquals("[]", Lists.mutable.empty().toString()); Assert.assertEquals("[1]", Lists.mutable.with(1).toString()); Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());- Specified by:
toStringin interfaceRichIterable<T>- Overrides:
toStringin classAbstractRichIterable<T>- Returns:
- a string representation of this collection.
- See Also:
-
containsAll
Description copied from interface:RichIterableReturns true if all elements in source are contained in this collection.- Specified by:
containsAllin interfaceCollection<T>- Specified by:
containsAllin interfaceList<T>- Specified by:
containsAllin interfaceRichIterable<T>- Overrides:
containsAllin classAbstractRichIterable<T>- See Also:
-
get
Description copied from interface:ListIterableReturns the item at the specified position in this list iterable. -
indexOf
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 interfaceList<T>- Specified by:
indexOfin interfaceOrderedIterable<T>- Overrides:
indexOfin classAbstractImmutableList<T>- See Also:
-
lastIndexOf
Description copied from interface:ListIterableReturns the index of the last occurrence of the specified item in this list, or -1 if this list does not contain the item.- Specified by:
lastIndexOfin interfaceList<T>- Specified by:
lastIndexOfin interfaceListIterable<T>- Overrides:
lastIndexOfin classAbstractImmutableList<T>
-
minBy
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 classAbstractImmutableList<T>
-
maxBy
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 classAbstractImmutableList<T>
-
take
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 interfaceImmutableList<T>- Specified by:
takein interfaceListIterable<T>- Specified by:
takein interfaceReversibleIterable<T>- Overrides:
takein classAbstractImmutableList<T>- Parameters:
count- the number of items to take.
-
takeWhile
Description copied from interface:ListIterableReturns the initial elements that satisfy the Predicate. Short circuits at the first element which does not satisfy the Predicate.- Specified by:
takeWhilein interfaceImmutableList<T>- Specified by:
takeWhilein interfaceListIterable<T>- Specified by:
takeWhilein interfaceOrderedIterable<T>- Specified by:
takeWhilein interfaceReversibleIterable<T>- Overrides:
takeWhilein classAbstractImmutableList<T>
-
drop
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 interfaceImmutableList<T>- Specified by:
dropin interfaceListIterable<T>- Specified by:
dropin interfaceReversibleIterable<T>- Overrides:
dropin classAbstractImmutableList<T>- Parameters:
count- the number of items to drop.
-
dropWhile
Description copied from interface:ListIterableReturns the final elements that do not satisfy the Predicate. Short circuits at the first element which does satisfy the Predicate.- Specified by:
dropWhilein interfaceImmutableList<T>- Specified by:
dropWhilein interfaceListIterable<T>- Specified by:
dropWhilein interfaceOrderedIterable<T>- Specified by:
dropWhilein interfaceReversibleIterable<T>- Overrides:
dropWhilein classAbstractImmutableList<T>
-
partitionWhile
Description copied from interface:ListIterableReturns 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 interfaceImmutableList<T>- Specified by:
partitionWhilein interfaceListIterable<T>- Specified by:
partitionWhilein interfaceOrderedIterable<T>- Specified by:
partitionWhilein interfaceReversibleIterable<T>- Overrides:
partitionWhilein classAbstractImmutableList<T>
-
detectNotIndex
-
spliterator
- Specified by:
spliteratorin interfaceCollection<T>- Specified by:
spliteratorin interfaceImmutableCollection<T>- Specified by:
spliteratorin interfaceIterable<T>- Specified by:
spliteratorin interfaceList<T>- Overrides:
spliteratorin classAbstractImmutableCollection<T>- Since:
- 9.0
-