@Override protected DataWord setValue(DataWord value) { return super.setValue(value); }
/** * Recalculate the hash code after deserialization. The hash code of some * keys might have change (hash codes based on the system hash code are * only stable for the same process). * @return the instance with recalculated hash code */ protected Object readResolve() { calculateHashCode(keys); return this; } }
/** * 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 * @return true if the key matches */ protected boolean isEqualKey(final AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry, final Object key1, final Object key2) { final MultiKey<? extends K> multi = entry.getKey(); return multi.size() == 2 && (key1 == multi.getKey(0) || key1 != null && key1.equals(multi.getKey(0))) && (key2 == multi.getKey(1) || key2 != null && key2.equals(multi.getKey(1))); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}, * however subclasses may override this. * * @return a suitable hash code */ @Override public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Returns a new <code>Map.Entry</code> object with key and value from this pair. * * @return a MapEntry instance */ public Map.Entry<K, V> toMapEntry() { return new DefaultMapEntry<>(this); }
@Override protected DataWord setKey(DataWord key) { return super.setKey(key); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()} * * @return a suitable hash code */ @Override public int hashCode() { return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); }
/** * Gets the entrySet view of the map. * Changes made via <code>setValue</code> affect this map. * To simply iterate through the entries, use {@link #mapIterator()}. * * @return the entrySet view */ @Override public Set<Map.Entry<K, V>> entrySet() { final Map.Entry<K, V> entry = new TiedMapEntry<>(this, getKey()); return Collections.singleton(entry); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)} * * @param obj the object to compare to * @return true if equal key and value */ @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; final Object value = getValue(); return (key == null ? other.getKey() == null : key.equals(other.getKey())) && (value == null ? other.getValue() == null : value.equals(other.getValue())); }
@Override public V setValue(final V value) { final K key = MapEntry.this.getKey(); if (parent.reverseMap.containsKey(value) && parent.reverseMap.get(value) != key) { throw new IllegalArgumentException( "Cannot use setValue() when the object being set is already in the map"); } parent.put(key, value); return super.setValue(value); } }
/** * 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))); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Returns true if the compared object is also a <code>DefaultKeyValue</code>, * and its key and value are equal to this object's key and value. * * @param obj the object to compare to * @return true if equal key and value */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof DefaultKeyValue == false) { return false; } final DefaultKeyValue<?, ?> other = (DefaultKeyValue<?, ?>) obj; return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue())); }
@Override public <T> T[] toArray(final T[] arr) { // special implementation to handle disappearing entries final ArrayList<Map.Entry<K, V>> list = new ArrayList<>(size()); for (final Map.Entry<K, V> entry : this) { list.add(new DefaultMapEntry<>(entry)); } return list.toArray(arr); } }
/** * Sets the value stored in this <code>Map.Entry</code>. * <p> * This <code>Map.Entry</code> is not connected to a Map, so only the * local data is changed. * * @param value the new value * @return the previous value */ @Override public V setValue(final V value) { // NOPMD return super.setValue(value); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()} * * @return a suitable hash code */ @Override public int hashCode() { final Object value = getValue(); return (getKey() == null ? 0 : getKey().hashCode()) ^ (value == null ? 0 : value.hashCode()); }
/** * Sets the key. * * @param key the new key * @return the old key * @throws IllegalArgumentException if key is this object */ @Override public K setKey(final K key) { if (key == this) { throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a key."); } return super.setKey(key); }
/** * 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))); }
/** * Sets the value. * * @return the old value of the value * @param value the new value * @throws IllegalArgumentException if value is this object */ @Override public V setValue(final V value) { if (value == this) { throw new IllegalArgumentException("DefaultKeyValue may not contain itself as a value."); } return super.setValue(value); }