at.tuwien.ifs.somtoolbox.util
Class LeastRecentelyUsedImageCache

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<java.lang.String,java.awt.image.BufferedImage>
              extended by at.tuwien.ifs.somtoolbox.util.LeastRecentelyUsedImageCache
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.awt.image.BufferedImage>

public final class LeastRecentelyUsedImageCache
extends java.util.LinkedHashMap<java.lang.String,java.awt.image.BufferedImage>

A least-recently-used LRU cache, based on LinkedHashMap. This cache can hold a fixed a number of BufferedImage elements, until the specified memory limit is reached. If a new element is added, and the cache is full, the least recently used entry is removed.

Version:
$Id: LeastRecentelyUsedImageCache.java 4156 2011-02-11 15:56:51Z mayer $
Author:
Rudolf Mayer
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
private  long maxCacheSize
           
private  java.lang.String maxCacheSizeReadable
           
private static long serialVersionUID
           
 
Constructor Summary
LeastRecentelyUsedImageCache(int maxCacheSizeInMBit)
           
LeastRecentelyUsedImageCache(long maxCacheSize)
           
 
Method Summary
 long getCurrentSize()
           
 double getCurrentSizeInMBit()
           
 long getMaxCacheSize()
           
 long getMaxCacheSizeInMBit()
           
protected  boolean removeEldestEntry(java.util.Map.Entry<java.lang.String,java.awt.image.BufferedImage> eldest)
           
 void setMaxCacheSize(long maxCacheSize)
           
 void setMaxCacheSizeInMBit(int maxCacheSizeInMBit)
           
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

maxCacheSize

private long maxCacheSize

maxCacheSizeReadable

private java.lang.String maxCacheSizeReadable
Constructor Detail

LeastRecentelyUsedImageCache

public LeastRecentelyUsedImageCache(int maxCacheSizeInMBit)

LeastRecentelyUsedImageCache

public LeastRecentelyUsedImageCache(long maxCacheSize)
Method Detail

removeEldestEntry

protected boolean removeEldestEntry(java.util.Map.Entry<java.lang.String,java.awt.image.BufferedImage> eldest)
Overrides:
removeEldestEntry in class java.util.LinkedHashMap<java.lang.String,java.awt.image.BufferedImage>

getMaxCacheSize

public long getMaxCacheSize()
Returns:
Returns the maxCacheSize.

getMaxCacheSizeInMBit

public long getMaxCacheSizeInMBit()

setMaxCacheSize

public void setMaxCacheSize(long maxCacheSize)
Parameters:
maxCacheSize - The maxCacheSize to set.

setMaxCacheSizeInMBit

public void setMaxCacheSizeInMBit(int maxCacheSizeInMBit)

getCurrentSize

public long getCurrentSize()
Returns:
The current size of the cache

getCurrentSizeInMBit

public double getCurrentSizeInMBit()