Class MruList
- java.lang.Object
-
- org.onemind.commons.java.datastructure.MruList
-
- All Implemented Interfaces:
java.lang.Iterable,java.util.Collection,java.util.Set
- Direct Known Subclasses:
MruMap.InnerMruList
public class MruList extends java.lang.Object implements java.util.SetMost 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
Nested Classes Modifier and Type Class Description protected static classMruList.MruEntryRepresent an entry in the MruListprotected static classMruList.MruIteratorAn iterator to the entries
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap_entryMapthe entries map *private long_lastCleanupTimethe last cleanup time *private java.util.TreeSet_mruListthe sorted mru list *private long_sizeLimitthe size *private long_timeoutthe timeout *
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccess(java.lang.Object o)Record that object o is being accessed.booleanadd(java.lang.Object o)booleanaddAll(java.util.Collection c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection c)voidexpireEntries(long t)Expire the entries that was last access longer that time t Document this method.protected voidexpireEntry(java.lang.Object obj)Remove the entry from the MruListlonggetLastAccessTime(java.lang.Object obj)Get the last access time object objbooleanisEmpty()java.util.Iteratoriterator()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection c)booleanretainAll(java.util.Collection c)intsize()java.lang.Object[]toArray()java.lang.Object[]toArray(java.lang.Object[] a)voidtruncateEntries(long size)Truncate the entries to specific sizeprotected voidtruncateEntry(java.lang.Object obj)Remove the object from the MruList
-
-
-
Field Detail
-
_entryMap
private java.util.HashMap _entryMap
the entries map *
-
_lastCleanupTime
private long _lastCleanupTime
the last cleanup time *
-
_mruList
private java.util.TreeSet _mruList
the sorted mru list *
-
_sizeLimit
private long _sizeLimit
the size *
-
_timeout
private long _timeout
the 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:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.Set- See Also:
access(java.lang.Object)
-
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAllin interfacejava.util.Collection- Specified by:
addAllin interfacejava.util.Set
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection- Specified by:
clearin interfacejava.util.Set
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection- Specified by:
containsin interfacejava.util.Set
-
containsAll
public boolean containsAll(java.util.Collection c)
- Specified by:
containsAllin interfacejava.util.Collection- Specified by:
containsAllin interfacejava.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:
isEmptyin interfacejava.util.Collection- Specified by:
isEmptyin interfacejava.util.Set
-
iterator
public java.util.Iterator iterator()
- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.Set
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection- Specified by:
removein interfacejava.util.Set
-
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAllin interfacejava.util.Collection- Specified by:
removeAllin interfacejava.util.Set
-
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAllin interfacejava.util.Collection- Specified by:
retainAllin interfacejava.util.Set
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection- Specified by:
sizein interfacejava.util.Set
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.Set
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.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
-
-