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 unitS- the scalar with unit UV- 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-2025 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 ClassesModifier and TypeClassDescriptionprotected classThe iterator class is loosely based in AbstractList.Itr. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DoubleVectorDataThe stored data as an object, can be sparse or dense. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Vabs()Return a new Scalar/Vector/Matrix with absolute value(s).final Vassign(DoubleFunction doubleFunction) Execute a function on a cell by cell basis.final Vceil()Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).protected final voidcheckIndex(int index) Check that a provided index is valid.protected final voidcheckSize(DoubleVector<?, ?, ?> other) Centralized size equality check.booleanfinal Vfloor()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 DoubleVectorDatagetData()Retrieve the data object.final doublegetInUnit(int index) Retrieve the value stored at a specified position in the original unit.final doubleRetrieve the value stored at a specified position converted into a specified unit.S[]Return the vector as an array of scalars.final doublegetSI(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.inthashCode()abstract SinstantiateScalarSI(double valueSI, U displayUnit) Instantiate a new scalar for the class of this vector.abstract VinstantiateVector(DoubleVectorData dvd, U displayUnit) Instantiate a new vector of the class of this vector.iterator()Create and return an iterator over the scalars in this vector in proper sequence.final Vneg()Return a new Scalar/Vector/Matrix with negated value(s).final Vrint()Return a new Scalar/Vector/Matrix with the nearest integer value(s).voidSet the scalar value at the specified position.protected voidsetData(DoubleVectorData data) Set the data object.voidsetInUnit(int index, double valueInUnit) Set the value, specified in the (current) display unit, at the specified position.voidSet the value, specified in thevalueUnit, at the specified position.final voidsetSI(int index, double valueSI) Set the value, specified in the standard SI unit, at the specified position.final intsize()Retrieve the size of the vector.toDense()Create and return a dense version of this internal storage.toSparse()Create and return a sparse version of this internal storage.toString()Concise description of this value.toString(boolean verbose, boolean withUnit) Somewhat verbose description of this value with optional type and unit information.Somewhat verbose description of this value with the values expressed in the specified unit.Somewhat verbose description of this value with the values expressed in the specified unit.Methods inherited from class org.djunits.value.IndexedValue
cardinality, checkCopyOnWrite, clone, getDisplayUnit, getScalarClass, getStorageType, immutable, isCopyOnWrite, isDense, isMutable, isSparse, mutable, setCopyOnWrite, setDisplayUnit, setMutableMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface org.djunits.value.Value
isAbsolute, isRelative
-
Field Details
-
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- an internal data objectunit- the unit
-
-
Method Details
-
instantiateVector
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- the data used to instantiate the vectordisplayUnit- the display unit of the vector- Returns:
- a vector of the correct type
-
instantiateScalarSI
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- the SI value of the scalardisplayUnit- the unit in which the value will be displayed- Returns:
- a scalar of the correct type, belonging to the vector type
-
getData
Description copied from class:IndexedValueRetrieve the data object. Method can only be used within package and by subclasses.- Specified by:
getDatain classIndexedValue<U extends Unit<U>,S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Returns:
- the internal data
-
setData
Description copied from class:IndexedValueSet the data object. Method can only be used within package and by subclasses.- Specified by:
setDatain classIndexedValue<U extends Unit<U>,S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Parameters:
data- the internal data
-
getValuesSI
public final double[] getValuesSI()Create a double[] array filled with the values in the standard SI unit.- Returns:
- 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:
- the values in the original unit
-
getValuesInUnit
Create a double[] array filled with the values converted into a specified unit.- Parameters:
targetUnit- the unit into which the values are converted for use- Returns:
- the values converted into the specified unit
-
size
public final int size()Description copied from class:VectorRetrieve the size of the vector.- Specified by:
sizein classVector<U extends Unit<U>,S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Returns:
- the size of the vector
-
checkIndex
Check that a provided index is valid.- Parameters:
index- the value to check- Throws:
IndexOutOfBoundsException- when index is invalid
-
getSI
Retrieve the value stored at a specified position in the standard SI unit.- Parameters:
index- index of the value to retrieve- Returns:
- value at position index in the standard SI unit
- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
get
Description copied from class:VectorRetrieve a value from the vector.- Specified by:
getin classVector<U extends Unit<U>,S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Parameters:
index- the index to retrieve the value at- Returns:
- the value as a Scalar
- Throws:
IndexOutOfBoundsException- in case index is out of bounds
-
getInUnit
Retrieve the value stored at a specified position in the original unit.- Parameters:
index- index of the value to retrieve- Returns:
- value at position index in the original unit
- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
getInUnit
Retrieve the value stored at a specified position converted into a specified unit.- Parameters:
index- index of the value to retrievetargetUnit- the unit for the result- Returns:
- value at position index converted into the specified unit
- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
setSI
Set the value, specified in the standard SI unit, at the specified position.- Parameters:
index- the index of the value to setvalueSI- the value, specified in the standard SI unit- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
setInUnit
Set the value, specified in the (current) display unit, at the specified position.- Parameters:
index- the index of the value to setvalueInUnit- the value, specified in the (current) display unit- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
setInUnit
Set the value, specified in thevalueUnit, at the specified position.- Parameters:
index- the index of the value to setvalueInUnit- the value, specified in the (current) display unitvalueUnit- the unit in which thevalueInUnitis expressed- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
set
Set the scalar value at the specified position.- Parameters:
index- the index of the value to setvalue- the value to set- Throws:
IndexOutOfBoundsException- when index out of range (index < 0 or index >= size())
-
getScalars
Description copied from class:VectorReturn the vector as an array of scalars.- Specified by:
getScalarsin classVector<U extends Unit<U>,S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Returns:
- the vector as an array of scalars
-
toSparse
Description copied from class:IndexedValueCreate 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:
toSparsein classIndexedValue<U extends Unit<U>,S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Returns:
- a sparse version of this internal storage
-
toDense
Description copied from class:IndexedValueCreate 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:
toDensein classIndexedValue<U extends Unit<U>,S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Returns:
- a dense version of this internal storage
-
assign
Execute a function on a cell by cell basis. Note: May be expensive when used on sparse data.- Parameters:
doubleFunction- the function to apply- Returns:
- this updated vector
-
abs
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with absolute value(s).- Returns:
- a new R with absolute value(s)
-
ceil
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).- Returns:
- a new R with absolute value(s)
-
floor
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).- Returns:
- a new R with absolute value(s)
-
neg
Description copied from interface:ValueReturn a new Scalar/Vector/Matrix with negated value(s).- Returns:
- a new R with negated value(s)
-
rint
Description copied from interface:ValueReturn 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:
- a new R with absolute value(s)
-
toString
Description copied from interface:ValueConcise description of this value. -
toString
Description copied from interface:ValueSomewhat verbose description of this value with the values expressed in the specified unit.- Parameters:
displayUnit- the unit into which the values are converted for display- Returns:
- printable string with the value contents expressed in the specified unit
-
toString
Description copied from interface:ValueSomewhat verbose description of this value with optional type and unit information.- Parameters:
verbose- if true; include type info; if false; exclude type infowithUnit- if true; include the unit; of false; exclude the unit- Returns:
- printable string with the value contents
-
toString
Description copied from interface:ValueSomewhat verbose description of this value with the values expressed in the specified unit.- Parameters:
displayUnit- the unit into which the values are converted for displayverbose- if true; include type info; if false; exclude type infowithUnit- if true; include the unit; of false; exclude the unit- Returns:
- printable string with the value contents
-
checkSize
Centralized size equality check.- Parameters:
other- other DoubleVector- Throws:
NullPointerException- when other vector is nullValueRuntimeException- when vectors have unequal size
-
hashCode
public int hashCode() -
equals
-
iterator
Description copied from class:VectorCreate and return an iterator over the scalars in this vector in proper sequence.
-