org.mmbase.util
Class LRUHashtable

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--org.mmbase.util.LRUHashtable
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable
Direct Known Subclasses:
MultilevelCacheHandler

public class LRUHashtable
extends java.util.Hashtable
implements java.lang.Cloneable

A hashtable which has a maximum of entries. Old entries are removed when the maximum is reached. This table is used mostly to implement a simple caching system.

Version:
24 Nov 1997
Author:
Rico Jansen
See Also:
Serialized Form

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
LRUHashtable()
          Creates the URL Hashtable with maximum capacity 100, starting capacity 101, and growing capacity 0.75.
LRUHashtable(int size)
          Creates the URL Hashtable with starting capacity 101 and growing capacity 0.75.
LRUHashtable(int size, int cap)
          Creates the URL Hashtable with growing capacity 0.75.
LRUHashtable(int size, int cap, float lf)
          Creates the URL Hashtable.
 
Method Summary
 void clear()
          Clears the table.
 java.lang.Object clone()
          NOT IMPLEMENTED
 boolean contains(java.lang.Object value)
          Checks if an element exists in the table, searching by value.
 boolean containsKey(java.lang.Object key)
          Checks if an element exists in the table, searching by key.
 java.util.Enumeration elements()
          Returns an Enumeration on the table's element values.
 java.lang.Object get(java.lang.Object key)
          Retrieve an element from the table.
 int getCount(java.lang.Object key)
          Retrieve the getcount of the key object
 int getHits()
          Returns the number of times an element was succesfully retrieved from the table.
 int getMisses()
          Returns the number of times an element cpould not be retrieved from the table.
 java.util.Enumeration getOrderedElements()
           
 java.util.Enumeration getOrderedElements(int maxnumber)
           
 int getPuts()
          Returns the number of times an element was committed to the table.
 double getRatio()
          Returns the ratio of hits and misses.
 int getSize()
          Return the maximum size of the table
 java.lang.String getStats()
          Returns statistics on this table.
 boolean isEmpty()
          Returns true if no elements are in the table.
 java.util.Enumeration keys()
          Returns an Enumeration on the table's element keys.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Store an element in the table.
 java.lang.Object remove(java.lang.Object key)
          Remove an element from the table.
 void setSize(int size)
          Change the maximum size of the table.
 int size()
          Return the current size of the table
 java.lang.String toString()
          Returns a description of the table.
 java.lang.String toString(boolean which)
          Returns a description of the table.
 
Methods inherited from class java.util.Hashtable
containsValue, entrySet, equals, hashCode, keySet, putAll, rehash, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LRUHashtable

public LRUHashtable(int size,
                    int cap,
                    float lf)
Creates the URL Hashtable.
Parameters:
size - the maximum capacity
cap - the starting capacity (used to improve performance)
lf - the amount with which current capacity frows

LRUHashtable

public LRUHashtable(int size,
                    int cap)
Creates the URL Hashtable with growing capacity 0.75.
Parameters:
size - the maximum capacity
cap - the starting capacity (used to improve performance)

LRUHashtable

public LRUHashtable(int size)
Creates the URL Hashtable with starting capacity 101 and growing capacity 0.75.
Parameters:
size - the maximum capacity

LRUHashtable

public LRUHashtable()
Creates the URL Hashtable with maximum capacity 100, starting capacity 101, and growing capacity 0.75.
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Store an element in the table.
Overrides:
put in class java.util.Hashtable
Returns:
the original value of the element if it existed, null if it could not be found

getCount

public int getCount(java.lang.Object key)
Retrieve the getcount of the key object
Returns:
the times the key has been requested

get

public java.lang.Object get(java.lang.Object key)
Retrieve an element from the table.
Overrides:
get in class java.util.Hashtable
Returns:
the value of the element, or null if it could not be found

remove

public java.lang.Object remove(java.lang.Object key)
Remove an element from the table.
Overrides:
remove in class java.util.Hashtable
Returns:
the original value of the element if it existed, null if it could not be found

size

public int size()
Return the current size of the table
Overrides:
size in class java.util.Hashtable

setSize

public void setSize(int size)
Change the maximum size of the table. This may result in removal of entries in the table.

getSize

public int getSize()
Return the maximum size of the table

toString

public java.lang.String toString()
Returns a description of the table. The information shown includes current size, maximum size, ratio of misses and hits, and a description of the underlying hashtable
Overrides:
toString in class java.util.Hashtable

toString

public java.lang.String toString(boolean which)
Returns a description of the table. The information shown includes current size, maximum size, ratio of misses and hits, and either a description of the underlying hashtable, or a list of all stored values.
Parameters:
which - if true, the stored values are described.
Returns:
a description of the table.

clear

public void clear()
Clears the table.
Overrides:
clear in class java.util.Hashtable

containsKey

public boolean containsKey(java.lang.Object key)
Checks if an element exists in the table, searching by key.
Overrides:
containsKey in class java.util.Hashtable

contains

public boolean contains(java.lang.Object value)
Checks if an element exists in the table, searching by value.
Overrides:
contains in class java.util.Hashtable

clone

public java.lang.Object clone()
NOT IMPLEMENTED
Overrides:
clone in class java.util.Hashtable

elements

public java.util.Enumeration elements()
Returns an Enumeration on the table's element values.
Overrides:
elements in class java.util.Hashtable

isEmpty

public boolean isEmpty()
Returns true if no elements are in the table.
Overrides:
isEmpty in class java.util.Hashtable

keys

public java.util.Enumeration keys()
Returns an Enumeration on the table's element keys.
Overrides:
keys in class java.util.Hashtable

getRatio

public double getRatio()
Returns the ratio of hits and misses. The higher the ratio, the more succesfull the table retrieval is. A value of 1 means every attempt to retrieve data is succesfull, while a value nearing 0 means most times the object requested it is not available. Generally a high ratio means the table can be shrunk, while a low ratio means its size needs to be increased.

getHits

public int getHits()
Returns the number of times an element was succesfully retrieved from the table.

getMisses

public int getMisses()
Returns the number of times an element cpould not be retrieved from the table.

getPuts

public int getPuts()
Returns the number of times an element was committed to the table.

getStats

public java.lang.String getStats()
Returns statistics on this table. The information shown includes number of accesses, ratio of misses and hits, current size, and number of puts.

getOrderedElements

public java.util.Enumeration getOrderedElements()

getOrderedElements

public java.util.Enumeration getOrderedElements(int maxnumber)


MMBase 2001