@Override public String toString() { if (isEmpty()) { return "{}"; } StringBuilder result = new StringBuilder(); result.append('{'); for (int i = 0; i < keys.length; i++) { long key = keys[i]; if (key != NULL && key != REMOVED) { result.append(key).append('=').append(values[i]).append(','); } } result.setCharAt(result.length() - 1, '}'); return result.toString(); }
@Override public String toString() { if (isEmpty()) { return "{}"; } StringBuilder result = new StringBuilder(); result.append('{'); for (int i = 0; i < keys.length; i++) { long key = keys[i]; if (key != NULL && key != REMOVED) { result.append(key).append('=').append(values[i]).append(','); } } result.setCharAt(result.length() - 1, '}'); return result.toString(); }
@Override public String toString() { if (isEmpty()) { return "{}"; } StringBuilder result = new StringBuilder(); result.append('{'); for (int i = 0; i < keys.length; i++) { long key = keys[i]; if (key != NULL && key != REMOVED) { result.append(key).append('=').append(values[i]).append(','); } } result.setCharAt(result.length() - 1, '}'); return result.toString(); }
@Test public void testVersusHashMap() { FastByIDMap<String> actual = new FastByIDMap<String>(); Map<Long, String> expected = Maps.newHashMapWithExpectedSize(1000000); Random r = RandomUtils.getRandom(); for (int i = 0; i < 1000000; i++) { double d = r.nextDouble(); Long key = (long) r.nextInt(100); if (d < 0.4) { assertEquals(expected.get(key), actual.get(key)); } else { if (d < 0.7) { assertEquals(expected.put(key, "bang"), actual.put(key, "bang")); } else { assertEquals(expected.remove(key), actual.remove(key)); } assertEquals(expected.size(), actual.size()); assertEquals(expected.isEmpty(), actual.isEmpty()); } } }
@Test public void testRemove() { FastByIDMap<Long> map = new FastByIDMap<Long>(); map.put(500000L, 2L); map.remove(500000L); assertEquals(0, map.size()); assertTrue(map.isEmpty()); assertNull(map.get(500000L)); }
@Test public void testClear() { FastByIDMap<Long> map = new FastByIDMap<Long>(); map.put(500000L, 2L); map.clear(); assertEquals(0, map.size()); assertTrue(map.isEmpty()); assertNull(map.get(500000L)); }