Package com.terracottatech.store
Interface Selection<T>
- Type Parameters:
T- element type
- All Superinterfaces:
Collection<T>,Iterable<T>
- All Known Subinterfaces:
Selection.ComparableSelection<T>,Selection.DoubleSelection,Selection.IntSelection,Selection.LongSelection,Selection.NumberSelection<T>,TypedValueSelection
- All Known Implementing Classes:
SelectionImpl,TypedValueSelectionImpl
Read only, random accessible heap of typed values. Values can be iterated over,
and fetched by index. Negative indexes reference values from the end of the
heap; get(-1) returns the last entry, etc.
Selections form a middle ground between Java Collection and
List. They lack the mutability of Lists, but do support
indexed random addressing.
Selections support access to the first and last elements, arbitrary index elements access, etc.
All of the mutation functions throw UnsupportedOperationException.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceSelection.ComparableSelection<T extends Comparable<T>>Selection of Comparable elements.static interfaceDouble specific Selectionstatic interfaceInteger specific Selectionstatic interfaceLong specific Selectionstatic interfaceSelection.NumberSelection<T extends Number & Comparable<T>>Selection where all the elements are a subclass ofNumber. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleandefault voidclear()first()Alias forget(int)where index=0;default TfirstOrElse(T other) Alias forgetOrElse(int, Object)where index=0.default TAlias forgetOrFail(int)where index=0.get(int index) Fetch a value at a specific index in theSelection.default TFetch a value at a specific index in theSelection.default TgetOrFail(int index) Fetch a value at a specific index in theSelection.last()Alias forget(int)where index = size()-1;default TlastOrElse(T other) Alias forgetOrElse(int, Object)where index = size()-1.default TAlias forgetOrFail(int)where index = size()-1.default booleandefault booleanremoveAll(Collection<?> c) default booleandefault booleanretainAll(Collection<?> c) default Tsole()Fetch the single value in this Selection, throwing an exception if size()!=1;default TsoleOrElse(T other) Fetch the single value is the size()==1, return the alternative if size()=0, throw an exception is size()>1.Methods inherited from interface java.util.Collection
addAll, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, size, spliterator, stream, toArray, toArray, toArray
-
Method Details
-
get
Fetch a value at a specific index in theSelection. If the resolved index is outside the bounds of 0...size(), Optional.empty() will be returned. It supports negative indexes to allow for easy retrieval of tail values.- Parameters:
index- 0..size()-1, returns the value at the index. If < 0, returns the value at size()-index (so -1 returns the last, -2 returns 1 from the last, etc).- Returns:
- Optional of value.
-
getOrElse
Fetch a value at a specific index in theSelection. If the resolved index is outside the bounds of 0...size(), the supplied value is returned. It supports negative indexes to allow for easy retrieval of tail values.- Parameters:
index- 0..size()-1, returns the value at the index. If < 0, returns the value at size()-index (so -1 returns the last, -2 returns 1 from the last, etc).other- alternate value to be returned if not found- Returns:
- value
-
getOrFail
Fetch a value at a specific index in theSelection. If the resolved index is outside the bounds of 0...size(), a NoSuchValueException is thrown. It supports negative indexes to allow for easy retrieval of tail values.- Parameters:
index- 0..size()-1, returns the value at the index. If < 0, returns the value at size()-index (so -1 returns the last, -2 returns 1 from the last, etc).- Returns:
- value.
-
sole
Fetch the single value in this Selection, throwing an exception if size()!=1;- Returns:
- value
-
soleOrElse
Fetch the single value is the size()==1, return the alternative if size()=0, throw an exception is size()>1.- Parameters:
other- alt value- Returns:
- value or other value
-
first
Alias forget(int)where index=0;- Returns:
- Optional of T
-
firstOrElse
Alias forgetOrElse(int, Object)where index=0.- Returns:
- T
-
firstOrFail
Alias forgetOrFail(int)where index=0.- Returns:
- T
-
last
Alias forget(int)where index = size()-1;- Returns:
- Optional of T
-
lastOrElse
Alias forgetOrElse(int, Object)where index = size()-1.- Returns:
- T
-
lastOrFail
Alias forgetOrFail(int)where index = size()-1.- Returns:
- T
-
add
- Specified by:
addin interfaceCollection<T>
-
remove
- Specified by:
removein interfaceCollection<T>
-
removeAll
- Specified by:
removeAllin interfaceCollection<T>
-
retainAll
- Specified by:
retainAllin interfaceCollection<T>
-
clear
default void clear()- Specified by:
clearin interfaceCollection<T>
-
removeIf
- Specified by:
removeIfin interfaceCollection<T>
-