Class ArrayListIterate
java.lang.Object
org.eclipse.collections.impl.utility.ArrayListIterate
public final class ArrayListIterate extends Object
This utility class provides optimized iteration pattern implementations that work with java.util.ArrayList.
-
Method Summary
Modifier and Type Method Description static <T, K, V> MutableMap<K,V>
aggregateBy(ArrayList<T> list, Function<? super T,? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V,? super T,? extends V> nonMutatingAggregator)
static <T, K, V> MutableMap<K,V>
aggregateInPlaceBy(ArrayList<T> list, Function<? super T,? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V,? super T> mutatingAggregator)
static <T> boolean
allSatisfy(ArrayList<T> list, Predicate<? super T> predicate)
static <T, IV> boolean
allSatisfyWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue)
static <T> boolean
anySatisfy(ArrayList<T> list, Predicate<? super T> predicate)
static <T, P> boolean
anySatisfyWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T, A> ArrayList<A>
collect(ArrayList<T> list, Function<? super T,? extends A> function)
static <T, A, R extends Collection<A>>
Rcollect(ArrayList<T> list, Function<? super T,? extends A> function, R targetCollection)
static <T> MutableBooleanList
collectBoolean(ArrayList<T> list, BooleanFunction<? super T> booleanFunction)
static <T, R extends MutableBooleanCollection>
RcollectBoolean(ArrayList<T> list, BooleanFunction<? super T> booleanFunction, R target)
static <T> MutableByteList
collectByte(ArrayList<T> list, ByteFunction<? super T> byteFunction)
static <T, R extends MutableByteCollection>
RcollectByte(ArrayList<T> list, ByteFunction<? super T> byteFunction, R target)
static <T> MutableCharList
collectChar(ArrayList<T> list, CharFunction<? super T> charFunction)
static <T, R extends MutableCharCollection>
RcollectChar(ArrayList<T> list, CharFunction<? super T> charFunction, R target)
static <T> MutableDoubleList
collectDouble(ArrayList<T> list, DoubleFunction<? super T> doubleFunction)
static <T, R extends MutableDoubleCollection>
RcollectDouble(ArrayList<T> list, DoubleFunction<? super T> doubleFunction, R target)
static <T> MutableFloatList
collectFloat(ArrayList<T> list, FloatFunction<? super T> floatFunction)
static <T, R extends MutableFloatCollection>
RcollectFloat(ArrayList<T> list, FloatFunction<? super T> floatFunction, R target)
static <T, A> ArrayList<A>
collectIf(ArrayList<T> list, Predicate<? super T> predicate, Function<? super T,? extends A> function)
static <T, A, R extends Collection<A>>
RcollectIf(ArrayList<T> list, Predicate<? super T> predicate, Function<? super T,? extends A> function, R targetCollection)
static <T> MutableIntList
collectInt(ArrayList<T> list, IntFunction<? super T> intFunction)
static <T, R extends MutableIntCollection>
RcollectInt(ArrayList<T> list, IntFunction<? super T> intFunction, R target)
static <T> MutableLongList
collectLong(ArrayList<T> list, LongFunction<? super T> longFunction)
static <T, R extends MutableLongCollection>
RcollectLong(ArrayList<T> list, LongFunction<? super T> longFunction, R target)
static <T> MutableShortList
collectShort(ArrayList<T> list, ShortFunction<? super T> shortFunction)
static <T, R extends MutableShortCollection>
RcollectShort(ArrayList<T> list, ShortFunction<? super T> shortFunction, R target)
static <T, P, A> ArrayList<A>
collectWith(ArrayList<T> list, Function2<? super T,? super P,? extends A> function, P parameter)
static <T, P, A, R extends Collection<A>>
RcollectWith(ArrayList<T> list, Function2<? super T,? super P,? extends A> function, P parameter, R targetCollection)
static <T> int
count(ArrayList<T> list, Predicate<? super T> predicate)
static <T, P> int
countWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T> T
detect(ArrayList<T> list, Predicate<? super T> predicate)
static <T> T
detectIfNone(ArrayList<T> list, Predicate<? super T> predicate, T ifNone)
static <T> int
detectIndex(ArrayList<T> list, Predicate<? super T> predicate)
static <T, P> int
detectIndexWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T> int
detectLastIndex(ArrayList<T> list, Predicate<? super T> predicate)
static <T> Optional<T>
detectOptional(ArrayList<T> list, Predicate<? super T> predicate)
static <T, P> T
detectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T, IV> T
detectWithIfNone(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue, T ifNone)
static <T, P> Optional<T>
detectWithOptional(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T> ArrayList<T>
distinct(ArrayList<T> list)
static <T> ArrayList<T>
distinct(ArrayList<T> list, HashingStrategy<? super T> hashingStrategy)
static <T, R extends List<T>>
Rdistinct(ArrayList<T> list, R targetList)
Deprecated.in 7.0.static <T, V> ArrayList<T>
distinctBy(ArrayList<T> list, Function<? super T,? extends V> function)
static <T> ArrayList<T>
drop(ArrayList<T> list, int count)
static <T, R extends Collection<T>>
Rdrop(ArrayList<T> list, int count, R targetList)
static <T> MutableList<T>
dropWhile(ArrayList<T> list, Predicate<? super T> predicate)
static <T, A> ArrayList<A>
flatCollect(ArrayList<T> list, Function<? super T,? extends Iterable<A>> function)
static <T, A, R extends Collection<A>>
RflatCollect(ArrayList<T> list, Function<? super T,? extends Iterable<A>> function, R targetCollection)
static <T> void
forEach(ArrayList<T> list, int from, int to, Procedure<? super T> procedure)
Iterates over the section of the list covered by the specified indexes.static <T> void
forEach(ArrayList<T> list, Procedure<? super T> procedure)
static <T1, T2> void
forEachInBoth(ArrayList<T1> list1, ArrayList<T2> list2, Procedure2<? super T1,? super T2> procedure)
static <T, P> void
forEachWith(ArrayList<T> list, Procedure2<? super T,? super P> procedure, P parameter)
static <T> void
forEachWithIndex(ArrayList<T> list, int from, int to, ObjectIntProcedure<? super T> objectIntProcedure)
Iterates over the section of the list covered by the specified indexes.static <T> void
forEachWithIndex(ArrayList<T> list, ObjectIntProcedure<? super T> objectIntProcedure)
static <T, V> FastListMultimap<V,T>
groupBy(ArrayList<T> list, Function<? super T,? extends V> function)
static <T, V, R extends MutableMultimap<V, T>>
RgroupBy(ArrayList<T> list, Function<? super T,? extends V> function, R target)
static <T, V> FastListMultimap<V,T>
groupByEach(ArrayList<T> list, Function<? super T,? extends Iterable<V>> function)
static <T, V, R extends MutableMultimap<V, T>>
RgroupByEach(ArrayList<T> list, Function<? super T,? extends Iterable<V>> function, R target)
static <T, V> MutableMap<V,T>
groupByUniqueKey(ArrayList<T> list, Function<? super T,? extends V> function)
static <T, V, R extends MutableMapIterable<V, T>>
RgroupByUniqueKey(ArrayList<T> list, Function<? super T,? extends V> function, R target)
static <T> double
injectInto(double injectValue, ArrayList<T> list, DoubleObjectToDoubleFunction<? super T> function)
static <T> float
injectInto(float injectValue, ArrayList<T> list, FloatObjectToFloatFunction<? super T> function)
static <T> int
injectInto(int injectValue, ArrayList<T> list, IntObjectToIntFunction<? super T> function)
static <T> long
injectInto(long injectValue, ArrayList<T> list, LongObjectToLongFunction<? super T> function)
static <T, IV> IV
injectInto(IV injectValue, ArrayList<T> list, Function2<? super IV,? super T,? extends IV> function)
static <T, IV, P> IV
injectIntoWith(IV injectedValue, ArrayList<T> list, Function3<? super IV,? super T,? super P,? extends IV> function, P parameter)
static <T> boolean
noneSatisfy(ArrayList<T> list, Predicate<? super T> predicate)
static <T, IV> boolean
noneSatisfyWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue)
static <T> PartitionMutableList<T>
partition(ArrayList<T> list, Predicate<? super T> predicate)
static <T> PartitionMutableList<T>
partitionWhile(ArrayList<T> list, Predicate<? super T> predicate)
static <T, P> PartitionMutableList<T>
partitionWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T> ArrayList<T>
reject(ArrayList<T> list, Predicate<? super T> predicate)
static <T, R extends Collection<T>>
Rreject(ArrayList<T> list, Predicate<? super T> predicate, R targetCollection)
static <T, IV> ArrayList<T>
rejectWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue)
static <T, P, R extends Collection<T>>
RrejectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P injectedValue, R targetCollection)
static <T> boolean
removeIf(ArrayList<T> list, Predicate<? super T> predicate)
static <T, P> boolean
removeIfWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T> void
reverseForEach(ArrayList<T> list, Procedure<? super T> procedure)
Reverses over the List in reverse order executing the Procedure for each element.static <T> void
reverseForEachWithIndex(ArrayList<T> list, ObjectIntProcedure<? super T> procedure)
Reverses over the List in reverse order executing the Procedure with index for each element.static <T> ArrayList<T>
select(ArrayList<T> list, Predicate<? super T> predicate)
static <T, R extends Collection<T>>
Rselect(ArrayList<T> list, Predicate<? super T> predicate, R targetCollection)
static <T, P> Twin<MutableList<T>>
selectAndRejectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter)
static <T> MutableList<T>
selectInstancesOf(ArrayList<?> list, Class<T> clazz)
static <T, IV> ArrayList<T>
selectWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue)
static <T, P, R extends Collection<T>>
RselectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter, R targetCollection)
static <T extends Comparable<? super T>>
ArrayList<T>sortThis(ArrayList<T> list)
Mutates the internal array of the ArrayList by sorting it and then returns the same ArrayList.static <T> ArrayList<T>
sortThis(ArrayList<T> list, Comparator<? super T> comparator)
Mutates the internal array of the ArrayList by sorting it and then returns the same ArrayList.static <T> ArrayList<T>
take(ArrayList<T> list, int count)
static <T, R extends Collection<T>>
Rtake(ArrayList<T> list, int count, R targetList)
static <T> MutableList<T>
takeWhile(ArrayList<T> list, Predicate<? super T> predicate)
static <T> void
toArray(ArrayList<T> list, T[] target, int startIndex, int sourceSize)
static <X, Y> MutableList<Pair<X,Y>>
zip(ArrayList<X> xs, Iterable<Y> ys)
static <X, Y, R extends Collection<Pair<X, Y>>>
Rzip(ArrayList<X> xs, Iterable<Y> ys, R targetCollection)
static <T> MutableList<Pair<T,Integer>>
zipWithIndex(ArrayList<T> list)
static <T, R extends Collection<Pair<T, Integer>>>
RzipWithIndex(ArrayList<T> list, R targetCollection)
-
Method Details
-
select
- See Also:
Iterate.select(Iterable, Predicate)
-
selectWith
public static <T, IV> ArrayList<T> selectWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue) -
select
public static <T, R extends Collection<T>> R select(ArrayList<T> list, Predicate<? super T> predicate, R targetCollection) -
selectWith
public static <T, P, R extends Collection<T>> R selectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter, R targetCollection) -
selectInstancesOf
-
count
- See Also:
Iterate.count(Iterable, Predicate)
-
countWith
public static <T, P> int countWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
collectIf
-
collectIf
public static <T, A, R extends Collection<A>> R collectIf(ArrayList<T> list, Predicate<? super T> predicate, Function<? super T,? extends A> function, R targetCollection) -
reject
- See Also:
Iterate.reject(Iterable, Predicate)
-
rejectWith
public static <T, IV> ArrayList<T> rejectWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue) -
reject
public static <T, R extends Collection<T>> R reject(ArrayList<T> list, Predicate<? super T> predicate, R targetCollection) -
rejectWith
public static <T, P, R extends Collection<T>> R rejectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P injectedValue, R targetCollection) -
collect
public static <T, A> ArrayList<A> collect(ArrayList<T> list, Function<? super T,? extends A> function)- See Also:
Iterate.collect(Iterable, Function)
-
collectBoolean
public static <T> MutableBooleanList collectBoolean(ArrayList<T> list, BooleanFunction<? super T> booleanFunction) -
collectBoolean
public static <T, R extends MutableBooleanCollection> R collectBoolean(ArrayList<T> list, BooleanFunction<? super T> booleanFunction, R target) -
collectByte
public static <T> MutableByteList collectByte(ArrayList<T> list, ByteFunction<? super T> byteFunction) -
collectByte
public static <T, R extends MutableByteCollection> R collectByte(ArrayList<T> list, ByteFunction<? super T> byteFunction, R target) -
collectChar
public static <T> MutableCharList collectChar(ArrayList<T> list, CharFunction<? super T> charFunction) -
collectChar
public static <T, R extends MutableCharCollection> R collectChar(ArrayList<T> list, CharFunction<? super T> charFunction, R target) -
collectDouble
public static <T> MutableDoubleList collectDouble(ArrayList<T> list, DoubleFunction<? super T> doubleFunction) -
collectDouble
public static <T, R extends MutableDoubleCollection> R collectDouble(ArrayList<T> list, DoubleFunction<? super T> doubleFunction, R target) -
collectFloat
public static <T> MutableFloatList collectFloat(ArrayList<T> list, FloatFunction<? super T> floatFunction) -
collectFloat
public static <T, R extends MutableFloatCollection> R collectFloat(ArrayList<T> list, FloatFunction<? super T> floatFunction, R target) -
collectInt
-
collectInt
public static <T, R extends MutableIntCollection> R collectInt(ArrayList<T> list, IntFunction<? super T> intFunction, R target) -
collectLong
public static <T> MutableLongList collectLong(ArrayList<T> list, LongFunction<? super T> longFunction) -
collectLong
public static <T, R extends MutableLongCollection> R collectLong(ArrayList<T> list, LongFunction<? super T> longFunction, R target) -
collectShort
public static <T> MutableShortList collectShort(ArrayList<T> list, ShortFunction<? super T> shortFunction) -
collectShort
public static <T, R extends MutableShortCollection> R collectShort(ArrayList<T> list, ShortFunction<? super T> shortFunction, R target) -
collect
public static <T, A, R extends Collection<A>> R collect(ArrayList<T> list, Function<? super T,? extends A> function, R targetCollection) -
flatCollect
public static <T, A> ArrayList<A> flatCollect(ArrayList<T> list, Function<? super T,? extends Iterable<A>> function)- See Also:
Iterate.flatCollect(Iterable, Function)
-
flatCollect
public static <T, A, R extends Collection<A>> R flatCollect(ArrayList<T> list, Function<? super T,? extends Iterable<A>> function, R targetCollection) -
forEach
- See Also:
Iterate.forEach(Iterable, Procedure)
-
reverseForEach
Reverses over the List in reverse order executing the Procedure for each element. -
reverseForEachWithIndex
public static <T> void reverseForEachWithIndex(ArrayList<T> list, ObjectIntProcedure<? super T> procedure)Reverses over the List in reverse order executing the Procedure with index for each element. -
forEach
public static <T> void forEach(ArrayList<T> list, int from, int to, Procedure<? super T> procedure)Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the list is iterated in the reverse order.e.g. ArrayList<People> people = new ArrayList<People>(FastList.newListWith(ted, mary, bob, sally)); ArrayListIterate.forEach(people, 0, 1, new Procedure<Person>() { public void value(Person person) { LOGGER.info(person.getName()); } });
This code would output ted and mary's names.
-
forEachWithIndex
public static <T> void forEachWithIndex(ArrayList<T> list, int from, int to, ObjectIntProcedure<? super T> objectIntProcedure)Iterates over the section of the list covered by the specified indexes. The indexes are both inclusive. If the from is less than the to, the list is iterated in forward order. If the from is greater than the to, then the list is iterated in the reverse order. The index passed into the ObjectIntProcedure is the actual index of the range.e.g. ArrayList<People> people = new ArrayList<People>(FastList.newListWith(ted, mary, bob, sally)); ArrayListIterate.forEachWithIndex(people, 0, 1, new ObjectIntProcedure<Person>() { public void value(Person person, int index) { LOGGER.info(person.getName() + " at index: " + index); } });
This code would output ted and mary's names.
-
forEachInBoth
public static <T1, T2> void forEachInBoth(ArrayList<T1> list1, ArrayList<T2> list2, Procedure2<? super T1,? super T2> procedure) -
forEachWithIndex
public static <T> void forEachWithIndex(ArrayList<T> list, ObjectIntProcedure<? super T> objectIntProcedure) -
detect
- See Also:
Iterate.detect(Iterable, Predicate)
-
detectWith
public static <T, P> T detectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
detectOptional
-
detectWithOptional
public static <T, P> Optional<T> detectWithOptional(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
detectIfNone
-
detectWithIfNone
public static <T, IV> T detectWithIfNone(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue, T ifNone) -
injectInto
-
injectInto
public static <T> int injectInto(int injectValue, ArrayList<T> list, IntObjectToIntFunction<? super T> function) -
injectInto
public static <T> long injectInto(long injectValue, ArrayList<T> list, LongObjectToLongFunction<? super T> function) -
injectInto
public static <T> double injectInto(double injectValue, ArrayList<T> list, DoubleObjectToDoubleFunction<? super T> function) -
injectInto
public static <T> float injectInto(float injectValue, ArrayList<T> list, FloatObjectToFloatFunction<? super T> function) -
anySatisfy
- See Also:
Iterate.anySatisfy(Iterable, Predicate)
-
anySatisfyWith
public static <T, P> boolean anySatisfyWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
allSatisfy
- See Also:
Iterate.allSatisfy(Iterable, Predicate)
-
allSatisfyWith
public static <T, IV> boolean allSatisfyWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue) -
noneSatisfy
- See Also:
Iterate.noneSatisfy(Iterable, Predicate)
-
noneSatisfyWith
public static <T, IV> boolean noneSatisfyWith(ArrayList<T> list, Predicate2<? super T,? super IV> predicate, IV injectedValue) -
selectAndRejectWith
public static <T, P> Twin<MutableList<T>> selectAndRejectWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
partition
public static <T> PartitionMutableList<T> partition(ArrayList<T> list, Predicate<? super T> predicate)- See Also:
Iterate.partition(Iterable, Predicate)
-
partitionWith
public static <T, P> PartitionMutableList<T> partitionWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
detectIndex
- See Also:
Iterate.detectIndex(Iterable, Predicate)
-
detectIndexWith
public static <T, P> int detectIndexWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
detectLastIndex
-
injectIntoWith
-
forEachWith
public static <T, P> void forEachWith(ArrayList<T> list, Procedure2<? super T,? super P> procedure, P parameter) -
collectWith
-
collectWith
public static <T, P, A, R extends Collection<A>> R collectWith(ArrayList<T> list, Function2<? super T,? super P,? extends A> function, P parameter, R targetCollection) -
removeIf
- See Also:
Iterate.removeIf(Iterable, Predicate)
-
removeIfWith
public static <T, P> boolean removeIfWith(ArrayList<T> list, Predicate2<? super T,? super P> predicate, P parameter) -
distinct
-
distinct
Deprecated.in 7.0. -
distinct
public static <T> ArrayList<T> distinct(ArrayList<T> list, HashingStrategy<? super T> hashingStrategy)- Since:
- 7.0.
-
distinctBy
public static <T, V> ArrayList<T> distinctBy(ArrayList<T> list, Function<? super T,? extends V> function)- Since:
- 9.0.
-
sortThis
Mutates the internal array of the ArrayList by sorting it and then returns the same ArrayList. -
sortThis
Mutates the internal array of the ArrayList by sorting it and then returns the same ArrayList. -
toArray
-
take
- See Also:
Iterate.take(Iterable, int)
-
take
- See Also:
Iterate.take(Iterable, int)
-
drop
- See Also:
Iterate.drop(Iterable, int)
-
drop
- See Also:
Iterate.drop(Iterable, int)
-
groupBy
public static <T, V> FastListMultimap<V,T> groupBy(ArrayList<T> list, Function<? super T,? extends V> function)- See Also:
Iterate.groupBy(Iterable, Function)
-
groupBy
public static <T, V, R extends MutableMultimap<V, T>> R groupBy(ArrayList<T> list, Function<? super T,? extends V> function, R target) -
groupByEach
public static <T, V> FastListMultimap<V,T> groupByEach(ArrayList<T> list, Function<? super T,? extends Iterable<V>> function)- See Also:
Iterate.groupByEach(Iterable, Function)
-
groupByEach
public static <T, V, R extends MutableMultimap<V, T>> R groupByEach(ArrayList<T> list, Function<? super T,? extends Iterable<V>> function, R target) -
groupByUniqueKey
public static <T, V> MutableMap<V,T> groupByUniqueKey(ArrayList<T> list, Function<? super T,? extends V> function) -
groupByUniqueKey
public static <T, V, R extends MutableMapIterable<V, T>> R groupByUniqueKey(ArrayList<T> list, Function<? super T,? extends V> function, R target) -
zip
- See Also:
Iterate.zip(Iterable, Iterable)
-
zip
public static <X, Y, R extends Collection<Pair<X, Y>>> R zip(ArrayList<X> xs, Iterable<Y> ys, R targetCollection) -
zipWithIndex
- See Also:
Iterate.zipWithIndex(Iterable)
-
zipWithIndex
public static <T, R extends Collection<Pair<T, Integer>>> R zipWithIndex(ArrayList<T> list, R targetCollection) -
takeWhile
-
dropWhile
-
partitionWhile
public static <T> PartitionMutableList<T> partitionWhile(ArrayList<T> list, Predicate<? super T> predicate) -
aggregateInPlaceBy
public static <T, K, V> MutableMap<K,V> aggregateInPlaceBy(ArrayList<T> list, Function<? super T,? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V,? super T> mutatingAggregator) -
aggregateBy
public static <T, K, V> MutableMap<K,V> aggregateBy(ArrayList<T> list, Function<? super T,? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V,? super T,? extends V> nonMutatingAggregator)
-