Search in sources :

Example 6 with CharArrayList

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

the class AbstractRichIterableTestCase method collectCharWithTarget.

@Test
public void collectCharWithTarget() {
    MutableCharCollection target = new CharArrayList();
    CharIterable result = this.newWith(1, 2, 3, 4).collectChar(PrimitiveFunctions.unboxIntegerToChar(), target);
    Assert.assertSame("Target list sent as parameter not returned", target, result);
    Assert.assertEquals(CharHashBag.newBagWith((char) 1, (char) 2, (char) 3, (char) 4), result.toBag());
}
Also used : MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) CharIterable(org.eclipse.collections.api.CharIterable) Test(org.junit.Test)

Example 7 with CharArrayList

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

the class ArrayIterateTest method collectCharWithTarget.

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

Example 8 with CharArrayList

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

the class ArrayListIterateTest method collectCharWithTargetOverOptimizeLimit.

@Test
public void collectCharWithTargetOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableCharList target = new CharArrayList();
    MutableCharList actual = ArrayListIterate.collectChar(list, PrimitiveFunctions.unboxIntegerToChar(), target);
    CharArrayList expected = new CharArrayList(list.size());
    for (int i = 0; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add((char) i);
    }
    Assert.assertEquals(expected, actual);
    Assert.assertSame("Target sent as parameter was not returned as result", target, actual);
}
Also used : MutableCharList(org.eclipse.collections.api.list.primitive.MutableCharList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) 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) Test(org.junit.Test)

Example 9 with CharArrayList

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

the class ArrayListIterateTest method collectCharWithTarget.

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

Example 10 with CharArrayList

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

the class AbstractImmutableList method collectChar.

@Override
public ImmutableCharList collectChar(CharFunction<? super T> charFunction) {
    CharArrayList result = new CharArrayList(this.size());
    this.forEach(new CollectCharProcedure<>(charFunction, result));
    return result.toImmutable();
}
Also used : CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList)

Aggregations

CharArrayList (org.eclipse.collections.impl.list.mutable.primitive.CharArrayList)20 Test (org.junit.Test)10 MutableCharCollection (org.eclipse.collections.api.collection.primitive.MutableCharCollection)3 MutableCharList (org.eclipse.collections.api.list.primitive.MutableCharList)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 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 ShortArrayList (org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList)2 BigInteger (java.math.BigInteger)1 CharIterable (org.eclipse.collections.api.CharIterable)1 MutableBag (org.eclipse.collections.api.bag.MutableBag)1 Function (org.eclipse.collections.api.block.function.Function)1 CharProcedure (org.eclipse.collections.api.block.procedure.primitive.CharProcedure)1 MutableList (org.eclipse.collections.api.list.MutableList)1 CharList (org.eclipse.collections.api.list.primitive.CharList)1 ImmutableCharList (org.eclipse.collections.api.list.primitive.ImmutableCharList)1