ariba.util.core
Class ReadOnlyMap<K,V>

java.lang.Object
  extended by 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.


Nested Class Summary
 class ReadOnlyMap.Entry<K,V>
           
 
Field Summary
static char Dot
           
 
Constructor Summary
ReadOnlyMap(java.util.Map<K,V> aMap)
           
 
Method Summary
 boolean containsKey(K key)
           
 boolean containsValue(V value)
           
static ReadOnlyMap emptyInstance()
           
 java.util.Set<ReadOnlyMap.Entry<K,V>> entrySet()
           
 boolean equals(java.lang.Object o)
           
 V get(K key)
           
 java.lang.Object getPath(java.lang.String path)
          Fetch a value from a nested map using a path of keys using dot notation.
 int hashCode()
           
 java.util.Map<K,V> immutableMap()
           
static java.util.Map immutableMap(ReadOnlyMap roMap)
           
 boolean isEmpty()
           
static
<K,V> boolean
isNullOrEmpty(ReadOnlyMap<K,V> m)
           
 java.util.Set<K> keySet()
           
 java.util.Map<K,V> mapCopy()
          Get a copy of the underlying Map.
static java.util.Map mapCopy(ReadOnlyMap roMap)
          Get a copy of the underlying Map.
 int size()
           
 java.lang.String toString()
           
 java.util.Collection<V> values()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

Dot

public static final char Dot
See Also:
Constant Field Values
Constructor Detail

ReadOnlyMap

public ReadOnlyMap(java.util.Map<K,V> aMap)
Method Detail

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.