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:
java.util.Map<K,V>

public class ImmutableHashMap<K,V>
extends java.util.AbstractMap<K,V>
implements java.util.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
 class ImmutableHashMap.Mutable
           
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
ImmutableHashMap()
           
ImmutableHashMap(int nominalSize)
           
 
Method Summary
 ImmutableHashMap.Mutable asMutable()
          Get the immutable API to this map.
 boolean containsKey(java.lang.Object key)
           
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 V get(java.lang.Object key)
           
 java.util.Map.Entry<K,V> getEntry(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 java.util.Map.Entry<K,V> getEntry(K key)
Get an entry reference. The first [nominalSize] entries added are guaranteed never to be deleted from the map, so the references may be used as repeated quick lookups of the same key.

Parameters:
key -
Returns:

onChange

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

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

entrySet

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

containsKey

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

get

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

size

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


Copyright © 2010 Dojo Foundation. All Rights Reserved.