Class InterpolationLibrary
- java.lang.Object
-
- org.onebusaway.gtfs_transformer.updates.InterpolationLibrary
-
public class InterpolationLibrary extends Object
Generic methods to support interpolation of values against a sorted key-value map given a new target key. Note that these interpolation methods do not conform to the GTFS-rt spec. For GTFS-rt compliant interpolation/extrapolation. Ported from onebusaway-application-modules.- Author:
- bdferris
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInterpolationLibrary.EInRangeStrategystatic classInterpolationLibrary.EOutOfRangeStrategystatic interfaceInterpolationLibrary.InterpolationStrategy<KEY extends Number,VALUE>
-
Constructor Summary
Constructors Constructor Description InterpolationLibrary()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleinterpolate(double[] keys, double[] values, double target, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy)static doubleinterpolate(double[] keys, double[] values, double target, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy, InterpolationLibrary.EInRangeStrategy inRangeStrategy)static <K extends Number,V extends Number>
doubleinterpolate(SortedMap<K,V> values, K target)Same behavior asinterpolate(SortedMap, Number, EOutOfRangeStrategy)but with a defaultInterpolationLibrary.EOutOfRangeStrategyofInterpolationLibrary.EOutOfRangeStrategy.INTERPOLATE.static <K extends Number,V extends Number>
doubleinterpolate(SortedMap<K,V> values, K target, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy)static <KEY extends Number,VALUE,ANY_KEY extends KEY,ANY_VALUE extends VALUE>
VALUEinterpolate(InterpolationLibrary.InterpolationStrategy<KEY,VALUE> interpolationStrategy, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy, SortedMap<ANY_KEY,ANY_VALUE> values, ANY_KEY target)Given aSortedMapwith key-values that of arbitrary type and aInterpolationLibrary.InterpolationStrategyto define interpolation over those types, interpolate a value for a target key within the key-range of the map.static doubleinterpolatePair(double fromValue, double toValue, double ratio)Simple numeric interpolation between two double values using the equationratio * (toValue - fromValue) + fromValuestatic doubleinterpolatePair(double keyA, double valueA, double keyB, double valueB, double targetKey)Simple numeric interpolation between two pairs of key-values and a third key.
-
-
-
Method Detail
-
interpolate
public static <K extends Number,V extends Number> double interpolate(SortedMap<K,V> values, K target)
Same behavior asinterpolate(SortedMap, Number, EOutOfRangeStrategy)but with a defaultInterpolationLibrary.EOutOfRangeStrategyofInterpolationLibrary.EOutOfRangeStrategy.INTERPOLATE.- Parameters:
values- a sorted-map of key-value number pairstarget- the target key used to interpolate a value- Returns:
- an interpolated value for the target key
-
interpolate
public static <K extends Number,V extends Number> double interpolate(SortedMap<K,V> values, K target, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy)
Given aSortedMapwith key-values that all extend fromNumber, interpolate using linear interpolation a value for a target key within the key-range of the map. For a key outside the range of the keys of the map, theoutOfRangeInterpolationLibrary.EOutOfRangeStrategystrategy will determine the interpolation behavior.- Parameters:
values- a sorted-map of key-value number pairstarget- the target key used to interpolate a valueoutOfRangeStrategy- the strategy to use for a target key that outside the key-range of the value map- Returns:
- an interpolated value for the target key
-
interpolate
public static double interpolate(double[] keys, double[] values, double target, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy)
-
interpolate
public static double interpolate(double[] keys, double[] values, double target, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy, InterpolationLibrary.EInRangeStrategy inRangeStrategy)
-
interpolatePair
public static double interpolatePair(double fromValue, double toValue, double ratio)Simple numeric interpolation between two double values using the equationratio * (toValue - fromValue) + fromValue- Parameters:
fromValue-toValue-ratio-- Returns:
ratio * (toValue - fromValue) + fromValue
-
interpolatePair
public static double interpolatePair(double keyA, double valueA, double keyB, double valueB, double targetKey)Simple numeric interpolation between two pairs of key-values and a third key. Here,ratio = (targetKey - keyA) / (keyB - keyA)and the result isratio * (valueB - valueA) + valueA.- Returns:
ratio * (toValue - fromValue) + fromValue
-
interpolate
public static <KEY extends Number,VALUE,ANY_KEY extends KEY,ANY_VALUE extends VALUE> VALUE interpolate(InterpolationLibrary.InterpolationStrategy<KEY,VALUE> interpolationStrategy, InterpolationLibrary.EOutOfRangeStrategy outOfRangeStrategy, SortedMap<ANY_KEY,ANY_VALUE> values, ANY_KEY target)
Given aSortedMapwith key-values that of arbitrary type and aInterpolationLibrary.InterpolationStrategyto define interpolation over those types, interpolate a value for a target key within the key-range of the map. For a key outside the range of the keys of the map, theoutOfRangeInterpolationLibrary.EOutOfRangeStrategystrategy will determine the interpolation behavior.- Parameters:
interpolationStrategy- the interpolation strategy used to perform interpolation between key-value pairs of arbitrary typeoutOfRangeStrategy- the strategy to use for a target key that outside the key-range of the value mapvalues- a sorted-map of key-value pairstarget- the target key used to interpolate a value- Returns:
- an interpolated value for the target key
-
-