public java.util.Map<K, V> toMap() { final java.util.HashMap<K, V> result = new java.util.HashMap<>(); for (K key : keys()) { result.put(key, get(key).some()); } return result; }
/** * Returns all key entries in this hash map. * * @return All key entries in this hash map. */ public List<K> keys() { final List.Buffer<K> b = new List.Buffer<>(); for (final Key k : m.keySet()) { b.snoc(k.k); } return b.toList(); }
/** * Deletes the entry in the hash map that corresponds to the given key and returns any associated * value. * * @param k The key to delete from this hash map. * @return The value that was associated with the given key, if there was one. */ public Option<V> getDelete(final K k) { return fromNull(m.remove(new Key(k))); }
/** * Deletes the entry in the hash map that corresponds to the given key. * * @param k The key to delete from this hash map. */ public void delete(final K k) { m.remove(new Key(k)); }
/** * Inserts the given key and value association into the hash map. * * @param k The key to insert. * @param v The value to insert. */ public void set(final K k, final V v) { if (v != null) { m.put(new Key(k), v); } }
/** * Returns the number of entries in this hash map. * * @return The number of entries in this hash map. */ public int size() { return m.size(); }
/** * Determines if this hash map has any entries. * * @return <code>true</code> if this hash map has no entries, <code>false</code> otherwise. */ public boolean isEmpty() { return m.isEmpty(); }
/** * Returns all values in this hash map. * * @return All values in this hash map. */ public List<V> values() { return iterableList(m.values()); }
/** * Determines if the given key value exists in this hash map. * * @param k The key value to look for in this hash map. * @return <code>true</code> if this hash map contains the given key, <code>false</code> * otherwise. */ public boolean contains(final K k) { return m.containsKey(new Key(k)); }
/** Clear all entries from this hash map. */ public void clear() { m.clear(); }
/** * Returns a potential value that the given key maps to. * * @param k The key to look up in the hash map. * @return A potential value for the given key. */ public Option<V> get(final K k) { return fromNull(m.get(new Key(k))); }