org.nees.util.cache
Class Cache

java.lang.Object
  extended byorg.nees.util.cache.Cache

public class Cache
extends java.lang.Object

Base Cache class. Provides a simple Dictionary-like API for associating objects with keys, as well providing means for removing objects based on access time or size.


Constructor Summary
Cache()
          Constructor for Cache.
 
Method Summary
 long byteSize()
          Return the size of the cache in bytes.
 boolean contains(java.lang.Object key)
           
 java.lang.Object get(java.lang.Object key)
           
 CachedObject getLargest()
           
 CachedObject getLeastAccessed()
           
 CachedObject getLeastRecentlyAccessed()
           
 CachedObject getOldest()
           
 void put(CachedObject cachedObject)
           
 void put(java.lang.Object key, java.lang.Object objectToCache)
           
 void remove(CachedObject o)
           
 void remove(CachedObject[] cachedObjectArray)
           
 int size()
          Return the number of objects in the cache.
 CachedObject[] sortByByteSize()
           
 CachedObject[] sortByCreationTime()
           
 CachedObject[] sortByLastAccessedTime()
           
 CachedObject[] sortByNumberOfAccesses()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

public Cache()
Constructor for Cache.

Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object objectToCache)

put

public void put(CachedObject cachedObject)

get

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

contains

public boolean contains(java.lang.Object key)

remove

public void remove(CachedObject[] cachedObjectArray)

remove

public void remove(CachedObject o)

size

public int size()
Return the number of objects in the cache.

Returns:
the number of objects in the cache.

byteSize

public long byteSize()
Return the size of the cache in bytes. This depends on the cached objects implementing the Sizeable interface.

Returns:
the size of the cache in bytes.
See Also:
Sizeable

sortByLastAccessedTime

public CachedObject[] sortByLastAccessedTime()

sortByCreationTime

public CachedObject[] sortByCreationTime()

sortByByteSize

public CachedObject[] sortByByteSize()

sortByNumberOfAccesses

public CachedObject[] sortByNumberOfAccesses()

getLeastRecentlyAccessed

public CachedObject getLeastRecentlyAccessed()
Returns:
the object that was accessed least recently

getOldest

public CachedObject getOldest()
Returns:
the object that was put in the cache the least recently

getLargest

public CachedObject getLargest()
Returns:
the largest object in the cache (for this to work, the objects must implement Sizeable)
See Also:
Sizeable

getLeastAccessed

public CachedObject getLeastAccessed()
Returns:
the object that has been accessed the least number of times