protected void setProperty(QualifiedName key, Object value) { // thread safety: (Concurrency001 - copy on write) if (value == null) { if (properties == null) return; ObjectMap temp = (ObjectMap) properties.clone(); temp.remove(key); if (temp.isEmpty()) properties = null; else properties = temp; } else { ObjectMap temp = properties; if (temp == null) temp = new ObjectMap(5); else temp = (ObjectMap) properties.clone(); temp.put(key, value); properties = temp; } }
/** * Creates a new object map of the same size as the given map and populate * it with the key/attribute pairs found in the map. * * @param map * The entries in the given map will be added to the new map. */ public ObjectMap(Map map) { this(map.size()); putAll(map); }
/** * Creates a new hash map with the same contents as this map. */ private HashMap toHashMap() { HashMap result = new HashMap(size()); for (int i = 0; i < elements.length; i = i + 2) { if (elements[i] != null) { result.put(elements[i], elements[i + 1]); } } return result; }
/** * @see Map#entrySet() * * Note: This implementation does not conform properly to the * specification in the Map interface. The returned collection will not * be bound to this map and will not remain in sync with this map. */ @Override public Set entrySet() { return count == 0 ? Collections.EMPTY_SET : toHashMap().entrySet(); }
/** * @see java.lang.Object#clone() */ @Override public Object clone() { return new ObjectMap(this); }
/** * @see Map#putAll(java.util.Map) */ public void putAll(Map map) { for (Iterator i = map.keySet().iterator(); i.hasNext();) { Object key = i.next(); Object value = map.get(key); put(key, value); } }
/** * @see Object#equals(java.lang.Object) */ @Override public boolean equals(Object o) { if (!(o instanceof Map)) return false; Map other = (Map) o; //must be same size if (count != other.size()) return false; //keysets must be equal if (!keySet().equals(other.keySet())) return false; //values for each key must be equal for (int i = 0; i < elements.length; i = i + 2) { if (elements[i] != null && (!elements[i + 1].equals(other.get(elements[i])))) return false; } return true; }
/** * @see Map#entrySet() * * Note: This implementation does not conform properly to the * specification in the Map interface. The returned collection will not * be bound to this map and will not remain in sync with this map. */ public Set entrySet() { return count == 0 ? Collections.EMPTY_SET : toHashMap().entrySet(); }
/** * @see java.lang.Object#clone() */ public Object clone() { return new ObjectMap(this); }
/** * @see Map#putAll(java.util.Map) */ @Override public void putAll(Map map) { for (Iterator i = map.keySet().iterator(); i.hasNext();) { Object key = i.next(); Object value = map.get(key); put(key, value); } }
/** * @see Object#equals(java.lang.Object) */ public boolean equals(Object o) { if (!(o instanceof Map)) return false; Map other = (Map) o; //must be same size if (count != other.size()) return false; //keysets must be equal if (!keySet().equals(other.keySet())) return false; //values for each key must be equal for (int i = 0; i < elements.length; i = i + 2) { if (elements[i] != null && (!elements[i + 1].equals(other.get(elements[i])))) return false; } return true; }
protected void setProperty(QualifiedName key, Object value) { // thread safety: (Concurrency001 - copy on write) if (value == null) { if (properties == null) return; ObjectMap temp = (ObjectMap) properties.clone(); temp.remove(key); if (temp.isEmpty()) properties = null; else properties = temp; } else { ObjectMap temp = properties; if (temp == null) temp = new ObjectMap(5); else temp = (ObjectMap) properties.clone(); temp.put(key, value); properties = temp; } }
/** * Creates a new hash map with the same contents as this map. */ private HashMap toHashMap() { HashMap result = new HashMap(size()); for (int i = 0; i < elements.length; i = i + 2) { if (elements[i] != null) { result.put(elements[i], elements[i + 1]); } } return result; }
/** * @see Map#entrySet() * * Note: This implementation does not conform properly to the * specification in the Map interface. The returned collection will not * be bound to this map and will not remain in sync with this map. */ @Override public Set entrySet() { return count == 0 ? Collections.EMPTY_SET : toHashMap().entrySet(); }
/** * Creates a new object map of the same size as the given map and populate * it with the key/attribute pairs found in the map. * * @param map * The entries in the given map will be added to the new map. */ public ObjectMap(Map map) { this(map.size()); putAll(map); }
/** * @see java.lang.Object#clone() */ @Override public Object clone() { return new ObjectMap(this); }
/** * @see Map#putAll(java.util.Map) */ @Override public void putAll(Map map) { for (Iterator i = map.keySet().iterator(); i.hasNext();) { Object key = i.next(); Object value = map.get(key); put(key, value); } }