org.edg.security.authorization.map
Class CachedMap

java.lang.Object
  |
  +--org.edg.security.authorization.map.CachedMap
All Implemented Interfaces:
java.util.Map

public class CachedMap
extends java.lang.Object
implements java.util.Map

Class CachedMap A map with constraints on time and/or size. Various map instances may be slow in their lookups. This class can be wrapped around another map. It caches the results from the lookups in a hash table, only accessing the underlying map when needed. The caching policy can be altered in two ways:

NOTE: The implementation is rather conservative with regard to the underlying map. Any call to methods put(), remove(), clear() of the cached map is immediately propagated to the underlying map. Insert 'the right' copyright

Version:
%I%, %G%
Author:
Olle Mulmo

Nested Class Summary
 class CachedMap.Result
           
 
Field Summary
protected  java.util.LinkedHashMap myCache
           
protected  java.util.Map myMap
           
protected  long myMaxSize
           
protected  long myMaxTime
           
protected  long mySize
           
static long theDefaultMaxSize
          theDefaultMaxSize The maximum number of lookup results stored in the cache.
static long theDefaultMaxTime
          theDefaultMaxTime The maximum time period a result is cached, in seconds.
 
Constructor Summary
CachedMap(java.util.Map mapToCache)
          Constructor CachedMap.
CachedMap(java.util.Map mapToCache, long maxSize, long maxTime)
          Constructor CachedMap.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 boolean isEmpty()
           
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map t)
           
 java.lang.Object remove(java.lang.Object key)
           
 int size()
          Deprecated. Hmm... what to return here? The current size of the cache or the size of the underlying Map? Unsupported for now...
 java.lang.String toString()
           
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

theDefaultMaxSize

public static long theDefaultMaxSize
theDefaultMaxSize The maximum number of lookup results stored in the cache. Negative means no limits. Default is 1000.


theDefaultMaxTime

public static long theDefaultMaxTime
theDefaultMaxTime The maximum time period a result is cached, in seconds. Negative means no limits. Default is -1.


myMap

protected java.util.Map myMap

myMaxSize

protected long myMaxSize

myMaxTime

protected long myMaxTime

mySize

protected long mySize

myCache

protected java.util.LinkedHashMap myCache
Constructor Detail

CachedMap

public CachedMap(java.util.Map mapToCache)
Constructor CachedMap. Initializes a CachedMap with the default max size of the cache

See Also:
theDefaultMaxSize, CachedMap(Map, long, long)

CachedMap

public CachedMap(java.util.Map mapToCache,
                 long maxSize,
                 long maxTime)
Constructor CachedMap.

Parameters:
mapToCache - - the map to cache result of lookups from
maxSize - - the max size of the cache
maxTime - - the max time to cache a result, in seconds
See Also:
theDefaultMaxSize, theDefaultMaxTime
Method Detail

size

public int size()
Deprecated. Hmm... what to return here? The current size of the cache or the size of the underlying Map? Unsupported for now...

Specified by:
size in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map
See Also:
Map.isEmpty()

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
See Also:
Map.containsKey(Object)

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map
See Also:
Map.containsValue(Object)

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
See Also:
Map.get(Object)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
See Also:
Map.put(Object, Object)

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map
See Also:
Map.remove(Object)

putAll

public void putAll(java.util.Map t)
Specified by:
putAll in interface java.util.Map
See Also:
Map.putAll(Map)

clear

public void clear()
Specified by:
clear in interface java.util.Map
See Also:
Map.clear()

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map
See Also:
Map.keySet()

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map
See Also:
Map.values()

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map
See Also:
Map.entrySet()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object