Class AbstractArrayAdapter<T>
- All Implemented Interfaces:
Cloneable
,Iterable<T>
,Collection<T>
,List<T>
,RandomAccess
,MutableCollection<T>
,InternalIterable<T>
,ListIterable<T>
,MutableList<T>
,OrderedIterable<T>
,ReversibleIterable<T>
,RichIterable<T>
- Direct Known Subclasses:
ArrayAdapter
public abstract class AbstractArrayAdapter<T> extends AbstractMutableList<T> implements RandomAccess
-
Method Summary
Modifier and Type Method Description boolean
abstractArrayAdapterEquals(AbstractArrayAdapter<?> list)
void
add(int index, T element)
boolean
addAll(int index, Collection<? extends T> collection)
boolean
addAll(Collection<? extends T> collection)
boolean
addAllIterable(Iterable<? extends T> iterable)
boolean
allSatisfy(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> boolean
allSatisfyWith(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.boolean
anySatisfy(Predicate<? super T> predicate)
Returns true if the predicate evaluates to true for any element of the iterable.<P> boolean
anySatisfyWith(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.void
appendString(Appendable appendable, String start, String separator, String end)
Prints a string representation of this collection onto the givenAppendable
.void
clear()
<V> MutableList<V>
collect(Function<? super T,? extends V> function)
Returns a new MutableCollection with the results of applying the specified function to each element of the source collection.<V, R extends Collection<V>>
Rcollect(Function<? super T,? extends V> function, R target)
Same asRichIterable.collect(Function)
, except that the results are gathered into the specifiedtarget
collection.<V, R extends Collection<V>>
RcollectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function, R target)
Same as the collectIf method with two parameters but uses the specified target collection for the results.<P, A> MutableList<A>
collectWith(Function2<? super T,? super P,? extends A> function, P parameter)
Same asRichIterable.collect(Function)
with aFunction2
and specified parameter which is passed to the block.<P, A, R extends Collection<A>>
RcollectWith(Function2<? super T,? super P,? extends A> function, P parameter, R target)
Same as collectWith but with a targetCollection parameter to gather the results.boolean
contains(Object o)
Returns true if the iterable has an element which responds true to element.equals(object).boolean
containsAll(Collection<?> collection)
Returns true if all elements in source are contained in this collection.<S> boolean
corresponds(OrderedIterable<S> other, Predicate2<? super T,? super S> predicate)
Returns true if both OrderedIterables have the same length andpredicate
returns true for all corresponding elements e1 of thisOrderedIterable
and e2 ofother
.int
count(Predicate<? super T> predicate)
Return the total number of elements that answer true to the specified predicate.<P> int
countWith(Predicate2<? super T,? super P> predicate, P parameter)
Returns the total number of elements that evaluate to true for the specified predicate.T
detect(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.int
detectIndex(Predicate<? super T> predicate)
Returns the index of the first element of theOrderedIterable
for which thepredicate
evaluates to true.int
detectLastIndex(Predicate<? super T> predicate)
Returns the index of the last element of theReversibleIterable
for which thepredicate
evaluates to true.Optional<T>
detectOptional(Predicate<? super T> predicate)
Returns the first element of the iterable for which the predicate evaluates to true as an Optional.<P> T
detectWith(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.<P> Optional<T>
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.MutableList<T>
distinct()
Returns a newListIterable
containing the distinct elements in this list.MutableList<T>
distinct(HashingStrategy<? super T> hashingStrategy)
Returns a newListIterable
containing the distinct elements in this list.MutableList<T>
drop(int count)
Returns an iterable after skipping the firstcount
elements or an empty iterable if thecount
is greater than the length of the iterable.void
each(Procedure<? super T> procedure)
The procedure is executed for each element in the iterable.boolean
equals(Object that)
Follows the same general contract asList.equals(Object)
.<V> MutableList<V>
flatCollect(Function<? super T,? extends Iterable<V>> function)
flatCollect
is 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.void
forEach(int fromIndex, int toIndex, Procedure<? super T> procedure)
Iterates over the section of the iterable covered by the specified inclusive indexes.<P> void
forEachWith(Procedure2<? super T,? super P> procedure, P parameter)
The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.void
forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure)
Iterates over the section of the iterable covered by the specified inclusive indexes.void
forEachWithIndex(ObjectIntProcedure<? super T> objectIntProcedure)
Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.T
get(int index)
Returns the item at the specified position in this list iterable.T
getFirst()
Returns the first element of an iterable.T
getLast()
Returns the last element of an iterable.int
hashCode()
Follows the same general contract asList.hashCode()
.int
indexOf(Object item)
Returns the index of the first occurrence of the specified item in this iterable, or -1 if this iterable does not contain the item.<IV> IV
injectInto(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.<IV, P> IV
injectIntoWith(IV injectValue, Function3<? super IV,? super T,? super P,? extends IV> function, P parameter)
Returns the final result of evaluating function using each element of the iterable, the previous evaluation result and the parameters.boolean
isEmpty()
Returns true if this iterable has zero items.Iterator<T>
iterator()
int
lastIndexOf(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.ListIterator<T>
listIterator(int index)
boolean
noneSatisfy(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> boolean
noneSatisfyWith(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.boolean
notEmpty()
The English equivalent of !this.isEmpty()<R extends Collection<T>>
Rreject(Predicate<? super T> predicate, R target)
Same as the reject method with one parameter but uses the specified target collection for the results.<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
.T
remove(int index)
boolean
remove(Object o)
boolean
removeAll(Collection<?> collection)
boolean
removeAllIterable(Iterable<?> iterable)
boolean
removeIf(Predicate<? super T> predicate)
Removes all elements in the collection that evaluate to true for the specified predicate.<P> boolean
removeIfWith(Predicate2<? super T,? super P> predicate, P parameter)
Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.void
replaceAll(UnaryOperator<T> operator)
boolean
retainAll(Collection<?> collection)
boolean
retainAllIterable(Iterable<?> iterable)
<R extends Collection<T>>
Rselect(Predicate<? super T> predicate, R target)
Same as the select method with one parameter but uses the specified target collection for the results.<P> Twin<MutableList<T>>
selectAndRejectWith(Predicate2<? super T,? super P> predicate, P parameter)
Filters a collection into two separate collections based on a predicate returned via a Pair.<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
.int
size()
Returns the number of items in this iterable.void
sort(Comparator<? super T> comparator)
MutableList<T>
subList(int fromIndex, int toIndex)
MutableList<T>
take(int count)
Returns the firstcount
elements of the iterable or all the elements in the iterable ifcount
is greater than the length of the iterable.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.Methods inherited from class org.eclipse.collections.impl.list.mutable.AbstractMutableList
appendString, asParallel, asReversed, asSynchronized, asUnmodifiable, binarySearch, chunk, clone, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, distinctBy, dropWhile, groupBy, groupByEach, groupByUniqueKey, injectInto, injectInto, injectInto, listIterator, max, max, maxBy, min, min, minBy, newEmpty, partition, partitionWhile, partitionWith, selectInstancesOf, sortThisBy, sortThisByBoolean, sortThisByByte, sortThisByChar, sortThisByDouble, sortThisByFloat, sortThisByInt, sortThisByLong, sortThisByShort, sumOfDouble, sumOfFloat, sumOfInt, sumOfLong, takeWhile, tap, toSet, toSortedList, toStack, zip, zip, zipWithIndex, zipWithIndex
Methods inherited from class org.eclipse.collections.impl.collection.mutable.AbstractMutableCollection
add, aggregateInPlaceBy, countBy, countByEach, countByWith, reduce, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from class org.eclipse.collections.impl.AbstractRichIterable
asLazy, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAllArguments, containsAllIterable, detectWithIfNone, forEach, groupBy, groupByEach, groupByUniqueKey, injectInto, into, toBag, toBiMap, toList, toMap, toSortedBag, toSortedBag, toSortedBagBy, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
Methods inherited from interface org.eclipse.collections.api.list.ListIterable
binarySearch, forEachInBoth
Methods inherited from interface org.eclipse.collections.api.collection.MutableCollection
aggregateBy, aggregateInPlaceBy, countBy, countByEach, countByWith, sumByDouble, sumByFloat, sumByInt, sumByLong
Methods inherited from interface org.eclipse.collections.api.list.MutableList
collectIf, collectWithIndex, flatCollectWith, reject, rejectWith, reverseThis, select, selectWith, shuffleThis, shuffleThis, sortThis, sortThis, toImmutable, toReversed, with, withAll, without, withoutAll
Methods inherited from interface org.eclipse.collections.api.ordered.OrderedIterable
collectWithIndex, getFirstOptional, getLastOptional
Methods inherited from interface org.eclipse.collections.api.ordered.ReversibleIterable
reverseForEach, reverseForEachWithIndex
Methods inherited from interface org.eclipse.collections.api.RichIterable
aggregateBy, appendString, asLazy, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAllArguments, containsAllIterable, containsBy, countBy, countByEach, countByWith, detectIfNone, detectWithIfNone, flatCollectBoolean, flatCollectByte, flatCollectChar, flatCollectDouble, flatCollectFloat, flatCollectInt, flatCollectLong, flatCollectShort, flatCollectWith, forEach, getAny, getOnly, groupBy, groupByAndCollect, groupByEach, groupByUniqueKey, injectInto, into, makeString, makeString, makeString, maxByOptional, maxOptional, maxOptional, minByOptional, minOptional, minOptional, reduce, reduceInPlace, reduceInPlace, summarizeDouble, summarizeFloat, summarizeInt, summarizeLong, toBag, toBiMap, toList, toMap, toMap, toSortedBag, toSortedBag, toSortedBagBy, toSortedList, toSortedListBy, toSortedMap, toSortedMap, toSortedMapBy, toSortedSet, toSortedSet, toSortedSetBy, toString
-
Method Details
-
notEmpty
public boolean notEmpty()Description copied from interface:RichIterable
The English equivalent of !this.isEmpty()- Specified by:
notEmpty
in interfaceRichIterable<T>
-
getFirst
Description copied from interface:RichIterable
Returns 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:
getFirst
in interfaceListIterable<T>
- Specified by:
getFirst
in interfaceOrderedIterable<T>
- Specified by:
getFirst
in interfaceRichIterable<T>
- Overrides:
getFirst
in classAbstractMutableList<T>
-
getLast
Description copied from interface:RichIterable
Returns 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:
getLast
in interfaceListIterable<T>
- Specified by:
getLast
in interfaceOrderedIterable<T>
- Specified by:
getLast
in interfaceRichIterable<T>
- Overrides:
getLast
in classAbstractMutableList<T>
-
each
Description copied from interface:RichIterable
The procedure is executed for each element in the iterable.Example using a Java 8 lambda expression:
people.each(person -> LOGGER.info(person.getName()));
Example using an anonymous inner class:
people.each(new Procedure<Person>() { public void value(Person 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:
each
in interfaceRichIterable<T>
- Overrides:
each
in classAbstractMutableList<T>
- See Also:
InternalIterable.forEach(Procedure)
,Iterable.forEach(java.util.function.Consumer)
-
forEachWithIndex
Description copied from interface:InternalIterable
Iterates 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:
forEachWithIndex
in interfaceInternalIterable<T>
- Specified by:
forEachWithIndex
in interfaceOrderedIterable<T>
- Overrides:
forEachWithIndex
in classAbstractMutableList<T>
-
forEachWithIndex
public void forEachWithIndex(int fromIndex, int toIndex, ObjectIntProcedure<? super T> objectIntProcedure)Description copied from interface:OrderedIterable
Iterates 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, new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
- Specified by:
forEachWithIndex
in interfaceOrderedIterable<T>
- Overrides:
forEachWithIndex
in classAbstractMutableList<T>
-
removeIf
Description copied from interface:MutableCollection
Removes all elements in the collection that evaluate to true for the specified predicate.e.g. return lastNames.removeIf(Predicates.isNull());
- Specified by:
removeIf
in interfaceMutableCollection<T>
- Overrides:
removeIf
in classAbstractMutableList<T>
-
removeIfWith
Description copied from interface:MutableCollection
Removes all elements in the collection that evaluate to true for the specified predicate2 and parameter.return lastNames.removeIfWith(Predicates2.isNull(), null);
- Specified by:
removeIfWith
in interfaceMutableCollection<T>
- Overrides:
removeIfWith
in classAbstractMutableList<T>
-
detect
Description copied from interface:RichIterable
Returns 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"));
Example using an anonymous inner class:
Person person = people.detect(new Predicate<Person>() { public boolean accept(Person person) { return person.getFirstName().equals("John") && person.getLastName().equals("Smith"); } });
- Specified by:
detect
in interfaceRichIterable<T>
- Overrides:
detect
in classAbstractMutableList<T>
-
detectWith
Description copied from interface:RichIterable
Returns 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");
Example using an anonymous inner class:
Person person = people.detectWith(new Predicate2<Person, String>() { public boolean accept(Person person, String fullName) { return person.getFullName().equals(fullName); } }, "John Smith");
- Specified by:
detectWith
in interfaceRichIterable<T>
- Overrides:
detectWith
in classAbstractMutableList<T>
-
detectOptional
Description copied from interface:RichIterable
Returns 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:
detectOptional
in interfaceRichIterable<T>
- Overrides:
detectOptional
in classAbstractMutableList<T>
-
detectWithOptional
Description copied from interface:RichIterable
Returns 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:
detectWithOptional
in interfaceRichIterable<T>
- Overrides:
detectWithOptional
in classAbstractMutableList<T>
-
detectIndex
Description copied from interface:OrderedIterable
Returns the index of the first element of theOrderedIterable
for which thepredicate
evaluates to true. Returns -1 if no element evaluates true for thepredicate
.- Specified by:
detectIndex
in interfaceOrderedIterable<T>
- Overrides:
detectIndex
in classAbstractMutableList<T>
-
detectLastIndex
Description copied from interface:ReversibleIterable
Returns the index of the last element of theReversibleIterable
for which thepredicate
evaluates to true. Returns -1 if no element evaluates true for thepredicate
.- Specified by:
detectLastIndex
in interfaceReversibleIterable<T>
- Overrides:
detectLastIndex
in classAbstractMutableList<T>
-
count
Description copied from interface:RichIterable
Return 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"));
Example using an anonymous inner class:
int count = people.count(new Predicate<Person>() { public boolean accept(Person person) { return person.getAddress().getState().getName().equals("New York"); } });
- Specified by:
count
in interfaceRichIterable<T>
- Overrides:
count
in classAbstractMutableList<T>
-
corresponds
public <S> boolean corresponds(OrderedIterable<S> other, Predicate2<? super T,? super S> predicate)Description copied from interface:OrderedIterable
Returns true if both OrderedIterables have the same length andpredicate
returns true for all corresponding elements e1 of thisOrderedIterable
and e2 ofother
. Thepredicate
is evaluated for each element at the same position of eachOrderedIterable
in a forward iteration order. This is a short circuit pattern.- Specified by:
corresponds
in interfaceOrderedIterable<T>
- Overrides:
corresponds
in classAbstractMutableList<T>
-
anySatisfy
Description copied from interface:RichIterable
Returns 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:
anySatisfy
in interfaceRichIterable<T>
- Overrides:
anySatisfy
in classAbstractMutableList<T>
-
allSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
allSatisfy
in interfaceRichIterable<T>
- Overrides:
allSatisfy
in classAbstractMutableList<T>
-
noneSatisfy
Description copied from interface:RichIterable
Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.- Specified by:
noneSatisfy
in interfaceRichIterable<T>
- Overrides:
noneSatisfy
in classAbstractMutableList<T>
-
injectInto
public <IV> IV injectInto(IV injectedValue, Function2<? super IV,? super T,? extends IV> function)Description copied from interface:RichIterable
Returns 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:
injectInto
in interfaceRichIterable<T>
- Overrides:
injectInto
in classAbstractMutableList<T>
-
select
Description copied from interface:RichIterable
Same as the select method with one parameter but uses the specified target collection for the results.Example using a Java 8 lambda expression:
MutableList<Person> selected = people.select(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<Person> selected = people.select(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, Lists.mutable.empty());
- Specified by:
select
in interfaceRichIterable<T>
- Overrides:
select
in classAbstractMutableList<T>
- Parameters:
predicate
- aPredicate
to use as the select criteriatarget
- the Collection to append to for all elements in thisRichIterable
that meet select criteriapredicate
- Returns:
target
, which contains appended elements as a result of the select criteria- See Also:
RichIterable.select(Predicate)
-
reject
Description copied from interface:RichIterable
Same as the reject method with one parameter but uses the specified target collection for the results.Example using a Java 8 lambda expression:
MutableList<Person> rejected = people.reject(person -> person.person.getLastName().equals("Smith"), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<Person> rejected = people.reject(new Predicate<Person>() { public boolean accept(Person person) { return person.person.getLastName().equals("Smith"); } }, Lists.mutable.empty());
- Specified by:
reject
in interfaceRichIterable<T>
- Overrides:
reject
in classAbstractMutableList<T>
- Parameters:
predicate
- aPredicate
to use as the reject criteriatarget
- the Collection to append to for all elements in thisRichIterable
that causePredicate#accept(Object)
method to evaluate to false- Returns:
target
, which contains appended elements as a result of the reject criteria
-
collect
Description copied from interface:MutableCollection
Returns a new MutableCollection with the results of applying the specified function to each element of the source collection.MutableCollection<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName());
- Specified by:
collect
in interfaceListIterable<T>
- Specified by:
collect
in interfaceMutableCollection<T>
- Specified by:
collect
in interfaceMutableList<T>
- Specified by:
collect
in interfaceOrderedIterable<T>
- Specified by:
collect
in interfaceReversibleIterable<T>
- Specified by:
collect
in interfaceRichIterable<T>
-
collect
public <V, R extends Collection<V>> R collect(Function<? super T,? extends V> function, R target)Description copied from interface:RichIterable
Same asRichIterable.collect(Function)
, except that the results are gathered into the specifiedtarget
collection.Example using a Java 8 lambda expression:
MutableList<String> names = people.collect(person -> person.getFirstName() + " " + person.getLastName(), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<String> names = people.collect(new Function<Person, String>() { public String valueOf(Person person) { return person.getFirstName() + " " + person.getLastName(); } }, Lists.mutable.empty());
- Specified by:
collect
in interfaceRichIterable<T>
- Overrides:
collect
in classAbstractMutableList<T>
- Parameters:
function
- aFunction
to use as the collect transformation functiontarget
- the Collection to append to for all elements in thisRichIterable
that meet select criteriafunction
- Returns:
target
, which contains appended elements as a result of the collect transformation- See Also:
RichIterable.collect(Function)
-
collectIf
public <V, R extends Collection<V>> R collectIf(Predicate<? super T> predicate, Function<? super T,? extends V> function, R target)Description copied from interface:RichIterable
Same as the collectIf method with two parameters but uses the specified target collection for the results.- Specified by:
collectIf
in interfaceRichIterable<T>
- Overrides:
collectIf
in classAbstractMutableList<T>
- Parameters:
predicate
- aPredicate
to use as the select criteriafunction
- aFunction
to use as the collect transformation functiontarget
- the Collection to append to for all elements in thisRichIterable
that meet the collect criteriapredicate
- Returns:
targetCollection
, which contains appended elements as a result of the collect criteria and transformation- See Also:
RichIterable.collectIf(Predicate, Function)
-
flatCollect
Description copied from interface:MutableCollection
flatCollect
is a special case ofRichIterable.collect(Function)
. Withcollect
, when theFunction
returns a collection, the result is a collection of collections.flatCollect
outputs a single "flattened" collection instead. This method is commonly called flatMap.Consider the following example where we have a
Person
class, and eachPerson
has a list ofAddress
objects. Take the followingFunction
:Function<Person, List<Address>> addressFunction = Person::getAddresses; RichIterable<Person> people = ...;
Usingcollect
returns a collection of collections of addresses.RichIterable<List<Address>> addresses = people.collect(addressFunction);
UsingflatCollect
returns a single flattened list of addresses.RichIterable<Address> addresses = people.flatCollect(addressFunction);
Co-variant example for MutableCollection:Function<Person, List<Address>> addressFunction = Person::getAddresses; MutableCollection<Person> people = ...; MutableCollection<List<Address>> addresses = people.collect(addressFunction); MutableCollection<Address> addresses = people.flatCollect(addressFunction);
- Specified by:
flatCollect
in interfaceListIterable<T>
- Specified by:
flatCollect
in interfaceMutableCollection<T>
- Specified by:
flatCollect
in interfaceMutableList<T>
- Specified by:
flatCollect
in interfaceOrderedIterable<T>
- Specified by:
flatCollect
in interfaceReversibleIterable<T>
- Specified by:
flatCollect
in interfaceRichIterable<T>
- Parameters:
function
- TheFunction
to 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:RichIterable
Same as flatCollect, only the results are collected into the target collection.- Specified by:
flatCollect
in interfaceRichIterable<T>
- Overrides:
flatCollect
in classAbstractMutableList<T>
- Parameters:
function
- TheFunction
to 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:
RichIterable.flatCollect(Function)
-
selectAndRejectWith
public <P> Twin<MutableList<T>> selectAndRejectWith(Predicate2<? super T,? super P> predicate, P parameter)Description copied from interface:MutableCollection
Filters a collection into two separate collections based on a predicate returned via a Pair.e.g. return lastNames.selectAndRejectWith(Predicates2.lessThan(), "Mason");
- Specified by:
selectAndRejectWith
in interfaceMutableCollection<T>
- Overrides:
selectAndRejectWith
in classAbstractMutableList<T>
-
size
public int size()Description copied from interface:RichIterable
Returns the number of items in this iterable.- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceList<T>
- Specified by:
size
in interfaceRichIterable<T>
-
isEmpty
public boolean isEmpty()Description copied from interface:RichIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceList<T>
- Specified by:
isEmpty
in interfaceRichIterable<T>
- Overrides:
isEmpty
in classAbstractRichIterable<T>
-
contains
Description copied from interface:RichIterable
Returns true if the iterable has an element which responds true to element.equals(object).- Specified by:
contains
in interfaceCollection<T>
- Specified by:
contains
in interfaceList<T>
- Specified by:
contains
in interfaceRichIterable<T>
- Overrides:
contains
in classAbstractMutableList<T>
-
iterator
-
toArray
Description copied from interface:RichIterable
Converts this iterable to an array.- Specified by:
toArray
in interfaceCollection<T>
- Specified by:
toArray
in interfaceList<T>
- Specified by:
toArray
in interfaceRichIterable<T>
- Overrides:
toArray
in classAbstractRichIterable<T>
- See Also:
Collection.toArray()
-
toArray
public <E> E[] toArray(E[] array)Description copied from interface:RichIterable
Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.- Specified by:
toArray
in interfaceCollection<T>
- Specified by:
toArray
in interfaceList<T>
- Specified by:
toArray
in interfaceRichIterable<T>
- Overrides:
toArray
in classAbstractRichIterable<T>
- See Also:
Collection.toArray(Object[])
-
remove
- Specified by:
remove
in interfaceCollection<T>
- Specified by:
remove
in interfaceList<T>
- Overrides:
remove
in classAbstractMutableCollection<T>
-
containsAll
Description copied from interface:RichIterable
Returns true if all elements in source are contained in this collection.- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceList<T>
- Specified by:
containsAll
in interfaceRichIterable<T>
- Overrides:
containsAll
in classAbstractMutableList<T>
- See Also:
Collection.containsAll(Collection)
-
addAll
- Specified by:
addAll
in interfaceCollection<T>
- Specified by:
addAll
in interfaceList<T>
- Overrides:
addAll
in classAbstractMutableCollection<T>
-
addAllIterable
- Specified by:
addAllIterable
in interfaceMutableCollection<T>
- Overrides:
addAllIterable
in classAbstractMutableCollection<T>
- See Also:
Collection.addAll(Collection)
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
- Specified by:
removeAll
in interfaceList<T>
- Overrides:
removeAll
in classAbstractMutableList<T>
-
removeAllIterable
- Specified by:
removeAllIterable
in interfaceMutableCollection<T>
- Overrides:
removeAllIterable
in classAbstractMutableCollection<T>
- See Also:
Collection.removeAll(Collection)
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
- Specified by:
retainAll
in interfaceList<T>
- Overrides:
retainAll
in classAbstractMutableList<T>
-
retainAllIterable
- Specified by:
retainAllIterable
in interfaceMutableCollection<T>
- Overrides:
retainAllIterable
in classAbstractMutableCollection<T>
- See Also:
Collection.retainAll(Collection)
-
replaceAll
- Specified by:
replaceAll
in interfaceList<T>
- Since:
- 10.0 - Overridden for efficiency
-
sort
-
clear
public void clear() -
addAll
-
get
Description copied from interface:ListIterable
Returns the item at the specified position in this list iterable. -
add
-
remove
-
indexOf
Description copied from interface:OrderedIterable
Returns 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:
indexOf
in interfaceList<T>
- Specified by:
indexOf
in interfaceOrderedIterable<T>
- Overrides:
indexOf
in classAbstractMutableList<T>
- See Also:
List.indexOf(Object)
-
lastIndexOf
Description copied from interface:ListIterable
Returns 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:
lastIndexOf
in interfaceList<T>
- Specified by:
lastIndexOf
in interfaceListIterable<T>
- Overrides:
lastIndexOf
in classAbstractMutableList<T>
-
listIterator
- Specified by:
listIterator
in interfaceList<T>
- Specified by:
listIterator
in interfaceListIterable<T>
- Overrides:
listIterator
in classAbstractMutableList<T>
- See Also:
List.listIterator(int)
-
subList
- Specified by:
subList
in interfaceList<T>
- Specified by:
subList
in interfaceListIterable<T>
- Specified by:
subList
in interfaceMutableList<T>
- Overrides:
subList
in classAbstractMutableList<T>
- See Also:
List.subList(int, int)
-
equals
Description copied from interface:ListIterable
Follows the same general contract asList.equals(Object)
.- Specified by:
equals
in interfaceCollection<T>
- Specified by:
equals
in interfaceList<T>
- Specified by:
equals
in interfaceListIterable<T>
- Overrides:
equals
in classAbstractMutableList<T>
-
abstractArrayAdapterEquals
-
hashCode
public int hashCode()Description copied from interface:ListIterable
Follows the same general contract asList.hashCode()
.- Specified by:
hashCode
in interfaceCollection<T>
- Specified by:
hashCode
in interfaceList<T>
- Specified by:
hashCode
in interfaceListIterable<T>
- Overrides:
hashCode
in classAbstractMutableList<T>
-
forEachWith
Description copied from interface:InternalIterable
The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.Example using a Java 8 lambda:
people.forEachWith((Person person, Person other) -> { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } }, fred);
Example using an anonymous inner class:
people.forEachWith(new Procedure2<Person, Person>() { public void value(Person person, Person other) { if (person.isRelatedTo(other)) { LOGGER.info(person.getName()); } } }, fred);
- Specified by:
forEachWith
in interfaceInternalIterable<T>
- Overrides:
forEachWith
in classAbstractMutableList<T>
-
selectWith
public <P, R extends Collection<T>> R selectWith(Predicate2<? super T,? super P> predicate, P parameter, R target)Description copied from interface:RichIterable
Similar toRichIterable.select(Predicate, Collection)
, except with an evaluation parameter for the second generic argument inPredicate2
.E.g. return a
Collection
of Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
MutableList<Person> selected = people.selectWith((Person person, Integer age) -> person.getAge()>= age, Integer.valueOf(18), Lists.mutable.empty());
Example using an anonymous inner class:
MutableList<Person> selected = people.selectWith(new Predicate2<Person, Integer>() { public boolean accept(Person person, Integer age) { return person.getAge()>= age; } }, Integer.valueOf(18), Lists.mutable.empty());
- Specified by:
selectWith
in interfaceRichIterable<T>
- Overrides:
selectWith
in classAbstractMutableList<T>
- Parameters:
predicate
- aPredicate2
to use as the select criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
target
- the Collection to append to for all elements in thisRichIterable
that meet select criteriapredicate
- Returns:
targetCollection
, which contains appended elements as a result of the select criteria- See Also:
RichIterable.select(Predicate)
,RichIterable.select(Predicate, Collection)
-
rejectWith
public <P, R extends Collection<T>> R rejectWith(Predicate2<? super T,? super P> predicate, P parameter, R target)Description copied from interface:RichIterable
Similar toRichIterable.reject(Predicate, Collection)
, except with an evaluation parameter for the second generic argument inPredicate2
.E.g. return a
Collection
of Person elements where the person has an age greater than or equal to 18 yearsExample using a Java 8 lambda expression:
MutableList<Person> rejected = people.rejectWith((Person person, Integer age) -> person.getAge() < age, Integer.valueOf(18), Lists.mutable.empty());
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), Lists.mutable.empty());
- Specified by:
rejectWith
in interfaceRichIterable<T>
- Overrides:
rejectWith
in classAbstractMutableList<T>
- Parameters:
predicate
- aPredicate2
to use as the reject criteriaparameter
- a parameter to pass in for evaluation of the second argumentP
inpredicate
target
- the Collection to append to for all elements in thisRichIterable
that causePredicate#accept(Object)
method to evaluate to false- Returns:
targetCollection
, which contains appended elements as a result of the reject criteria- See Also:
RichIterable.reject(Predicate)
,RichIterable.reject(Predicate, Collection)
-
collectWith
public <P, A> MutableList<A> collectWith(Function2<? super T,? super P,? extends A> function, P parameter)Description copied from interface:MutableCollection
Same asRichIterable.collect(Function)
with aFunction2
and 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));
Example using an anonymous inner class:
Function2<Integer, Integer, Integer> addParameterFunction = new Function2<Integer, Integer, Integer>() { public Integer value(Integer each, Integer parameter) { return each + parameter; } }; RichIterable<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1));
Co-variant example for MutableCollection:MutableCollection<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith((each, parameter) -> each + parameter, Integer.valueOf(1));
- Specified by:
collectWith
in interfaceListIterable<T>
- Specified by:
collectWith
in interfaceMutableCollection<T>
- Specified by:
collectWith
in interfaceMutableList<T>
- Specified by:
collectWith
in interfaceOrderedIterable<T>
- Specified by:
collectWith
in interfaceReversibleIterable<T>
- Specified by:
collectWith
in interfaceRichIterable<T>
- Parameters:
function
- AFunction2
to use as the collect transformation functionparameter
- A parameter to pass in for evaluation of the second argumentP
infunction
- Returns:
- A new
RichIterable
that contains the transformed elements returned byFunction2.value(Object, Object)
- See Also:
RichIterable.collect(Function)
-
collectWith
public <P, A, R extends Collection<A>> R collectWith(Function2<? super T,? super P,? extends A> function, P parameter, R target)Description copied from interface:RichIterable
Same 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());
Example using an anonymous inner class:
Function2<Integer, Integer, Integer> addParameterFunction = new Function2<Integer, Integer, Integer>() { public Integer value(final Integer each, final Integer parameter) { return each + parameter; } }; MutableSet<Integer> integers = Lists.mutable.with(1, 2, 3).collectWith(addParameterFunction, Integer.valueOf(1), Sets.mutable.empty());
- Specified by:
collectWith
in interfaceRichIterable<T>
- Overrides:
collectWith
in classAbstractMutableList<T>
- Parameters:
function
- aFunction2
to use as the collect transformation functionparameter
- a parameter to pass in for evaluation of the second argumentP
infunction
target
- the Collection to append to for all elements in thisRichIterable
that meet select criteriafunction
- Returns:
targetCollection
, which contains appended elements as a result of the collect transformation
-
injectIntoWith
public <IV, P> IV injectIntoWith(IV injectValue, Function3<? super IV,? super T,? super P,? extends IV> function, P parameter)Description copied from interface:MutableCollection
Returns the final result of evaluating function using each element of the iterable, the previous evaluation result and 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. The parameter value is always used as the third parameter to the function call.- Specified by:
injectIntoWith
in interfaceMutableCollection<T>
- Overrides:
injectIntoWith
in classAbstractMutableList<T>
- See Also:
RichIterable.injectInto(Object, Function2)
-
forEach
Description copied from interface:OrderedIterable
Iterates 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.forEach(0, 1, new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
- Specified by:
forEach
in interfaceOrderedIterable<T>
- Overrides:
forEach
in classAbstractMutableList<T>
-
countWith
Description copied from interface:RichIterable
Returns the total number of elements that evaluate to true for the specified predicate.e.g. return lastNames.countWith(Predicates2.equal(), "Smith");
- Specified by:
countWith
in interfaceRichIterable<T>
- Overrides:
countWith
in classAbstractMutableList<T>
-
anySatisfyWith
Description copied from interface:RichIterable
Returns 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:
anySatisfyWith
in interfaceRichIterable<T>
- Overrides:
anySatisfyWith
in classAbstractMutableList<T>
-
allSatisfyWith
Description copied from interface:RichIterable
Returns true if the predicate evaluates to true for every element of the collection, or returns false.- Specified by:
allSatisfyWith
in interfaceRichIterable<T>
- Overrides:
allSatisfyWith
in classAbstractMutableList<T>
-
noneSatisfyWith
Description copied from interface:RichIterable
Returns 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:
noneSatisfyWith
in interfaceRichIterable<T>
- Overrides:
noneSatisfyWith
in classAbstractMutableList<T>
-
distinct
Description copied from interface:MutableList
Returns a newListIterable
containing the distinct elements in this list.- Specified by:
distinct
in interfaceListIterable<T>
- Specified by:
distinct
in interfaceMutableList<T>
- Specified by:
distinct
in interfaceOrderedIterable<T>
- Specified by:
distinct
in interfaceReversibleIterable<T>
- Overrides:
distinct
in classAbstractMutableList<T>
- Returns:
ListIterable
of distinct elements
-
distinct
Description copied from interface:MutableList
Returns a newListIterable
containing the distinct elements in this list. Takes HashingStrategy.- Specified by:
distinct
in interfaceListIterable<T>
- Specified by:
distinct
in interfaceMutableList<T>
- Overrides:
distinct
in classAbstractMutableList<T>
- Returns:
ListIterable
of distinct elements
-
appendString
Description copied from interface:RichIterable
Prints a string representation of this collection onto the givenAppendable
. Prints the string returned byRichIterable.makeString(String, String, String)
.- Specified by:
appendString
in interfaceRichIterable<T>
- Overrides:
appendString
in classAbstractMutableList<T>
-
take
Description copied from interface:ReversibleIterable
Returns the firstcount
elements of the iterable or all the elements in the iterable ifcount
is greater than the length of the iterable.- Specified by:
take
in interfaceListIterable<T>
- Specified by:
take
in interfaceMutableList<T>
- Specified by:
take
in interfaceReversibleIterable<T>
- Overrides:
take
in classAbstractMutableList<T>
- Parameters:
count
- the number of items to take.
-
drop
Description copied from interface:ReversibleIterable
Returns an iterable after skipping the firstcount
elements or an empty iterable if thecount
is greater than the length of the iterable.- Specified by:
drop
in interfaceListIterable<T>
- Specified by:
drop
in interfaceMutableList<T>
- Specified by:
drop
in interfaceReversibleIterable<T>
- Overrides:
drop
in classAbstractMutableList<T>
- Parameters:
count
- the number of items to drop.
-