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:
Serializable,Iterable<T>
final class RankedSequence<T>
extends AtomicReference<RankedSequence.Content>
implements Iterable<T>
Ordered
List that arranges elements by descending rank; supports concurrent iteration and modification.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classRepresents an immutable snapshot of ranked elements.(package private) final classCustomIteratorthat copes with modification by repositioning itself in the updated list. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleanbooleancontainsThis(Object element) voidInserts the given element into the ordered list, using the assigned rank as a guide.booleanisEmpty()iterator()peek()(package private) static longrank2uid(int rank, int uniq) Turns the given (potentially non-unique) rank into a unique id by appending a counter.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()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, weakCompareAndSetVolatileMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
RankedSequence
RankedSequence() -
RankedSequence
RankedSequence(RankedSequence<T> sequence)
-
-
Method Details
-
insert
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
-
contains
-
containsThis
-
remove
-
removeThis
-
snapshot
-
clear
public void clear() -
isEmpty
public boolean isEmpty() -
size
public int size() -
iterator
-
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
-