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 type
S - the scalar type for the U unit
T - the value type for this unit
D - the data storage type
All Implemented Interfaces:
Serializable, Cloneable, Value<U,T>
Direct Known Subclasses:
Matrix, Vector

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

    Constructors
    Constructor
    Description
    IndexedValue(U displayUnit)
    Construct a new IndexedValue.
  • Method Summary

    Modifier and Type
    Method
    Description
    final 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.
     
    protected abstract D
    Retrieve the data object.
    final U
    Retrieve the unit of this Value.
    abstract Class<S>
    Return the class of the corresponding scalar.
    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
    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
    Return whether the internal storage type of the indexed value is sparse or not.
    final T
    Turn the immutable flag off for this internal storage.
    protected final void
    setCopyOnWrite(boolean copyOnWrite)
    Change the copyOnWrite flag.
    protected abstract void
    setData(D data)
    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
    Create and return a dense version of this internal storage.
    abstract T
    Create and return a sparse version of this internal storage.

    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

    abs, ceil, floor, isAbsolute, isRelative, neg, rint, toString, toString, toString, toString
  • Constructor Details

    • IndexedValue

      public IndexedValue(U displayUnit)
      Construct a new IndexedValue.
      Parameters:
      displayUnit - U; the unit of the new AbstractValue
  • Method Details

    • getDisplayUnit

      public final U getDisplayUnit()
      Description copied from interface: Value
      Retrieve the unit of this Value.
      Specified by:
      getDisplayUnit in interface Value<U extends Unit<U>,S extends Scalar<U,S>>
      Returns:
      U; the unit of this Value
    • setDisplayUnit

      public void setDisplayUnit(U newUnit)
      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.
      Specified by:
      setDisplayUnit in interface Value<U extends Unit<U>,S extends Scalar<U,S>>
      Parameters:
      newUnit - U; the new display unit of this Value
    • getData

      protected abstract D getData()
      Retrieve the data object. Method can only be used within package and by subclasses.
      Returns:
      D; the internal data
    • setData

      protected abstract void setData(D data)
      Set the data object. Method can only be used within package and by subclasses.
      Parameters:
      data - D; the internal data
    • getStorageType

      public final StorageType 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

      public final T immutable()
      Turn the immutable flag on for this vector.
      Returns:
      T; the vector with a raised immutable flag
    • mutable

      public final T 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

      public abstract T 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

      public abstract T 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

      public abstract Class<S> getScalarClass()
      Return the class of the corresponding scalar.
      Returns:
      Class<S>; the class of the corresponding scalar
    • clone

      public T clone()
      Overrides:
      clone in class Object