Package org.rrd4j.data
Class CubicSplineInterpolator
- java.lang.Object
-
- org.rrd4j.data.Plottable
-
- org.rrd4j.data.CubicSplineInterpolator
-
- All Implemented Interfaces:
IPlottable
public class CubicSplineInterpolator extends Plottable
Class used to interpolate datasource values from the collection of (timestamp, values) points using natural cubic spline interpolation.WARNING: So far, this class cannot handle NaN datasource values (an exception will be thrown by the constructor). Future releases might change this.
-
-
Constructor Summary
Constructors Constructor Description CubicSplineInterpolator(double[] x, double[] y)
Creates cubic spline interpolator for an array of 2D-points.CubicSplineInterpolator(long[] timestamps, double[] values)
Creates cubic spline interpolator from arrays of timestamps and corresponding datasource values.CubicSplineInterpolator(Calendar[] dates, double[] values)
Creates cubic spline interpolator from arrays of GregorianCalendar objects and corresponding datasource values.CubicSplineInterpolator(Date[] dates, double[] values)
Creates cubic spline interpolator from arrays of Date objects and corresponding datasource values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getValue(double xval)
Calculates spline-interpolated y-value for the corresponding x-value.double
getValue(long timestamp)
Retrieves datapoint value based on a given timestamp.
-
-
-
Constructor Detail
-
CubicSplineInterpolator
public CubicSplineInterpolator(long[] timestamps, double[] values)
Creates cubic spline interpolator from arrays of timestamps and corresponding datasource values.- Parameters:
timestamps
- timestamps in secondsvalues
- corresponding datasource values- Throws:
IllegalArgumentException
- Thrown if supplied arrays do not contain at least 3 values, or if timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN.
-
CubicSplineInterpolator
public CubicSplineInterpolator(Date[] dates, double[] values)
Creates cubic spline interpolator from arrays of Date objects and corresponding datasource values.- Parameters:
dates
- Array of Date objectsvalues
- corresponding datasource values- Throws:
IllegalArgumentException
- Thrown if supplied arrays do not contain at least 3 values, or if timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN.
-
CubicSplineInterpolator
public CubicSplineInterpolator(Calendar[] dates, double[] values)
Creates cubic spline interpolator from arrays of GregorianCalendar objects and corresponding datasource values.- Parameters:
dates
- Array of GregorianCalendar objectsvalues
- corresponding datasource values- Throws:
IllegalArgumentException
- Thrown if supplied arrays do not contain at least 3 values, or if timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN.
-
CubicSplineInterpolator
public CubicSplineInterpolator(double[] x, double[] y)
Creates cubic spline interpolator for an array of 2D-points.- Parameters:
x
- x-axis point coordinatesy
- y-axis point coordinates- Throws:
IllegalArgumentException
- Thrown if supplied arrays do not contain at least 3 values, or if timestamps are not ordered, or array lengths are not equal, or some datasource value is NaN.
-
-
Method Detail
-
getValue
public double getValue(double xval)
Calculates spline-interpolated y-value for the corresponding x-value. Call this if you need spline-interpolated values in your code.- Parameters:
xval
- x-value- Returns:
- inteprolated y-value
-
getValue
public double getValue(long timestamp)
Retrieves datapoint value based on a given timestamp. Use this method if you only have one series of data in this class. Method overridden from the base class. This method will be called by the framework. Call this method only if you need spline-interpolated values in your code.- Specified by:
getValue
in interfaceIPlottable
- Specified by:
getValue
in classPlottable
- Parameters:
timestamp
- Timestamp in seconds for the datapoint.- Returns:
- Double value of the datapoint.
-
-