Search in sources :

Example 1 with LongToLongFunction

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);
}
Also used : LongToLongFunction(org.eclipse.collections.api.block.function.primitive.LongToLongFunction) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Example 2 with LongToLongFunction

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);
}
Also used : LongToLongFunction(org.eclipse.collections.api.block.function.primitive.LongToLongFunction) MutableLongLongMap(org.eclipse.collections.api.map.primitive.MutableLongLongMap) Test(org.junit.Test)

Aggregations

LongToLongFunction (org.eclipse.collections.api.block.function.primitive.LongToLongFunction)2 MutableLongLongMap (org.eclipse.collections.api.map.primitive.MutableLongLongMap)2 Test (org.junit.Test)2