Search in sources :

Example 1 with MutableLongBag

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;
}
Also used : MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag)

Example 2 with MutableLongBag

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();
}
Also used : MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag)

Example 3 with MutableLongBag

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;
}
Also used : MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag)

Example 4 with MutableLongBag

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);
}
Also used : IntStream(java.util.stream.IntStream) ImmutableLongList(org.eclipse.collections.api.list.primitive.ImmutableLongList) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) ImmutableIntStack(org.eclipse.collections.api.stack.primitive.ImmutableIntStack) MutableIntBag(org.eclipse.collections.api.bag.primitive.MutableIntBag) ImmutableDoubleList(org.eclipse.collections.api.list.primitive.ImmutableDoubleList) DoubleLists(org.eclipse.collections.impl.factory.primitive.DoubleLists) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableDoubleStack(org.eclipse.collections.api.stack.primitive.MutableDoubleStack) IntSets(org.eclipse.collections.impl.factory.primitive.IntSets) ImmutableDoubleBag(org.eclipse.collections.api.bag.primitive.ImmutableDoubleBag) DoubleSets(org.eclipse.collections.impl.factory.primitive.DoubleSets) MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) ImmutableLongSet(org.eclipse.collections.api.set.primitive.ImmutableLongSet) IntStacks(org.eclipse.collections.impl.factory.primitive.IntStacks) ImmutableDoubleStack(org.eclipse.collections.api.stack.primitive.ImmutableDoubleStack) ImmutableIntBag(org.eclipse.collections.api.bag.primitive.ImmutableIntBag) LongStream(java.util.stream.LongStream) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) MutableDoubleSet(org.eclipse.collections.api.set.primitive.MutableDoubleSet) LongStacks(org.eclipse.collections.impl.factory.primitive.LongStacks) DoubleStacks(org.eclipse.collections.impl.factory.primitive.DoubleStacks) ImmutableDoubleSet(org.eclipse.collections.api.set.primitive.ImmutableDoubleSet) MutableIntStack(org.eclipse.collections.api.stack.primitive.MutableIntStack) Test(org.junit.Test) ImmutableIntList(org.eclipse.collections.api.list.primitive.ImmutableIntList) LongBags(org.eclipse.collections.impl.factory.primitive.LongBags) DoubleStream(java.util.stream.DoubleStream) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IntLists(org.eclipse.collections.impl.factory.primitive.IntLists) MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) MutableLongStack(org.eclipse.collections.api.stack.primitive.MutableLongStack) IntInterval(org.eclipse.collections.impl.list.primitive.IntInterval) ImmutableLongBag(org.eclipse.collections.api.bag.primitive.ImmutableLongBag) LongSets(org.eclipse.collections.impl.factory.primitive.LongSets) ImmutableLongStack(org.eclipse.collections.api.stack.primitive.ImmutableLongStack) ImmutableIntSet(org.eclipse.collections.api.set.primitive.ImmutableIntSet) DoubleBags(org.eclipse.collections.impl.factory.primitive.DoubleBags) Assert(org.junit.Assert) IntBags(org.eclipse.collections.impl.factory.primitive.IntBags) MutableDoubleBag(org.eclipse.collections.api.bag.primitive.MutableDoubleBag) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) Test(org.junit.Test)

Aggregations

MutableLongBag (org.eclipse.collections.api.bag.primitive.MutableLongBag)4 LongHashBag (org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag)2 DoubleStream (java.util.stream.DoubleStream)1 IntStream (java.util.stream.IntStream)1 LongStream (java.util.stream.LongStream)1 ImmutableDoubleBag (org.eclipse.collections.api.bag.primitive.ImmutableDoubleBag)1 ImmutableIntBag (org.eclipse.collections.api.bag.primitive.ImmutableIntBag)1 ImmutableLongBag (org.eclipse.collections.api.bag.primitive.ImmutableLongBag)1 MutableDoubleBag (org.eclipse.collections.api.bag.primitive.MutableDoubleBag)1 MutableIntBag (org.eclipse.collections.api.bag.primitive.MutableIntBag)1 ImmutableDoubleList (org.eclipse.collections.api.list.primitive.ImmutableDoubleList)1 ImmutableIntList (org.eclipse.collections.api.list.primitive.ImmutableIntList)1 ImmutableLongList (org.eclipse.collections.api.list.primitive.ImmutableLongList)1 MutableDoubleList (org.eclipse.collections.api.list.primitive.MutableDoubleList)1 MutableIntList (org.eclipse.collections.api.list.primitive.MutableIntList)1 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)1 ImmutableDoubleSet (org.eclipse.collections.api.set.primitive.ImmutableDoubleSet)1 ImmutableIntSet (org.eclipse.collections.api.set.primitive.ImmutableIntSet)1 ImmutableLongSet (org.eclipse.collections.api.set.primitive.ImmutableLongSet)1 MutableDoubleSet (org.eclipse.collections.api.set.primitive.MutableDoubleSet)1