Search in sources :

Example 1 with ImmutableIntBag

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

the class ImmutableBagTestCase method collectInt.

@Override
@Test
public void collectInt() {
    super.collectInt();
    ImmutableIntBag result = this.newBag().collectInt(Integer::parseInt);
    Assert.assertEquals(this.numKeys(), result.sizeDistinct());
    for (int i = 1; i <= this.numKeys(); i++) {
        Assert.assertEquals(i, result.occurrencesOf(i));
    }
}
Also used : ImmutableIntBag(org.eclipse.collections.api.bag.primitive.ImmutableIntBag) Test(org.junit.Test)

Example 2 with ImmutableIntBag

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

the class PersonAndPetKataTest method getCountsByPetAge.

@Test
public void getCountsByPetAge() {
    ImmutableIntBag countsLazy = this.people.asLazy().flatCollect(Person::getPets).collectInt(Pet::getAge).toBag().toImmutable();
    Assert.assertEquals(4, countsLazy.occurrencesOf(1));
    Assert.assertEquals(3, countsLazy.occurrencesOf(2));
    Assert.assertEquals(1, countsLazy.occurrencesOf(3));
    Assert.assertEquals(1, countsLazy.occurrencesOf(4));
    Assert.assertEquals(0, countsLazy.occurrencesOf(5));
}
Also used : ImmutableIntBag(org.eclipse.collections.api.bag.primitive.ImmutableIntBag) Test(org.junit.Test)

Example 3 with ImmutableIntBag

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

the class PrimitiveStreamsTest method toImmutableIntBag.

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

Aggregations

ImmutableIntBag (org.eclipse.collections.api.bag.primitive.ImmutableIntBag)3 Test (org.junit.Test)3