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

@API(status=STABLE) public interface ShortSlice extends ShortView, Slice<Short>
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 Details

    • empty

      static ShortSlice empty()
      Creates a new short slice which has no elements.
      Returns:
      A new short slice which has no elements.
    • of

      @NotNull static @NotNull ShortSlice of(short[] ref, int offset, int size)
      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

      @NotNull static @NotNull ShortSlice of(short... ref)
      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 a short 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

      @NotNull default @NotNull Short get(int index)
      Description copied from interface: Slice
      Retrieves an element of type Slice at the given index.
      Specified by:
      get in interface Slice<Short>
      Parameters:
      index - The index of the element which to retrieve.
      Returns:
      The element at the given index.
    • toShortArray

      short[] toShortArray(int offset, int size)
      Creates a new short array with the appropriate size, and copies all values from start to end into new newly created array using System.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 to end.
    • toShortArray

      default short[] toShortArray()
      Description copied from interface: ShortView
      Creates a new short array with the appropriate size, and copies all values into new newly created array using System.arraycopy(Object, int, Object, int, int).
      Specified by:
      toShortArray in interface ShortView
      Returns:
      A new array containing all elements referenced by this slice instance.
    • map

      default <R> R map(int index, @NotNull @NotNull ShortFunction<R> function)
      Maps the short value at the given index to a new object of type ShortSlice.
      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

      @NotNull default @NotNull Slice<Short> 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, see Slice.of(Object[]) and it's overloads.
      Specified by:
      asSlice in interface View<Short>
      Returns:
      A new slice instance with a reference to the same collection/array as this view instance.