org.scijava.util
Class LastRecentlyUsed<T>

java.lang.Object
  extended by org.scijava.util.LastRecentlyUsed<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>

public class LastRecentlyUsed<T>
extends Object
implements Iterable<T>, Collection<T>

A simple container for N last-recently-used items.

Author:
Johannes Schindelin

Constructor Summary
LastRecentlyUsed(int size)
           
 
Method Summary
 boolean add(T value)
          Add a new newest entry.
 boolean addAll(Collection<? extends T> values)
           
 void addToEnd(T value)
          Add a new oldest entry.
protected  void assertConsistency()
           
 void clear()
          Empties the data structure.
 boolean contains(Object value)
           
 boolean containsAll(Collection<?> values)
           
 T get(int index)
          Returns the entry for the given index.
 boolean isEmpty()
           
 Iterator<T> iterator()
          Returns an Iterator.
 int lookup(T value)
          Looks up the index for a given entry.
 int next(int index)
          Given the index of an entry, returns the index of the next newer entry.
 int previous(int index)
          Given the index of an entry, returns the index of the next older entry.
 boolean remove(Object value)
           
 boolean removeAll(Collection<?> values)
           
 boolean replace(int index, T newValue)
           
 boolean retainAll(Collection<?> values)
           
 int size()
           
 Object[] toArray()
           
<S> S[]
toArray(S[] array)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

LastRecentlyUsed

public LastRecentlyUsed(int size)
Method Detail

next

public int next(int index)
Given the index of an entry, returns the index of the next newer entry.

Parameters:
index - the index of the current entry, or -1 to wrap around to the oldest entry.
Returns:
the index of the next newer entry, or -1 when there is no such entry.

previous

public int previous(int index)
Given the index of an entry, returns the index of the next older entry.

Parameters:
index - the index of the current entry, or -1 to wrap around to the newest entry.
Returns:
the index of the next older entry, or -1 when there is no such entry.

get

public T get(int index)
Returns the entry for the given index.

Parameters:
index - the index of the entry
Returns:
the entry

lookup

public int lookup(T value)
Looks up the index for a given entry.

Parameters:
value - the value of the entry to find
Returns:
the corresponding index, or -1 if the entry was not found

add

public boolean add(T value)
Add a new newest entry.

Specified by:
add in interface Collection<T>
Parameters:
value - the value of the entry
Returns:
whether the entry was added

addToEnd

public void addToEnd(T value)
Add a new oldest entry.

This method helps recreating LastRecentlyUsed instances given the entries in the order newest first, oldest last.

Parameters:
value - the value of the entry to add

replace

public boolean replace(int index,
                       T newValue)

clear

public void clear()
Empties the data structure.

Specified by:
clear in interface Collection<T>

addAll

public boolean addAll(Collection<? extends T> values)
Specified by:
addAll in interface Collection<T>

contains

public boolean contains(Object value)
Specified by:
contains in interface Collection<T>

containsAll

public boolean containsAll(Collection<?> values)
Specified by:
containsAll in interface Collection<T>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<T>

remove

public boolean remove(Object value)
Specified by:
remove in interface Collection<T>

removeAll

public boolean removeAll(Collection<?> values)
Specified by:
removeAll in interface Collection<T>

retainAll

public boolean retainAll(Collection<?> values)
Specified by:
retainAll in interface Collection<T>

size

public int size()
Specified by:
size in interface Collection<T>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<T>

toArray

public <S> S[] toArray(S[] array)
Specified by:
toArray in interface Collection<T>

iterator

public Iterator<T> iterator()
Returns an Iterator.

Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>
Returns:
the iterator

assertConsistency

protected void assertConsistency()


Copyright © 2009–2014 SciJava. All rights reserved.