Package org.djunits.value
Class AbstractIndexedValue<U extends Unit<U>,S extends Scalar<U,S>,T extends AbstractIndexedValue<U,S,T,D>,D extends AbstractStorage<D>>
java.lang.Object
org.djunits.value.AbstractValue<U,T>
org.djunits.value.AbstractIndexedValue<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
,ValueFunctions<U,T>
,IndexedValue<U,S,T>
,Value<U,T>
- Direct Known Subclasses:
AbstractDoubleMatrix
,AbstractDoubleVector
,AbstractFloatMatrix
,AbstractFloatVector
public abstract class AbstractIndexedValue<U extends Unit<U>,S extends Scalar<U,S>,T extends AbstractIndexedValue<U,S,T,D>,D extends AbstractStorage<D>> extends AbstractValue<U,T> implements IndexedValue<U,S,T>, Cloneable
AbstractIndexedValue.java.
Copyright (c) 2019-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
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractIndexedValue(U unit)
Construct a new AbstractIndexedValue. -
Method Summary
Modifier and Type Method Description int
cardinality()
Count the number of cells that have a non-zero SI value.protected void
checkCopyOnWrite()
Check the copyOnWrite flag and, if it is set, make a deep copy of the data and clear the flag.T
clone()
protected abstract D
getData()
Retrieve the data object.StorageType
getStorageType()
Return the StorageType (DENSE, SPARSE, etc.) for the stored vector.T
immutable()
Turn the immutable flag on for this vector.protected boolean
isCopyOnWrite()
Retrieve the value of the copyOnWrite flag.boolean
isDense()
Return whether the internal storage type of the indexed value is dense or not.boolean
isMutable()
Return whether the data is mutable or not.boolean
isSparse()
Return whether the internal storage type of the indexed value is sparse or not.T
mutable()
Turn the immutable flag off for this internal storage.protected void
setCopyOnWrite(boolean copyOnWrite)
Change the copyOnWrite flag.protected abstract void
setData(D data)
Set the data object.protected void
setMutable(boolean mutable)
Set helper flag to indicate whether the data is mutable or not.Methods inherited from class org.djunits.value.AbstractValue
getDisplayUnit, isAbsolute, isRelative, setDisplayUnit
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.djunits.value.Value
getDisplayUnit, isAbsolute, isRelative, setDisplayUnit, toString, toString, toString, toString
-
Constructor Details
-
AbstractIndexedValue
Construct a new AbstractIndexedValue.- Parameters:
unit
- U; the unit
-
-
Method Details
-
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.- Specified by:
getStorageType
in interfaceIndexedValue<U extends Unit<U>,S extends Scalar<U,S>,T extends AbstractIndexedValue<U,S,T,D>>
- 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. -
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. -
mutable
Turn the immutable flag off for this internal storage. -
isDense
public final boolean isDense()Return 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. -
cardinality
public final int cardinality()Count the number of cells that have a non-zero SI value.- Specified by:
cardinality
in interfaceIndexedValue<U extends Unit<U>,S extends Scalar<U,S>,T extends AbstractIndexedValue<U,S,T,D>>
- Returns:
- int; the number of cells having non-zero SI value
-
clone
-