@Test public void updateValueWith() { MutableMapIterable<Integer, Integer> map = this.newMap(); Iterate.forEach( Interval.oneTo(1000), each -> map.updateValueWith( each % 10, () -> 0, (integer, parameter) -> { Assert.assertEquals("test", parameter); return integer + 1; }, "test")); Assert.assertEquals(Interval.zeroTo(9).toSet(), map.keySet()); Assert.assertEquals( FastList.newList(Collections.nCopies(10, 100)), FastList.newList(map.values())); }
@Test public void updateValueWith_collisions() { MutableMapIterable<Integer, Integer> map = this.newMap(); MutableList<Integer> list = Interval.oneTo(2000).toList(); Collections.shuffle(list); Iterate.forEach( list, each -> map.updateValueWith( each % 1000, () -> 0, (integer, parameter) -> { Assert.assertEquals("test", parameter); return integer + 1; }, "test")); Assert.assertEquals(Interval.zeroTo(999).toSet(), map.keySet()); Assert.assertEquals( HashBag.newBag(map.values()).toStringOfItemToCount(), FastList.newList(Collections.nCopies(1000, 2)), FastList.newList(map.values())); }