Class DoubleVector<U extends Unit<U>,S extends DoubleScalar<U,S>,V extends DoubleVector<U,S,V>>

java.lang.Object
org.djunits.value.IndexedValue<U,S,V,D>
org.djunits.value.base.Vector<U,S,V,DoubleVectorData>
org.djunits.value.vdouble.vector.base.DoubleVector<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:
DoubleVectorAbs, DoubleVectorRel

public abstract class DoubleVector<U extends Unit<U>,S extends DoubleScalar<U,S>,V extends DoubleVector<U,S,V>> extends Vector<U,S,V,DoubleVectorData>
The most basic abstract class for the DoubleVector.

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
    The stored data as an object, can be sparse or dense.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a new DoubleVector.
  • Method Summary

    Modifier and Type
    Method
    Description
    final V
    abs()
    Return a new Scalar/Vector/Matrix with absolute value(s).
    final V
    assign(DoubleFunction doubleFunction)
    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(DoubleVector<?,?,?> 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 DoubleVectorData
    Retrieve the data object.
    final double
    getInUnit(int index)
    Retrieve the value stored at a specified position in the original unit.
    final double
    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 double
    getSI(int index)
    Retrieve the value stored at a specified position in the standard SI unit.
    final double[]
    Create a double[] array filled with the values in the original unit.
    final double[]
    getValuesInUnit(U targetUnit)
    Create a double[] array filled with the values converted into a specified unit.
    final double[]
    Create a double[] array filled with the values in the standard SI unit.
    int
    abstract S
    instantiateScalarSI(double valueSI, U displayUnit)
    Instantiate a new scalar for the class of this vector.
    abstract V
    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, double valueInUnit)
    Set the value, specified in the (current) display unit, at the specified position.
    void
    setInUnit(int index, double valueInUnit, U valueUnit)
    Set the value, specified in the valueUnit, at the specified position.
    final void
    setSI(int index, double 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 DoubleVectorData data
      The stored data as an object, can be sparse or dense.
  • Constructor Details

    • DoubleVector

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

    • instantiateVector

      public abstract V instantiateVector(DoubleVectorData dvd, U displayUnit)
      Instantiate a new vector of the class of this vector. This can be used instead of the DoubleVector.instiantiate() methods in case another vector of this class is known. The method is faster than DoubleVector.instantiate, and it will also work if the vector is user-defined.
      Parameters:
      dvd - DoubleVectorData; 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(double valueSI, U displayUnit)
      Instantiate a new scalar for the class of this vector. This can be used instead of the DoubleScalar.instiantiate() methods in case a vector of this class is known. The method is faster than DoubleScalar.instantiate, and it will also work if the vector and/or scalar are user-defined.
      Parameters:
      valueSI - double; 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 DoubleVectorData getData()
      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 DoubleScalar<U,S>,V extends DoubleVector<U,S,V>,DoubleVectorData>
      Returns:
      D; the internal data
    • setData

      protected void setData(DoubleVectorData data)
      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 DoubleScalar<U,S>,V extends DoubleVector<U,S,V>,DoubleVectorData>
      Parameters:
      data - D; the internal data
    • getValuesSI

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

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

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

      public final int size()
      Retrieve the size of the vector.
      Specified by:
      size in class Vector<U extends Unit<U>,S extends DoubleScalar<U,S>,V extends DoubleVector<U,S,V>,DoubleVectorData>
      Returns:
      int; the size of the vector
    • checkIndex

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

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

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

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

      public final double getInUnit(int index, U targetUnit) throws ValueRuntimeException
      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:
      double; value at position index converted into the specified unit
      Throws:
      ValueRuntimeException - when index out of range (index < 0 or index >= size())
    • setSI

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

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

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

      public void set(int index, S value) throws ValueRuntimeException
      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:
      ValueRuntimeException - when index out of range (index < 0 or index >= size())
    • getScalars

      public S[] getScalars()
      Return the vector as an array of scalars.
      Specified by:
      getScalars in class Vector<U extends Unit<U>,S extends DoubleScalar<U,S>,V extends DoubleVector<U,S,V>,DoubleVectorData>
      Returns:
      S[]; the vector as an array of scalars
    • toSparse

      public V toSparse()
      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 DoubleScalar<U,S>,V extends DoubleVector<U,S,V>,DoubleVectorData>
      Returns:
      T; a sparse version of this internal storage
    • toDense

      public V toDense()
      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 DoubleScalar<U,S>,V extends DoubleVector<U,S,V>,DoubleVectorData>
      Returns:
      T; a dense version of this internal storage
    • assign

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

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

      public final V ceil()
      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()
      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()
      Return a new Scalar/Vector/Matrix with negated value(s).
      Returns:
      R; a new R with negated value(s)
    • rint

      public final V rint()
      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()
      Concise description of this value.
      Specified by:
      toString in interface Value<U extends Unit<U>,S extends DoubleScalar<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)
      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)
      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)
      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(DoubleVector<?,?,?> other) throws ValueRuntimeException
      Centralized size equality check.
      Parameters:
      other - DoubleVector<?, ?, ?>; other DoubleVector
      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()
      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 DoubleScalar<U,S>,V extends DoubleVector<U,S,V>,DoubleVectorData>
      Returns:
      Iterator<S>; an iterator over the scalars in this vector in proper sequence