Search in sources :

Example 1 with CharIterable

use of org.eclipse.collections.api.CharIterable 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 2 with CharIterable

use of org.eclipse.collections.api.CharIterable in project eclipse-collections by eclipse.

the class AbstractRichIterableTestCase method collectChar.

@Test
public void collectChar() {
    CharIterable result = this.newWith(1, 2, 3, 4).collectChar(PrimitiveFunctions.unboxIntegerToChar());
    Assert.assertEquals(CharBags.mutable.of((char) 1, (char) 2, (char) 3, (char) 4), result.toBag());
    Assert.assertEquals(CharBags.mutable.of((char) 1, (char) 2, (char) 3, (char) 4), CharBags.mutable.ofAll(result));
}
Also used : CharIterable(org.eclipse.collections.api.CharIterable) Test(org.junit.Test)

Example 3 with CharIterable

use of org.eclipse.collections.api.CharIterable in project eclipse-collections by eclipse.

the class CharAdapter method chunk.

@Override
public RichIterable<CharIterable> chunk(int size) {
    if (size <= 0) {
        throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
    }
    MutableList<CharIterable> result = Lists.mutable.empty();
    if (this.notEmpty()) {
        CharIterator iterator = this.charIterator();
        while (iterator.hasNext()) {
            MutableCharList batch = CharLists.mutable.empty();
            for (int i = 0; i < size && iterator.hasNext(); i++) {
                batch.add(iterator.next());
            }
            result.add(batch);
        }
    }
    return result;
}
Also used : MutableCharList(org.eclipse.collections.api.list.primitive.MutableCharList) LazyCharIterable(org.eclipse.collections.api.LazyCharIterable) ReverseCharIterable(org.eclipse.collections.impl.lazy.primitive.ReverseCharIterable) CharIterable(org.eclipse.collections.api.CharIterable) AbstractCharIterable(org.eclipse.collections.impl.primitive.AbstractCharIterable) CharIterator(org.eclipse.collections.api.iterator.CharIterator)

Example 4 with CharIterable

use of org.eclipse.collections.api.CharIterable in project eclipse-collections by eclipse.

the class MapIterableTestCase method collectChar.

@Test
public void collectChar() {
    MapIterable<String, String> map = this.newMapWithKeysValues("One", "A1", "Two", "B", "Three", "C#++");
    CharIterable actual = map.collectChar((CharFunction<String>) string -> string.charAt(0));
    Assert.assertEquals(CharHashBag.newBagWith('A', 'B', 'C'), actual.toBag());
}
Also used : Maps(org.eclipse.collections.impl.factory.Maps) CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) CharFunction(org.eclipse.collections.api.block.function.primitive.CharFunction) Multimap(org.eclipse.collections.api.multimap.Multimap) Verify(org.eclipse.collections.impl.test.Verify) StringFunctions(org.eclipse.collections.impl.block.factory.StringFunctions) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) UnifiedSetMultimap(org.eclipse.collections.impl.multimap.set.UnifiedSetMultimap) MutableSet(org.eclipse.collections.api.set.MutableSet) RichIterable(org.eclipse.collections.api.RichIterable) IntegerWithCast(org.eclipse.collections.impl.IntegerWithCast) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Functions(org.eclipse.collections.impl.block.factory.Functions) Map(java.util.Map) LongIterable(org.eclipse.collections.api.LongIterable) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) Tuples(org.eclipse.collections.impl.tuple.Tuples) Interval(org.eclipse.collections.impl.list.Interval) ShortHashBag(org.eclipse.collections.impl.bag.mutable.primitive.ShortHashBag) Comparators(org.eclipse.collections.impl.block.factory.Comparators) DoubleHashBag(org.eclipse.collections.impl.bag.mutable.primitive.DoubleHashBag) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) SumProcedure(org.eclipse.collections.impl.math.SumProcedure) MutableSortedBag(org.eclipse.collections.api.bag.sorted.MutableSortedBag) ObjectDoubleMap(org.eclipse.collections.api.map.primitive.ObjectDoubleMap) ByteHashBag(org.eclipse.collections.impl.bag.mutable.primitive.ByteHashBag) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) CharIterable(org.eclipse.collections.api.CharIterable) MutableSortedSet(org.eclipse.collections.api.set.sorted.MutableSortedSet) TreeSortedSet(org.eclipse.collections.impl.set.sorted.mutable.TreeSortedSet) List(java.util.List) ObjectLongMap(org.eclipse.collections.api.map.primitive.ObjectLongMap) DoubleIterable(org.eclipse.collections.api.DoubleIterable) Lists(org.eclipse.collections.impl.factory.Lists) SortedMap(java.util.SortedMap) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) FloatIterable(org.eclipse.collections.api.FloatIterable) Function(org.eclipse.collections.api.block.function.Function) IntIterable(org.eclipse.collections.api.IntIterable) Bag(org.eclipse.collections.api.bag.Bag) Iterables.iBag(org.eclipse.collections.impl.factory.Iterables.iBag) Sum(org.eclipse.collections.impl.math.Sum) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag) FastList(org.eclipse.collections.impl.list.mutable.FastList) ConcurrentMap(java.util.concurrent.ConcurrentMap) LazyIterable(org.eclipse.collections.api.LazyIterable) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) Function2(org.eclipse.collections.api.block.function.Function2) TreeBag(org.eclipse.collections.impl.bag.sorted.mutable.TreeBag) ByteIterable(org.eclipse.collections.api.ByteIterable) MutableSetMultimap(org.eclipse.collections.api.multimap.set.MutableSetMultimap) CharAdapter(org.eclipse.collections.impl.string.immutable.CharAdapter) SerializeTestHelper(org.eclipse.collections.impl.test.SerializeTestHelper) Pair(org.eclipse.collections.api.tuple.Pair) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Iterator(java.util.Iterator) BooleanIterable(org.eclipse.collections.api.BooleanIterable) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) ShortIterable(org.eclipse.collections.api.ShortIterable) Bags(org.eclipse.collections.impl.factory.Bags) TreeSortedMap(org.eclipse.collections.impl.map.sorted.mutable.TreeSortedMap) Test(org.junit.Test) PassThruFunction0(org.eclipse.collections.impl.block.function.PassThruFunction0) Iterables.iSet(org.eclipse.collections.impl.factory.Iterables.iSet) IntegerSum(org.eclipse.collections.impl.math.IntegerSum) MapIterable(org.eclipse.collections.api.map.MapIterable) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) FloatHashBag(org.eclipse.collections.impl.bag.mutable.primitive.FloatHashBag) Assert(org.junit.Assert) Collections(java.util.Collections) IntHashBag(org.eclipse.collections.impl.bag.mutable.primitive.IntHashBag) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) CharIterable(org.eclipse.collections.api.CharIterable) Test(org.junit.Test)

Aggregations

CharIterable (org.eclipse.collections.api.CharIterable)4 Test (org.junit.Test)2 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BooleanIterable (org.eclipse.collections.api.BooleanIterable)1 ByteIterable (org.eclipse.collections.api.ByteIterable)1 DoubleIterable (org.eclipse.collections.api.DoubleIterable)1 FloatIterable (org.eclipse.collections.api.FloatIterable)1 IntIterable (org.eclipse.collections.api.IntIterable)1 LazyCharIterable (org.eclipse.collections.api.LazyCharIterable)1 LazyIterable (org.eclipse.collections.api.LazyIterable)1 LongIterable (org.eclipse.collections.api.LongIterable)1 RichIterable (org.eclipse.collections.api.RichIterable)1 ShortIterable (org.eclipse.collections.api.ShortIterable)1 Bag (org.eclipse.collections.api.bag.Bag)1