grinda.common
Class HashedCache

java.lang.Object
  extended by grinda.common.HashedCache

public class HashedCache
extends java.lang.Object

A simple cache that contains object. Each new object has a counter associated with it that is used to check if the object can really be deleted. It simply take trace of the other object interested in it like a garbage collector does.


Constructor Summary
HashedCache()
           
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Retrives an object using its key and increasing its reference counter
 java.lang.Object getRegistered(java.lang.Object key)
           
 void put(java.lang.Object key, java.lang.Object value)
          Puts a new object in the cache.
 java.lang.Object remove(java.lang.Object key)
          Removes an object from the cache.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashedCache

public HashedCache()
Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object value)
Puts a new object in the cache. If it is already present only its associated counter if increased.

Parameters:
key - the key for the object
value - its value

get

public java.lang.Object get(java.lang.Object key)
Retrives an object using its key and increasing its reference counter

Parameters:
key -
Returns:
the value or null if it isn't present

getRegistered

public java.lang.Object getRegistered(java.lang.Object key)

remove

public java.lang.Object remove(java.lang.Object key)
Removes an object from the cache. Only when its associated counter reaches zero the object is really deleted.

Parameters:
key -
Returns:
the object removed

size

public int size()


Copyright © 2006 Sirio Capizzi. All Rights Reserved.