use of org.eclipse.collections.api.block.function.primitive.LongToLongFunction 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);
}
use of org.eclipse.collections.api.block.function.primitive.LongToLongFunction 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);
}
Aggregations