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.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
Nested Classes Modifier and Type Class Description protected static class
MruList.MruEntry
Represent an entry in the MruListprotected static class
MruList.MruIterator
An iterator to the entries
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap
_entryMap
the entries map *private long
_lastCleanupTime
the last cleanup time *private java.util.TreeSet
_mruList
the sorted mru list *private long
_sizeLimit
the size *private long
_timeout
the timeout *
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 MruListlong
getLastAccessTime(java.lang.Object obj)
Get the last access time object objboolean
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 sizeprotected void
truncateEntry(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:
add
in interfacejava.util.Collection
- Specified by:
add
in interfacejava.util.Set
- See Also:
access(java.lang.Object)
-
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAll
in interfacejava.util.Collection
- Specified by:
addAll
in interfacejava.util.Set
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection
- Specified by:
clear
in interfacejava.util.Set
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection
- Specified by:
contains
in interfacejava.util.Set
-
containsAll
public boolean containsAll(java.util.Collection c)
- Specified by:
containsAll
in interfacejava.util.Collection
- Specified by:
containsAll
in 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:
isEmpty
in interfacejava.util.Collection
- Specified by:
isEmpty
in interfacejava.util.Set
-
iterator
public java.util.Iterator iterator()
- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
- Specified by:
iterator
in interfacejava.util.Set
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection
- Specified by:
remove
in interfacejava.util.Set
-
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAll
in interfacejava.util.Collection
- Specified by:
removeAll
in interfacejava.util.Set
-
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAll
in interfacejava.util.Collection
- Specified by:
retainAll
in interfacejava.util.Set
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection
- Specified by:
size
in interfacejava.util.Set
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection
- Specified by:
toArray
in interfacejava.util.Set
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Specified by:
toArray
in interfacejava.util.Collection
- Specified by:
toArray
in 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
-
-