@ThreadSafe public final class ConcurrentIntrusiveList<T extends ConcurrentIntrusiveList.Element<T>> extends Object
ConcurrentIntrusiveList<T> is a doubly-linked list where the link pointers are
embedded in the elements. This makes insertion and removal into a known position constant time.
Elements must derive from the Element<T extends Element<T>> interface:
class MyClass implements Element<MyClass> {
private MyClass next = null;
private MyClass prev = null;
@Override
MyClass getNext() {
return next;
}
@Override
void setNext(MyClass element) {
next = element;
}
@Override
MyClass getPrev() {
return prev;
}
@Override
void setPrev(MyClass element) {
prev = element;
}
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
ConcurrentIntrusiveList.Element<T extends ConcurrentIntrusiveList.Element<T>>
This is an interface that must be implemented by any element that uses
ConcurrentIntrusiveList. |
| Constructor and Description |
|---|
ConcurrentIntrusiveList(int capacity)
Constructs a new
ConcurrentIntrusiveList. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addElement(T element)
Adds the given
element to the list. |
void |
clear()
Clears all the elements from the list.
|
Collection<T> |
getAll()
Returns all the elements from this list.
|
boolean |
removeElement(T element)
Removes the given
element from the list. |
int |
size()
Returns the number of elements in this list.
|
public ConcurrentIntrusiveList(int capacity)
ConcurrentIntrusiveList.capacity - must be greater than 0.public boolean addElement(T element)
element to the list. If the number of elements will be larger than the
capacity then the oldest element in the list will be removed.element - the element to add.false if the element is already in the list or if adding this element will
exceed capacity.public boolean removeElement(T element)
element from the list.element - the element to remove.public int size()
public void clear()
public Collection<T> getAll()