org.egothor.cache.lfu
Class LfuNode<K>

java.lang.Object
  extended by org.egothor.cache.AbstractNode<K,LfuNode<K>>
      extended by org.egothor.cache.lfu.LfuNode<K>
Type Parameters:
K - type of the key
All Implemented Interfaces:
java.lang.Comparable<LfuNode<K>>

public class LfuNode<K>
extends AbstractNode<K,LfuNode<K>>

Represents a node that can be used as a key for TreeMap. Uses frequency and recency to compare nodes.


Field Summary
 
Fields inherited from class org.egothor.cache.AbstractNode
key
 
Constructor Summary
LfuNode(K key)
          Constructor for the LfuNode object.
 
Method Summary
 int compareTo(LfuNode<K> node)
          Compares this node with the specified node.
 long getFrequency()
          Returns the value of frequency counter of this node.
 long getId()
          Returns the time of the last access to this node.
 long setFrequency(long newFrequency)
          Set the access frequency counter of this node.
 long update()
          Increments the frequency of this node and sets is access time to the current time.
 
Methods inherited from class org.egothor.cache.AbstractNode
equals, getKey, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LfuNode

public LfuNode(K key)
Constructor for the LfuNode object.

Parameters:
key - key associated with the node
Method Detail

getFrequency

public long getFrequency()
Returns the value of frequency counter of this node.

Returns:
value of the frequency counter

setFrequency

public long setFrequency(long newFrequency)
Set the access frequency counter of this node.

Parameters:
newFrequency - new frequency of this node
Returns:
previous value of the frequency counter

getId

public long getId()
Returns the time of the last access to this node.

Returns:
time of the last access to this node

update

public long update()
Increments the frequency of this node and sets is access time to the current time.

Returns:
new frequency of the node

compareTo

public int compareTo(LfuNode<K> node)
Compares this node with the specified node. Uses frequency (more frequent means smaller) and recency (more recent is smaller) in that order to compare the nodes.

Returns:
-1 if this node is smaller than the specified node, 1 if it is greater and 0 if the are equal