Class FloatVector<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>>

java.lang.Object
org.djunits.value.IndexedValue<U,S,V,D>
org.djunits.value.base.Vector<U,S,V,FloatVectorData>
org.djunits.value.vfloat.vector.base.FloatVector<U,S,V>
Type Parameters:
U - the unit
S - the scalar with unit U
V - the generic vector type
All Implemented Interfaces:
Serializable, Cloneable, Iterable<S>, Value<U,V>
Direct Known Subclasses:
FloatVectorAbs, FloatVectorRel

public abstract class FloatVector<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>> extends Vector<U,S,V,FloatVectorData>
The most basic abstract class for the FloatVector.

Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.

Author:
Alexander Verbraeck, Peter Knoppers
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
    The iterator class is loosely based in AbstractList.Itr.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected FloatVectorData
    The stored data as an object, can be sparse or dense.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a new FloatVector.
  • Method Summary

    Modifier and Type
    Method
    Description
    final V
    abs()
    Return a new Scalar/Vector/Matrix with absolute value(s).
    final V
    assign(FloatFunction floatFunction)
    Execute a function on a cell by cell basis.
    final V
    Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).
    protected final void
    checkIndex(int index)
    Check that a provided index is valid.
    protected final void
    checkSize(FloatVector<?,?,?> other)
    Centralized size equality check.
    boolean
     
    final V
    Return a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).
    get(int index)
    Retrieve a value from the vector.
    protected final FloatVectorData
    Retrieve the data object.
    final float
    getInUnit(int index)
    Retrieve the value stored at a specified position in the original unit.
    final float
    getInUnit(int index, U targetUnit)
    Retrieve the value stored at a specified position converted into a specified unit.
    S[]
    Return the vector as an array of scalars.
    final float
    getSI(int index)
    Retrieve the value stored at a specified position in the standard SI unit.
    final float[]
    Create a float[] array filled with the values in the original unit.
    final float[]
    getValuesInUnit(U targetUnit)
    Create a float[] array filled with the values converted into a specified unit.
    final float[]
    Create a float[] array filled with the values in the standard SI unit.
    int
     
    abstract S
    instantiateScalarSI(float valueSI, U displayUnit)
    Instantiate a new scalar for the class of this vector.
    abstract V
    instantiateVector(FloatVectorData fvd, U displayUnit)
    Instantiate a new vector of the class of this vector.
    Create and return an iterator over the scalars in this vector in proper sequence.
    final V
    neg()
    Return a new Scalar/Vector/Matrix with negated value(s).
    final V
    Return a new Scalar/Vector/Matrix with the nearest integer value(s).
    void
    set(int index, S value)
    Set the scalar value at the specified position.
    protected void
    Set the data object.
    void
    setInUnit(int index, float valueInUnit)
    Set the value, specified in the (current) display unit, at the specified position.
    void
    setInUnit(int index, float valueInUnit, U valueUnit)
    Set the value, specified in the valueUnit, at the specified position.
    final void
    setSI(int index, float valueSI)
    Set the value, specified in the standard SI unit, at the specified position.
    final int
    Retrieve the size of the vector.
    Create and return a dense version of this internal storage.
    Create and return a sparse version of this internal storage.
    Concise description of this value.
    toString(boolean verbose, boolean withUnit)
    Somewhat verbose description of this value with optional type and unit information.
    toString(U displayUnit)
    Somewhat verbose description of this value with the values expressed in the specified unit.
    toString(U displayUnit, boolean verbose, boolean withUnit)
    Somewhat verbose description of this value with the values expressed in the specified unit.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface org.djunits.value.Value

    isAbsolute, isRelative
  • Field Details

    • data

      protected FloatVectorData data
      The stored data as an object, can be sparse or dense.
  • Constructor Details

    • FloatVector

      FloatVector(FloatVectorData data, U unit)
      Construct a new FloatVector.
      Parameters:
      data - FloatVectorData; an internal data object
      unit - U; the unit
  • Method Details

    • instantiateVector

      public abstract V instantiateVector(FloatVectorData fvd, U displayUnit)
      Instantiate a new vector of the class of this vector. This can be used instead of the FloatVector.instiantiate() methods in case another vector of this class is known. The method is faster than FloatVector.instantiate, and it will also work if the vector is user-defined.
      Parameters:
      fvd - FloatVectorData; the data used to instantiate the vector
      displayUnit - U; the display unit of the vector
      Returns:
      V; a vector of the correct type
    • instantiateScalarSI

      public abstract S instantiateScalarSI(float valueSI, U displayUnit)
      Instantiate a new scalar for the class of this vector. This can be used instead of the FloatScalar.instiantiate() methods in case a vector of this class is known. The method is faster than FloatScalar.instantiate, and it will also work if the vector and/or scalar are user-defined.
      Parameters:
      valueSI - float; the SI value of the scalar
      displayUnit - U; the unit in which the value will be displayed
      Returns:
      S; a scalar of the correct type, belonging to the vector type
    • getData

      protected final FloatVectorData getData()
      Description copied from class: IndexedValue
      Retrieve the data object. Method can only be used within package and by subclasses.
      Specified by:
      getData in class IndexedValue<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Returns:
      D; the internal data
    • setData

      protected void setData(FloatVectorData data)
      Description copied from class: IndexedValue
      Set the data object. Method can only be used within package and by subclasses.
      Specified by:
      setData in class IndexedValue<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Parameters:
      data - D; the internal data
    • getValuesSI

      public final float[] getValuesSI()
      Create a float[] array filled with the values in the standard SI unit.
      Returns:
      float[]; array of values in the standard SI unit
    • getValuesInUnit

      public final float[] getValuesInUnit()
      Create a float[] array filled with the values in the original unit.
      Returns:
      float[]; the values in the original unit
    • getValuesInUnit

      public final float[] getValuesInUnit(U targetUnit)
      Create a float[] array filled with the values converted into a specified unit.
      Parameters:
      targetUnit - U; the unit into which the values are converted for use
      Returns:
      float[]; the values converted into the specified unit
    • size

      public final int size()
      Description copied from class: Vector
      Retrieve the size of the vector.
      Specified by:
      size in class Vector<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Returns:
      int; the size of the vector
    • checkIndex

      protected final void checkIndex(int index) throws IndexOutOfBoundsException
      Check that a provided index is valid.
      Parameters:
      index - int; the value to check
      Throws:
      IndexOutOfBoundsException - when index is invalid
    • getSI

      public final float getSI(int index) throws IndexOutOfBoundsException
      Retrieve the value stored at a specified position in the standard SI unit.
      Parameters:
      index - int; index of the value to retrieve
      Returns:
      float; value at position index in the standard SI unit
      Throws:
      IndexOutOfBoundsException - when index out of range (index < 0 or index >= size())
    • get

      public S get(int index) throws IndexOutOfBoundsException
      Description copied from class: Vector
      Retrieve a value from the vector.
      Specified by:
      get in class Vector<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Parameters:
      index - int; the index to retrieve the value at
      Returns:
      S; the value as a Scalar
      Throws:
      IndexOutOfBoundsException - in case index is out of bounds
    • getInUnit

      public final float getInUnit(int index) throws IndexOutOfBoundsException
      Retrieve the value stored at a specified position in the original unit.
      Parameters:
      index - int; index of the value to retrieve
      Returns:
      float; value at position index in the original unit
      Throws:
      IndexOutOfBoundsException - when index out of range (index < 0 or index >= size())
    • getInUnit

      public final float getInUnit(int index, U targetUnit) throws IndexOutOfBoundsException
      Retrieve the value stored at a specified position converted into a specified unit.
      Parameters:
      index - int; index of the value to retrieve
      targetUnit - U; the unit for the result
      Returns:
      float; value at position index converted into the specified unit
      Throws:
      IndexOutOfBoundsException - when index out of range (index < 0 or index >= size())
    • setSI

      public final void setSI(int index, float valueSI) throws IndexOutOfBoundsException
      Set the value, specified in the standard SI unit, at the specified position.
      Parameters:
      index - int; the index of the value to set
      valueSI - float; the value, specified in the standard SI unit
      Throws:
      IndexOutOfBoundsException - when index out of range (index < 0 or index >= size())
    • setInUnit

      public void setInUnit(int index, float valueInUnit) throws IndexOutOfBoundsException
      Set the value, specified in the (current) display unit, at the specified position.
      Parameters:
      index - int; the index of the value to set
      valueInUnit - float; the value, specified in the (current) display unit
      Throws:
      IndexOutOfBoundsException - when index out of range (index < 0 or index >= size())
    • setInUnit

      public void setInUnit(int index, float valueInUnit, U valueUnit) throws IndexOutOfBoundsException
      Set the value, specified in the valueUnit, at the specified position.
      Parameters:
      index - int; the index of the value to set
      valueInUnit - float; the value, specified in the (current) display unit
      valueUnit - U; the unit in which the valueInUnit is expressed
      Throws:
      IndexOutOfBoundsException - when index out of range (index < 0 or index >= size())
    • set

      public void set(int index, S value) throws IndexOutOfBoundsException
      Set the scalar value at the specified position.
      Parameters:
      index - int; the index of the value to set
      value - S; the value to set
      Throws:
      IndexOutOfBoundsException - when index out of range (index < 0 or index >= size())
    • getScalars

      public S[] getScalars()
      Description copied from class: Vector
      Return the vector as an array of scalars.
      Specified by:
      getScalars in class Vector<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Returns:
      S[]; the vector as an array of scalars
    • toSparse

      public V toSparse()
      Description copied from class: IndexedValue
      Create and return a sparse version of this internal storage. When the data was already sparse, the current version is returned and no copy will be made of the data.
      Specified by:
      toSparse in class IndexedValue<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Returns:
      T; a sparse version of this internal storage
    • toDense

      public V toDense()
      Description copied from class: IndexedValue
      Create and return a dense version of this internal storage. When the data was already dense, the current version is returned and no copy will be made of the data.
      Specified by:
      toDense in class IndexedValue<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Returns:
      T; a dense version of this internal storage
    • assign

      public final V assign(FloatFunction floatFunction)
      Execute a function on a cell by cell basis. Note: May be expensive when used on sparse data.
      Parameters:
      floatFunction - FloatFunction; the function to apply
      Returns:
      V; this updated vector
    • abs

      public final V abs()
      Description copied from interface: Value
      Return a new Scalar/Vector/Matrix with absolute value(s).
      Returns:
      R; a new R with absolute value(s)
    • ceil

      public final V ceil()
      Description copied from interface: Value
      Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).
      Returns:
      R; a new R with absolute value(s)
    • floor

      public final V floor()
      Description copied from interface: Value
      Return a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).
      Returns:
      R; a new R with absolute value(s)
    • neg

      public final V neg()
      Description copied from interface: Value
      Return a new Scalar/Vector/Matrix with negated value(s).
      Returns:
      R; a new R with negated value(s)
    • rint

      public final V rint()
      Description copied from interface: Value
      Return a new Scalar/Vector/Matrix with the nearest integer value(s). When the value is exactly in the middle between two integer values, the even one is returned.
      Returns:
      R; a new R with absolute value(s)
    • toString

      public String toString()
      Description copied from interface: Value
      Concise description of this value.
      Specified by:
      toString in interface Value<U extends Unit<U>,S extends FloatScalar<U,S>>
      Overrides:
      toString in class Object
      Returns:
      a String with the value, non-verbose, with the unit attached.
    • toString

      public String toString(U displayUnit)
      Description copied from interface: Value
      Somewhat verbose description of this value with the values expressed in the specified unit.
      Parameters:
      displayUnit - U; the unit into which the values are converted for display
      Returns:
      String; printable string with the value contents expressed in the specified unit
    • toString

      public String toString(boolean verbose, boolean withUnit)
      Description copied from interface: Value
      Somewhat verbose description of this value with optional type and unit information.
      Parameters:
      verbose - boolean; if true; include type info; if false; exclude type info
      withUnit - boolean; if true; include the unit; of false; exclude the unit
      Returns:
      String; printable string with the value contents
    • toString

      public String toString(U displayUnit, boolean verbose, boolean withUnit)
      Description copied from interface: Value
      Somewhat verbose description of this value with the values expressed in the specified unit.
      Parameters:
      displayUnit - U; the unit into which the values are converted for display
      verbose - boolean; if true; include type info; if false; exclude type info
      withUnit - boolean; if true; include the unit; of false; exclude the unit
      Returns:
      String; printable string with the value contents
    • checkSize

      protected final void checkSize(FloatVector<?,?,?> other) throws ValueRuntimeException
      Centralized size equality check.
      Parameters:
      other - FloatVector<?, ?, ?>; other FloatVector
      Throws:
      NullPointerException - when other vector is null
      ValueRuntimeException - when vectors have unequal size
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • iterator

      public Iterator<S> iterator()
      Description copied from class: Vector
      Create and return an iterator over the scalars in this vector in proper sequence.
      Specified by:
      iterator in interface Iterable<U extends Unit<U>>
      Specified by:
      iterator in class Vector<U extends Unit<U>,S extends FloatScalar<U,S>,V extends FloatVector<U,S,V>,FloatVectorData>
      Returns:
      Iterator<S>; an iterator over the scalars in this vector in proper sequence