@Override public String toString() { return new StringBuilder().append(getKey()).append('=').append(getValue()).toString(); } }
@Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof Map.Entry == false) { return false; } final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
@Override public V getValue() { final HashEntry<K, V> current = currentEntry(); if (current == null) { throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID); } return current.getValue(); }
/** * Puts a key-value mapping into this map. * * @param key the key to add * @param value the value to add * @return the value previously mapped to this key, null if none */ @Override public V put(final K key, final V value) { final Object convertedKey = convertKey(key); final int hashCode = hash(convertedKey); final int index = hashIndex(hashCode, data.length); HashEntry<K, V> entry = data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(convertedKey, entry.key)) { final V oldValue = entry.getValue(); updateEntry(entry, value); return oldValue; } entry = entry.next; } addMapping(index, hashCode, key, value); return null; }
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public V put(final K key1, final K key2, final K key3, final V value) { final int hashCode = hash(key1, key2, key3); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2, key3), value); return null; }
/** * Removes the specified multi-key from this map. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param key5 the fifth key * @return the value mapped to the removed key, null if key not in map * @since 4.0 (previous name: remove(Object, Object, Object, Object, Object)) */ public V removeMultiKey(final Object key1, final Object key2, final Object key3, final Object key4, final Object key5) { final int hashCode = hash(key1, key2, key3, key4, key5); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> previous = null; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) { final V oldValue = entry.getValue(); decorated().removeMapping(entry, index, previous); return oldValue; } previous = entry; entry = entry.next; } return null; }
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public V put(final K key1, final K key2, final V value) { final int hashCode = hash(key1, key2); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2), value); return null; }
/** * Stores the value against the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param key5 the fifth key * @param value the value to store * @return the value previously mapped to this combined key, null if none */ public V put(final K key1, final K key2, final K key3, final K key4, final K key5, final V value) { final int hashCode = hash(key1, key2, key3, key4, key5); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2, key3, key4, key5), value); return null; }
/** * Removes the specified multi-key from this map. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return the value mapped to the removed key, null if key not in map * @since 4.0 (previous name: remove(Object, Object, Object)) */ public V removeMultiKey(final Object key1, final Object key2, final Object key3) { final int hashCode = hash(key1, key2, key3); final int index = decorated().hashIndex(hashCode, decorated().data.length); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[index]; AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> previous = null; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) { final V oldValue = entry.getValue(); decorated().removeMapping(entry, index, previous); return oldValue; } previous = entry; entry = entry.next; } return null; }
/** * Removes the specified mapping from this map. * * @param key the mapping to remove * @return the value mapped to the removed key, null if key not in map */ @Override public V remove(Object key) { key = convertKey(key); final int hashCode = hash(key); final int index = hashIndex(hashCode, data.length); HashEntry<K, V> entry = data[index]; HashEntry<K, V> previous = null; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) { final V oldValue = entry.getValue(); removeMapping(entry, index, previous); return oldValue; } previous = entry; entry = entry.next; } return null; }
/** * Gets the value mapped to the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return the mapped value, null if no match */ public V get(final Object key1, final Object key2, final Object key3, final Object key4) { final int hashCode = hash(key1, key2, key3, key4); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4)) { return entry.getValue(); } entry = entry.next; } return null; }
/** * Gets the value mapped to the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @param key5 the fifth key * @return the mapped value, null if no match */ public V get(final Object key1, final Object key2, final Object key3, final Object key4, final Object key5) { final int hashCode = hash(key1, key2, key3, key4, key5); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3, key4, key5)) { return entry.getValue(); } entry = entry.next; } return null; }
/** * Gets the value mapped to the specified multi-key. * * @param key1 the first key * @param key2 the second key * @return the mapped value, null if no match */ public V get(final Object key1, final Object key2) { final int hashCode = hash(key1, key2); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) { return entry.getValue(); } entry = entry.next; } return null; }
/** * Gets the value mapped to the specified multi-key. * * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return the mapped value, null if no match */ public V get(final Object key1, final Object key2, final Object key3) { final int hashCode = hash(key1, key2, key3); AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)]; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2, key3)) { return entry.getValue(); } entry = entry.next; } return null; }
/** * Gets the value mapped to the key specified. * * @param key the key * @return the mapped value, null if no match */ @Override public V get(Object key) { key = convertKey(key); final int hashCode = hash(key); HashEntry<K, V> entry = data[hashIndex(hashCode, data.length)]; // no local for hash index while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) { return entry.getValue(); } entry = entry.next; } return null; }
/** * Gets the <code>value</code> field from a <code>HashEntry</code>. * Used in subclasses that have no visibility of the field. * * @param entry the entry to query, must not be null * @return the <code>value</code> field of the entry * @throws NullPointerException if the entry is null * @since 3.1 */ protected V entryValue(final HashEntry<K, V> entry) { return entry.getValue(); }
@Override public String toString() { if (last != null) { return "Iterator[" + last.getKey() + "=" + last.getValue() + "]"; } return "Iterator[]"; } }
@Override public V next() { return super.nextEntry().getValue(); } }
@Override public V getValue() { final HashEntry<K, V> current = currentEntry(); if (current == null) { throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID); } return current.getValue(); }