Class ConcurrentIntrusiveList<T extends ConcurrentIntrusiveList.Element<T>>
java.lang.Object
io.opencensus.implcore.trace.internal.ConcurrentIntrusiveList<T>
@ThreadSafe
public final class ConcurrentIntrusiveList<T extends ConcurrentIntrusiveList.Element<T>>
extends Object
An
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;
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis is an interface that must be implemented by any element that usesConcurrentIntrusiveList. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentIntrusiveList(int capacity) Constructs a newConcurrentIntrusiveList. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddElement(T element) Adds the givenelementto the list.voidclear()Clears all the elements from the list.getAll()Returns all the elements from this list.booleanremoveElement(T element) Removes the givenelementfrom the list.intsize()Returns the number of elements in this list.
-
Field Details
-
capacity
private final int capacity -
size
private int size -
head
-
-
Constructor Details
-
ConcurrentIntrusiveList
public ConcurrentIntrusiveList(int capacity) Constructs a newConcurrentIntrusiveList.- Parameters:
capacity- must be greater than0.
-
-
Method Details
-
addElement
Adds the givenelementto the list. If the number of elements will be larger than the capacity then the oldest element in the list will be removed.- Parameters:
element- the element to add.- Returns:
falseif the element is already in the list or if adding this element will exceed capacity.
-
removeElement
Removes the givenelementfrom the list.- Parameters:
element- the element to remove.
-
size
public int size()Returns the number of elements in this list.- Returns:
- the number of elements in this list.
-
clear
public void clear()Clears all the elements from the list. -
getAll
Returns all the elements from this list.- Returns:
- all the elements from this list.
-