Search in sources :

Example 6 with ShortArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList in project eclipse-collections by eclipse.

the class ArrayIterateTest method collectShortWithTarget.

@Test
public void collectShortWithTarget() {
    Integer[] objectArray = { -1, 0, 42 };
    ShortArrayList target = new ShortArrayList();
    ShortArrayList result = ArrayIterate.collectShort(objectArray, PrimitiveFunctions.unboxIntegerToShort(), target);
    Assert.assertEquals(this.getExpectedShortResults(), result);
    Assert.assertSame("Target List not returned as result", target, result);
}
Also used : BigInteger(java.math.BigInteger) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) Test(org.junit.Test)

Example 7 with ShortArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList in project eclipse-collections by eclipse.

the class ArrayListIterateTest method collectShortWithTarget.

@Test
public void collectShortWithTarget() {
    ArrayList<Integer> list = this.createIntegerList();
    MutableShortList target = new ShortArrayList();
    MutableShortList actual = ArrayListIterate.collectShort(list, PrimitiveFunctions.unboxIntegerToShort(), target);
    Assert.assertSame("Target list sent as parameter not returned", target, actual);
    Assert.assertEquals(ShortArrayList.newListWith((short) -1, (short) 0, (short) 4), actual);
}
Also used : ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) MutableShortList(org.eclipse.collections.api.list.primitive.MutableShortList) Test(org.junit.Test)

Example 8 with ShortArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList in project eclipse-collections by eclipse.

the class ArrayListIterateTest method collectShortWithTargetOverOptimizeLimit.

@Test
public void collectShortWithTargetOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableShortList target = new ShortArrayList();
    MutableShortList actual = ArrayListIterate.collectShort(list, PrimitiveFunctions.unboxIntegerToShort(), target);
    ShortArrayList expected = new ShortArrayList(list.size());
    for (int i = 0; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add((short) i);
    }
    Assert.assertEquals(expected, actual);
    Assert.assertSame("Target sent as parameter was not returned as result", target, actual);
}
Also used : ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableShortList(org.eclipse.collections.api.list.primitive.MutableShortList) Test(org.junit.Test)

Example 9 with ShortArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList in project eclipse-collections by eclipse.

the class ArrayListIterateTest method collectShortOverOptimizeLimit.

@Test
public void collectShortOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableShortList actual = ArrayListIterate.collectShort(list, PrimitiveFunctions.unboxIntegerToShort());
    ShortArrayList expected = new ShortArrayList(list.size());
    for (int i = 0; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add((short) i);
    }
    Assert.assertEquals(expected, actual);
}
Also used : ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) MutableShortList(org.eclipse.collections.api.list.primitive.MutableShortList) Test(org.junit.Test)

Example 10 with ShortArrayList

use of org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList in project eclipse-collections by eclipse.

the class AbstractImmutableList method collectShort.

@Override
public ImmutableShortList collectShort(ShortFunction<? super T> shortFunction) {
    ShortArrayList result = new ShortArrayList(this.size());
    this.forEach(new CollectShortProcedure<>(shortFunction, result));
    return result.toImmutable();
}
Also used : ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList)

Aggregations

ShortArrayList (org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList)20 Test (org.junit.Test)9 MutableShortCollection (org.eclipse.collections.api.collection.primitive.MutableShortCollection)3 MutableShortList (org.eclipse.collections.api.list.primitive.MutableShortList)3 ArrayList (java.util.ArrayList)2 BooleanArrayList (org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList)2 ByteArrayList (org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList)2 CharArrayList (org.eclipse.collections.impl.list.mutable.primitive.CharArrayList)2 DoubleArrayList (org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList)2 FloatArrayList (org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList)2 IntArrayList (org.eclipse.collections.impl.list.mutable.primitive.IntArrayList)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 BigInteger (java.math.BigInteger)1 ShortIterable (org.eclipse.collections.api.ShortIterable)1 ShortHashBag (org.eclipse.collections.impl.bag.mutable.primitive.ShortHashBag)1 AbstractSentinelValues (org.eclipse.collections.impl.map.mutable.primitive.AbstractSentinelValues)1