Package org.eclipse.sisu.inject
Class RankedSequence<T>
- java.lang.Object
-
- java.util.concurrent.atomic.AtomicReference<RankedSequence.Content>
-
- org.eclipse.sisu.inject.RankedSequence<T>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<T>
final class RankedSequence<T> extends java.util.concurrent.atomic.AtomicReference<RankedSequence.Content> implements java.lang.Iterable<T>
OrderedList
that arranges elements by descending rank; supports concurrent iteration and modification.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
RankedSequence.Content
Represents an immutable snapshot of ranked elements.(package private) class
RankedSequence.Itr
CustomIterator
that copes with modification by repositioning itself in the updated list.
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description RankedSequence()
RankedSequence(RankedSequence<T> sequence)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
contains(java.lang.Object element)
boolean
containsThis(java.lang.Object element)
void
insert(T element, int rank)
Inserts the given element into the ordered list, using the assigned rank as a guide.boolean
isEmpty()
RankedSequence.Itr
iterator()
T
peek()
(package private) static long
rank2uid(int rank, int uniq)
Turns the given (potentially non-unique) rank into a unique id by appending a counter.T
remove(java.lang.Object element)
boolean
removeThis(T element)
(package private) static int
safeBinarySearch(long[] uids, long uid)
Finds the insertion point with the nearest UID, regardless of whether the UID is in the list or not.int
size()
java.lang.Iterable<T>
snapshot()
(package private) static int
uid2rank(long uid)
Extracts the original (potentially non-unique) assigned rank from the given unique id.-
Methods inherited from class java.util.concurrent.atomic.AtomicReference
accumulateAndGet, compareAndExchange, compareAndExchangeAcquire, compareAndExchangeRelease, compareAndSet, get, getAcquire, getAndAccumulate, getAndSet, getAndUpdate, getOpaque, getPlain, lazySet, set, setOpaque, setPlain, setRelease, toString, updateAndGet, weakCompareAndSet, weakCompareAndSetAcquire, weakCompareAndSetPlain, weakCompareAndSetRelease, weakCompareAndSetVolatile
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RankedSequence
RankedSequence()
-
RankedSequence
RankedSequence(RankedSequence<T> sequence)
-
-
Method Detail
-
insert
public void insert(T element, int rank)
Inserts the given element into the ordered list, using the assigned rank as a guide.The rank can be any value from
Integer.MIN_VALUE
toInteger.MAX_VALUE
.- Parameters:
element
- The element to insertrank
- The assigned rank
-
peek
public T peek()
-
contains
public boolean contains(java.lang.Object element)
-
containsThis
public boolean containsThis(java.lang.Object element)
-
remove
public T remove(java.lang.Object element)
-
removeThis
public boolean removeThis(T element)
-
snapshot
public java.lang.Iterable<T> snapshot()
-
clear
public void clear()
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
iterator
public RankedSequence.Itr iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
rank2uid
static long rank2uid(int rank, int uniq)
Turns the given (potentially non-unique) rank into a unique id by appending a counter.- Parameters:
rank
- The assigned rankuniq
- The unique counter- Returns:
- The unique id
-
uid2rank
static int uid2rank(long uid)
Extracts the original (potentially non-unique) assigned rank from the given unique id.- Parameters:
uid
- The unique id- Returns:
- Assigned rank
-
safeBinarySearch
static int safeBinarySearch(long[] uids, long uid)
Finds the insertion point with the nearest UID, regardless of whether the UID is in the list or not.Unlike
Arrays.binarySearch(long[], long)
this will always return a number from zero tosize()
inclusive.- Parameters:
uids
- The UIDs arrayuid
- The UID to find- Returns:
- Index with nearest UID
-
-