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 Object
Sorted Least Recently Used (LRU) queue implementation. Entries are sorted using long timestamp. Oldest entries are returned first. The LRUQueue class is NOT thread safe. Concurrent access must be synchronized.
  • Constructor Details

    • LRUQueue

      public LRUQueue()
  • Method Details

    • add

      public void add(T entry, long timestamp) throws IllegalArgumentException
      Adds an entry to the queue. If entry already exists, an IllegalArgumentException is thrown.
      Parameters:
      entry - the entry to add to the queue
      timestamp - the entry timestamp to set
      Throws:
      IllegalArgumentException - if entry already exists
    • update

      public boolean update(T entry, long timestamp)
      Updates an existing entry timestamp
      Parameters:
      entry - the existing entry to update
      timestamp - the entry timestamp to update
      Returns:
      true is entry has been updated, false if entry was not found.
    • contains

      public boolean contains(T entry)
      Returns true if this queue contains the specified entry.
      Parameters:
      entry - the entry whose presence in this queue is to be tested
      Returns:
      true is 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:
      true is the entry was removed, false otherwise.
    • iterator

      public Iterator<T> iterator()
      Returns an iterator over the queue. Older entries are returned first. Iterator supports Iterator.remove() to remove entries while iterating.
      Returns:
      An iterator over the elements of the queue.
    • isEmpty

      public boolean isEmpty()
      Returns:
      true is the queue is empty, false otherwise.
    • size

      public int size()
      Returns:
      queue size