org.webmacro.util
Class SimpleIdentityMap

java.lang.Object
  extended byorg.webmacro.util.SimpleIdentityMap
All Implemented Interfaces:
SimpleMap

public final class SimpleIdentityMap
extends java.lang.Object
implements SimpleMap

Identity map, that is especially suited to canonical mappings. This map is identical to SimpleMap, except two special featurs.
1. Two keys are compared for equality only by reference. There equals() and hashCode() method are not called. Instead a special system hash function is used, that is based upon the reference. This leads to a superior performance to hash-functions used for strings for example.
2. Keys are only held via a WeakReference. This means, that if the key object is not referenced at another place, it will be removed from this map. This makes sense, as you cannot access the value mapped to this key anymore, since you do not have a reference to the key anymore.

Since:
0.96
Author:
skanthak@muehlheim.de

Constructor Summary
SimpleIdentityMap()
          Create a new SimpleMap with 1001 LRU buckets
SimpleIdentityMap(int size)
          Create a new SimpleMap with 'size' LRU buckets
 
Method Summary
 void clear()
           
 java.lang.Object get(java.lang.Object key)
          Get the value of 'key' back.
 void put(java.lang.Object key, java.lang.Object value)
          Add a key to the SimpleMap.
 java.lang.Object remove(java.lang.Object key)
          Ensure that the key does not appear in the map Remember that you have to use the identical object (same reference) as the key, that was used when you placed the object into the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleIdentityMap

public SimpleIdentityMap()
Create a new SimpleMap with 1001 LRU buckets


SimpleIdentityMap

public SimpleIdentityMap(int size)
Create a new SimpleMap with 'size' LRU buckets

Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object value)
Add a key to the SimpleMap.

Specified by:
put in interface SimpleMap

get

public java.lang.Object get(java.lang.Object key)
Get the value of 'key' back. Returns null if no such key. Remember that you have to use the identical object (same reference) as the key, that was used when you placed the object into the map.

Specified by:
get in interface SimpleMap

remove

public java.lang.Object remove(java.lang.Object key)
Ensure that the key does not appear in the map Remember that you have to use the identical object (same reference) as the key, that was used when you placed the object into the map.

Specified by:
remove in interface SimpleMap

clear

public void clear()
Specified by:
clear in interface SimpleMap