/** * Mutates the internal array of the ArrayList by sorting it and then returns the same ArrayList. */ public static <T> ArrayList<T> sortThis(ArrayList<T> list, Comparator<? super T> comparator) { int size = list.size(); if (ArrayListIterate.canAccessInternalArray(list)) { Arrays.sort(ArrayListIterate.getInternalArray(list), 0, size, comparator); } else { Collections.sort(list, comparator); } return list; }
public static <T> void toArray(ArrayList<T> list, T[] target, int startIndex, int sourceSize) { if (ArrayListIterate.canAccessInternalArray(list)) { System.arraycopy(ArrayListIterate.getInternalArray(list), 0, target, startIndex, sourceSize); } else { RandomAccessListIterate.toArray(list, target, startIndex, sourceSize); } }
private static <T, R extends MutableFloatCollection> R collectFloatFromInternalArray(ArrayList<T> source, FloatFunction<? super T> floatFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(floatFunction.floatValueOf(elements[i])); } return target; }
private static <T, R extends MutableLongCollection> R collectLongFromInternalArray(ArrayList<T> source, LongFunction<? super T> longFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(longFunction.longValueOf(elements[i])); } return target; }
private static <T, R extends MutableBooleanCollection> R collectBooleanFromInternalArray(ArrayList<T> source, BooleanFunction<? super T> booleanFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(booleanFunction.booleanValueOf(elements[i])); } return target; }
private static <T, R extends MutableIntCollection> R collectIntFromInternalArray(ArrayList<T> source, IntFunction<? super T> intFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(intFunction.intValueOf(elements[i])); } return target; }
private static <T, R extends MutableCharCollection> R collectCharFromInternalArray(ArrayList<T> source, CharFunction<? super T> charFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(charFunction.charValueOf(elements[i])); } return target; }
private static <T, R extends MutableShortCollection> R collectShortFromInternalArray(ArrayList<T> source, ShortFunction<? super T> shortFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(shortFunction.shortValueOf(elements[i])); } return target; }
private static <T, R extends MutableByteCollection> R collectByteFromInternalArray(ArrayList<T> source, ByteFunction<? super T> byteFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(byteFunction.byteValueOf(elements[i])); } return target; }
private static <T, R extends MutableDoubleCollection> R collectDoubleFromInternalArray(ArrayList<T> source, DoubleFunction<? super T> doubleFunction, int elementsToCollect, R target) { T[] elements = ArrayListIterate.getInternalArray(source); for (int i = 0; i < elementsToCollect; i++) { target.add(doubleFunction.doubleValueOf(elements[i])); } return target; }
/** * @see Iterate#zip(Iterable, Iterable, Collection) */ public static <X, Y, R extends Collection<Pair<X, Y>>> R zip(ArrayList<X> xs, Iterable<Y> ys, R targetCollection) { int size = xs.size(); if (ArrayListIterate.isOptimizableArrayList(xs, size)) { Iterator<Y> yIterator = ys.iterator(); X[] elements = ArrayListIterate.getInternalArray(xs); for (int i = 0; i < size && yIterator.hasNext(); i++) { targetCollection.add(Tuples.pair(elements[i], yIterator.next())); } return targetCollection; } return RandomAccessListIterate.zip(xs, ys, targetCollection); }
/** * @see Iterate#zipWithIndex(Iterable, Collection) */ public static <T, R extends Collection<Pair<T, Integer>>> R zipWithIndex(ArrayList<T> list, R targetCollection) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { targetCollection.add(Tuples.pair(elements[i], i)); } return targetCollection; } return RandomAccessListIterate.zipWithIndex(list, targetCollection); }
/** * @see Iterate#collectWith(Iterable, Function2, Object, Collection) */ 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) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { targetCollection.add(function.value(elements[i], parameter)); } return targetCollection; } return RandomAccessListIterate.collectWith(list, function, parameter, targetCollection); }
/** * @see Iterate#forEach(Iterable, Procedure) */ public static <T> void forEach(ArrayList<T> list, Procedure<? super T> procedure) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { procedure.value(elements[i]); } } else { RandomAccessListIterate.forEach(list, procedure); } }
/** * @see Iterate#allSatisfy(Iterable, Predicate) */ public static <T> boolean allSatisfy(ArrayList<T> list, Predicate<? super T> predicate) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { if (!predicate.accept(elements[i])) { return false; } } return true; } return RandomAccessListIterate.allSatisfy(list, predicate); }
/** * @see Iterate#noneSatisfy(Iterable, Predicate) */ public static <T> boolean noneSatisfy(ArrayList<T> list, Predicate<? super T> predicate) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { if (predicate.accept(elements[i])) { return false; } } return true; } return RandomAccessListIterate.noneSatisfy(list, predicate); }
/** * @see Iterate#forEachWithIndex(Iterable, ObjectIntProcedure) */ public static <T> void forEachWithIndex(ArrayList<T> list, ObjectIntProcedure<? super T> objectIntProcedure) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { objectIntProcedure.value(elements[i], i); } } else { RandomAccessListIterate.forEachWithIndex(list, objectIntProcedure); } }
/** * @see Iterate#injectInto(int, Iterable, IntObjectToIntFunction) */ public static <T> int injectInto( int injectValue, ArrayList<T> list, IntObjectToIntFunction<? super T> function) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { int result = injectValue; T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { result = function.intValueOf(result, elements[i]); } return result; } return RandomAccessListIterate.injectInto(injectValue, list, function); }
/** * @see Iterate#flatCollect(Iterable, Function, Collection) */ public static <T, A, R extends Collection<A>> R flatCollect( ArrayList<T> list, Function<? super T, ? extends Iterable<A>> function, R targetCollection) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { Iterate.addAllTo(function.valueOf(elements[i]), targetCollection); } return targetCollection; } return RandomAccessListIterate.flatCollect(list, function, targetCollection); }
public static <T, P> PartitionMutableList<T> partitionWith(ArrayList<T> list, Predicate2<? super T, ? super P> predicate, P parameter) { int size = list.size(); if (ArrayListIterate.isOptimizableArrayList(list, size)) { PartitionFastList<T> partitionFastList = new PartitionFastList<T>(); MutableList<T> selected = partitionFastList.getSelected(); MutableList<T> rejected = partitionFastList.getRejected(); T[] elements = ArrayListIterate.getInternalArray(list); for (int i = 0; i < size; i++) { T each = elements[i]; MutableList<T> bucket = predicate.accept(each, parameter) ? selected : rejected; bucket.add(each); } return partitionFastList; } return RandomAccessListIterate.partitionWith(list, predicate, parameter); }