Skip to content

Commit

Permalink
Refactor to use internal array iterate - closes #1350
Browse files Browse the repository at this point in the history
  • Loading branch information
Desislav-Petrov committed Jul 25, 2022
1 parent 08422b4 commit 6c3d3b1
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,7 @@ public <V> FastList<V> collect(Function<? super T, ? extends V> function)
@Override
public <R extends MutableBooleanCollection> R collectBoolean(BooleanFunction<? super T> booleanFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(booleanFunction.booleanValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectBoolean(this.items, this.size, booleanFunction, target);
}

@Override
Expand All @@ -775,11 +771,7 @@ public <R extends MutableBooleanCollection> R flatCollectBoolean(
@Override
public <R extends MutableByteCollection> R collectByte(ByteFunction<? super T> byteFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(byteFunction.byteValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectByte(this.items, this.size, byteFunction, target);
}

@Override
Expand All @@ -796,11 +788,7 @@ public <R extends MutableByteCollection> R flatCollectByte(
@Override
public <R extends MutableCharCollection> R collectChar(CharFunction<? super T> charFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(charFunction.charValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectChar(this.items, this.size, charFunction, target);
}

@Override
Expand All @@ -817,11 +805,7 @@ public <R extends MutableCharCollection> R flatCollectChar(
@Override
public <R extends MutableDoubleCollection> R collectDouble(DoubleFunction<? super T> doubleFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(doubleFunction.doubleValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectDouble(this.items, this.size, doubleFunction, target);
}

@Override
Expand All @@ -838,11 +822,7 @@ public <R extends MutableDoubleCollection> R flatCollectDouble(
@Override
public <R extends MutableFloatCollection> R collectFloat(FloatFunction<? super T> floatFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(floatFunction.floatValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectFloat(this.items, this.size, floatFunction, target);
}

@Override
Expand All @@ -859,11 +839,7 @@ public <R extends MutableFloatCollection> R flatCollectFloat(
@Override
public <R extends MutableIntCollection> R collectInt(IntFunction<? super T> intFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(intFunction.intValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectInt(this.items, this.size, intFunction, target);
}

@Override
Expand All @@ -880,11 +856,7 @@ public <R extends MutableIntCollection> R flatCollectInt(
@Override
public <R extends MutableLongCollection> R collectLong(LongFunction<? super T> longFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(longFunction.longValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectLong(this.items, this.size, longFunction, target);
}

@Override
Expand All @@ -901,11 +873,7 @@ public <R extends MutableLongCollection> R flatCollectLong(
@Override
public <R extends MutableShortCollection> R collectShort(ShortFunction<? super T> shortFunction, R target)
{
for (int i = 0; i < this.size; i++)
{
target.add(shortFunction.shortValueOf(this.items[i]));
}
return target;
return InternalArrayIterate.collectShort(this.items, this.size, shortFunction, target);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,7 @@ public static <T, R extends MutableBooleanCollection> R collectBoolean(
{
throw new IllegalArgumentException("Cannot perform a collectBoolean on null");
}
for (T each : objectArray)
{
target.add(booleanFunction.booleanValueOf(each));
}
return target;
return InternalArrayIterate.collectBoolean(objectArray, objectArray.length, booleanFunction, target);
}

/**
Expand All @@ -495,11 +491,7 @@ public static <T, R extends MutableByteCollection> R collectByte(
{
throw new IllegalArgumentException("Cannot perform a collectByte on null");
}
for (T each : objectArray)
{
target.add(byteFunction.byteValueOf(each));
}
return target;
return InternalArrayIterate.collectByte(objectArray, objectArray.length, byteFunction, target);
}

/**
Expand All @@ -526,11 +518,7 @@ public static <T, R extends MutableCharCollection> R collectChar(
{
throw new IllegalArgumentException("Cannot perform a collectChar on null");
}
for (T each : objectArray)
{
target.add(charFunction.charValueOf(each));
}
return target;
return InternalArrayIterate.collectChar(objectArray, objectArray.length, charFunction, target);
}

/**
Expand All @@ -557,11 +545,7 @@ public static <T, R extends MutableDoubleCollection> R collectDouble(
{
throw new IllegalArgumentException("Cannot perform a collectDouble on null");
}
for (T each : objectArray)
{
target.add(doubleFunction.doubleValueOf(each));
}
return target;
return InternalArrayIterate.collectDouble(objectArray, objectArray.length, doubleFunction, target);
}

/**
Expand All @@ -588,11 +572,7 @@ public static <T, R extends MutableFloatCollection> R collectFloat(
{
throw new IllegalArgumentException("Cannot perform a collectFloat on null");
}
for (T each : objectArray)
{
target.add(floatFunction.floatValueOf(each));
}
return target;
return InternalArrayIterate.collectFloat(objectArray, objectArray.length, floatFunction, target);
}

/**
Expand Down Expand Up @@ -621,11 +601,7 @@ public static <T, R extends MutableIntCollection> R collectInt(
{
throw new IllegalArgumentException("Cannot perform a collectInt on null");
}
for (T each : objectArray)
{
target.add(intFunction.intValueOf(each));
}
return target;
return InternalArrayIterate.collectInt(objectArray, objectArray.length, intFunction, target);
}

/**
Expand Down Expand Up @@ -654,11 +630,7 @@ public static <T, R extends MutableLongCollection> R collectLong(
{
throw new IllegalArgumentException("Cannot perform a collectLong on null");
}
for (T each : objectArray)
{
target.add(longFunction.longValueOf(each));
}
return target;
return InternalArrayIterate.collectLong(objectArray, objectArray.length, longFunction, target);
}

/**
Expand Down Expand Up @@ -687,11 +659,7 @@ public static <T, R extends MutableShortCollection> R collectShort(
{
throw new IllegalArgumentException("Cannot perform a collectShort on null");
}
for (T each : objectArray)
{
target.add(shortFunction.shortValueOf(each));
}
return target;
return InternalArrayIterate.collectShort(objectArray, objectArray.length, shortFunction, target);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,28 @@
import org.eclipse.collections.api.block.HashingStrategy;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.function.primitive.BooleanFunction;
import org.eclipse.collections.api.block.function.primitive.ByteFunction;
import org.eclipse.collections.api.block.function.primitive.CharFunction;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.FloatFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.function.primitive.LongFunction;
import org.eclipse.collections.api.block.function.primitive.ObjectIntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.ShortFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.predicate.primitive.ObjectIntPredicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.collection.primitive.MutableBooleanCollection;
import org.eclipse.collections.api.collection.primitive.MutableByteCollection;
import org.eclipse.collections.api.collection.primitive.MutableCharCollection;
import org.eclipse.collections.api.collection.primitive.MutableDoubleCollection;
import org.eclipse.collections.api.collection.primitive.MutableFloatCollection;
import org.eclipse.collections.api.collection.primitive.MutableIntCollection;
import org.eclipse.collections.api.collection.primitive.MutableLongCollection;
import org.eclipse.collections.api.collection.primitive.MutableShortCollection;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.factory.primitive.ObjectDoubleMaps;
Expand Down Expand Up @@ -1214,4 +1226,156 @@ public static <R extends Collection<T>, T> R rejectWithIndex(
}
return target;
}

/**
* Adds all array elements to the target MutableBooleanCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableBooleanCollection, T> R collectBoolean(
T[] items,
int size,
BooleanFunction<? super T> booleanFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(booleanFunction.booleanValueOf(items[i]));
}
return target;
}

/**
* Adds all array elements to the target MutableByteCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableByteCollection, T> R collectByte(
T[] items,
int size,
ByteFunction<? super T> byteFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(byteFunction.byteValueOf(items[i]));
}
return target;
}

/**
* Adds all array elements to the target MutableCharCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableCharCollection, T> R collectChar(
T[] items,
int size,
CharFunction<? super T> charFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(charFunction.charValueOf(items[i]));
}
return target;
}

/**
* Adds all array elements to the target MutableDoubleCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableDoubleCollection, T> R collectDouble(
T[] items,
int size,
DoubleFunction<? super T> doubleFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(doubleFunction.doubleValueOf(items[i]));
}
return target;
}

/**
* Adds all array elements to the target MutableFloatCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableFloatCollection, T> R collectFloat(
T[] items,
int size,
FloatFunction<? super T> floatFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(floatFunction.floatValueOf(items[i]));
}
return target;
}

/**
* Adds all array elements to the target MutableIntCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableIntCollection, T> R collectInt(
T[] items,
int size,
IntFunction<? super T> intFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(intFunction.intValueOf(items[i]));
}
return target;
}

/**
* Adds all array elements to the target MutableLongCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableLongCollection, T> R collectLong(
T[] items,
int size,
LongFunction<? super T> longFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(longFunction.longValueOf(items[i]));
}
return target;
}

/**
* Adds all array elements to the target MutableShortCollection after using the function supplied to convert
* each source element to the appropriate type
*
* @since 12.0
*/
public static <R extends MutableShortCollection, T> R collectShort(
T[] items,
int size,
ShortFunction<? super T> shortFunction,
R target)
{
for (int i = 0; i < size; i++)
{
target.add(shortFunction.shortValueOf(items[i]));
}
return target;
}
}
Loading

0 comments on commit 6c3d3b1

Please sign in to comment.