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>
OrderedListthat arranges elements by descending rank; supports concurrent iteration and modification.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classRankedSequence.ContentRepresents an immutable snapshot of ranked elements.(package private) classRankedSequence.ItrCustomIteratorthat copes with modification by repositioning itself in the updated list.
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUID
-
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 voidclear()booleancontains(java.lang.Object element)booleancontainsThis(java.lang.Object element)voidinsert(T element, int rank)Inserts the given element into the ordered list, using the assigned rank as a guide.booleanisEmpty()RankedSequence.Itriterator()Tpeek()(package private) static longrank2uid(int rank, int uniq)Turns the given (potentially non-unique) rank into a unique id by appending a counter.Tremove(java.lang.Object element)booleanremoveThis(T element)(package private) static intsafeBinarySearch(long[] uids, long uid)Finds the insertion point with the nearest UID, regardless of whether the UID is in the list or not.intsize()java.lang.Iterable<T>snapshot()(package private) static intuid2rank(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_VALUEtoInteger.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:
iteratorin 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
-
-