Search in sources :

Example 1 with MutableLongLongMap

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

the class LongLongHashMapValuesTest method removeAll_iterable.

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

Example 2 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method getIfAbsentPutWithKey.

@Test
public void getIfAbsentPutWithKey() {
    LongToLongFunction function = (long longParameter) -> (long) longParameter;
    LongToLongFunction functionThrows = (long longParameter) -> {
        throw new AssertionError();
    };
    MutableLongLongMap map1 = this.getEmptyMap();
    Assert.assertEquals(0L, map1.getIfAbsentPutWithKey(0L, function));
    Assert.assertEquals(0L, map1.getIfAbsentPutWithKey(0L, functionThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L), map1);
    Assert.assertEquals(1L, map1.getIfAbsentPutWithKey(1L, function));
    Assert.assertEquals(1L, map1.getIfAbsentPutWithKey(1L, functionThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 1L, 1L), map1);
    MutableLongLongMap map2 = this.getEmptyMap();
    Assert.assertEquals(1L, map2.getIfAbsentPutWithKey(1L, function));
    Assert.assertEquals(1L, map2.getIfAbsentPutWithKey(1L, functionThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), map2);
    Assert.assertEquals(0L, map2.getIfAbsentPutWithKey(0L, function));
    Assert.assertEquals(0L, map2.getIfAbsentPutWithKey(0L, functionThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(0L, 0L, 1L, 1L), map2);
    MutableLongLongMap map3 = this.getEmptyMap();
    Assert.assertEquals(32L, map3.getIfAbsentPutWithKey(32L, function));
    Assert.assertEquals(32L, map3.getIfAbsentPutWithKey(32L, functionThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(32L, 32L), map3);
    MutableLongLongMap map4 = this.getEmptyMap();
    Assert.assertEquals(33L, map4.getIfAbsentPutWithKey(33L, function));
    Assert.assertEquals(33L, map4.getIfAbsentPutWithKey(33L, functionThrows));
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(33L, 33L), map4);
}
Also used : LongToLongFunction(org.eclipse.collections.api.block.function.primitive.LongToLongFunction) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 3 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method withKeysValues.

@Test
public void withKeysValues() {
    MutableLongLongMap hashMap = this.getEmptyMap();
    Assert.assertSame(hashMap.withKeyValue(1L, 1L), hashMap);
    Assert.assertEquals(LongLongHashMap.newWithKeysValues(1L, 1L), hashMap);
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 4 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method getOrThrow.

@Override
@Test
public void getOrThrow() {
    super.getOrThrow();
    MutableLongLongMap map1 = this.classUnderTest();
    map1.removeKey(0L);
    Verify.assertThrows(IllegalStateException.class, () -> map1.getOrThrow(0L));
    map1.put(0L, 1L);
    Assert.assertEquals(1L, map1.getOrThrow(0L));
    map1.put(1L, 1L);
    Assert.assertEquals(1L, map1.getOrThrow(1L));
    map1.put(5L, 5L);
    Assert.assertEquals(5L, map1.getOrThrow(5L));
    map1.put(35L, 35L);
    Assert.assertEquals(35L, map1.getOrThrow(35L));
}
Also used : MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 5 with MutableLongLongMap

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

the class AbstractMutableLongLongMapTestCase method size.

@Override
@Test
public void size() {
    super.size();
    MutableLongLongMap hashMap1 = this.newWithKeysValues(1L, 1L, 0L, 0L);
    Assert.assertEquals(2, hashMap1.size());
    hashMap1.removeKey(1L);
    Assert.assertEquals(1, hashMap1.size());
    hashMap1.removeKey(0L);
    Assert.assertEquals(0, hashMap1.size());
    MutableLongLongMap hashMap = this.newWithKeysValues(6L, 6L, 5L, 5L);
    hashMap.removeKey(5L);
    Assert.assertEquals(1, hashMap.size());
}
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