Package io.karma.sliced.slice
Interface ShortSlice
- All Superinterfaces:
Enumeration<Short>
,Iterable<Short>
,Resettable
,ResettableEnumeration<Short>
,ShortView
,Slice<Short>
,View<Short>
- All Known Subinterfaces:
MutableShortSlice
- All Known Implementing Classes:
ArrayShortSlice
,EmptyShortSlice
,MutableArrayShortSlice
A primitive specialization of a regular
Slice
<Short
>,
which allows mutating the start- and end-index of the slice.
This allows the reduction of allocation overhead in loops for example.- Since:
- 25/08/2022
-
Method Summary
Modifier and TypeMethodDescriptionasSlice()
Creates a new slice instance from this view instance containing the same underlying collection reference, or a newly created wrapper list if there's no specialization available for the type of the underlying collection.static ShortSlice
empty()
Creates a new short slice which has no elements.default @NotNull Short
get
(int index) Retrieves an element of typeSlice
at the given index.short
getShort
(int index) Retrieves ashort
value from this slice instance at the given index.default <R> R
map
(int index, @NotNull ShortFunction<R> function) Maps theshort
value at the given index to a new object of typeShortSlice
.static @NotNull ShortSlice
of
(short... ref) Creates a new slice instance which references the given array.static @NotNull ShortSlice
of
(short[] ref, int offset, int size) Creates a new slice instance which references the given array.default short[]
Creates a newshort
array with the appropriate size, and copies all values into new newly created array usingSystem.arraycopy(Object, int, Object, int, int)
.short[]
toShortArray
(int offset, int size) Creates a newshort
array with the appropriate size, and copies all values fromstart
toend
into new newly created array usingSystem.arraycopy(Object, int, Object, int, int)
.Methods inherited from interface java.util.Enumeration
asIterator, hasMoreElements, nextElement
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.karma.sliced.util.Resettable
reset
Methods inherited from interface io.karma.sliced.view.ShortView
iterator, shortIterator
Methods inherited from interface io.karma.sliced.slice.Slice
copy, copy, copy, copyArrayList, copyHashSet, forEachIndexed, getOptional, getOrElse, getOrThrow, map, offset, slice, toArray, toArray
Methods inherited from interface io.karma.sliced.view.View
contains, containsAll, containsAllRefs, containsRef, contentEquals, contentEquals, copyArrayList, copyHashSet, forAll, forAllIndexed, parallelStream, referencesEqual, referencesEqual, size, stream
-
Method Details
-
empty
Creates a new short slice which has no elements.- Returns:
- A new short slice which has no elements.
-
of
Creates a new slice instance which references the given array.- Parameters:
ref
- The array of which to create a slice.offset
- The index at which the newly created slice should begin.size
- The size of the newly created slice.- Returns:
- A new mutable slice instance, which references the given array.
-
of
Creates a new slice instance which references the given array.- Parameters:
ref
- The array of which to create a slice.- Returns:
- A new mutable slice instance, which references the given array.
-
getShort
short getShort(int index) Retrieves ashort
value from this slice instance at the given index.- Parameters:
index
- The index at which to retrieve the element.- Returns:
- The
short
value at the given index.
-
get
Description copied from interface:Slice
Retrieves an element of typeSlice
at the given index. -
toShortArray
short[] toShortArray(int offset, int size) Creates a newshort
array with the appropriate size, and copies all values fromstart
toend
into new newly created array usingSystem.arraycopy(Object, int, Object, int, int)
.- Parameters:
offset
- The index at which the newly created array should begin (relative to the offset of this slice).size
- The size of the newly created array.- Returns:
- A new array containing all elements from
start
toend
.
-
toShortArray
default short[] toShortArray()Description copied from interface:ShortView
Creates a newshort
array with the appropriate size, and copies all values into new newly created array usingSystem.arraycopy(Object, int, Object, int, int)
.- Specified by:
toShortArray
in interfaceShortView
- Returns:
- A new array containing all elements referenced by this slice instance.
-
map
Maps theshort
value at the given index to a new object of typeShortSlice
.- Type Parameters:
R
- The return value type.- Parameters:
index
- The index of the value to map.function
- The function to map the value with.- Returns:
- A new object of type
ShortSlice
.
-
asSlice
Description copied from interface:View
Creates a new slice instance from this view instance containing the same underlying collection reference, or a newly created wrapper list if there's no specialization available for the type of the underlying collection. Note If you want to create slices directly, seeSlice.of(Object[])
and it's overloads.
-