Search in sources :

Example 6 with CharHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag 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 7 with CharHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag in project eclipse-collections by eclipse.

the class MapIterableTestCase method collectCharWithTarget.

@Test
public void collectCharWithTarget() {
    CharHashBag target = new CharHashBag();
    MapIterable<String, String> map = this.newMapWithKeysValues("One", "A1", "Two", "B", "Three", "C#++");
    CharHashBag result = map.collectChar((CharFunction<String>) string -> string.charAt(0), target);
    Assert.assertSame("Target sent as parameter not returned", target, result);
    Assert.assertEquals(CharHashBag.newBagWith('A', 'B', 'C'), result.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) CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) Test(org.junit.Test)

Example 8 with CharHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag in project eclipse-collections by eclipse.

the class AbstractImmutableMap method collectChar.

@Override
public ImmutableCharBag collectChar(CharFunction<? super V> charFunction) {
    MutableCharBag result = new CharHashBag();
    this.forEach(new CollectCharProcedure<>(charFunction, result));
    return result.toImmutable();
}
Also used : CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) MutableCharBag(org.eclipse.collections.api.bag.primitive.MutableCharBag)

Example 9 with CharHashBag

use of org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag in project eclipse-collections by eclipse.

the class ImmutableBagTestCase method collectCharWithTarget.

@Override
@Test
public void collectCharWithTarget() {
    super.collectCharWithTarget();
    CharHashBag target = new CharHashBag();
    CharHashBag result = this.newBag().collectChar((CharFunction<String>) string -> string.charAt(0), target);
    Assert.assertSame("Target sent as parameter not returned", target, result);
    Assert.assertEquals(this.numKeys(), result.sizeDistinct());
    for (int i = 1; i <= this.numKeys(); i++) {
        Assert.assertEquals(i, result.occurrencesOf((char) ('0' + i)));
    }
}
Also used : 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) ObjectIntPair(org.eclipse.collections.api.tuple.primitive.ObjectIntPair) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) MutableSortedMap(org.eclipse.collections.api.map.sorted.MutableSortedMap) ImmutableShortBag(org.eclipse.collections.api.bag.primitive.ImmutableShortBag) MutableSet(org.eclipse.collections.api.set.MutableSet) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) Functions(org.eclipse.collections.impl.block.factory.Functions) MutableMultimap(org.eclipse.collections.api.multimap.MutableMultimap) 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) AbstractRichIterableTestCase(org.eclipse.collections.impl.AbstractRichIterableTestCase) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) PartitionImmutableBag(org.eclipse.collections.api.partition.bag.PartitionImmutableBag) Collection(java.util.Collection) Set(java.util.Set) MutableSortedBag(org.eclipse.collections.api.bag.sorted.MutableSortedBag) ByteHashBag(org.eclipse.collections.impl.bag.mutable.primitive.ByteHashBag) BooleanHashBag(org.eclipse.collections.impl.bag.mutable.primitive.BooleanHashBag) ImmutableFloatBag(org.eclipse.collections.api.bag.primitive.ImmutableFloatBag) List(java.util.List) Lists(org.eclipse.collections.impl.factory.Lists) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) Function(org.eclipse.collections.api.block.function.Function) Bag(org.eclipse.collections.api.bag.Bag) ImmutableCharBag(org.eclipse.collections.api.bag.primitive.ImmutableCharBag) ImmutableDoubleBag(org.eclipse.collections.api.bag.primitive.ImmutableDoubleBag) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag) FastList(org.eclipse.collections.impl.list.mutable.FastList) LazyIterable(org.eclipse.collections.api.LazyIterable) ImmutableBagMultimap(org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap) Function0(org.eclipse.collections.api.block.function.Function0) MutableMap(org.eclipse.collections.api.map.MutableMap) HashBagMultimap(org.eclipse.collections.impl.multimap.bag.HashBagMultimap) Function2(org.eclipse.collections.api.block.function.Function2) TreeBag(org.eclipse.collections.impl.bag.sorted.mutable.TreeBag) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) ImmutableBag(org.eclipse.collections.api.bag.ImmutableBag) ImmutableByteBag(org.eclipse.collections.api.bag.primitive.ImmutableByteBag) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) StringIterate(org.eclipse.collections.impl.utility.StringIterate) ImmutableIntBag(org.eclipse.collections.api.bag.primitive.ImmutableIntBag) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) Iterator(java.util.Iterator) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) Bags(org.eclipse.collections.impl.factory.Bags) IntPredicates(org.eclipse.collections.impl.block.factory.primitive.IntPredicates) Test(org.junit.Test) PassThruFunction0(org.eclipse.collections.impl.block.function.PassThruFunction0) ImmutableBooleanBag(org.eclipse.collections.api.bag.primitive.ImmutableBooleanBag) ObjectIntProcedures(org.eclipse.collections.impl.block.factory.ObjectIntProcedures) Sets(org.eclipse.collections.impl.factory.Sets) ImmutableLongBag(org.eclipse.collections.api.bag.primitive.ImmutableLongBag) MapIterable(org.eclipse.collections.api.map.MapIterable) AddFunction(org.eclipse.collections.impl.block.function.AddFunction) ImmutableSet(org.eclipse.collections.api.set.ImmutableSet) Comparator(java.util.Comparator) 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) CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) Test(org.junit.Test)

Aggregations

CharHashBag (org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag)9 Test (org.junit.Test)5 Iterator (java.util.Iterator)3 List (java.util.List)3 Bag (org.eclipse.collections.api.bag.Bag)3 MutableBag (org.eclipse.collections.api.bag.MutableBag)3 Function (org.eclipse.collections.api.block.function.Function)3 Function2 (org.eclipse.collections.api.block.function.Function2)3 MutableList (org.eclipse.collections.api.list.MutableList)3 MapIterable (org.eclipse.collections.api.map.MapIterable)3 MutableMap (org.eclipse.collections.api.map.MutableMap)3 Multimap (org.eclipse.collections.api.multimap.Multimap)3 MutableMultimap (org.eclipse.collections.api.multimap.MutableMultimap)3 Pair (org.eclipse.collections.api.tuple.Pair)3 HashBag (org.eclipse.collections.impl.bag.mutable.HashBag)3 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 BooleanIterable (org.eclipse.collections.api.BooleanIterable)2 ByteIterable (org.eclipse.collections.api.ByteIterable)2 CharIterable (org.eclipse.collections.api.CharIterable)2