public boolean contains(Object object) { return parent.containsValue(object); } public void clear() {
/** * 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 */ public Object put(Object key, Object 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 */ public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof Map == false) { return false; } Map other = (Map) obj; if (other.size() != 1) { return false; } Map.Entry entry = (Map.Entry) other.entrySet().iterator().next(); return isEqualKey(entry.getKey()) && isEqualValue(entry.getValue()); }
/** * Gets the first (and only) key in the map. * * @return the key */ public Object firstKey() { return getKey(); }
public void testKeyValue() { SingletonMap map = new SingletonMap(ONE, TWO); assertEquals(1, map.size()); assertEquals(ONE, map.getKey()); assertEquals(TWO, map.getValue()); assertTrue(map instanceof KeyValue); }
/** * Checks whether the map contains the specified key. * * @param key the key to search for * @return true if the map contains the key */ public boolean containsKey(Object key) { return (isEqualKey(key)); }
public void testClone() { SingletonMap map = new SingletonMap(ONE, TWO); assertEquals(1, map.size()); SingletonMap cloned = (SingletonMap) map.clone(); assertEquals(1, cloned.size()); assertEquals(true, cloned.containsKey(ONE)); assertEquals(true, cloned.containsValue(TWO)); }
public Object setValue(Object value) { if (canGetSet == false) { throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID); } return parent.setValue(value); }
/** * Checks whether the map contains the specified value. * * @param value the value to search for * @return true if the map contains the key */ public boolean containsValue(Object value) { return (isEqualValue(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 */ public void putAll(Map map) { switch (map.size()) { case 0: return; case 1: Map.Entry entry = (Map.Entry) map.entrySet().iterator().next(); put(entry.getKey(), entry.getValue()); return; default: throw new IllegalArgumentException("The map size must be 0 or 1"); } }
public void testBoundedMap() { SingletonMap map = new SingletonMap(ONE, TWO); assertEquals(1, map.size()); assertEquals(true, map.isFull()); assertEquals(1, map.maxSize()); assertTrue(map instanceof BoundedMap); }
public Map makeFullMap() { return new SingletonMap(ONE, TWO); }
/** * Compares this map with another. * * @param obj the object to compare to * @return true if equal */ public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof Map == false) { return false; } Map other = (Map) obj; if (other.size() != 1) { return false; } Map.Entry entry = (Map.Entry) other.entrySet().iterator().next(); return isEqualKey(entry.getKey()) && isEqualValue(entry.getValue()); }
/** * Gets the last (and only) key in the map. * * @return the key */ public Object lastKey() { return getKey(); }
public Object getValue() { if (canGetSet == false) { throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID); } return parent.getValue(); }
/** * Gets the value mapped to the key specified. * * @param key the key * @return the mapped value, null if no match */ public Object get(Object key) { if (isEqualKey(key)) { return value; } return null; }
public Object setValue(Object value) { if (canGetSet == false) { throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID); } return parent.setValue(value); }
/** * Checks whether the map contains the specified value. * * @param value the value to search for * @return true if the map contains the key */ public boolean containsValue(Object value) { return (isEqualValue(value)); }