Class ArrayVector.Longs

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

private static class ArrayVector.Longs extends ArrayVector<Long>
A vector backed by an array of type long[]. This class handles signed values. The ArrayVector.UnsignedLongs subclass handle unsigned long values.
  • Field Details

    • serialVersionUID

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

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

    • Longs

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

    • getElementType

      public final Class<Long> getElementType()
      Returns the type of elements in the backing array.
      Specified by:
      getElementType in interface CheckedContainer<Long>
      Specified by:
      getElementType in class Vector
      Returns:
      the type of elements in this vector.
      See Also:
    • isEmptyOrNaN

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

      public final 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:
    • isInteger

      public final boolean isInteger()
      Values in this vector are guaranteed to be integers.
      Overrides:
      isInteger in class Vector
      Returns:
      true if this vector contains only integer values.
    • stringValue

      public 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:
    • size

      public final int size()
      Description copied from class: Vector
      Returns the number of elements in this vector.
      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.
    • 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.
    • get

      public final 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)
      Description copied from class: Vector
      Sets the number at the given index. The given number should be an instance of the same type than the number returned by Vector.get(int). If not, the stored value may lost precision as a result of the cast.
      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.
    • 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

      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.
    • increment

      public final Number increment(double tolerance)
      Returns the increment between values if this increment is constant, or null otherwise. Addition or subtraction of unsigned integers are bitwise identical to the same operations on signed integers. Consequently, we do not need to distinguish the two cases during the loop.
      Overrides:
      increment in class Vector
      Parameters:
      tolerance - the tolerance threshold for verifying if the increment is constant.
      Returns:
      the increment as a signed value, or null if the increment is not constant.
    • 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.
    • hashCode

      public final 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.