/** * Gets the value mapped to the key specified. * * @param key the key * @return the mapped value, null if no match */ @Override public V get(final Object key) { if (isEqualKey(key)) { return value; } return null; }
/** * Checks whether the map contains the specified key. * * @param key the key to search for * @return true if the map contains the key */ @Override public boolean containsKey(final Object key) { return isEqualKey(key); }
/** * Puts a key-value mapping into this map where the key must match the existing key. * <p> * An IllegalArgumentException is thrown if the key does not match as the map * is fixed size. * * @param key the key to set, must be the key of the map * @param value the value to set * @return the value previously mapped to this key, null if none * @throws IllegalArgumentException if the key does not match */ @Override public V put(final K key, final V value) { if (isEqualKey(key)) { return setValue(value); } throw new IllegalArgumentException("Cannot put new key/value pair - Map is fixed size singleton"); }
/** * Compares this map with another. * * @param obj the object to compare to * @return true if equal */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof Map == false) { return false; } final Map<?,?> other = (Map<?,?>) obj; if (other.size() != 1) { return false; } final Map.Entry<?,?> entry = other.entrySet().iterator().next(); return isEqualKey(entry.getKey()) && isEqualValue(entry.getValue()); }