Package org.scijava.util
Class LastRecentlyUsed<T>
- java.lang.Object
-
- org.scijava.util.LastRecentlyUsed<T>
-
- All Implemented Interfaces:
Iterable<T>,Collection<T>
public class LastRecentlyUsed<T> extends Object implements Collection<T>
A simple container forNlast-recently-used items.- Author:
- Johannes Schindelin
-
-
Constructor Summary
Constructors Constructor Description LastRecentlyUsed(int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T value)Add a new newest entry.booleanaddAll(Collection<? extends T> values)voidaddToEnd(T value)Add a new oldest entry.protected voidassertConsistency()voidclear()Empties the data structure.booleancontains(Object value)booleancontainsAll(Collection<?> values)Tget(int index)Returns the entry for the given index.booleanisEmpty()Iterator<T>iterator()Returns anIterator.intlookup(T value)Looks up the index for a given entry.intnext(int index)Given the index of an entry, returns the index of the next newer entry.intprevious(int index)Given the index of an entry, returns the index of the next older entry.booleanremove(Object value)booleanremoveAll(Collection<?> values)booleanreplace(int index, T newValue)booleanretainAll(Collection<?> values)intsize()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, parallelStream, removeIf, spliterator, stream
-
-
-
-
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
-1if the entry was not found
-
add
public boolean add(T value)
Add a new newest entry.- Specified by:
addin interfaceCollection<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
LastRecentlyUsedinstances 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:
clearin interfaceCollection<T>
-
addAll
public boolean addAll(Collection<? extends T> values)
- Specified by:
addAllin interfaceCollection<T>
-
contains
public boolean contains(Object value)
- Specified by:
containsin interfaceCollection<T>
-
containsAll
public boolean containsAll(Collection<?> values)
- Specified by:
containsAllin interfaceCollection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<T>
-
remove
public boolean remove(Object value)
- Specified by:
removein interfaceCollection<T>
-
removeAll
public boolean removeAll(Collection<?> values)
- Specified by:
removeAllin interfaceCollection<T>
-
retainAll
public boolean retainAll(Collection<?> values)
- Specified by:
retainAllin interfaceCollection<T>
-
size
public int size()
- Specified by:
sizein interfaceCollection<T>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<T>
-
toArray
public <S> S[] toArray(S[] array)
- Specified by:
toArrayin interfaceCollection<T>
-
assertConsistency
protected void assertConsistency()
-
-