helma.util
Class CacheMap

java.lang.Object
  extended by helma.util.CacheMap
All Implemented Interfaces:
ObjectCache
Direct Known Subclasses:
WeakCacheMap

public class CacheMap
extends java.lang.Object
implements ObjectCache


Constructor Summary
CacheMap()
          Zero argument constructor.
CacheMap(int initialCapacity)
           
CacheMap(int initialCapacity, float loadFactor)
           
 
Method Summary
 boolean clear()
          Removes all items currently stored in the cache.
 boolean containsKey(java.lang.Object key)
          Returns true if the collection contains an element for the key.
 int containsKeys(java.lang.Object[] keys)
          Returns the number of keys in object array keys that were not found in the Map.
 boolean containsValue(java.lang.Object value)
           
protected  java.util.Map createTable(int capacity, float loadFactor)
          Override this method to use custom Map implementations.
 java.lang.Object get(java.lang.Object key)
          Gets the object associated with the specified key in the hashtable.
 java.lang.Object[] getCachedObjects()
          Return an array with all objects currently contained in the cache.
 void init(Application app)
          Set the Application instance for the cache.
 boolean isEmpty()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Puts the specified element into the hashtable, using the specified key.
 java.lang.Object remove(java.lang.Object key)
          Removes the element corresponding to the key.
 void setCapacity(int capacity)
           
 void shutdown()
          Called when the application holding the cache is stopped.
 int size()
          Return the number of objects currently stored in the cache.
 java.lang.String toString()
           
 void updateProperties(java.util.Properties props)
          Called when the application's properties have been updated to let the cache implementation update its settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheMap

public CacheMap()
Zero argument constructor. Creates a CacheMap with capacity of 1000 and load factor 0.75


CacheMap

public CacheMap(int initialCapacity,
                float loadFactor)

CacheMap

public CacheMap(int initialCapacity)
Method Detail

size

public int size()
Description copied from interface: ObjectCache
Return the number of objects currently stored in the cache.

Specified by:
size in interface ObjectCache
Returns:
the number of cached items

isEmpty

public boolean isEmpty()

setCapacity

public void setCapacity(int capacity)

containsValue

public boolean containsValue(java.lang.Object value)

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from interface: ObjectCache
Returns true if the collection contains an element for the key.

Specified by:
containsKey in interface ObjectCache
Parameters:
key - the key that we are looking for

containsKeys

public int containsKeys(java.lang.Object[] keys)
Description copied from interface: ObjectCache
Returns the number of keys in object array keys that were not found in the Map. Those keys that are contained in the Map are nulled out in the array.

Specified by:
containsKeys in interface ObjectCache
Parameters:
keys - an array of key objects we are looking for
See Also:
ObjectCache.containsKey(java.lang.Object)

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: ObjectCache
Gets the object associated with the specified key in the hashtable.

Specified by:
get in interface ObjectCache
Parameters:
key - the specified key
Returns:
the element for the key or null if the key is not defined in the hash table.
See Also:
ObjectCache.put(java.lang.Object, java.lang.Object)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: ObjectCache
Puts the specified element into the hashtable, using the specified key. The element may be retrieved by doing a get() with the same key. The key and the element cannot be null.

Specified by:
put in interface ObjectCache
Parameters:
key - the specified key in the hashtable
value - the specified element
Returns:
the old value of the key, or null if it did not have one.
See Also:
ObjectCache.get(java.lang.Object)

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from interface: ObjectCache
Removes the element corresponding to the key. Does nothing if the key is not present.

Specified by:
remove in interface ObjectCache
Parameters:
key - the key that needs to be removed
Returns:
the value of key, or null if the key was not found.

clear

public boolean clear()
Description copied from interface: ObjectCache
Removes all items currently stored in the cache.

Specified by:
clear in interface ObjectCache
Returns:
true if the operation succeeded

shutdown

public void shutdown()
Description copied from interface: ObjectCache
Called when the application holding the cache is stopped.

Specified by:
shutdown in interface ObjectCache

init

public void init(Application app)
Description copied from interface: ObjectCache
Set the Application instance for the cache.

Specified by:
init in interface ObjectCache
Parameters:
app - the app instance

updateProperties

public void updateProperties(java.util.Properties props)
Description copied from interface: ObjectCache
Called when the application's properties have been updated to let the cache implementation update its settings.

Specified by:
updateProperties in interface ObjectCache

getCachedObjects

public java.lang.Object[] getCachedObjects()
Description copied from interface: ObjectCache
Return an array with all objects currently contained in the cache.

Specified by:
getCachedObjects in interface ObjectCache

toString

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

createTable

protected java.util.Map createTable(int capacity,
                                    float loadFactor)
Override this method to use custom Map implementations. The default implementation returns a java.util.HashMap instance.

Parameters:
capacity - the initial capacity
loadFactor - the load factor
Returns:
a new Map used for internal caching


Copyright © 1998-1998-${year} Helma.org. All Rights Reserved.