Search in sources :

Example 11 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method removeKeyIfAbsent.

@Test
public void removeKeyIfAbsent() {
    MutableLongLongMap map0 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    Assert.assertEquals(1L, map0.removeKeyIfAbsent(1L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L), map0);
    Assert.assertEquals(0L, map0.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map0);
    Assert.assertEquals(100L, map0.removeKeyIfAbsent(1L, 100L));
    Assert.assertEquals(100L, map0.removeKeyIfAbsent(0L, 100L));
    MutableLongLongMap map1 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    Assert.assertEquals(0L, map1.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), map1);
    Assert.assertEquals(1L, map1.removeKeyIfAbsent(1L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map1);
    Assert.assertEquals(100L, map1.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(100L, map1.removeKeyIfAbsent(1L, 100L));
    MutableLongLongMap map2 = this.classUnderTest();
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(5L, 100L));
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(50L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 31L, 31L, 32L, 32L), map2);
    Assert.assertEquals(0L, map2.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(31L, 31L, 32L, 32L), map2);
    Assert.assertEquals(31L, map2.removeKeyIfAbsent(31L, 100L));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(32L, 32L), map2);
    Assert.assertEquals(32L, map2.removeKeyIfAbsent(32L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map2);
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(0L, 100L));
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(31L, 100L));
    Assert.assertEquals(100L, map2.removeKeyIfAbsent(32L, 100L));
    Assert.assertEquals(new LongLongHashMap(), map2);
    Verify.assertEmpty(map2);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(0), 1L);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(1), 2L);
    Assert.assertEquals(1L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    Assert.assertEquals(1L, map2.removeKeyIfAbsent(AbstractMutableLongLongMapTestCase.generateCollisions().get(0), 100L));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    Assert.assertEquals(2L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
    Assert.assertEquals(2L, map2.removeKeyIfAbsent(AbstractMutableLongLongMapTestCase.generateCollisions().get(1), 100L));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 12 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method put.

@Test
public void put() {
    MutableLongLongMap map1 = this.classUnderTest();
    map1.put(0L, 1L);
    map1.put(31L, 32L);
    map1.put(32L, 33L);
    LongLongHashMap expected = LongLongHashMap.newWithKeysValues(0L, 1L, 31L, 32L, 32L, 33L);
    Assert.assertEquals(expected, map1);
    map1.put(1L, 2L);
    expected.put(1L, 2L);
    Assert.assertEquals(expected, map1);
    map1.put(33L, 34L);
    expected.put(33L, 34L);
    Assert.assertEquals(expected, map1);
    map1.put(30L, 31L);
    expected.put(30L, 31L);
    Assert.assertEquals(expected, map1);
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 13 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method removeKey.

@Test
public void removeKey() {
    MutableLongLongMap map0 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    map0.removeKey(1L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L), map0);
    map0.removeKey(0L);
    Assert.assertEquals(new LongLongHashMap(), map0);
    MutableLongLongMap map1 = this.newWithKeysValues(0L, 0L, 1L, 1L);
    map1.removeKey(0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), map1);
    map1.removeKey(1L);
    Assert.assertEquals(new LongLongHashMap(), map1);
    MutableLongLongMap map2 = this.classUnderTest();
    map2.removeKey(5L);
    map2.removeKey(50L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 31L, 31L, 32L, 32L), map2);
    map2.removeKey(0L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(31L, 31L, 32L, 32L), map2);
    map2.removeKey(31L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(32L, 32L), map2);
    map2.removeKey(32L);
    Assert.assertEquals(new LongLongHashMap(), map2);
    map2.removeKey(0L);
    map2.removeKey(31L);
    map2.removeKey(32L);
    Assert.assertEquals(new LongLongHashMap(), map2);
    Verify.assertEmpty(map2);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(0), 1L);
    map2.put(AbstractMutableLongLongMapTestCase.generateCollisions().get(1), 2L);
    Assert.assertEquals(1L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    map2.removeKey(AbstractMutableLongLongMapTestCase.generateCollisions().get(0));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(0)));
    Assert.assertEquals(2L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
    map2.removeKey(AbstractMutableLongLongMapTestCase.generateCollisions().get(1));
    Assert.assertEquals(0L, map2.get(AbstractMutableLongLongMapTestCase.generateCollisions().get(1)));
}
Also used : LongLongHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 14 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method putDuplicateWithRemovedSlot.

@Test
public void putDuplicateWithRemovedSlot() {
    long collision1 = AbstractMutableLongLongMapTestCase.generateCollisions().getFirst();
    long collision2 = AbstractMutableLongLongMapTestCase.generateCollisions().get(1);
    long collision3 = AbstractMutableLongLongMapTestCase.generateCollisions().get(2);
    long collision4 = AbstractMutableLongLongMapTestCase.generateCollisions().get(3);
    MutableLongLongMap hashMap = this.getEmptyMap();
    hashMap.put(collision1, 1L);
    hashMap.put(collision2, 2L);
    hashMap.put(collision3, 3L);
    Assert.assertEquals(2L, hashMap.get(collision2));
    hashMap.removeKey(collision2);
    hashMap.put(collision4, 4L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(collision1, 1L, collision3, 3L, collision4, 4L), hashMap);
    MutableLongLongMap hashMap1 = this.getEmptyMap();
    hashMap1.put(collision1, 1L);
    hashMap1.put(collision2, 2L);
    hashMap1.put(collision3, 3L);
    Assert.assertEquals(1L, hashMap1.get(collision1));
    hashMap1.removeKey(collision1);
    hashMap1.put(collision4, 4L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(collision2, 2L, collision3, 3L, collision4, 4L), hashMap1);
    MutableLongLongMap hashMap2 = this.getEmptyMap();
    hashMap2.put(collision1, 1L);
    hashMap2.put(collision2, 2L);
    hashMap2.put(collision3, 3L);
    Assert.assertEquals(3L, hashMap2.get(collision3));
    hashMap2.removeKey(collision3);
    hashMap2.put(collision4, 4L);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(collision1, 1L, collision2, 2L, collision4, 4L), hashMap2);
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 15 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method containsValue.

@Override
@Test
public void containsValue() {
    super.containsValue();
    MutableLongLongMap map1 = this.classUnderTest();
    map1.put(35L, 35L);
    Assert.assertTrue(map1.containsValue(35L));
    map1.removeKey(0L);
    Assert.assertFalse(map1.containsValue(0L));
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Aggregations

MutableLongLongMap (org.eclipse.collections.api.map.primitive.MutableLongLongMap)30 Test (org.junit.Test)30 MutableLongCollection (org.eclipse.collections.api.collection.primitive.MutableLongCollection)6 LongLongHashMap (org.eclipse.collections.impl.map.mutable.primitive.LongLongHashMap)6 LongToLongFunction (org.eclipse.collections.api.block.function.primitive.LongToLongFunction)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 LongFunction0 (org.eclipse.collections.api.block.function.primitive.LongFunction0)1 MutableLongIterator (org.eclipse.collections.api.iterator.MutableLongIterator)1 LongSet (org.eclipse.collections.api.set.primitive.LongSet)1