/** Auto-boxing version of {@link #put}. */ public TypeV put ( Long key, TypeV val ) { return put(key.longValue(),val); } /** Auto-boxing version of {@link #replace}. */
assertThat(_nbhml.put(1, "v1"), nullValue()); checkSizes(1); assertThat(_nbhml.putIfAbsent(2, "v2"), nullValue()); checkSizes(2); assertTrue(_nbhml.containsKey(2)); assertThat(_nbhml.put(1, "v1a"), is("v1")); assertThat(_nbhml.put(2, "v2a"), is("v2")); checkSizes(2); assertThat(_nbhml.putIfAbsent(2, "v2b"), is("v2a")); assertTrue(_nbhml.isEmpty()); assertThat(_nbhml.put(0, "v0"), nullValue()); assertTrue(_nbhml.containsKey(0)); checkSizes(1); assertThat(_nbhml.put(0, "v0"), nullValue()); assertEquals(_nbhml.replace(0, "v0a"), "v0"); assertEquals(_nbhml.get(0), "v0a"); assertThat(_nbhml.put(1, "v1"), nullValue()); assertEquals(_nbhml.replace(1, "v1a"), "v1"); assertEquals(_nbhml.get(1), "v1a"); for (int i = 1; i < 32; i++) map.put(i, new Object());
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read nothing initialize(MIN_SIZE); for (;;) { final long K = s.readLong(); final TypeV V = (TypeV) s.readObject(); if( K == NO_KEY && V == null ) break; put(K,V); // Insert with an offical put } }
_hash.put(k1, key1); put_ops++;
public Object call() throws Exception { _barrier.await(); // barrier, to force racing start for (long j = 0; j < _count; j++) { _map.put( j + _offset, new TestKey(_rand.nextLong(), _rand.nextInt(), (short) _rand.nextInt(Short.MAX_VALUE))); } return null; } }
HM.put(i, KEYS[i]); for (int j = 0; j < i; j++) { if (HM.get(j) != KEYS[j]) {
@Test public void testIterationBig2() { final int CNT = 10000; assertThat(_nbhml.size(), is(0)); final String v = "v"; for (int i = 0; i < CNT; i++) { _nbhml.put(i, v); String s = _nbhml.get(i); assertThat(s, is(v)); } assertThat(_nbhml.size(), is(CNT)); _nbhml.clear(); }
@Test public void testIteration() { assertTrue(_nbhml.isEmpty()); assertThat(_nbhml.put(1, "v1"), nullValue()); assertThat(_nbhml.put(2, "v2"), nullValue()); String str1 = ""; for (Map.Entry<Long, String> e : _nbhml.entrySet()) { str1 += e.getKey(); } assertThat("found all entries", str1, anyOf(is("12"), is("21"))); String str2 = ""; for (Long key : _nbhml.keySet()) { str2 += key; } assertThat("found all keys", str2, anyOf(is("12"), is("21"))); String str3 = ""; for (String val : _nbhml.values()) { str3 += val; } assertThat("found all vals", str3, anyOf(is("v1v2"), is("v2v1"))); assertThat("toString works", _nbhml.toString(), anyOf(is("{1=v1, 2=v2}"), is("{2=v2, 1=v1}"))); _nbhml.clear(); }
for (int i = 0; i < CNT; i++) _nbhml.put(i, "v" + i);
/** Auto-boxing version of {@link #put}. */ public TypeV put ( Long key, TypeV val ) { return put(key.longValue(),val); } /** Auto-boxing version of {@link #replace}. */
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read nothing initialize(MIN_SIZE); for (;;) { final long K = s.readLong(); final TypeV V = (TypeV) s.readObject(); if( K == NO_KEY && V == null ) break; put(K,V); // Insert with an offical put } }