Search in sources :

Example 1 with MutableIntBag

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

the class AbstractMutableMap method collectInt.

@Override
public MutableIntBag collectInt(IntFunction<? super V> intFunction) {
    MutableIntBag result = new IntHashBag();
    this.forEach(new CollectIntProcedure<>(intFunction, result));
    return result;
}
Also used : MutableIntBag(org.eclipse.collections.api.bag.primitive.MutableIntBag) IntHashBag(org.eclipse.collections.impl.bag.mutable.primitive.IntHashBag)

Example 2 with MutableIntBag

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

the class AbstractBag method collectInt.

@Override
public <R extends MutableIntCollection> R collectInt(IntFunction<? super T> intFunction, R target) {
    if (target instanceof MutableIntBag) {
        MutableIntBag targetBag = (MutableIntBag) target;
        this.forEachWithOccurrences((each, occurrences) -> targetBag.addOccurrences(intFunction.intValueOf(each), occurrences));
    } else {
        this.forEachWithOccurrences((each, occurrences) -> {
            int value = intFunction.intValueOf(each);
            for (int i = 0; i < occurrences; i++) {
                target.add(value);
            }
        });
    }
    return target;
}
Also used : MutableIntBag(org.eclipse.collections.api.bag.primitive.MutableIntBag)

Example 3 with MutableIntBag

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

the class AbstractImmutableMap method collectInt.

@Override
public ImmutableIntBag collectInt(IntFunction<? super V> intFunction) {
    MutableIntBag result = new IntHashBag();
    this.forEach(new CollectIntProcedure<>(intFunction, result));
    return result.toImmutable();
}
Also used : MutableIntBag(org.eclipse.collections.api.bag.primitive.MutableIntBag) IntHashBag(org.eclipse.collections.impl.bag.mutable.primitive.IntHashBag)

Example 4 with MutableIntBag

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

the class PrimitiveStreamsTest method toIntBag.

@Test
public void toIntBag() {
    MutableIntBag bag = PrimitiveStreams.mIntBag(IntStream.rangeClosed(1, 10));
    Assert.assertEquals(IntInterval.oneTo(10).toBag(), bag);
    Assert.assertEquals(IntBags.immutable.ofAll(IntStream.rangeClosed(1, 10)), bag);
}
Also used : MutableIntBag(org.eclipse.collections.api.bag.primitive.MutableIntBag) Test(org.junit.Test)

Aggregations

MutableIntBag (org.eclipse.collections.api.bag.primitive.MutableIntBag)4 IntHashBag (org.eclipse.collections.impl.bag.mutable.primitive.IntHashBag)2 Test (org.junit.Test)1