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 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, 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-2020 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 Details

    • AbstractIndexedValue

      protected AbstractIndexedValue​(U unit)
      Construct a new AbstractIndexedValue.
      Parameters:
      unit - U; the unit
  • Method Details

    • 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.
      Specified by:
      getStorageType in interface IndexedValue<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.
      Specified by:
      isMutable in interface IndexedValue<U extends Unit<U>,​S extends Scalar<U,​S>,​T extends AbstractIndexedValue<U,​S,​T,​D>>
      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.
      Specified by:
      immutable in interface IndexedValue<U extends Unit<U>,​S extends Scalar<U,​S>,​T extends AbstractIndexedValue<U,​S,​T,​D>>
      Returns:
      T; the vector with a raised immutable flag
    • mutable

      public final T mutable()
      Turn the immutable flag off for this internal storage.
      Specified by:
      mutable in interface IndexedValue<U extends Unit<U>,​S extends Scalar<U,​S>,​T extends AbstractIndexedValue<U,​S,​T,​D>>
      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.
      Specified by:
      isDense in interface IndexedValue<U extends Unit<U>,​S extends Scalar<U,​S>,​T extends AbstractIndexedValue<U,​S,​T,​D>>
      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.
      Specified by:
      isSparse in interface IndexedValue<U extends Unit<U>,​S extends Scalar<U,​S>,​T extends AbstractIndexedValue<U,​S,​T,​D>>
      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.
      Specified by:
      cardinality in interface IndexedValue<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

      public T clone()
      Overrides:
      clone in class Object