public class LastRecentlyUsed<T> extends Object implements Collection<T>
N
last-recently-used items.Constructor and Description |
---|
LastRecentlyUsed(int size) |
Modifier and Type | Method and Description |
---|---|
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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public int next(int index)
index
- the index of the current entry, or -1 to wrap around to the oldest entry.public int previous(int index)
index
- the index of the current entry, or -1 to wrap around to the newest entry.public T get(int index)
index
- the index of the entrypublic int lookup(T value)
value
- the value of the entry to find-1
if the entry was not foundpublic boolean add(T value)
add
in interface Collection<T>
value
- the value of the entrypublic void addToEnd(T value)
This method helps recreating LastRecentlyUsed
instances given the
entries in the order newest first, oldest last.
value
- the value of the entry to addpublic boolean replace(int index, T newValue)
public void clear()
clear
in interface Collection<T>
public boolean addAll(Collection<? extends T> values)
addAll
in interface Collection<T>
public boolean contains(Object value)
contains
in interface Collection<T>
public boolean containsAll(Collection<?> values)
containsAll
in interface Collection<T>
public boolean isEmpty()
isEmpty
in interface Collection<T>
public boolean remove(Object value)
remove
in interface Collection<T>
public boolean removeAll(Collection<?> values)
removeAll
in interface Collection<T>
public boolean retainAll(Collection<?> values)
retainAll
in interface Collection<T>
public int size()
size
in interface Collection<T>
public Object[] toArray()
toArray
in interface Collection<T>
public <S> S[] toArray(S[] array)
toArray
in interface Collection<T>
protected void assertConsistency()
Copyright © 2015–2022 SciJava. All rights reserved.