org.sape.carbon.services.cache.mru
Class KeyInfo

java.lang.Object
  |
  +--org.sape.carbon.services.cache.mru.KeyInfo
All Implemented Interfaces:
Comparable

class KeyInfo
extends Object
implements Comparable

Package visibility class used by the MRUCache to store a reference to the key object along with the last accessed time and expiration time for that key/value in milliseconds.

Implements the java.lang.Comparable interface, to allow fast sorting of KeyInfo objects in a Collection - or in this case, a TreeSet. Comparision is based on the lastAccessedTime for the key (which is set by the MRUCache each time the key is passed into a call to get. If the lastAccessedTime of two KeyInfo objects is the same the compareTo method of the Comparable interface is invoked on the key object to determine the natural ordering.

Copyright 2000 Sapient

Version:
$Revision: 1.17 $
Author:
$Author: ghinkl $ $Date: 2003/07/03 18:47:48 $

Field Summary
private  long expirationTime
          Internal variable to hold the time when this key's element will expire
private  Object key
          Internal variable to hold the key.
private  long lastAccessTime
          Internal variable to hold the time this key was last accessed.
 
Constructor Summary
(package private) KeyInfo(Object key, long expirationInterval)
          Default constructor, which constructs a KeyInfo object from a key, and initialized the lastAccessTime to the current time.
 
Method Summary
 int compareTo(Object other)
          Implementation of the compareTo method from the Comparable interface.
 boolean equals(Object other)
          Checks if the KeyInfo objects are equal.
(package private)  long getExpirationTime()
          Simple getter for the expirationTime held inside this KeyInfo object.
(package private)  Object getKey()
          Simple getter for the key held inside this KeyInfo object.
(package private)  boolean hasExpired()
          A simple method to determine whether or not the element has expired
 int hashCode()
          Returns a hash code value for the object based on the key.
 String toString()
          Overrides the toString() method to return the toString() of the key object, prints the lastAccessTime and expirationTime in milliseconds.
(package private)  void updateAccessTime()
          Updates the lastAccessedTime of the KeyInfo, which is used to determine its natural ordering for the compareTo method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

key

private Object key
Internal variable to hold the key.


lastAccessTime

private long lastAccessTime
Internal variable to hold the time this key was last accessed.


expirationTime

private long expirationTime
Internal variable to hold the time when this key's element will expire

Constructor Detail

KeyInfo

KeyInfo(Object key,
        long expirationInterval)

Default constructor, which constructs a KeyInfo object from a key, and initialized the lastAccessTime to the current time.

Parameters:
key - The object representing the key for this KeyInfo.
expirationInterval - duration of time of the element in milliseconds.
Method Detail

getKey

Object getKey()

Simple getter for the key held inside this KeyInfo object.

Returns:
Object The key object held internally.

getExpirationTime

long getExpirationTime()

Simple getter for the expirationTime held inside this KeyInfo object.

Returns:
long The time in millis when this key should be expired

hasExpired

boolean hasExpired()

A simple method to determine whether or not the element has expired

Returns:
boolean true if the current system time >= the elements expiration time

updateAccessTime

void updateAccessTime()

Updates the lastAccessedTime of the KeyInfo, which is used to determine its natural ordering for the compareTo method.


compareTo

public final int compareTo(Object other)
Implementation of the compareTo method from the Comparable interface. This method performs a three level comparison. First, we compare lastAccess time, Secound, we compare expirationTime, and Last, we compare the keyInfo's key. Basically, this method will return -1 if this "is Older than" other. 1 if this "is Younger than" other. and 0 if they are the same.

Specified by:
compareTo in interface Comparable
Parameters:
other - Another KeyInfo object to compare this one to.
Returns:
int 0 if the objects contain the same key, hav
See Also:
Comparable

equals

public final boolean equals(Object other)

Checks if the KeyInfo objects are equal.

Overrides:
equals in class Object
Parameters:
other - The other object to check for equality.
Returns:
boolean True if the two objects are equal, false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the object based on the key.

Overrides:
hashCode in class Object
Returns:
a hash code for the key.

toString

public String toString()

Overrides the toString() method to return the toString() of the key object, prints the lastAccessTime and expirationTime in milliseconds.

Overrides:
toString in class Object
Returns:
String a String representation of the KeyInfo object.


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.