Search in sources :

Example 26 with LongLongMap

use of org.eclipse.collections.api.map.primitive.LongLongMap in project mapdb by jankotek.

the class AbstractLongLongMapTestCase method collect.

@Test
public void collect() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    LongToObjectFunction<Long> function = (parameter) -> parameter + 1;
    Assert.assertEquals(Bags.immutable.with(1L, 2L, 3L, 4L), map.collect(function));
    Assert.assertEquals(Bags.immutable.empty(), this.getEmptyMap().collect(function));
    Assert.assertEquals(Bags.immutable.with(2L), this.newWithKeysValues(1L, 1L).collect(function));
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) Arrays(java.util.Arrays) Bags(org.eclipse.collections.impl.factory.Bags) Test(org.junit.Test) LongBags(org.eclipse.collections.impl.factory.primitive.LongBags) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) LongHashBag(org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) LongIterator(org.eclipse.collections.api.iterator.LongIterator) LongLongMaps(org.eclipse.collections.impl.factory.primitive.LongLongMaps) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) LongIterable(org.eclipse.collections.api.LongIterable) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) LongToObjectFunction(org.eclipse.collections.api.block.function.primitive.LongToObjectFunction) LongPredicates(org.eclipse.collections.impl.block.factory.primitive.LongPredicates) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) LongLongPair(org.eclipse.collections.api.tuple.primitive.LongLongPair) ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 27 with LongLongMap

use of org.eclipse.collections.api.map.primitive.LongLongMap in project mapdb by jankotek.

the class AbstractLongLongMapTestCase method forEach.

@Test
public void forEach() {
    LongLongMap map0 = this.newWithKeysValues(0L, 1L, 3L, 4L);
    long[] sum0 = new long[1];
    map0.forEach(each -> sum0[0] += each);
    Assert.assertEquals(5L, sum0[0]);
    LongLongMap map1 = this.newWithKeysValues(1L, 2L, 3L, 4L);
    long[] sum1 = new long[1];
    map1.forEach(each -> sum1[0] += each);
    Assert.assertEquals(6L, sum1[0]);
    LongLongMap map01 = this.newWithKeysValues(0L, 1L, 1L, 2L);
    long[] sum01 = new long[1];
    map01.forEach(each -> sum01[0] += each);
    Assert.assertEquals(3L, sum01[0]);
    LongLongMap map = this.newWithKeysValues(3L, 4L, 4L, 5L);
    long[] sum = new long[1];
    map.forEach(each -> sum[0] += each);
    Assert.assertEquals(9L, sum[0]);
    LongLongMap map2 = this.getEmptyMap();
    long[] sum2 = new long[1];
    map2.forEach(each -> sum2[0] += each);
    Assert.assertEquals(0L, sum2[0]);
    LongLongMap map3 = this.newWithKeysValues(1L, 2L);
    long[] sum3 = new long[1];
    map3.forEach(each -> sum3[0] += each);
    Assert.assertEquals(2L, sum3[0]);
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 28 with LongLongMap

use of org.eclipse.collections.api.map.primitive.LongLongMap in project mapdb by jankotek.

the class AbstractLongLongMapTestCase method median.

@Test
public void median() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    Assert.assertEquals(1.5, map.median(), 0.0);
    LongLongMap map2 = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L);
    Assert.assertEquals(1.0, map2.median(), 0.0);
    LongLongMap map3 = this.newWithKeysValues(1L, 1L);
    Assert.assertEquals(1.0, map3.median(), 0.0);
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 29 with LongLongMap

use of org.eclipse.collections.api.map.primitive.LongLongMap in project mapdb by jankotek.

the class AbstractLongLongMapTestCase method reject.

@Test
public void reject() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    LongLongMap actual1 = map.reject((long key, long value) -> key == 1L || value == 3L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 2L, 2L), actual1);
    LongLongMap actual2 = map.reject((long key, long value) -> key == 0L || value == 2L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L, 3L, 3L), actual2);
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 30 with LongLongMap

use of org.eclipse.collections.api.map.primitive.LongLongMap in project mapdb by jankotek.

the class AbstractLongLongMapTestCase method minIfEmpty.

@Test
public void minIfEmpty() {
    Assert.assertEquals(5L, this.getEmptyMap().minIfEmpty(5L));
    Assert.assertEquals(0L, this.getEmptyMap().minIfEmpty(0L));
    LongLongMap map = this.newWithKeysValues(1L, 1L, 0L, 0L, 9L, 9L, 7L, 7L);
    Assert.assertEquals(0L, map.minIfEmpty(5L));
    Assert.assertEquals(3L, this.newWithKeysValues(3L, 3L).maxIfEmpty(5L));
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Aggregations

ImmutableLongLongMap (org.eclipse.collections.api.map.primitive.ImmutableLongLongMap)30 LongLongMap (org.eclipse.collections.api.map.primitive.LongLongMap)30 Test (org.junit.Test)30 LazyLongIterable (org.eclipse.collections.api.LazyLongIterable)3 LongIterable (org.eclipse.collections.api.LongIterable)3 Arrays (java.util.Arrays)1 NoSuchElementException (java.util.NoSuchElementException)1 MutableBag (org.eclipse.collections.api.bag.MutableBag)1 LongToObjectFunction (org.eclipse.collections.api.block.function.primitive.LongToObjectFunction)1 LongIterator (org.eclipse.collections.api.iterator.LongIterator)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 LongLongPair (org.eclipse.collections.api.tuple.primitive.LongLongPair)1 LongHashBag (org.eclipse.collections.impl.bag.mutable.primitive.LongHashBag)1 LongPredicates (org.eclipse.collections.impl.block.factory.primitive.LongPredicates)1 Bags (org.eclipse.collections.impl.factory.Bags)1 LongBags (org.eclipse.collections.impl.factory.primitive.LongBags)1 LongLongMaps (org.eclipse.collections.impl.factory.primitive.LongLongMaps)1 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)1 LongLongHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap)1 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)1