Search in sources :

Example 11 with CharArrayList

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

the class ImmutableEmptySortedBagTest method collectChar_target.

@Override
@Test
public void collectChar_target() {
    ImmutableSortedBag<Integer> bag = this.classUnderTest();
    Assert.assertEquals(new CharArrayList(), bag.collectChar(PrimitiveFunctions.unboxIntegerToChar(), new CharArrayList()));
    ImmutableSortedBag<Integer> bag2 = this.classUnderTest();
    Assert.assertEquals(new CharHashBag(), bag2.collectChar(PrimitiveFunctions.unboxIntegerToChar(), new CharHashBag()));
}
Also used : CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) Test(org.junit.Test)

Example 12 with CharArrayList

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

the class OrderedMapAdapter method collectChar.

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

Example 13 with CharArrayList

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

the class AbstractImmutableSortedSet 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)

Example 14 with CharArrayList

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

the class IterateTest method collectCharWithTarget.

@Test
public void collectCharWithTarget() {
    this.iterables.each(each -> {
        MutableCharCollection expected = new CharArrayList();
        MutableCharCollection actual = Iterate.collectChar(each, PrimitiveFunctions.unboxIntegerToChar(), expected);
        Assert.assertTrue(actual.containsAll((char) 1, (char) 2, (char) 3, (char) 4, (char) 5));
        Assert.assertSame("Target list sent as parameter not returned", expected, actual);
    });
    Verify.assertThrows(IllegalArgumentException.class, () -> Iterate.collectChar(null, PrimitiveFunctions.unboxIntegerToChar(), new CharArrayList()));
}
Also used : MutableCharCollection(org.eclipse.collections.api.collection.primitive.MutableCharCollection) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) Test(org.junit.Test)

Example 15 with CharArrayList

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

the class StringIterateTest method asCharAdapter.

@Test
public void asCharAdapter() {
    CharAdapter answer = StringIterate.asCharAdapter("HelloHellow").collectChar(Character::toUpperCase).select(c -> c != 'W').distinct().toReversed().reject(CharAdapter.adapt("LE")::contains).newWith('!');
    Assert.assertEquals("OH!", answer.toString());
    Assert.assertEquals("OH!", answer.toStringBuilder().toString());
    Assert.assertEquals("OH!", answer.makeString(""));
    CharList charList = StringIterate.asCharAdapter("HelloHellow").asLazy().collectChar(Character::toUpperCase).select(c -> c != 'W').toList().distinct().toReversed().reject(CharAdapter.adapt("LE")::contains).with('!');
    Assert.assertEquals("OH!", CharAdapter.from(charList).toString());
    Assert.assertEquals("OH!", CharAdapter.from(CharAdapter.from(charList)).toString());
    String helloUppercase2 = StringIterate.asCharAdapter("Hello").asLazy().collectChar(Character::toUpperCase).makeString("");
    Assert.assertEquals("HELLO", helloUppercase2);
    CharArrayList arraylist = new CharArrayList();
    StringIterate.asCharAdapter("Hello".toUpperCase()).chars().sorted().forEach(e -> arraylist.add((char) e));
    Assert.assertEquals(StringIterate.asCharAdapter("EHLLO"), arraylist);
    ImmutableCharList arrayList2 = StringIterate.asCharAdapter("Hello".toUpperCase()).toSortedList().toImmutable();
    Assert.assertEquals(StringIterate.asCharAdapter("EHLLO"), arrayList2);
    Assert.assertEquals(StringIterate.asCharAdapter("HELLO"), CharAdapter.adapt("hello").collectChar(Character::toUpperCase));
}
Also used : CharPredicates(org.eclipse.collections.impl.block.factory.primitive.CharPredicates) Function(org.eclipse.collections.api.block.function.Function) CodePointList(org.eclipse.collections.impl.string.immutable.CodePointList) CharProcedure(org.eclipse.collections.api.block.procedure.primitive.CharProcedure) Verify(org.eclipse.collections.impl.test.Verify) IntSets(org.eclipse.collections.impl.factory.primitive.IntSets) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) CharToCharFunctions(org.eclipse.collections.impl.block.factory.primitive.CharToCharFunctions) CodePointAdapter(org.eclipse.collections.impl.string.immutable.CodePointAdapter) MutableSet(org.eclipse.collections.api.set.MutableSet) CodePointPredicate(org.eclipse.collections.impl.block.predicate.CodePointPredicate) MutableMap(org.eclipse.collections.api.map.MutableMap) Functions(org.eclipse.collections.impl.block.factory.Functions) Tuples(org.eclipse.collections.impl.tuple.Tuples) CharAdapter(org.eclipse.collections.impl.string.immutable.CharAdapter) CharList(org.eclipse.collections.api.list.primitive.CharList) IntList(org.eclipse.collections.api.list.primitive.IntList) CodePointProcedure(org.eclipse.collections.impl.block.procedure.primitive.CodePointProcedure) Twin(org.eclipse.collections.api.tuple.Twin) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) ImmutableCharList(org.eclipse.collections.api.list.primitive.ImmutableCharList) Procedures(org.eclipse.collections.impl.block.factory.Procedures) Test(org.junit.Test) CharSets(org.eclipse.collections.impl.factory.primitive.CharSets) Lists(org.eclipse.collections.impl.factory.Lists) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) ImmutableIntSet(org.eclipse.collections.api.set.primitive.ImmutableIntSet) Assert(org.junit.Assert) ImmutableCharSet(org.eclipse.collections.api.set.primitive.ImmutableCharSet) CodePointFunction(org.eclipse.collections.impl.block.function.primitive.CodePointFunction) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) CharAdapter(org.eclipse.collections.impl.string.immutable.CharAdapter) CharList(org.eclipse.collections.api.list.primitive.CharList) ImmutableCharList(org.eclipse.collections.api.list.primitive.ImmutableCharList) ImmutableCharList(org.eclipse.collections.api.list.primitive.ImmutableCharList) Test(org.junit.Test)

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