/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @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 true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2, final Object key3, final Object key4, final Object key5) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 5 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) && (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))) && (key4 == multi.getKey(3) || key4 != null && key4.equals(multi.getKey(3))) && (key5 == multi.getKey(4) || key5 != null && key5.equals(multi.getKey(4))); }
@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 setValue(final V value) { final HashEntry<K, V> current = currentEntry(); if (current == null) { throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID); } return current.setValue(value); } }
/** * 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 * @return the value mapped to the removed key, null if key not in map * @since 4.0 (previous name: remove(Object, Object, Object, Object)) */ public V removeMultiKey(final Object key1, final Object key2, final Object key3, final Object key4) { final int hashCode = hash(key1, key2, key3, key4); 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)) { 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 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 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 V value) { final int hashCode = hash(key1, key2, key3, key4); 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)) { final V oldValue = entry.getValue(); decorated().updateEntry(entry, value); return oldValue; } entry = entry.next; } decorated().addMapping(index, hashCode, new MultiKey<>(key1, key2, key3, key4), 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; }
/** * 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 * @return the value mapped to the removed key, null if key not in map * @since 4.0 (previous name: remove(Object, Object)) */ public V removeMultiKey(final Object key1, final Object key2) { 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]; AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> previous = null; while (entry != null) { if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) { final V oldValue = entry.getValue(); decorated().removeMapping(entry, index, previous); return oldValue; } previous = entry; entry = entry.next; } return null; }
/** * 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; }
/** * 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; }
/** * 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 * @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 * @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; }
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @return true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2, final Object key3) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 3 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) && (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))); }
/** * 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; }
/** * Is the key equal to the combined key. * * @param entry the entry to compare to * @param key1 the first key * @param key2 the second key * @param key3 the third key * @param key4 the fourth key * @return true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2, final Object key3, final Object key4) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 4 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))) && (key3 == multi.getKey(2) || key3 != null && key3.equals(multi.getKey(2))) && (key4 == multi.getKey(3) || key4 != null && key4.equals(multi.getKey(3))); }