Class LRUQueue<T>
- java.lang.Object
-
- fr.gouv.vitam.storage.offers.tape.cache.LRUQueue<T>
-
- Type Parameters:
T- the type of elements maintained by this queue.
@NotThreadSafe public class LRUQueue<T> extends java.lang.ObjectSorted Least Recently Used (LRU) queue implementation. Entries are sorted usinglongtimestamp. Oldest entries are returned first. TheLRUQueueclass is NOT thread safe. Concurrent access must be synchronized.
-
-
Constructor Summary
Constructors Constructor Description LRUQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T entry, long timestamp)Adds an entry to the queue.booleancontains(T entry)Returnstrueif this queue contains the specified entry.booleanisEmpty()java.util.Iterator<T>iterator()Returns an iterator over the queue.booleanremove(T entry)Removes an entry from the queueintsize()booleanupdate(T entry, long timestamp)Updates an existing entry timestamp
-
-
-
Method Detail
-
add
public void add(T entry, long timestamp) throws java.lang.IllegalArgumentException
Adds an entry to the queue. If entry already exists, anIllegalArgumentExceptionis thrown.- Parameters:
entry- the entry to add to the queuetimestamp- the entry timestamp to set- Throws:
java.lang.IllegalArgumentException- if entry already exists
-
update
public boolean update(T entry, long timestamp)
Updates an existing entry timestamp- Parameters:
entry- the existing entry to updatetimestamp- the entry timestamp to update- Returns:
trueis entry has been updated,falseif entry was not found.
-
contains
public boolean contains(T entry)
Returnstrueif this queue contains the specified entry.- Parameters:
entry- the entry whose presence in this queue is to be tested- Returns:
trueis the entry exists in the queue.
-
remove
public boolean remove(T entry)
Removes an entry from the queue- Parameters:
entry- the entry to remove- Returns:
trueis the entry was removed,falseotherwise.
-
iterator
public java.util.Iterator<T> iterator()
Returns an iterator over the queue. Older entries are returned first. Iterator supportsIterator.remove()to remove entries while iterating.- Returns:
- An iterator over the elements of the queue.
-
isEmpty
public boolean isEmpty()
- Returns:
trueis the queue is empty,falseotherwise.
-
size
public int size()
- Returns:
- queue size
-
-