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);
}
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;
}
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();
}
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;
}
Aggregations