@Test public void testPut() throws Exception { fillMap(10); for (int i = 0; i < 10; i++) { assertEquals("Put should return the previous value", Integer.valueOf(i), map.put(i, i + 1)); } assertNull(map.put(11, 11)); }
@Override public V put(K key, V value) { checkNotNull(key, "Key cannot be null."); checkNotNull(value, "Value cannot be null."); byte[] prevVal = items.put(serializer.encode(key), serializer.encode(value)); if (prevVal == null) { return null; } return serializer.decode(prevVal); }
PersistentMap implements Map<K, V> { @Override public V put(K key, V value) { checkNotNull(key, "Key cannot be null."); checkNotNull(value, "Value cannot be null."); byte[] prevVal = items.put(serializer.encode(key), serializer.encode(value)); if (prevVal == null) { return null; } return serializer.decode(prevVal); } }
PersistentMap implements Map<K, V> { @Override public V put(K key, V value) { checkNotNull(key, "Key cannot be null."); checkNotNull(value, "Value cannot be null."); byte[] prevVal = items.put(serializer.encode(key), serializer.encode(value)); if (prevVal == null) { return null; } return serializer.decode(prevVal); } PersistentMap(Serializer serializer, DB database, String name); }
PersistentMap implements Map<K, V> { @Override public V put(K key, V value) { checkNotNull(key, "Key cannot be null."); checkNotNull(value, "Value cannot be null."); byte[] prevVal = items.put(serializer.encode(key), serializer.encode(value)); if (prevVal == null) { return null; } return serializer.decode(prevVal); } PersistentMap(Serializer serializer, DB database, String name); void readInto(Map<K, V> items); @Override V remove(Object key); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> m); @Override void clear(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); @Override boolean equals(Object map); @Override int hashCode(); }
PersistentMap implements Map<K, V> { @Override public V put(K key, V value) { checkNotNull(key, "Key cannot be null."); checkNotNull(value, "Value cannot be null."); byte[] prevVal = items.put(serializer.encode(key), serializer.encode(value)); if (prevVal == null) { return null; } return serializer.decode(prevVal); } PersistentMap(Serializer serializer, DB database, String name); void readInto(Map<K, V> items); @Override V remove(Object key); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override void putAll(Map<? extends K, ? extends V> m); @Override void clear(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); @Override boolean equals(Object map); @Override int hashCode();  }