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 java.lang.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
|
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Dot
public static final char Dot
- See Also:
- Constant Field Values
ReadOnlyMap
public ReadOnlyMap(java.util.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(java.lang.Object o)
- Overrides:
equals
in class java.lang.Object
isEmpty
public boolean isEmpty()
isNullOrEmpty
public static <K,V> boolean isNullOrEmpty(ReadOnlyMap<K,V> m)
size
public int size()
keySet
public java.util.Set<K> keySet()
values
public java.util.Collection<V> values()
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
entrySet
public java.util.Set<ReadOnlyMap.Entry<K,V>> entrySet()
getPath
public java.lang.Object getPath(java.lang.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 java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
mapCopy
public java.util.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 java.util.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 java.util.Map<K,V> immutableMap()
immutableMap
public static java.util.Map immutableMap(ReadOnlyMap roMap)
AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.