Class ExtendedDataType<T,​O,​S,​G extends GtuDataInterface>

  • Type Parameters:
    T - type of value
    O - output type
    S - storage type
    G - gtu data type
    All Implemented Interfaces:
    Identifiable
    Direct Known Subclasses:
    ExtendedDataTypeFloat, ExtendedDataTypeList, ExtendedDataTypeNumber

    public abstract class ExtendedDataType<T,​O,​S,​G extends GtuDataInterface>
    extends Object
    implements Identifiable
    Type class to define different types of data by which trajectories can be extended beyond the basic t, x, v, a. Extend this class to define a new data type. Extended data types are defined with 3 generic types. <T> is the type of a single scalar value, <O> is the output type of the whole trajectory, e.g. List<Double> or FloatLengthVector, and <S> is the storage type by which the data is gathered, e.g. List<Double> or float[].

    Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
    BSD-style license. See OpenTrafficSim License.

    Version:
    $Revision$, $LastChangedDate$, by $Author$, initial version 11 okt. 2016
    Author:
    Alexander Verbraeck, Peter Knoppers, Wouter Schakel
    • Constructor Detail

      • ExtendedDataType

        public ExtendedDataType​(String id,
                                Class<T> type)
        Constructor setting the id.
        Parameters:
        id - String; id
        type - Class<T>; type class
    • Method Detail

      • getType

        public Class<T> getType()
        Returns the type.
        Returns:
        the type
      • getValue

        public abstract T getValue​(G gtu)
        Returns the current value of the gtu.
        Parameters:
        gtu - G; gtu
        Returns:
        current value of the gtu
      • setValue

        public abstract S setValue​(S storage,
                                   int index,
                                   T value)
        Returns an updated list/array/vector of the storage type, including a new value at given index.
        Parameters:
        storage - S; storage
        index - int; index to store next value
        value - T; value to add
        Returns:
        updated list/array/vector of the storage type, including a new value at given index
      • getOutputValue

        public abstract T getOutputValue​(O output,
                                         int index)
                                  throws SamplingException
        Returns a specific output value. This is used to store extended data types as generic file, i.e. text file.
        Parameters:
        output - O; output
        index - int; index of value to return
        Returns:
        the i'th output value
        Throws:
        SamplingException - when i is out of bounds.
      • getStorageValue

        public abstract T getStorageValue​(S storage,
                                          int index)
                                   throws SamplingException
        Returns a specific storage value. This is used to bypass conversion to the output type when trajectories are cut.
        Parameters:
        storage - S; storage
        index - int; index of value to return
        Returns:
        the i'th output value
        Throws:
        SamplingException - when i is out of bounds.
      • initializeStorage

        public abstract S initializeStorage()
        Returns an initial storage object.
        Returns:
        initial storage object.
      • convert

        public abstract O convert​(S storage,
                                  int size)
        Convert storage type to output type.
        Parameters:
        storage - S; stored data
        size - int; size of trajectory
        Returns:
        converted output
      • formatValue

        public abstract String formatValue​(String format,
                                           T value)
        Formats the value into a string. If the value is numeric, the default implementation is:
         String.format(format, value.si);
         
        Parameters:
        format - String; format
        value - T; value
        Returns:
        formatted value
      • parseValue

        public abstract T parseValue​(String string)
        Parses a stored string representation to original type.
        Parameters:
        string - String; stored string representation
        Returns:
        T; value in original type
      • interpolate

        public <AU extends AbsoluteLinearUnit<AU,​RU>,​RU extends Unit<RU>,​R extends DoubleScalarInterface.Rel<RU,​R>,​RA extends DoubleScalarInterface.RelWithAbs<AU,​A,​RU,​RA>,​A extends DoubleScalarInterface.Abs<AU,​A,​RU,​RA>,​FR extends FloatScalarInterface.Rel<RU,​FR>,​FRA extends FloatScalarInterface.RelWithAbs<AU,​FA,​RU,​FRA>,​FA extends FloatScalarInterface.Abs<AU,​FA,​RU,​FRA>> T interpolate​(T value0,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     T value1,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     double f)
        Interpolate value between two measured values. The default implementation takes a linear interpolation over time for DoubleScalar, FloatScalar, Double and Float, or the closest value in time otherwise.
        Type Parameters:
        AU - unit of value, if values are DoubleScalar
        RU - the corresponding relative unit
        R - the relative double type
        RA - the relative double type belonging to the absolute type
        A - the absolute double type
        FR - the relative float type
        FRA - the relative float type belonging to the absolute type
        FA - the absolute float type
        Parameters:
        value0 - T; first value
        value1 - T; second value
        f - double; interpolation fraction
        Returns:
        interpolated value
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public final boolean equals​(Object obj)
        Overrides:
        equals in class Object