de.fu_berlin.ties.util
Class AdaptableLRUMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.apache.commons.collections.map.AbstractHashedMap
          extended by org.apache.commons.collections.map.AbstractLinkedMap
              extended by org.apache.commons.collections.map.LRUMap
                  extended by de.fu_berlin.ties.util.AdaptableLRUMap
All Implemented Interfaces:
Serializable, Cloneable, Map, BoundedMap, IterableMap, OrderedMap

public class AdaptableLRUMap
extends org.apache.commons.collections.map.LRUMap

A fixed-size map that uses an flexible adaptable strategy for pruning entries based on LRU (pruning one the least recently used entries). Instances of this class are not thread-safe and must be synchronized externally, if required.

Version:
$Revision: 1.7 $, $Date: 2004/06/04 17:13:22 $, $Author: siefkes $
Author:
Christian Siefkes
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractLinkedMap
org.apache.commons.collections.map.AbstractLinkedMap.EntrySetIterator, org.apache.commons.collections.map.AbstractLinkedMap.KeySetIterator, org.apache.commons.collections.map.AbstractLinkedMap.LinkEntry, org.apache.commons.collections.map.AbstractLinkedMap.LinkIterator, org.apache.commons.collections.map.AbstractLinkedMap.LinkMapIterator, org.apache.commons.collections.map.AbstractLinkedMap.ValuesIterator
 
Nested classes/interfaces inherited from class org.apache.commons.collections.map.AbstractHashedMap
org.apache.commons.collections.map.AbstractHashedMap.EntrySet, org.apache.commons.collections.map.AbstractHashedMap.HashEntry, org.apache.commons.collections.map.AbstractHashedMap.HashIterator, org.apache.commons.collections.map.AbstractHashedMap.HashMapIterator, org.apache.commons.collections.map.AbstractHashedMap.KeySet, org.apache.commons.collections.map.AbstractHashedMap.Values
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.apache.commons.collections.map.LRUMap
DEFAULT_MAX_SIZE
 
Fields inherited from class org.apache.commons.collections.map.AbstractLinkedMap
header
 
Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap
data, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, entrySet, GETKEY_INVALID, GETVALUE_INVALID, keySet, loadFactor, MAXIMUM_CAPACITY, modCount, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID, size, threshold, values
 
Constructor Summary
AdaptableLRUMap(int maxSize, float loadFactor, Pruner prun, int candidates, int pruneNum)
          Constructs a new, empty map with the specified initial capacity and load factor.
AdaptableLRUMap(int maxSize, Pruner prun, int candidates, int pruneNum)
          Constructs a new, empty map with the specified initial capacity and the default load factor.
 
Method Summary
 int getCandidateNumber()
          Returns the number of candidates considered for each pruning operation.
 int getPruneNumber()
          Returns the number of elements removed by each pruning operation.
protected  boolean removeLRU(org.apache.commons.collections.map.AbstractLinkedMap.LinkEntry entry)
          Controls removal of one of the least recently used entries from the map.
 
Methods inherited from class org.apache.commons.collections.map.LRUMap
addMapping, clone, doReadObject, doWriteObject, get, isFull, isScanUntilRemovable, maxSize, moveToMRU, reuseMapping, updateEntry
 
Methods inherited from class org.apache.commons.collections.map.AbstractLinkedMap
addEntry, clear, containsValue, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, entryAfter, entryBefore, firstKey, getEntry, init, lastKey, mapIterator, nextKey, orderedMapIterator, previousKey, removeEntry
 
Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap
calculateNewCapacity, calculateThreshold, checkCapacity, containsKey, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, getEntry, hash, hashCode, hashIndex, isEmpty, isEqualKey, isEqualValue, keySet, put, putAll, remove, removeMapping, reuseEntry, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

AdaptableLRUMap

public AdaptableLRUMap(int maxSize,
                       Pruner prun,
                       int candidates,
                       int pruneNum)
                throws IllegalArgumentException
Constructs a new, empty map with the specified initial capacity and the default load factor. If the number of candidates is one, this class behaves like a normal LRUMap; otherwise the Pruner is consulted to decide which entry to prune.

Parameters:
maxSize - the maximum size of the map
prun - Used to decide which entries to prune
candidates - The number of candidates to consider for each pruning operation
pruneNum - The number of elements to remove by each pruning operation, must not be larger than candidates
Throws:
IllegalArgumentException - if one of the input parameters is invalid

AdaptableLRUMap

public AdaptableLRUMap(int maxSize,
                       float loadFactor,
                       Pruner prun,
                       int candidates,
                       int pruneNum)
                throws IllegalArgumentException
Constructs a new, empty map with the specified initial capacity and load factor. If the number of candidates is one, this class behaves like a normal LRUMap; otherwise the Pruner is consulted to decide which entry to prune.

Parameters:
maxSize - the maximum size of the map
loadFactor - the load factor
prun - Used to decide which entries to prune
candidates - The number of candidates to consider for each pruning operation
pruneNum - The number of elements to remove by each pruning operation, must not be larger than candidates
Throws:
IllegalArgumentException - if one of the input parameters is invalid
Method Detail

getCandidateNumber

public int getCandidateNumber()
Returns the number of candidates considered for each pruning operation.

Returns:
the value of the attribute

getPruneNumber

public int getPruneNumber()
Returns the number of elements removed by each pruning operation.

Returns:
the value of the attribute

removeLRU

protected boolean removeLRU(org.apache.commons.collections.map.AbstractLinkedMap.LinkEntry entry)
Controls removal of one of the least recently used entries from the map. Lets the pruner decide if there are multiple candidates to consider.

Overrides:
removeLRU in class org.apache.commons.collections.map.LRUMap
Parameters:
entry - the least recently used entry
Returns:
true if the superclass should delete the specified entry; false if this class took the necessary action by deleting the first getPruneNumber() entries selected by the pruner


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.