Search in sources :

Example 1 with MutableCharBag

use of org.eclipse.collections.api.bag.primitive.MutableCharBag in project eclipse-collections by eclipse.

the class AbstractMutableMap method collectChar.

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

Example 2 with MutableCharBag

use of org.eclipse.collections.api.bag.primitive.MutableCharBag in project eclipse-collections by eclipse.

the class AbstractBag method collectChar.

@Override
public <R extends MutableCharCollection> R collectChar(CharFunction<? super T> charFunction, R target) {
    if (target instanceof MutableCharBag) {
        MutableCharBag targetBag = (MutableCharBag) target;
        this.forEachWithOccurrences((each, occurrences) -> targetBag.addOccurrences(charFunction.charValueOf(each), occurrences));
    } else {
        this.forEachWithOccurrences((each, occurrences) -> {
            char value = charFunction.charValueOf(each);
            for (int i = 0; i < occurrences; i++) {
                target.add(value);
            }
        });
    }
    return target;
}
Also used : MutableCharBag(org.eclipse.collections.api.bag.primitive.MutableCharBag)

Example 3 with MutableCharBag

use of org.eclipse.collections.api.bag.primitive.MutableCharBag 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 4 with MutableCharBag

use of org.eclipse.collections.api.bag.primitive.MutableCharBag in project eclipse-collections by eclipse.

the class CharAdapterTest method toBag.

@Override
public void toBag() {
    super.toBag();
    MutableCharBag expected = CharBags.mutable.empty();
    expected.addOccurrences('a', 3);
    expected.addOccurrences('b', 3);
    expected.addOccurrences('c', 3);
    Assert.assertEquals(expected, CharAdapter.adapt("aaabbbccc").toBag());
}
Also used : MutableCharBag(org.eclipse.collections.api.bag.primitive.MutableCharBag)

Aggregations

MutableCharBag (org.eclipse.collections.api.bag.primitive.MutableCharBag)4 CharHashBag (org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag)2