Search in sources :

Example 6 with LongLongMap

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

the class AbstractLongLongMapTestCase method detectIfNone_value.

@Test
public void detectIfNone_value() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    long resultNotFound = map.detectIfNone(LongPredicates.greaterThan(5L), 5L);
    Assert.assertEquals(5L, resultNotFound);
    Assert.assertEquals(5L, this.getEmptyMap().detectIfNone(LongPredicates.equal(0L), 5L));
    Assert.assertEquals(5L, this.newWithKeysValues(1L, 1L).detectIfNone(LongPredicates.equal(0L), 5L));
    Assert.assertEquals(1L, this.newWithKeysValues(1L, 1L).detectIfNone(LongPredicates.equal(1L), 5L));
    Assert.assertEquals(0L, map.detectIfNone(LongPredicates.equal(0L), 5L));
    Assert.assertEquals(1L, map.detectIfNone(LongPredicates.equal(1L), 5L));
    Assert.assertEquals(2L, map.detectIfNone(LongPredicates.equal(2L), 5L));
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 7 with LongLongMap

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

the class AbstractLongLongMapTestCase method forEachKey.

@Test
public void forEachKey() {
    LongLongMap map0 = this.newWithKeysValues(0L, 1L, 3L, 4L);
    long[] sum0 = new long[1];
    map0.forEachKey(each -> sum0[0] += each);
    Assert.assertEquals(3L, sum0[0]);
    LongLongMap map1 = this.newWithKeysValues(1L, 2L, 3L, 4L);
    long[] sum1 = new long[1];
    map1.forEachKey(each -> sum1[0] += each);
    Assert.assertEquals(4L, sum1[0]);
    LongLongMap map01 = this.newWithKeysValues(0L, 1L, 1L, 2L);
    long[] sum01 = new long[1];
    map01.forEachKey(each -> sum01[0] += each);
    Assert.assertEquals(1L, sum01[0]);
    LongLongMap map = this.newWithKeysValues(3L, 4L, 4L, 5L);
    long[] sum = new long[1];
    map.forEachKey(each -> sum[0] += each);
    Assert.assertEquals(7L, sum[0]);
    LongLongMap map2 = this.getEmptyMap();
    long[] sum2 = new long[1];
    map2.forEachKey(each -> sum2[0] += each);
    Assert.assertEquals(0L, sum2[0]);
    LongLongMap map3 = this.newWithKeysValues(1L, 1L);
    long[] sum3 = new long[1];
    map3.forEachKey(each -> sum3[0] += each);
    Assert.assertEquals(1L, 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 8 with LongLongMap

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

the class AbstractLongLongMapTestCase method allSatisfy.

@Test
public void allSatisfy() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    Assert.assertTrue(this.getEmptyMap().allSatisfy(LongPredicates.equal(0L)));
    Assert.assertFalse(this.newWithKeysValues(1L, 1L).allSatisfy(LongPredicates.equal(0L)));
    Assert.assertTrue(this.newWithKeysValues(1L, 1L).allSatisfy(LongPredicates.equal(1L)));
    Assert.assertFalse(map.allSatisfy(LongPredicates.equal(0L)));
    Assert.assertFalse(map.allSatisfy(LongPredicates.equal(1L)));
    Assert.assertFalse(map.allSatisfy(LongPredicates.equal(2L)));
    Assert.assertTrue(map.allSatisfy(LongPredicates.lessThan(5L)));
    LongLongMap map1 = this.newWithKeysValues(2L, 2L, 3L, 3L);
    Assert.assertFalse(map1.allSatisfy(LongPredicates.equal(0L)));
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 9 with LongLongMap

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

the class AbstractLongLongMapTestCase method toSortedList.

@Test
public void toSortedList() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    Assert.assertEquals(LongArrayList.newListWith(0L, 1L, 2L, 3L), map.toSortedList());
    Assert.assertEquals(LongArrayList.newListWith(), this.getEmptyMap().toSortedList());
    Assert.assertEquals(LongArrayList.newListWith(1L), this.newWithKeysValues(1L, 1L).toSortedList());
}
Also used : ImmutableLongLongMap(org.eclipse.collections.api.map.primitive.ImmutableLongLongMap) LongLongMap(org.eclipse.collections.api.map.primitive.LongLongMap) Test(org.junit.Test)

Example 10 with LongLongMap

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

the class AbstractLongLongMapTestCase method select_value.

@Test
public void select_value() {
    LongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    LongIterable actual1 = map.select(LongPredicates.greaterThan(1L));
    Assert.assertEquals(LongBags.immutable.with(2L, 3L), actual1);
    LongIterable actual2 = map.select(LongPredicates.lessThan(2L));
    Assert.assertEquals(LongBags.immutable.with(0L, 1L), actual2);
}
Also used : LazyLongIterable(org.eclipse.collections.api.LazyLongIterable) LongIterable(org.eclipse.collections.api.LongIterable) 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