Package org.eclipse.sisu.inject
Class RankedSequence<T>
java.lang.Object
org.eclipse.sisu.inject.RankedSequence<T>
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescription(package private) RankedSequence.Contentprivate static final AtomicReferenceFieldUpdater<RankedSequence, RankedSequence.Content> private static final long -
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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
CONTENT_UPDATER
private static final AtomicReferenceFieldUpdater<RankedSequence,RankedSequence.Content> CONTENT_UPDATER -
-
-
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
-