@Test public void testPairsSortedByKey() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 100); map.put((int) 12, (byte) 70); map.put((int) 13, (byte) 30); map.put((int) 14, (byte) 3); IntArrayList keys = new IntArrayList(); ByteArrayList values = new ByteArrayList(); map.pairsSortedByKey(keys, values); assertEquals(4, keys.size()); assertEquals(4, values.size()); assertEquals((int) 11, keys.get(0)); assertEquals((byte) 100, values.get(0)); assertEquals((int) 12, keys.get(1)); assertEquals((byte) 70, values.get(1)); assertEquals((int) 13, keys.get(2)); assertEquals((byte) 30, values.get(2)); assertEquals((int) 14, keys.get(3)); assertEquals((byte) 3, values.get(3)); keys.clear(); values.clear(); map.pairsSortedByValue(keys, values); assertEquals((int) 11, keys.get(3)); assertEquals((byte) 100, values.get(3)); assertEquals((int) 12, keys.get(2)); assertEquals((byte) 70, values.get(2)); assertEquals((int) 13, keys.get(1)); assertEquals((byte) 30, values.get(1)); assertEquals((int) 14, keys.get(0)); assertEquals((byte) 3, values.get(0)); }
@Test public void testPairsMatching() { IntArrayList keyList = new IntArrayList(); ByteArrayList valueList = new ByteArrayList(); OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); map.pairsMatching( new IntByteProcedure() { @Override public boolean apply(int first, byte second) { return (first % 2) == 0; } }, keyList, valueList); keyList.sort(); valueList.sort(); assertEquals(2, keyList.size()); assertEquals(2, valueList.size()); assertEquals(12, keyList.get(0)); assertEquals(14, keyList.get(1)); assertEquals(23, valueList.get(0)); assertEquals(25, valueList.get(1)); }
@Test public void testKeysSortedByValue() { OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); IntArrayList keys = new IntArrayList(); map.keysSortedByValue(keys); int[] keysArray = keys.toArray(new int[keys.size()]); assertArrayEquals(new int[] {11, 12, 14}, keysArray); }
@Test public void testForEachKey() { final IntArrayList keys = new IntArrayList(); OpenIntByteHashMap map = new OpenIntByteHashMap(); map.put((int) 11, (byte) 22); map.put((int) 12, (byte) 23); map.put((int) 13, (byte) 24); map.put((int) 14, (byte) 25); map.removeKey((int) 13); map.forEachKey( new IntProcedure() { @Override public boolean apply(int element) { keys.add(element); return true; } }); int[] keysArray = keys.toArray(new int[keys.size()]); Arrays.sort(keysArray); assertArrayEquals(new int[] {11, 12, 14}, keysArray); }