org.cometd.util
Class ImmutableHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.cometd.util.ImmutableHashMap<K,V>
Type Parameters:
K - The key type
V - The key value
All Implemented Interfaces:
Map<K,V>

public class ImmutableHashMap<K,V>
extends AbstractMap<K,V>
implements Map<K,V>

Immutable Hash Map.

FixedHashMap is a hash Map implementation that provides both mutable and immutable APIs to the same data structure. The immutable API applies to deep structures of FixedHashMaps of FixedHashMaps.

The implementation uses a fixed size array of hash entries whose keys and hashes are retained when removed from the map, which is optimal for pooled maps that will frequently contain the same key over and over.

FixedMap keys cannot be null. FixedMap values may be null, but null values are treated exactly as if the entry is not added to the map. Setting a value to null is equivalent to removing the entry

The #getEntry(Object)) may be used to obtain references to Map.Entry instances that will not change for a given key and thus may be used for direct access to the related value.

This map is not thread safe and multiple threads should not access the map without some synchronization

.


Nested Class Summary
static class ImmutableHashMap.ImmutableEntry<K,V>
           
 class ImmutableHashMap.Mutable
           
static class ImmutableHashMap.MutableEntry<K,V>
           
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
ImmutableHashMap()
           
ImmutableHashMap(int nominalSize)
           
 
Method Summary
 ImmutableHashMap.Mutable asMutable()
          Get the immutable API to this map.
 boolean containsKey(Object key)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
 Map.Entry<K,V> getEntry(K key)
          Get an entry reference.
 ImmutableHashMap.ImmutableEntry<K,V> getEntryReference(K key)
          Get an entry reference.
protected  void onChange(K key)
          Called if the map is about to be changed.
 int size()
           
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, equals, hashCode, isEmpty, keySet, put, putAll, remove, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsValue, equals, hashCode, isEmpty, keySet, put, putAll, remove, values
 

Constructor Detail

ImmutableHashMap

public ImmutableHashMap()

ImmutableHashMap

public ImmutableHashMap(int nominalSize)
Method Detail

asMutable

public ImmutableHashMap.Mutable asMutable()
Get the immutable API to this map.

Returns:
an Immutable map backed by this map.

getEntry

public Map.Entry<K,V> getEntry(K key)
Get an entry reference.

Parameters:
key - The key to lookup.
Returns:
The found entry.

getEntryReference

public ImmutableHashMap.ImmutableEntry<K,V> getEntryReference(K key)
Get an entry reference.

The entries stored in the top level of the maps entry buckets are never deleted, only nulled. Thus references returned to them can be kept over calls to reset and used to directly access the value without a hash lookup.

This method returns only such top level entries.

Parameters:
key - The key to lookup.
Returns:
The found entry or null
Throws:
IllegalStateException - if key is not a top level entry

onChange

protected void onChange(K key)
                 throws UnsupportedOperationException
Called if the map is about to be changed.

Parameters:
key - The key to be changed, or null if multiple keys.
Throws:
UnsupportedOperationException - If change is not allowed/

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>


Copyright © 2008-2010 Dojo Foundation. All Rights Reserved.