Class Measurement
- java.lang.Object
-
- org.osgi.util.measurement.Measurement
-
- All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>
public class Measurement extends java.lang.Object implements java.lang.Comparable<java.lang.Object>Represents a value with an error, a unit and a time-stamp.A
Measurementobject is used for maintaining the tuple of value, error, unit and time-stamp. The value and error are represented as doubles and the time is measured in milliseconds since midnight, January 1, 1970 UTC.Mathematic methods are provided that correctly calculate taking the error into account. A runtime error will occur when two measurements are used in an incompatible way. E.g., when a speed (m/s) is added to a distance (m). The measurement class will correctly track changes in unit during multiplication and division, always coercing the result to the most simple form. See
Unitfor more information on the supported units.Errors in the measurement class are absolute errors. Measurement errors should use the P95 rule. Actual values must fall in the range value +/- error 95% or more of the time.
A
Measurementobject is immutable in order to be easily shared.Note: This class has a natural ordering that is inconsistent with equals. See
compareTo(Object).
-
-
Constructor Summary
Constructors Constructor Description Measurement(double value)Create a newMeasurementobject with an error of 0.0, a unit ofUnit.unityand a time of zero.Measurement(double value, double error, Unit unit)Create a newMeasurementobject with a time of zero.Measurement(double value, double error, Unit unit, long time)Create a newMeasurementobject.Measurement(double value, Unit unit)Create a newMeasurementobject with an error of 0.0 and a time of zero.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Measurementadd(double d)Returns a newMeasurementobject that is the sum of this object added to the specified value.Measurementadd(double d, Unit u)Returns a newMeasurementobject that is the sum of this object added to the specified value.Measurementadd(Measurement m)Returns a newMeasurementobject that is the sum of this object added to the specified object.intcompareTo(java.lang.Object obj)Compares this object with the specified object for order.Measurementdiv(double d)Returns a newMeasurementobject that is the quotient of this object divided by the specified value.Measurementdiv(double d, Unit u)Returns a newMeasurementobject that is the quotient of this object divided by the specified value.Measurementdiv(Measurement m)Returns a newMeasurementobject that is the quotient of this object divided by the specified object.booleanequals(java.lang.Object obj)Returns whether the specified object is equal to this object.doublegetError()Returns the error of thisMeasurementobject.longgetTime()Returns the time at which thisMeasurementobject was taken.UnitgetUnit()Returns theUnitobject of thisMeasurementobject.doublegetValue()Returns the value of thisMeasurementobject.inthashCode()Returns a hash code value for this object.Measurementmul(double d)Returns a newMeasurementobject that is the product of this object multiplied by the specified value.Measurementmul(double d, Unit u)Returns a newMeasurementobject that is the product of this object multiplied by the specified value.Measurementmul(Measurement m)Returns a newMeasurementobject that is the product of this object multiplied by the specified object.Measurementsub(double d)Returns a newMeasurementobject that is the subtraction of the specified value from this object.Measurementsub(double d, Unit u)Returns a newMeasurementobject that is the subtraction of the specified value from this object.Measurementsub(Measurement m)Returns a newMeasurementobject that is the subtraction of the specified object from this object.java.lang.StringtoString()Returns aStringobject representing thisMeasurementobject.
-
-
-
Constructor Detail
-
Measurement
public Measurement(double value, double error, Unit unit, long time)Create a newMeasurementobject.- Parameters:
value- The value of theMeasurement.error- The error of theMeasurement.unit- TheUnitobject in which the value is measured. If this argument isnull, then the unit will be set toUnit.unity.time- The time measured in milliseconds since midnight, January 1, 1970 UTC.
-
Measurement
public Measurement(double value, double error, Unit unit)Create a newMeasurementobject with a time of zero.- Parameters:
value- The value of theMeasurement.error- The error of theMeasurement.unit- TheUnitobject in which the value is measured. If this argument isnull, then the unit will be set toUnit.unity.
-
Measurement
public Measurement(double value, Unit unit)Create a newMeasurementobject with an error of 0.0 and a time of zero.- Parameters:
value- The value of theMeasurement.unit- TheUnitin which the value is measured. If this argument isnull, then the unit will be set toUnit.unity.
-
Measurement
public Measurement(double value)
Create a newMeasurementobject with an error of 0.0, a unit ofUnit.unityand a time of zero.- Parameters:
value- The value of theMeasurement.
-
-
Method Detail
-
getValue
public final double getValue()
Returns the value of thisMeasurementobject.- Returns:
- The value of this
Measurementobject as a double.
-
getError
public final double getError()
Returns the error of thisMeasurementobject. The error is always a positive value.- Returns:
- The error of this
Measurementas a double.
-
getUnit
public final Unit getUnit()
Returns theUnitobject of thisMeasurementobject.- Returns:
- The
Unitobject of thisMeasurementobject. - See Also:
Unit
-
getTime
public final long getTime()
Returns the time at which thisMeasurementobject was taken. The time is measured in milliseconds since midnight, January 1, 1970 UTC, or zero when not defined.- Returns:
- The time at which this
Measurementobject was taken or zero.
-
mul
public Measurement mul(Measurement m)
Returns a newMeasurementobject that is the product of this object multiplied by the specified object.- Parameters:
m- TheMeasurementobject that will be multiplied with this object.- Returns:
- A new
Measurementthat is the product of this object multiplied by the specified object. The error and unit of the new object are computed. The time of the new object is set to the time of this object. - Throws:
java.lang.ArithmeticException- If theUnitobjects of this object and the specified object cannot be multiplied.- See Also:
Unit
-
mul
public Measurement mul(double d, Unit u)
Returns a newMeasurementobject that is the product of this object multiplied by the specified value.- Parameters:
d- The value that will be multiplied with this object.u- TheUnitof the specified value.- Returns:
- A new
Measurementobject that is the product of this object multiplied by the specified value. The error and unit of the new object are computed. The time of the new object is set to the time of this object. - Throws:
java.lang.ArithmeticException- If the units of this object and the specified value cannot be multiplied.- See Also:
-
-