Class ArrayVector.Floats

All Implemented Interfaces:
Serializable, Iterable<Number>, Collection<Number>, List<Number>, RandomAccess, CheckedContainer<Float>
Direct Known Subclasses:
ArrayVector.Decimal
Enclosing class:
ArrayVector<E extends Number>

private static class ArrayVector.Floats extends ArrayVector<Float>
A vector backed by an array of type float[]. In this class, conversions to the double type use the standard Java cast operator (i.e. the double value is padded with zero fraction digits in its base 2 representation). The ArrayVector.Decimal subclass overrides this behavior with a more costly cast that tries to preserve the representation in base 10.
  • Field Details

    • serialVersionUID

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

      private final float[] array
      The backing array.
  • Constructor Details

    • Floats

      Floats(float[] array)
      Creates a new vector for the given array.
  • Method Details

    • getElementType

      public final Class<Float> getElementType()
      Returns the type of elements in the backing array.
      Specified by:
      getElementType in interface CheckedContainer<Float>
      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 final int size()
      Returns the length of the backing array.
      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.
    • isNaN

      public final boolean isNaN(int index)
      Returns true if the value at the given index is NaN.
      Overrides:
      isNaN in class ArrayVector<Float>
      Parameters:
      index - the index in the [0 … size-1] range.
      Returns:
      true if the value at the given index is NaN.
    • stringValue

      public final String stringValue(int index)
      Returns the string representation at the given index.
      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:
    • doubleValue

      public double doubleValue(int index)
      Returns the value at the given index.
      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 final 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:
    • 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 final Number set(int index, Number value)
      Sets the value at the given index.
      Specified by:
      set in interface List<Number>
      Specified by:
      set in class Vector
      Parameters:
      index - the index in the [0 … size-1] range.
      value - the value to set at the given index.
      Returns:
      the value previously stored at the given index.
    • fill

      public void fill(int fromIndex, int toIndex, Number value)
      Sets the value of all elements in the given range.
      Overrides:
      fill in class Vector
      Parameters:
      fromIndex - index of the first element (inclusive) to be filled with the specified value.
      toIndex - index of the last element (exclusive) to be filled with the specified value.
      value - the value to be stored in elements of the vector.
    • indexOf

      final int indexOf(int toSearch, int index, boolean equality)
      Finds index of a match or mismatch (depending on equality).
      Overrides:
      indexOf in class Vector
      Parameters:
      toSearch - index of the value to search.
      index - index of the first value where to start the search.
      equality - whether we search the first equal value, or the first different value.
      Returns:
      index of the value found, or the vector size if the value has not been found.
    • isEmptyOrNaN

      public final boolean isEmptyOrNaN()
      Returns true if this vector is empty or contains only NaN values.
      Overrides:
      isEmptyOrNaN in class Vector
      Returns:
      whether this vector is empty or contains only NaN values.
    • equals

      final boolean equals(int lower, int upper, Vector other, int otherOffset)
      Returns whether this vector in the given range is equal to the specified vector.
      Overrides:
      equals in class Vector
      Parameters:
      lower - index of the first value to compare in this vector, inclusive.
      upper - index after the last value to compare in this vector.
      other - the other vector to compare values with this vector. May be this.
      otherOffset - index of the first element to compare in the other vector.
      Returns:
      whether values over the specified range of the two vectors are equal.
    • range

      final NumberRange<?> range(IntSupplier indices, int n)
      Finds the minimum and maximum values in the array or in a subset of the array.
      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.
    • createRange

      NumberRange<?> createRange(float min, float max)
      Creates a range from the given minimum and maximum values, inclusive. The default implementation creates a range of float, but this method is overridden by ArrayVector.Decimal which create a range of double.
    • buffer

      public final Optional<Buffer> buffer()
      Wraps this vector in a buffer.
      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.
    • floatValues

      public final float[] floatValues()
      Returns a copy of current data as a floating point array.
      Overrides:
      floatValues in class Vector
      Returns:
      a copy of all floating point values in this vector.
      See Also:
    • hashCode

      public int hashCode()
      Applies hash code contract specified Vector.hashCode().
      Specified by:
      hashCode in interface Collection<Number>
      Specified by:
      hashCode in interface List<Number>
      Overrides:
      hashCode in class Vector
      Returns:
      a hash code value for the values in this vector.