Search in sources :

Example 1 with MutableDoubleBag

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

the class PrimitiveStreamsTest method toDoubleBag.

@Test
public void toDoubleBag() {
    MutableDoubleBag bag = PrimitiveStreams.mDoubleBag(DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0));
    Assert.assertEquals(DoubleBags.mutable.ofAll(IntInterval.oneTo(10).asLazy().collectDouble(i -> (double) i)), bag);
    Assert.assertEquals(DoubleBags.immutable.ofAll(DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)), bag);
}
Also used : MutableDoubleBag(org.eclipse.collections.api.bag.primitive.MutableDoubleBag) Test(org.junit.Test)

Example 2 with MutableDoubleBag

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

the class AbstractBag method collectDouble.

@Override
public <R extends MutableDoubleCollection> R collectDouble(DoubleFunction<? super T> doubleFunction, R target) {
    if (target instanceof MutableDoubleBag) {
        MutableDoubleBag targetBag = (MutableDoubleBag) target;
        this.forEachWithOccurrences((each, occurrences) -> targetBag.addOccurrences(doubleFunction.doubleValueOf(each), occurrences));
    } else {
        this.forEachWithOccurrences((each, occurrences) -> {
            double value = doubleFunction.doubleValueOf(each);
            for (int i = 0; i < occurrences; i++) {
                target.add(value);
            }
        });
    }
    return target;
}
Also used : MutableDoubleBag(org.eclipse.collections.api.bag.primitive.MutableDoubleBag)

Example 3 with MutableDoubleBag

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

the class AbstractImmutableMap method collectDouble.

@Override
public ImmutableDoubleBag collectDouble(DoubleFunction<? super V> doubleFunction) {
    MutableDoubleBag result = new DoubleHashBag();
    this.forEach(new CollectDoubleProcedure<>(doubleFunction, result));
    return result.toImmutable();
}
Also used : DoubleHashBag(org.eclipse.collections.impl.bag.mutable.primitive.DoubleHashBag) MutableDoubleBag(org.eclipse.collections.api.bag.primitive.MutableDoubleBag)

Example 4 with MutableDoubleBag

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

the class AbstractMutableMap method collectDouble.

@Override
public MutableDoubleBag collectDouble(DoubleFunction<? super V> doubleFunction) {
    MutableDoubleBag result = new DoubleHashBag();
    this.forEach(new CollectDoubleProcedure<>(doubleFunction, result));
    return result;
}
Also used : DoubleHashBag(org.eclipse.collections.impl.bag.mutable.primitive.DoubleHashBag) MutableDoubleBag(org.eclipse.collections.api.bag.primitive.MutableDoubleBag)

Aggregations

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