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 interface
Selection.ComparableSelection<T extends Comparable<T>>
Selection of Comparable elements.static interface
Double specific Selectionstatic interface
Integer specific Selectionstatic interface
Long specific Selectionstatic interface
Selection.NumberSelection<T extends Number & Comparable<T>>
Selection where all the elements are a subclass ofNumber
. -
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
default void
clear()
first()
Alias forget(int)
where index=0;default T
firstOrElse
(T other) Alias forgetOrElse(int, Object)
where index=0.default T
Alias forgetOrFail(int)
where index=0.get
(int index) Fetch a value at a specific index in theSelection
.default T
Fetch a value at a specific index in theSelection
.default T
getOrFail
(int index) Fetch a value at a specific index in theSelection
.last()
Alias forget(int)
where index = size()-1;default T
lastOrElse
(T other) Alias forgetOrElse(int, Object)
where index = size()-1.default T
Alias forgetOrFail(int)
where index = size()-1.default boolean
default boolean
removeAll
(Collection<?> c) default boolean
default boolean
retainAll
(Collection<?> c) default T
sole()
Fetch the single value in this Selection, throwing an exception if size()!=1;default T
soleOrElse
(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:
add
in interfaceCollection<T>
-
remove
- Specified by:
remove
in interfaceCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
-
clear
default void clear()- Specified by:
clear
in interfaceCollection<T>
-
removeIf
- Specified by:
removeIf
in interfaceCollection<T>
-