Class Vector.SubSampling

All Implemented Interfaces:
Serializable, Iterable<Number>, Collection<Number>, List<Number>, RandomAccess
Enclosing class:
Vector

private final class Vector.SubSampling extends Vector implements Serializable
A view over another vector in a range of index.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • first

      final int first
      Index of the first element in the enclosing vector.
    • step

      final int step
      The index increment. May be negative but not zero.
    • length

      final int length
      The length of this vector.
  • Constructor Details

    • SubSampling

      SubSampling(int first, int step, int length)
      Creates a new view over the given range.
  • Method Details

    • backingVector

      Vector backingVector()
      Returns the backing vector.
      Overrides:
      backingVector in class Vector
    • toBacking

      final int toBacking(int index)
      Returns the index where to look for the value in the enclosing vector.
    • toBacking

      int[] toBacking(int[] index)
      Returns the index where to look for the value in the enclosing vector.
      Overrides:
      toBacking in class Vector
      Parameters:
      index - the indexes given by the user.
      Returns:
      the indexes to use. Must be a new array in order to protect it from user changes.
    • getElementType

      public Class<? extends Number> getElementType()
      Returns the type of elements in this vector.
      Specified by:
      getElementType in class Vector
      Returns:
      the type of elements in this vector.
      See Also:
    • isSinglePrecision

      public boolean isSinglePrecision()
      Returns whether values are convertible to float type.
      Overrides:
      isSinglePrecision in class Vector
      Returns:
      whether values in this vector can be casted to float primitive type.
      See Also:
    • size

      public int size()
      Returns the length of this subvector.
      Specified by:
      size in interface Collection<Number>
      Specified by:
      size in interface List<Number>
      Specified by:
      size in class Vector
      Returns:
      the number of elements in this vector.
    • isUnsigned

      public boolean isUnsigned()
      Delegates to the enclosing vector.
      Overrides:
      isUnsigned in class Vector
      Returns:
      true if the integer values shall be interpreted as unsigned values.
    • isNaN

      public boolean isNaN(int index)
      Description copied from class: Vector
      Returns true if the value at the given index is null or NaN.
      Specified by:
      isNaN in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      true if the value at the given index is NaN.
    • doubleValue

      public double doubleValue(int index)
      Description copied from class: Vector
      Returns the value at the given index as a double. This is the safest method since all primitive types supported by Vector are convertible to the double type.
      Specified by:
      doubleValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
      See Also:
    • floatValue

      public float floatValue(int index)
      Description copied from class: Vector
      Returns the value at the given index as a float. This method may result in a lost of precision if this vector stores or computes its values with the double type.

      The default implementation delegates to Vector.doubleValue(int) and cast the result to float.

      Overrides:
      floatValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
      See Also:
    • longValue

      public long longValue(int index)
      Description copied from class: Vector
      Returns the value at the given index as a long. If this vector uses floating point values, the value is rounded to the nearest integer.

      The default implementation delegates to Vector.doubleValue(int) and verifies if the result can be rounded to a long with an error not greater than 0.5. Subclasses that store or compute their values with an integer type should override this method.

      Overrides:
      longValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
    • intValue

      public int intValue(int index)
      Description copied from class: Vector
      Returns the value at the given index as an int. If this vector uses floating point values, the value is rounded to the nearest integer.

      The default implementation delegates to Vector.longValue(int) and verifies if the result fits in the int type. Subclasses that store or compute their values with the int, short or byte type should override this method.

      Overrides:
      intValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
    • shortValue

      public short shortValue(int index)
      Description copied from class: Vector
      Returns the value at the given index as a short. If this vector uses floating point values, the value is rounded to the nearest integer.

      The default implementation delegates to Vector.longValue(int) and verifies if the result fits in the short type. Subclasses that store or compute their values with the short or byte type should override this method.

      Overrides:
      shortValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
    • byteValue

      public byte byteValue(int index)
      Description copied from class: Vector
      Returns the value at the given index as a byte. If this vector uses floating point values, the value is rounded to the nearest integer.

      The default implementation delegates to Vector.longValue(int) and verifies if the result fits in the byte type. Subclasses that store or compute their values with the byte type should override this method.

      Overrides:
      byteValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index.
    • stringValue

      public String stringValue(int index)
      Description copied from class: Vector
      Returns a string representation of the value at the given index. Invoking this method is generally equivalent to invoking String.valueOf(get(index)) except if the values are unsigned integers.
      Specified by:
      stringValue in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      a string representation of the value at the given index (may be null).
      See Also:
    • get

      public Number get(int index)
      Description copied from class: Vector
      Returns the number at the given index, or null if none. The object returned by this method is usually an instance of the class returned by Vector.getElementType(), but may also be an instance of a wider type if this is necessary for representing the values.
      Example: if Vector.getElementType() returns Byte.class but Vector.isUnsigned() returns true, then this method will rather return instances of Short because that type is the smallest Java primitive type capable to hold byte values in the [0 … 255] range. But the elements are still stored internally as byte, and the vector cannot accept values outside the [0 … 255] range even if they are valid Short values.
      The class of returned objects should be stable. For example, this method should not use different types for different range of values. This stability is recommended but not guaranteed because Vector can also wrap arbitrary Number[] arrays.
      Specified by:
      get in interface List<Number>
      Specified by:
      get in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      the value at the given index (may be null).
    • set

      public Number set(int index, Number v)
      Delegates to the enclosing vector.
      Specified by:
      set in interface List<Number>
      Specified by:
      set in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      v - the value to set at the given index.
      Returns:
      the value previously stored at the given index.
    • createTransform

      Vector createTransform(double scale, double offset)
      Delegates to the enclosing vector.
      Overrides:
      createTransform in class Vector
    • createSubSampling

      Vector createSubSampling(int first, int step, int length)
      Delegates to the enclosing vector.
      Overrides:
      createSubSampling in class Vector
    • createConcatenate

      Vector createConcatenate(Vector toAppend)
      Delegates to the enclosing vector if possible.
      Overrides:
      createConcatenate in class Vector
    • range

      NumberRange<?> range(IntSupplier indices, int n)
      Delegates to the enclosing vector
      Overrides:
      range in class Vector
      Parameters:
      indices - supplier of indices of the values to examine for computing the range, or null for the 0, 1, 2, … n-1 sequence.
      n - number of indices to get from the supplier.
      Returns:
      the range of all values at the given indices.
    • compress

      public Vector compress(double tolerance)
      If the vector cannot be compressed, copies data in a new vector in order to have a smaller vector than the one backing this view. This is advantageous only on the assumption that user do not keep a reference to the original vector after Vector.compress(double) call.
      Overrides:
      compress in class Vector
      Parameters:
      tolerance - maximal difference allowed between original and compressed vectors (can be zero).
      Returns:
      a more compact vector with the same data than this vector, or this.
    • buffer

      public Optional<Buffer> buffer()
      Returns a buffer over the sub-section represented by this SubSampling instance.
      Overrides:
      buffer in class Vector
      Returns:
      the vector data as a buffer. Absent if this vector is not backed by an array or a buffer.