Oracle® Coherence Java API Reference
v3.5.3

E15583-01

com.tangosol.util
Class LiteMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by com.tangosol.util.LiteMap
All Implemented Interfaces:
ExternalizableLite, java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.util.Map

public class LiteMap
extends java.util.AbstractMap
implements java.lang.Cloneable, java.io.Externalizable, ExternalizableLite

An implementation of java.util.Map that is optimal (in terms of both size and speed) for very small sets of data but still works excellently with large sets of data. This implementation is not thread-safe.

The LiteMap implementation switches at runtime between several different sub-implementations for storing the Map of objects, described here:

  1. "empty map" - a map that contains no data;
  2. "single entry" - a reference directly to a single map entry
  3. "Object[]" - a reference to an array of entries; the item limit for this implementation is determined by the THRESHOLD constant;
  4. "delegation" - for more than THRESHOLD items, a map is created to delegate the map management to; sub-classes can override the default delegation class (java.util.HashMap) by overriding the factory method instantiateMap.

The LiteMap implementation supports the null key value.

Author:
cp 06/29/99

Nested Class Summary
static class LiteMap.EntryIterator
          A simple Iterator for LiteMap Entry objects.
protected  class LiteMap.EntrySet
          A Set of entries backed by this Map.
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry
 
Constructor Summary
LiteMap()
          Construct a LiteMap.
LiteMap(java.util.Map map)
          Construct a LiteMap with the same mappings as the given map.
 
Method Summary
protected  void checkShrinkFromOther()
          After a mutation operation has reduced the size of an underlying Map, check if the delegation model should be replaced with a more size- efficient storage approach, and switch accordingly.
 void clear()
          Clear all key/value mappings.
 java.lang.Object clone()
          Create a clone of the ImmutableArrayList.
 boolean containsKey(java.lang.Object oKey)
          Returns true if this map contains a mapping for the specified key.
 java.util.Set entrySet()
          Returns a set view of the mappings contained in this map.
 java.lang.Object get(java.lang.Object oKey)
          Returns the value to which this map maps the specified key.
protected  java.util.Map.Entry instantiateEntry(java.lang.Object key, java.lang.Object value)
          (Factory pattern) Instantiate a Map Entry.
protected  java.util.Set instantiateEntrySet()
          (Factory pattern) Instantiate an Entry Set.
protected  java.util.Map instantiateMap()
          (Factory pattern) Instantiate a Map object to store entries in once the "lite" threshold has been exceeded.
 boolean isEmpty()
          Returns true if this map contains no key-value mappings.
 java.lang.Object put(java.lang.Object oKey, java.lang.Object oValue)
          Associates the specified value with the specified key in this map.
 void readExternal(java.io.DataInput in)
          Restore the contents of this object by loading the object's state from the passed DataInput object.
 void readExternal(java.io.ObjectInput in)
          Initialize this object from the data in the passed ObjectInput stream.
 java.lang.Object remove(java.lang.Object oKey)
          Removes the mapping for this key from this map if present.
 int size()
          Returns the number of key-value mappings in this map.
 void writeExternal(java.io.DataOutput out)
          Save the contents of this object by storing the object's state into the passed DataOutput object.
 void writeExternal(java.io.ObjectOutput out)
          Write this object's data to the passed ObjectOutput stream.
 
Methods inherited from class java.util.AbstractMap
containsValue, equals, hashCode, keySet, putAll, toString, values
 

Constructor Detail

LiteMap

public LiteMap()
Construct a LiteMap.


LiteMap

public LiteMap(java.util.Map map)
Construct a LiteMap with the same mappings as the given map.

Parameters:
map - the map whose mappings are to be placed in this map.
Method Detail

isEmpty

public boolean isEmpty()
Returns true if this map contains no key-value mappings.

Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class java.util.AbstractMap
Returns:
true if this map contains no key-value mappings

size

public int size()
Returns the number of key-value mappings in this map.

Specified by:
size in interface java.util.Map
Overrides:
size in class java.util.AbstractMap
Returns:
the number of key-value mappings in this map

containsKey

public boolean containsKey(java.lang.Object oKey)
Returns true if this map contains a mapping for the specified key.

Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class java.util.AbstractMap
Returns:
true if this map contains a mapping for the specified key, false otherwise.

get

public java.lang.Object get(java.lang.Object oKey)
Returns the value to which this map maps the specified key.

Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.AbstractMap
Parameters:
oKey - the key object
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key

put

public java.lang.Object put(java.lang.Object oKey,
                            java.lang.Object oValue)
Associates the specified value with the specified key in this map.

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.AbstractMap
Parameters:
oKey - key with which the specified value is to be associated
oValue - value to be associated with the specified key
Returns:
previous value associated with specified key, or null if there was no mapping for key

remove

public java.lang.Object remove(java.lang.Object oKey)
Removes the mapping for this key from this map if present. Expensive: updates both the underlying cache and the local cache.

Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.AbstractMap
Parameters:
oKey - key whose mapping is to be removed from the map
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.

clear

public void clear()
Clear all key/value mappings.

Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.AbstractMap

clone

public java.lang.Object clone()
Create a clone of the ImmutableArrayList.

Overrides:
clone in class java.util.AbstractMap
Returns:
a clone of this list

entrySet

public java.util.Set entrySet()
Returns a set view of the mappings contained in this map. Each element in the returned set is an Map Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except by the iterator's own remove operation, or by the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It is not expected to support the add or addAll operations.

Specified by:
entrySet in interface java.util.Map
Specified by:
entrySet in class java.util.AbstractMap
Returns:
a set view of the mappings contained in this map

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Initialize this object from the data in the passed ObjectInput stream.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - the stream to read data from in order to restore the object
Throws:
java.io.IOException - if an I/O exception occurs
java.lang.ClassNotFoundException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Write this object's data to the passed ObjectOutput stream.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - the stream to write the object to
Throws:
java.io.IOException - if an I/O exception occurs

readExternal

public void readExternal(java.io.DataInput in)
                  throws java.io.IOException
Restore the contents of this object by loading the object's state from the passed DataInput object.

Specified by:
readExternal in interface ExternalizableLite
Parameters:
in - the DataInput stream to read data from in order to restore the state of this object
Throws:
java.io.IOException - if an I/O exception occurs
java.io.NotActiveException - if the object is not in its initial state, and therefore cannot be deserialized into

writeExternal

public void writeExternal(java.io.DataOutput out)
                   throws java.io.IOException
Save the contents of this object by storing the object's state into the passed DataOutput object.

Specified by:
writeExternal in interface ExternalizableLite
Parameters:
out - the DataOutput stream to write the state of this object to
Throws:
java.io.IOException - if an I/O exception occurs

instantiateEntry

protected java.util.Map.Entry instantiateEntry(java.lang.Object key,
                                               java.lang.Object value)
(Factory pattern) Instantiate a Map Entry. This method permits inheriting classes to easily override the implementation of the Entry object.

Returns:
an instance of a Map Entry

instantiateEntrySet

protected java.util.Set instantiateEntrySet()
(Factory pattern) Instantiate an Entry Set. This method permits inheriting classes to easily override the implementation of the EntrySet object.

Returns:
an instance of Entry Set

instantiateMap

protected java.util.Map instantiateMap()
(Factory pattern) Instantiate a Map object to store entries in once the "lite" threshold has been exceeded. This method permits inheriting classes to easily override the choice of the Map object.

Returns:
an instance of Map

checkShrinkFromOther

protected void checkShrinkFromOther()
After a mutation operation has reduced the size of an underlying Map, check if the delegation model should be replaced with a more size- efficient storage approach, and switch accordingly.


Oracle® Coherence Java API Reference
v3.5.3

E15583-01

Copyright © 2000, 2010, Oracle. All rights reserved.