org.onemind.commons.java.datastructure
Class MruList

java.lang.Object
  extended byorg.onemind.commons.java.datastructure.MruList
All Implemented Interfaces:
java.util.Collection, java.util.Set

public class MruList
extends java.lang.Object
implements java.util.Set

Most recently used list implementation. It support entries expiration by access time.

Version:
$Id: MruList.java,v 1.4 2005/04/26 17:41:59 thlee Exp $ $Name: $
Author:
TiongHiang Lee (thlee@onemindsoft.org)

Nested Class Summary
protected static class MruList.MruEntry
          Represent an entry in the MruList
protected static class MruList.MruIterator
          An iterator to the entries
 
Constructor Summary
MruList()
          {@inheritDoc}
MruList(long sizeLimit, long timeout)
          {@inheritDoc}
 
Method Summary
 boolean access(java.lang.Object o)
          Record that object o is being accessed.
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
          
 void clear()
          
 boolean contains(java.lang.Object o)
          
 boolean containsAll(java.util.Collection c)
          
 void expireEntries(long t)
          Expire the entries that was last access longer that time t Document this method.
protected  void expireEntry(java.lang.Object obj)
          Remove the entry from the MruList
 long getLastAccessTime(java.lang.Object obj)
          Get the last access time object obj
 boolean isEmpty()
          
 java.util.Iterator iterator()
          
 boolean remove(java.lang.Object o)
          
 boolean removeAll(java.util.Collection c)
          
 boolean retainAll(java.util.Collection c)
          
 int size()
          
 java.lang.Object[] toArray()
          
 java.lang.Object[] toArray(java.lang.Object[] a)
          
 void truncateEntries(long size)
          Truncate the entries to specific size
protected  void truncateEntry(java.lang.Object obj)
          Remove the object from the MruList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

MruList

public MruList()
{@inheritDoc}


MruList

public MruList(long sizeLimit,
               long timeout)
{@inheritDoc}

Parameters:
sizeLimit - the size limit of the MruList (0 for no size limit)
timeout - the timeout (0 for never timeout)
Method Detail

access

public boolean access(java.lang.Object o)
Record that object o is being accessed. This will put a timestamp to the object

Parameters:
o - the object
Returns:
true if the object was in the list before

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Set
See Also:
access(Object o)

addAll

public boolean addAll(java.util.Collection c)

Specified by:
addAll in interface java.util.Set

clear

public void clear()

Specified by:
clear in interface java.util.Set

contains

public boolean contains(java.lang.Object o)

Specified by:
contains in interface java.util.Set

containsAll

public boolean containsAll(java.util.Collection c)

Specified by:
containsAll in interface java.util.Set

expireEntries

public void expireEntries(long t)
Expire the entries that was last access longer that time t Document this method.

Parameters:
t - the elapse time

getLastAccessTime

public long getLastAccessTime(java.lang.Object obj)
Get the last access time object obj

Parameters:
obj - the object
Returns:
the access time, or -1 if the object is not in the cache

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Set

iterator

public java.util.Iterator iterator()

Specified by:
iterator in interface java.util.Set

remove

public boolean remove(java.lang.Object o)

Specified by:
remove in interface java.util.Set

removeAll

public boolean removeAll(java.util.Collection c)

Specified by:
removeAll in interface java.util.Set

retainAll

public boolean retainAll(java.util.Collection c)

Specified by:
retainAll in interface java.util.Set

size

public int size()

Specified by:
size in interface java.util.Set

toArray

public java.lang.Object[] toArray()

Specified by:
toArray in interface java.util.Set

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)

Specified by:
toArray in interface java.util.Set

truncateEntries

public void truncateEntries(long size)
Truncate the entries to specific size

Parameters:
size - the size

truncateEntry

protected void truncateEntry(java.lang.Object obj)
Remove the object from the MruList

Parameters:
obj - the object

expireEntry

protected void expireEntry(java.lang.Object obj)
Remove the entry from the MruList

Parameters:
obj - expire the entry


Copyright © 2004-2006 . All Rights Reserved.