/** Current count of elements in the set. Due to concurrent racing updates, * the size is only ever approximate. Updates due to the calling thread are * immediately visible to calling thread. * @return count of elements. */ public int size( ) { return _map.size(); } /** Empty the set. */
/** Returns <tt>size() == 0</tt>. * @return <tt>size() == 0</tt> */ @Override public boolean isEmpty ( ) { return size() == 0; }
@Override public int size ( ) { return NonBlockingHashMap.this.size ( ); } @Override public boolean contains( Object v ) { return NonBlockingHashMap.this.containsValue(v); }
@Override public int size ( ) { return NonBlockingHashMap.this.size ( ); } @Override public boolean contains( Object k ) { return NonBlockingHashMap.this.containsKey(k); }
private void checkSizes(int expectedSize) { assertEquals("size()", _nbhm.size(), expectedSize); Collection<String> vals = _nbhm.values(); checkSizes("values()", vals.size(), vals.iterator(), expectedSize); Set<String> keys = _nbhm.keySet(); checkSizes("keySet()", keys.size(), keys.iterator(), expectedSize); Set<Map.Entry<String, String>> ents = _nbhm.entrySet(); checkSizes("entrySet()", ents.size(), ents.iterator(), expectedSize); }
assertThat("concurrent size=0", nbhm.size(), is(0)); assertThat("keyset size=0", nbhm.keySet().size(), is(0));
@Test public void testIterationBig2() { final int CNT = 10000; NonBlockingHashMap<Integer, String> nbhm = new NonBlockingHashMap<>(); final String v = "v"; for (int i = 0; i < CNT; i++) { final Integer z = i; String s0 = nbhm.get(z); assertThat(s0, nullValue()); nbhm.put(z, v); String s1 = nbhm.get(z); assertThat(s1, is(v)); } assertThat(nbhm.size(), is(CNT)); }
@Test public void testNonBlockingHashMapIteratorMultithreaded() throws InterruptedException, ExecutionException { TestKeyFeeder feeder = getTestKeyFeeder(); final int itemCount = feeder.size(); // validate results final NonBlockingHashMap<Long, TestKey> items = feeder.getMapMultithreaded(); assertEquals("size()", itemCount, items.size()); assertEquals("values().size()", itemCount, items.values().size()); assertEquals("entrySet().size()", itemCount, items.entrySet().size()); int iteratorCount = 0; for (TestKey m : items.values()) { iteratorCount++; } // sometimes a different result comes back the second time int iteratorCount2 = 0; for (TestKey m2 : items.values()) { iteratorCount2++; } assertEquals("iterator counts differ", iteratorCount, iteratorCount2); assertEquals("values().iterator() count", itemCount, iteratorCount); }
/** Current count of elements in the set. Due to concurrent racing updates, * the size is only ever approximate. Updates due to the calling thread are * immediately visible to calling thread. * @return count of elements. */ public int size( ) { return _map.size(); } /** Empty the set. */
/** Returns <tt>size() == 0</tt>. * @return <tt>size() == 0</tt> */ @Override public boolean isEmpty ( ) { return size() == 0; }
@Override public int size ( ) { return NonBlockingHashMap.this.size ( ); } @Override public boolean contains( Object k ) { return NonBlockingHashMap.this.containsKey(k); }
@Override public int size ( ) { return NonBlockingHashMap.this.size ( ); } @Override public boolean contains( Object v ) { return NonBlockingHashMap.this.containsValue(v); }