Search in sources :

Example 1 with ImmutableCharList

use of org.eclipse.collections.api.list.primitive.ImmutableCharList in project eclipse-collections by eclipse.

the class CharAdapterTest method makeString.

@Override
@Test
public void makeString() {
    ImmutableCharList list = this.classUnderTest();
    StringBuilder expectedString = new StringBuilder("");
    StringBuilder expectedString1 = new StringBuilder("");
    int size = list.size();
    for (char each = 0; each < size; each++) {
        expectedString.append((char) (each + (char) 1));
        expectedString1.append((char) (each + (char) 1));
        expectedString.append(each == size - 1 ? "" : ", ");
        expectedString1.append(each == size - 1 ? "" : "/");
    }
    Assert.assertEquals(expectedString.toString(), list.makeString());
    Assert.assertEquals(expectedString1.toString(), list.makeString("/"));
}
Also used : ImmutableCharList(org.eclipse.collections.api.list.primitive.ImmutableCharList) Test(org.junit.Test)

Example 2 with ImmutableCharList

use of org.eclipse.collections.api.list.primitive.ImmutableCharList 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)

Example 3 with ImmutableCharList

use of org.eclipse.collections.api.list.primitive.ImmutableCharList in project eclipse-collections by eclipse.

the class CharAdapterTest method appendString.

@Override
@Test
public void appendString() {
    StringBuilder expectedString = new StringBuilder("");
    StringBuilder expectedString1 = new StringBuilder("");
    int size = this.classUnderTest().size();
    for (char each = 0; each < size; each++) {
        expectedString.append((char) (each + (char) 1));
        expectedString1.append((char) (each + (char) 1));
        expectedString.append(each == size - 1 ? "" : ", ");
        expectedString1.append(each == size - 1 ? "" : "/");
    }
    ImmutableCharList list = this.classUnderTest();
    StringBuilder appendable2 = new StringBuilder();
    list.appendString(appendable2);
    Assert.assertEquals(expectedString.toString(), appendable2.toString());
    StringBuilder appendable3 = new StringBuilder();
    list.appendString(appendable3, "/");
    Assert.assertEquals(expectedString1.toString(), appendable3.toString());
}
Also used : ImmutableCharList(org.eclipse.collections.api.list.primitive.ImmutableCharList) Test(org.junit.Test)

Aggregations

ImmutableCharList (org.eclipse.collections.api.list.primitive.ImmutableCharList)3 Test (org.junit.Test)3 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 IntList (org.eclipse.collections.api.list.primitive.IntList)1 MutableMap (org.eclipse.collections.api.map.MutableMap)1 MutableSet (org.eclipse.collections.api.set.MutableSet)1 ImmutableCharSet (org.eclipse.collections.api.set.primitive.ImmutableCharSet)1 ImmutableIntSet (org.eclipse.collections.api.set.primitive.ImmutableIntSet)1 Twin (org.eclipse.collections.api.tuple.Twin)1 Functions (org.eclipse.collections.impl.block.factory.Functions)1 Procedures (org.eclipse.collections.impl.block.factory.Procedures)1 CharPredicates (org.eclipse.collections.impl.block.factory.primitive.CharPredicates)1 CharToCharFunctions (org.eclipse.collections.impl.block.factory.primitive.CharToCharFunctions)1 AddFunction (org.eclipse.collections.impl.block.function.AddFunction)1 CodePointFunction (org.eclipse.collections.impl.block.function.primitive.CodePointFunction)1 CodePointPredicate (org.eclipse.collections.impl.block.predicate.CodePointPredicate)1