@Override public boolean contains(final Object object) { return parent.containsValue(object); } @Override
/** * 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; }
/** * Gets the last (and only) key in the map. * * @return the key */ @Override public K lastKey() { return getKey(); }
/** * 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()); }
/** * Checks whether the map contains the specified value. * * @param value the value to search for * @return true if the map contains the key */ @Override public boolean containsValue(final Object value) { return isEqualValue(value); }
@Override public V setValue(final V value) { if (canGetSet == false) { throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID); } return parent.setValue(value); }
/** * Puts the values from the specified map into this map. * <p> * The map must be of size 0 or size 1. * If it is size 1, the key must match the key of this map otherwise an * IllegalArgumentException is thrown. * * @param map the map to add, must be size 0 or 1, and the key must match * @throws NullPointerException if the map is null * @throws IllegalArgumentException if the key does not match */ @Override public void putAll(final Map<? extends K, ? extends V> map) { switch (map.size()) { case 0: return; case 1: final Map.Entry<? extends K, ? extends V> entry = map.entrySet().iterator().next(); put(entry.getKey(), entry.getValue()); return; default: throw new IllegalArgumentException("The map size must be 0 or 1"); } }
@Override protected Map<String, Object> doSelect(Object item) { Object value = DefaultNullValuePropertyValueGetter.getProperty(item, property); return new SingletonMap<String,Object>(alias, value); }
/** * Gets the first (and only) key in the map. * * @return the key */ @Override public K firstKey() { return getKey(); }
@Override public V getValue() { if (canGetSet == false) { throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID); } return parent.getValue(); }
/** * Gets the map as a String. * * @return a string version of the map */ @Override public String toString() { return new StringBuilder(128) .append('{') .append(getKey() == this ? "(this Map)" : getKey()) .append('=') .append(getValue() == this ? "(this Map)" : getValue()) .append('}') .toString(); }
@Override public Iterator<V> iterator() { return new SingletonIterator<>(parent.getValue(), false); } }
/** * 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); }
@Override public K previous() { if (hasNext == true) { throw new NoSuchElementException(AbstractHashedMap.NO_PREVIOUS_ENTRY); } hasNext = true; return parent.getKey(); }
@Override public K next() { if (hasNext == false) { throw new NoSuchElementException(AbstractHashedMap.NO_NEXT_ENTRY); } hasNext = false; canGetSet = true; return parent.getKey(); }
@Override public K getKey() { if (canGetSet == false) { throw new IllegalStateException(AbstractHashedMap.GETKEY_INVALID); } return parent.getKey(); }