Class AbstractDoubleVector<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
java.lang.Object
org.djunits.value.AbstractValue<U,T>
org.djunits.value.AbstractIndexedValue<U,S,V,DoubleVectorData>
org.djunits.value.vdouble.vector.base.AbstractDoubleVector<U,S,V>
- Type Parameters:
U
- the unitS
- the scalar with unit UV
- the generic vector type
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<S>
,Vector<U,S,V>
,ValueFunctions<U,V>
,IndexedValue<U,S,V>
,Value<U,V>
,DoubleVectorInterface<U,S,V>
- Direct Known Subclasses:
AbstractDoubleVectorAbs
,AbstractDoubleVectorRel
public abstract class AbstractDoubleVector<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>> extends AbstractIndexedValue<U,S,V,DoubleVectorData> implements DoubleVectorInterface<U,S,V>
The most basic abstract class for the DoubleVector.
Copyright (c) 2013-2019 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, Wouter Schakel
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractDoubleVector.Itr
The iterator class is loosely based in AbstractList.Itr.Nested classes/interfaces inherited from interface org.djunits.value.base.Vector
Vector.Abs<AU extends AbsoluteLinearUnit<AU,RU>,A extends Scalar<AU,A>,AV extends Vector.Abs<AU,A,AV,RU,R,RV>,RU extends Unit<RU>,R extends Scalar<RU,R>,RV extends Vector.RelWithAbs<AU,A,AV,RU,R,RV>>, Vector.Rel<U extends Unit<U>,S extends Scalar<U,S>,RV extends Vector.Rel<U,S,RV>>, Vector.RelWithAbs<AU extends AbsoluteLinearUnit<AU,RU>,A extends Scalar<AU,A>,AV extends Vector.Abs<AU,A,AV,RU,R,RV>,RU extends Unit<RU>,R extends Scalar<RU,R>,RV extends Vector.RelWithAbs<AU,A,AV,RU,R,RV>>
-
Field Summary
Fields Modifier and Type Field Description protected DoubleVectorData
data
The stored data as an object, can be sparse or dense. -
Constructor Summary
Constructors Constructor Description AbstractDoubleVector(DoubleVectorData data, U unit)
Construct a new AbstractDoubleVector. -
Method Summary
Modifier and Type Method Description V
abs()
Return a new Scalar/Vector/Matrix with absolute value(s).V
assign(DoubleFunction doubleFunction)
Execute a function on a cell by cell basis.V
ceil()
Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).protected void
checkIndex(int index)
Check that a provided index is valid.protected void
checkSize(DoubleVectorInterface<?,?,?> other)
Centralized size equality check.boolean
equals(Object obj)
V
floor()
Return a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).S
get(int index)
Retrieve a value from the vector.protected DoubleVectorData
getData()
Retrieve the data object.double
getInUnit(int index)
Retrieve the value stored at a specified position in the original unit.double
getInUnit(int index, U targetUnit)
Retrieve the value stored at a specified position converted into a specified unit.S[]
getScalars()
Return the vector as an array of scalars.double
getSI(int index)
Retrieve the value stored at a specified position in the standard SI unit.double[]
getValuesInUnit()
Create a double[] array filled with the values in the original unit.double[]
getValuesInUnit(U targetUnit)
Create a double[] array filled with the values converted into a specified unit.double[]
getValuesSI()
Create a double[] array filled with the values in the standard SI unit.int
hashCode()
Iterator<S>
iterator()
Create and return an iterator over the scalars in this vector in proper sequence.V
neg()
Return a new Scalar/Vector/Matrix with negated value(s).V
rint()
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
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
setInUnit(int index, double valueInUnit, U valueUnit)
Set the value, specified in thevalueUnit
, at the specified position.void
setSI(int index, double valueSI)
Set the value, specified in the standard SI unit, at the specified position.int
size()
Retrieve the size of the vector.V
toDense()
Create and return a dense version of this internal storage.V
toSparse()
Create and return a sparse version of this internal storage.String
toString()
Concise description of this value.String
toString(boolean verbose, boolean withUnit)
Somewhat verbose description of this value with optional type and unit information.String
toString(U displayUnit)
Somewhat verbose description of this value with the values expressed in the specified unit.String
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 org.djunits.value.AbstractIndexedValue
cardinality, checkCopyOnWrite, clone, getStorageType, immutable, isCopyOnWrite, isDense, isMutable, isSparse, mutable, setCopyOnWrite, setMutable
Methods inherited from class org.djunits.value.AbstractValue
getDisplayUnit, isAbsolute, isRelative, setDisplayUnit
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.djunits.value.vdouble.vector.base.DoubleVectorInterface
instantiateScalarSI, instantiateVector
Methods inherited from interface org.djunits.value.IndexedValue
cardinality, getScalarClass, getStorageType, immutable, isDense, isMutable, isSparse, mutable
Methods inherited from interface org.djunits.value.Value
getDisplayUnit, isAbsolute, isRelative, setDisplayUnit
-
Field Details
-
data
The stored data as an object, can be sparse or dense.
-
-
Constructor Details
-
AbstractDoubleVector
AbstractDoubleVector(DoubleVectorData data, U unit)Construct a new AbstractDoubleVector.- Parameters:
data
- DoubleVectorData; an internal data objectunit
- U; the unit
-
-
Method Details
-
getData
Retrieve the data object. Method can only be used within package and by subclasses.- Specified by:
getData
in classAbstractIndexedValue<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>,DoubleVectorData>
- Returns:
- D; the internal data
-
setData
Set the data object. Method can only be used within package and by subclasses.- Specified by:
setData
in classAbstractIndexedValue<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<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.- Specified by:
getValuesSI
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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.- Specified by:
getValuesInUnit
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- Returns:
- double[]; the values in the original unit
-
getValuesInUnit
Create a double[] array filled with the values converted into a specified unit.- Specified by:
getValuesInUnit
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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. -
checkIndex
Check that a provided index is valid.- Parameters:
index
- int; the value to check- Throws:
ValueRuntimeException
- when index is invalid
-
getSI
Retrieve the value stored at a specified position in the standard SI unit.- Specified by:
getSI
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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
Retrieve a value from the vector.- Specified by:
get
in interfaceVector<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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
Retrieve the value stored at a specified position in the original unit.- Specified by:
getInUnit
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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
Retrieve the value stored at a specified position converted into a specified unit.- Specified by:
getInUnit
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
setSI
Set the value, specified in the standard SI unit, at the specified position.- Specified by:
setSI
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- Parameters:
index
- int; the index of the value to setvalueSI
- double; the value, specified in the standard SI unit- Throws:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
setInUnit
Set the value, specified in the (current) display unit, at the specified position.- Specified by:
setInUnit
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- Parameters:
index
- int; the index of the value to setvalueInUnit
- double; the value, specified in the (current) display unit- Throws:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
setInUnit
Set the value, specified in thevalueUnit
, at the specified position.- Specified by:
setInUnit
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
set
Set the scalar value at the specified position.- Specified by:
set
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- Parameters:
index
- int; the index of the value to setvalue
- S; the value to set- Throws:
ValueRuntimeException
- when index out of range (index < 0 or index >= size())
-
getScalars
Return the vector as an array of scalars.- Specified by:
getScalars
in interfaceVector<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- Returns:
- S[]; the vector as an array of scalars
-
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 interfaceIndexedValue<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- Returns:
- T; a sparse version of this internal storage
-
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 interfaceIndexedValue<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- 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.- Specified by:
assign
in interfaceDoubleVectorInterface<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>,V extends AbstractDoubleVector<U,S,V>>
- Parameters:
doubleFunction
- DoubleFunction; the function to apply- Returns:
- V; this updated vector
-
abs
Return a new Scalar/Vector/Matrix with absolute value(s).- Specified by:
abs
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
ceil
Return a new Scalar/Vector/Matrix with the nearest integer value(s) above the current value(s).- Specified by:
ceil
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
floor
Return a new Scalar/Vector/Matrix with the nearest integer value(s) below the current value(s).- Specified by:
floor
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
neg
Return a new Scalar/Vector/Matrix with negated value(s).- Specified by:
neg
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>>
- Returns:
- R; a new R with negated value(s)
-
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.- Specified by:
rint
in interfaceValueFunctions<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>>
- Returns:
- R; a new R with absolute value(s)
-
toString
Concise description of this value. -
toString
Somewhat verbose description of this value with the values expressed in the specified unit. -
toString
Somewhat verbose description of this value with optional type and unit information.- Specified by:
toString
in interfaceValue<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>>
- 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
Somewhat verbose description of this value with the values expressed in the specified unit.- Specified by:
toString
in interfaceValue<U extends Unit<U>,S extends AbstractDoubleScalar<U,S>>
- 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
- AbstractDoubleVector<U, ?>; other DoubleVector- Throws:
NullPointerException
- when other vector is nullValueRuntimeException
- when vectors have unequal size
-
hashCode
public int hashCode() -
equals
-
iterator
Create and return an iterator over the scalars in this vector in proper sequence.
-