Search in sources :

Example 16 with MutableLongLongMap

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

the class LongLongHashMapValuesTest method retainAll.

@Override
@Test
public void retainAll() {
    Assert.assertFalse(this.newWith().retainAll());
    Assert.assertFalse(this.newWith().retainAll(1L));
    MutableLongLongMap map = newWithKeysValues(0L, 0L, 1L, 1L, 2L, 2L, 3L, 3L);
    MutableLongCollection collection = map.values();
    Assert.assertFalse(collection.retainAll(0L, 1L, 2L, 3L));
    Assert.assertTrue(collection.retainAll(0L, 2L, 3L, 5L));
    Assert.assertTrue(collection.contains(0L));
    Assert.assertFalse(collection.contains(1L));
    Assert.assertTrue(collection.contains(2L));
    Assert.assertTrue(collection.contains(3L));
    Assert.assertFalse(collection.contains(5L));
    Assert.assertTrue(map.contains(0L));
    Assert.assertFalse(map.contains(1L));
    Assert.assertTrue(map.contains(2L));
    Assert.assertTrue(map.contains(3L));
    Assert.assertFalse(map.contains(5L));
    Assert.assertTrue(collection.retainAll(2L, 3L, 5L));
    Assert.assertFalse(collection.contains(0L));
    Assert.assertFalse(collection.contains(1L));
    Assert.assertTrue(collection.contains(2L));
    Assert.assertTrue(collection.contains(3L));
    Assert.assertFalse(collection.contains(5L));
    Assert.assertFalse(map.contains(0L));
    Assert.assertFalse(map.contains(1L));
    Assert.assertTrue(map.contains(2L));
    Assert.assertTrue(map.contains(3L));
    Assert.assertFalse(map.contains(5L));
    Assert.assertTrue(collection.retainAll(3L, 5L));
    Assert.assertFalse(collection.contains(0L));
    Assert.assertFalse(collection.contains(1L));
    Assert.assertFalse(collection.contains(2L));
    Assert.assertTrue(collection.contains(3L));
    Assert.assertFalse(collection.contains(5L));
    Assert.assertFalse(map.contains(0L));
    Assert.assertFalse(map.contains(1L));
    Assert.assertFalse(map.contains(2L));
    Assert.assertTrue(map.contains(3L));
    Assert.assertFalse(map.contains(5L));
    Assert.assertTrue(collection.retainAll(0L, 0L, 1L));
    Assert.assertTrue(collection.isEmpty());
    Assert.assertFalse(collection.contains(0L));
    Assert.assertFalse(collection.contains(1L));
    Assert.assertFalse(collection.contains(2L));
    Assert.assertFalse(collection.contains(3L));
    Assert.assertFalse(collection.contains(5L));
    Assert.assertFalse(map.contains(0L));
    Assert.assertFalse(map.contains(1L));
    Assert.assertFalse(map.contains(2L));
    Assert.assertFalse(map.contains(3L));
    Assert.assertFalse(map.contains(5L));
    Assert.assertTrue(map.isEmpty());
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) Test(org.junit.Test)

Example 17 with MutableLongLongMap

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

the class LongLongHashMapValuesTest method remove.

@Override
@Test
public void remove() {
    MutableLongLongMap map = newWithKeysValues(1L, 1L, 2L, 2L, 3L, 3L);
    MutableLongCollection collection = map.values();
    Assert.assertTrue(collection.remove(3L));
    Assert.assertFalse(collection.contains(3L));
    Assert.assertTrue(collection.contains(1L));
    Assert.assertTrue(collection.contains(2L));
    Assert.assertFalse(map.contains(3L));
    Assert.assertTrue(map.contains(1L));
    Assert.assertTrue(map.contains(2L));
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) Test(org.junit.Test)

Example 18 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method updateValue.

@Test
public void updateValue() {
    LongToLongFunction incrementFunction = (long value) -> value + 1L;
    MutableLongLongMap map1 = this.getEmptyMap();
    Assert.assertEquals(1L, map1.updateValue(0L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 1L), map1);
    Assert.assertEquals(2L, map1.updateValue(0L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 2L), map1);
    Assert.assertEquals(1L, map1.updateValue(1L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 2L, 1L, 1L), map1);
    Assert.assertEquals(2L, map1.updateValue(1L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 2L, 1L, 2L), map1);
    MutableLongLongMap map2 = this.getEmptyMap();
    Assert.assertEquals(1L, map2.updateValue(1L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), map2);
    Assert.assertEquals(2L, map2.updateValue(1L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 2L), map2);
    Assert.assertEquals(1L, map2.updateValue(0L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 1L, 1L, 2L), map2);
    Assert.assertEquals(2L, map2.updateValue(0L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 2L, 1L, 2L), map2);
    MutableLongLongMap map3 = this.getEmptyMap();
    Assert.assertEquals(1L, map3.updateValue(33L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(33L, 1L), map3);
    Assert.assertEquals(2L, map3.updateValue(33L, 0L, incrementFunction));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(33L, 2L), map3);
}
Also used : LongToLongFunction(org.eclipse.collections.api.block.function.primitive.LongToLongFunction) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 19 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method withoutAllKeys.

@Test
public void withoutAllKeys() {
    MutableLongLongMap map = this.newWithKeysValues(0L, 0L, 1L, 1L, 31L, 31L, 32L, 32L);
    MutableLongLongMap mapWithout = map.withoutAllKeys(LongArrayList.newListWith(0L, 32L));
    Assert.assertSame(map, mapWithout);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L, 31L, 31L), mapWithout);
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 20 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method getIfAbsent.

@Override
@Test
public void getIfAbsent() {
    super.getIfAbsent();
    MutableLongLongMap map1 = this.classUnderTest();
    map1.removeKey(0L);
    Assert.assertEquals(5L, map1.getIfAbsent(0L, 5L));
    Assert.assertEquals(6L, map1.getIfAbsent(1L, 6L));
    Assert.assertEquals(6L, map1.getIfAbsent(33L, 6L));
    map1.put(0L, 1L);
    Assert.assertEquals(1L, map1.getIfAbsent(0L, 5L));
    map1.put(1L, 1L);
    Assert.assertEquals(1L, map1.getIfAbsent(1L, 5L));
    map1.put(5L, 5L);
    Assert.assertEquals(5L, map1.getIfAbsent(5L, 6L));
    map1.put(35L, 35L);
    Assert.assertEquals(35L, map1.getIfAbsent(35L, 5L));
}
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