ariba.util.core
Class ReadOnlyMap<K,V>
java.lang.Object
ariba.util.core.ReadOnlyMap<K,V>
- Direct Known Subclasses:
- WriteResistantMap
public class ReadOnlyMap<K,V>
- extends Object
A Map-like object that can't be modified - not because it is immutable
(which would raise a run-time exception), but because it has no API
for modifying it. In a better world, it could be defined as a superinterface
of Map.
A ReadOnlyMap wraps an ordinary Map, which may contain other maps as values
(i.e., the Map may be nested). In that case, when returning a value that
is a Map, the ReadOnlyMap wraps that value in another ReadOnlyMap, so that
IT can't be modified, either. The wrapping doesn't extend to values of
other types, unfortunately, but it is at least a good start toward getting
a declarative, statically-enforced, read-only data structure.
|
Field Summary |
static char |
Dot
|
Dot
public static final char Dot
- See Also:
- Constant Field Values
ReadOnlyMap
public ReadOnlyMap(Map<K,V> aMap)
emptyInstance
public static ReadOnlyMap emptyInstance()
get
public V get(K key)
containsKey
public boolean containsKey(K key)
containsValue
public boolean containsValue(V value)
equals
public boolean equals(Object o)
- Overrides:
equals in class Object
isEmpty
public boolean isEmpty()
isNullOrEmpty
public static <K,V> boolean isNullOrEmpty(ReadOnlyMap<K,V> m)
size
public int size()
keySet
public Set<K> keySet()
values
public Collection<V> values()
hashCode
public int hashCode()
- Overrides:
hashCode in class Object
entrySet
public Set entrySet()
getPath
public Object getPath(String path)
- Fetch a value from a nested map using a path of keys using
dot notation.
- Parameters:
path - The dotted path of key values
- Returns:
- The value at that path. If the value is a Map, return a
ReadOnlyMap, so the result is equivalent to doing a sequence of
get operations on the path elements.
toString
public String toString()
- Overrides:
toString in class Object
mapCopy
public Map<K,V> mapCopy()
- Get a copy of the underlying Map. It's not the actual
underlying Map, so is can't be used as a 'back door' to
modify the state of the ReadOnlyMap.
The static method
mapCopy(ReadOnlyMap) is
recommended unless the caller is certain that both this
and the Map it encloses are non-null.
- Returns:
- A copy of the wrapped Map.
mapCopy
public static Map mapCopy(ReadOnlyMap roMap)
- Get a copy of the underlying Map. It's not the actual
underlying Map, so is can't be used as a 'back door' to
modify the state of the ReadOnlyMap. If
- Parameters:
roMap - The ReadOnlyMap to copy. Return null if roMap is
null, or its enclosed Map is null or empty.
- Returns:
- A copy of the wrapped Map.
immutableMap
public Map<K,V> immutableMap()
immutableMap
public static Map immutableMap(ReadOnlyMap roMap)
AribaWeb User Interface Development Framework
Copyright © 2000-2009 Ariba, Inc. All Rights Reserved.