Class ExtendedDataType<T,O,S,G extends GtuDataInterface>
- java.lang.Object
-
- org.opentrafficsim.kpi.sampling.data.ExtendedDataType<T,O,S,G>
-
- Type Parameters:
T- type of valueO- output typeS- storage typeG- 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>orFloatLengthVector, and<S>is the storage type by which the data is gathered, e.g.List<Double>orfloat[].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 Summary
Constructors Constructor Description ExtendedDataType(String id, Class<T> type)Constructor setting the id.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Oconvert(S storage, int size)Convert storage type to output type.booleanequals(Object obj)abstract StringformatValue(String format, T value)Formats the value into a string.StringgetId()abstract TgetOutputValue(O output, int index)Returns a specific output value.abstract TgetStorageValue(S storage, int index)Returns a specific storage value.Class<T>getType()Returns the type.abstract TgetValue(G gtu)Returns the current value of the gtu.inthashCode()abstract SinitializeStorage()Returns an initial storage object.<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>>
Tinterpolate(T value0, T value1, double f)Interpolate value between two measured values.abstract TparseValue(String string)Parses a stored string representation to original type.abstract SsetValue(S storage, int index, T value)Returns an updated list/array/vector of the storage type, including a new value at given index.
-
-
-
Method Detail
-
getId
public final String getId()
- Specified by:
getIdin interfaceIdentifiable
-
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; storageindex- int; index to store next valuevalue- 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; outputindex- int; index of value to return- Returns:
- the i'th output value
- Throws:
SamplingException- wheniis 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; storageindex- int; index of value to return- Returns:
- the i'th output value
- Throws:
SamplingException- wheniis 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 datasize- 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; formatvalue- 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 forDoubleScalar,FloatScalar,DoubleandFloat, or the closest value in time otherwise.- Type Parameters:
AU- unit of value, if values areDoubleScalarRU- the corresponding relative unitR- the relative double typeRA- the relative double type belonging to the absolute typeA- the absolute double typeFR- the relative float typeFRA- the relative float type belonging to the absolute typeFA- the absolute float type- Parameters:
value0- T; first valuevalue1- T; second valuef- double; interpolation fraction- Returns:
- interpolated value
-
-