use of org.eclipse.collections.api.bag.primitive.MutableLongBag in project eclipse-collections by eclipse.
the class AbstractBag method collectLong.
@Override
public <R extends MutableLongCollection> R collectLong(LongFunction<? super T> longFunction, R target) {
if (target instanceof MutableLongBag) {
MutableLongBag targetBag = (MutableLongBag) target;
this.forEachWithOccurrences((each, occurrences) -> targetBag.addOccurrences(longFunction.longValueOf(each), occurrences));
} else {
this.forEachWithOccurrences((each, occurrences) -> {
long value = longFunction.longValueOf(each);
for (int i = 0; i < occurrences; i++) {
target.add(value);
}
});
}
return target;
}
use of org.eclipse.collections.api.bag.primitive.MutableLongBag in project eclipse-collections by eclipse.
the class AbstractImmutableMap method collectLong.
@Override
public ImmutableLongBag collectLong(LongFunction<? super V> longFunction) {
MutableLongBag result = new LongHashBag();
this.forEach(new CollectLongProcedure<>(longFunction, result));
return result.toImmutable();
}
use of org.eclipse.collections.api.bag.primitive.MutableLongBag in project eclipse-collections by eclipse.
the class AbstractMutableMap method collectLong.
@Override
public MutableLongBag collectLong(LongFunction<? super V> longFunction) {
MutableLongBag result = new LongHashBag();
this.forEach(new CollectLongProcedure<>(longFunction, result));
return result;
}
use of org.eclipse.collections.api.bag.primitive.MutableLongBag in project eclipse-collections by eclipse.
the class PrimitiveStreamsTest method toLongBag.
@Test
public void toLongBag() {
MutableLongBag bag = PrimitiveStreams.mLongBag(LongStream.rangeClosed(1, 10));
Assert.assertEquals(IntInterval.oneTo(10).collectLong(i -> (long) i, LongBags.mutable.empty()), bag);
Assert.assertEquals(LongBags.immutable.ofAll(LongStream.rangeClosed(1, 10)), bag);
}
Aggregations