com.mancrd.ahah.commons
Class LRUCache

java.lang.Object
  extended by com.mancrd.ahah.commons.LRUCache

public class LRUCache
extends Object

A specialized LRUCache where only keys are put into it. The values associated with the keys are managed internally.

Author:
timmolter

Constructor Summary
LRUCache(int cacheSize)
          Constructor
 
Method Summary
 Collection<Map.Entry<String,Integer>> getAll()
          Returns a Collection that contains a copy of all cache entries.
 LinkedHashMap<String,Integer> getMap()
          get the internal key/value (Signature/Lables) map of the CAM
 boolean isFull()
          check if the CAM is full
 boolean isReassign()
          Returns whether or not the last insert was an overwrite or not.
 int maxSize()
          check the max size of the CAM
 Integer put(String signature)
          Adds an entry to this cache.
 void reset()
          resets everything to new state
 String reverseLookup(Integer label)
          given a label, return the signature
 int size()
          Returns the number of used entries in the cache.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LRUCache

public LRUCache(int cacheSize)
Constructor

Parameters:
cacheSize - the maximum number of entries that will be kept in this cache.
Method Detail

put

public Integer put(String signature)
Adds an entry to this cache. The new entry becomes the MRU (most recently used) entry. If an entry with the specified key already exists in the cache, it is replaced by the new entry. If the cache is full, the LRU (least recently used) entry is removed from the cache.

Parameters:
signature - - the key with which the specified value is to be associated. This is usually a String or an Integer

isReassign

public boolean isReassign()
Returns whether or not the last insert was an overwrite or not.

Returns:

reset

public void reset()
resets everything to new state


size

public int size()
Returns the number of used entries in the cache.

Returns:
the number of entries currently in the cache.

isFull

public boolean isFull()
check if the CAM is full


maxSize

public int maxSize()
check the max size of the CAM


getMap

public LinkedHashMap<String,Integer> getMap()
get the internal key/value (Signature/Lables) map of the CAM


getAll

public Collection<Map.Entry<String,Integer>> getAll()
Returns a Collection that contains a copy of all cache entries.

Returns:
a Collection with a copy of the cache content.

reverseLookup

public String reverseLookup(Integer label)
given a label, return the signature


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013–2014 M. Alexander Nugent Consulting, Research and Devlopment. All rights reserved.