Package org.djunits.value
Class IndexedValue<U extends Unit<U>,S extends Scalar<U,S>,T extends IndexedValue<U,S,T,D>,D extends Storage<D>>
java.lang.Object
org.djunits.value.IndexedValue<U,S,T,D>
- Type Parameters:
U
- the unit typeS
- the scalar type for the U unitT
- the value type for this unitD
- the data storage type
- All Implemented Interfaces:
Serializable
,Cloneable
,Value<U,
T>
public abstract class IndexedValue<U extends Unit<U>,S extends Scalar<U,S>,T extends IndexedValue<U,S,T,D>,D extends Storage<D>>
extends Object
implements Value<U,T>
AbstractIndexedValue.java.
Copyright (c) 2019-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
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
Count the number of cells that have a non-zero SI value.protected final void
Check the copyOnWrite flag and, if it is set, make a deep copy of the data and clear the flag.clone()
protected abstract D
getData()
Retrieve the data object.final U
Retrieve the unit of this Value.Return the class of the corresponding scalar.final StorageType
Return the StorageType (DENSE, SPARSE, etc.) for the stored vector.final T
Turn the immutable flag on for this vector.protected final boolean
Retrieve the value of the copyOnWrite flag.final boolean
isDense()
Return whether the internal storage type of the indexed value is dense or not.final boolean
Return whether the data is mutable or not.final boolean
isSparse()
Return whether the internal storage type of the indexed value is sparse or not.final T
mutable()
Turn the immutable flag off for this internal storage.protected final void
setCopyOnWrite
(boolean copyOnWrite) Change the copyOnWrite flag.protected abstract void
Set the data object.void
setDisplayUnit
(U newUnit) Set a new display unit for the value.protected final void
setMutable
(boolean mutable) Set helper flag to indicate whether the data is mutable or not.abstract T
toDense()
Create and return a dense version of this internal storage.abstract T
toSparse()
Create and return a sparse version of this internal storage.
-
Constructor Details
-
IndexedValue
Construct a new IndexedValue.- Parameters:
displayUnit
- U; the unit of the new AbstractValue
-
-
Method Details
-
getDisplayUnit
Description copied from interface:Value
Retrieve the unit of this Value. -
setDisplayUnit
Description copied from interface:Value
Set a new display unit for the value. Internally, the value will stay stored in the default or SI unit. -
getData
Retrieve the data object. Method can only be used within package and by subclasses.- Returns:
- D; the internal data
-
setData
Set the data object. Method can only be used within package and by subclasses.- Parameters:
data
- D; the internal data
-
getStorageType
Return the StorageType (DENSE, SPARSE, etc.) for the stored vector.- Returns:
- StorageType; the storage type (DENSE, SPARSE, etc.) for the stored vector
-
checkCopyOnWrite
protected final void checkCopyOnWrite()Check the copyOnWrite flag and, if it is set, make a deep copy of the data and clear the flag.- Throws:
ValueRuntimeException
- if the vector is immutable
-
isCopyOnWrite
protected final boolean isCopyOnWrite()Retrieve the value of the copyOnWrite flag.- Returns:
- boolean
-
setCopyOnWrite
protected final void setCopyOnWrite(boolean copyOnWrite) Change the copyOnWrite flag.- Parameters:
copyOnWrite
- boolean; the new value for the copyOnWrite flag
-
isMutable
public final boolean isMutable()Return whether the data is mutable or not.- Returns:
- boolean; whether the data is mutable or not
-
setMutable
protected final void setMutable(boolean mutable) Set helper flag to indicate whether the data is mutable or not.- Parameters:
mutable
- boolean; helper flag to indicate whether the data is mutable or not
-
immutable
Turn the immutable flag on for this vector.- Returns:
- T; the vector with a raised immutable flag
-
mutable
Turn the immutable flag off for this internal storage.- Returns:
- T; the internal storage with a cleared immutable flag
-
isDense
public final boolean isDense()Return whether the internal storage type of the indexed value is dense or not.- Returns:
- boolean; whether the internal storage type of the indexed value is dense or not
-
isSparse
public final boolean isSparse()Return whether the internal storage type of the indexed value is sparse or not.- Returns:
- boolean; whether the internal storage type of the indexed value is sparse or not
-
cardinality
public final int cardinality()Count the number of cells that have a non-zero SI value.- Returns:
- int; the number of cells having non-zero SI value
-
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.- Returns:
- T; a dense version of this internal storage
-
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.- Returns:
- T; a sparse version of this internal storage
-
getScalarClass
Return the class of the corresponding scalar.- Returns:
- Class<S>; the class of the corresponding scalar
-
clone
-