org.ephman.utils
Class RandomCache

java.lang.Object
  |
  +--org.ephman.utils.RandomCache
Direct Known Subclasses:
IdentifiedCache

public class RandomCache
extends java.lang.Object

A class to cache any set of objects

Version:
1.0
Author:
Paul M. Bethe

Field Summary
protected  java.util.HashMap hm
           
 
Constructor Summary
RandomCache()
          constructs a cache of default elements (17)
RandomCache(int cacheSize)
          if cacheSize is greater than 17, initializes the cache with size = the first prime >= cacheSize
 
Method Summary
 void flush()
          a routine to flush out the cache
 java.lang.Object get(java.lang.Object key)
          Unsynchronized find of an Object which was hashed on key
 int getSize()
          Determine the number of elements in the cache never > than maxElements
 void put(java.lang.Object key, java.lang.Object obj)
          A synchronized placement of an element into the cache - to guarantee that no more than 1 copy of an item is cached
 void putForceUpdate(java.lang.Object key, java.lang.Object obj)
          A synchronized placement of an element into the cache - to guarantee that no more than 1 copy of an item is cached
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hm

protected java.util.HashMap hm
Constructor Detail

RandomCache

public RandomCache()
constructs a cache of default elements (17)


RandomCache

public RandomCache(int cacheSize)
if cacheSize is greater than 17, initializes the cache with size = the first prime >= cacheSize

Parameters:
cacheSize - the desired cache size
Method Detail

flush

public void flush()
a routine to flush out the cache


getSize

public int getSize()
Determine the number of elements in the cache never > than maxElements

Returns:
the number of elements currently in the cache

get

public java.lang.Object get(java.lang.Object key)
Unsynchronized find of an Object which was hashed on key

Parameters:
key - the Object whose hashcode will be used in lookup
Returns:
the Object last hashed on that code or null if none is found

putForceUpdate

public void putForceUpdate(java.lang.Object key,
                           java.lang.Object obj)
A synchronized placement of an element into the cache - to guarantee that no more than 1 copy of an item is cached

Parameters:
key - the Object whose hashcode should be used to store obj
obj - the Object to store in cache

put

public void put(java.lang.Object key,
                java.lang.Object obj)
A synchronized placement of an element into the cache - to guarantee that no more than 1 copy of an item is cached

Parameters:
key - the Object whose hashcode should be used to store obj
obj - the Object to store in cache