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 unitS
- the scalar with unit UV
- 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
Modifier and TypeClassDescriptionprotected class
The iterator class is loosely based in AbstractList.Itr. -
Field Summary
Modifier and TypeFieldDescriptionprotected FloatVectorData
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
(FloatFunction floatFunction) 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
(FloatVector<?, ?, ?> 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 FloatVectorData
getData()
Retrieve the data object.final float
getInUnit
(int index) Retrieve the value stored at a specified position in the original unit.final float
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
hashCode()
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.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
(FloatVectorData data) Set the data object.void
setInUnit
(int index, float 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, float 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
-
FloatVector
FloatVector(FloatVectorData data, U unit) Construct a new FloatVector.- Parameters:
data
- FloatVectorData; 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 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 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 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 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 FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData> - 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 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
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 classVector<U extends Unit<U>,
S extends FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData> - 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:
- float; 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 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
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
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:
- float; 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
- float; 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
- float; 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
- float; 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 FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData> - 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 FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData> - 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 FloatScalar<U, S>, V extends FloatVector<U, S, V>, FloatVectorData> - 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:
floatFunction
- FloatFunction; 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
- FloatVector<?, ?, ?>; other FloatVector- 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.
-