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-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
Modifier and TypeClassDescriptionprotected class
The iterator class is loosely based in AbstractList.Itr. -
Field Summary
Modifier and TypeFieldDescriptionprotected DoubleVectorData
The stored data as an object, can be sparse or dense. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal 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
ceil()
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
floor()
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
getData()
Retrieve the data object.final double
getInUnit
(int index) Retrieve the value stored at a specified position in the original unit.final double
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
hashCode()
abstract S
instantiateScalarSI
(double valueSI, U displayUnit) Instantiate a new scalar for the class of this vector.abstract V
instantiateVector
(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 V
neg()
Return a new Scalar/Vector/Matrix with negated value(s).final V
rint()
Return a new Scalar/Vector/Matrix with the nearest integer value(s).void
Set the scalar value at the specified position.protected void
setData
(DoubleVectorData data) Set the data object.void
setInUnit
(int index, double valueInUnit) Set the value, specified in the (current) display unit, at the specified position.void
Set the value, specified in thevalueUnit
, 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
size()
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, setMutable
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
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 objectunit
- U; 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
- DoubleVectorData; the data used to instantiate the vectordisplayUnit
- U; the display unit of the vector- Returns:
- V; 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
- double; the SI value of the scalardisplayUnit
- U; the unit in which the value will be displayed- Returns:
- S; a scalar of the correct type, belonging to the vector type
-
getData
Description copied from class:IndexedValue
Retrieve the data object. Method can only be used within package and by subclasses.- Specified by:
getData
in classIndexedValue<U extends Unit<U>,
S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Returns:
- D; the internal data
-
setData
Description copied from class:IndexedValue
Set the data object. Method can only be used within package and by subclasses.- Specified by:
setData
in classIndexedValue<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
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()Description copied from class:Vector
Retrieve the size of the vector.- Specified by:
size
in classVector<U extends Unit<U>,
S extends DoubleScalar<U, S>, V extends DoubleVector<U, S, V>, DoubleVectorData> - Returns:
- int; the size of the vector
-
checkIndex
Check that a provided index is valid.- Parameters:
index
- int; 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
- int; index of the value to retrieve- Returns:
- double; 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:Vector
Retrieve a value from the vector.- Specified by:
get
in classVector<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:
IndexOutOfBoundsException
- in case index is out of bounds
-
getInUnit
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:
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
- int; index of the value to retrievetargetUnit
- U; the unit for the result- Returns:
- double; 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
- int; the index of the value to setvalueSI
- double; 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
- int; the index of the value to setvalueInUnit
- double; 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
- int; the index of the value to setvalueInUnit
- double; the value, specified in the (current) display unitvalueUnit
- U; the unit in which thevalueInUnit
is expressed- Throws:
IndexOutOfBoundsException
- when index out of range (index < 0 or index >= size())
-
set
Set the scalar value at the specified position.- Parameters:
index
- int; the index of the value to setvalue
- S; the value to set- Throws:
IndexOutOfBoundsException
- when index out of range (index < 0 or index >= size())
-
getScalars
Description copied from class:Vector
Return the vector as an array of scalars.- Specified by:
getScalars
in classVector<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
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 classIndexedValue<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
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 classIndexedValue<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
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
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
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
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
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
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
Description copied from interface:Value
Concise description of this value. -
toString
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
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 infowithUnit
- boolean; if true; include the unit; of false; exclude the unit- Returns:
- String; printable string with the value contents
-
toString
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 displayverbose
- boolean; if true; include type info; if false; exclude type infowithUnit
- boolean; if true; include the unit; of false; exclude the unit- Returns:
- String; printable string with the value contents
-
checkSize
Centralized size equality check.- Parameters:
other
- DoubleVector<?, ?, ?>; other DoubleVector- Throws:
NullPointerException
- when other vector is nullValueRuntimeException
- when vectors have unequal size
-
hashCode
public int hashCode() -
equals
-
iterator
Description copied from class:Vector
Create and return an iterator over the scalars in this vector in proper sequence.
-