Package org.apache.sis.measure
Class DerivedScalar<Q extends javax.measure.Quantity<Q>>
java.lang.Object
java.lang.Number
org.apache.sis.measure.Scalar<Q>
org.apache.sis.measure.DerivedScalar<Q>
- Type Parameters:
Q
- the type of quantity implemented by this scalar.
- All Implemented Interfaces:
Serializable
,Comparable<Q>
,javax.measure.Quantity<Q>
- Direct Known Subclasses:
DerivedScalar.Fallback
,DerivedScalar.TemperatureMeasurement
A quantity related to a scalar by an arbitrary (not necessarily linear) conversion.
For example, a temperature in Celsius degrees is related to a temperature in Kelvin
by applying an offset.
The Scalar
parent class is restricted to cases where the relationship with system unit
is a scale factor. This DerivedScalar
subclass allow the relationship to be more generic.
It is a design similar to DerivedCRS
- Since:
- 1.0
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
DerivedScalar.Fallback<Q extends javax.measure.Quantity<Q>>
Fallback used when noDerivedScalar
implementation is available for a given quantity type.(package private) static final class
A temperature in Celsius degrees or any other units having an offset compared to Kelvin.Nested classes/interfaces inherited from class org.apache.sis.measure.Scalar
Scalar.Acceleration, Scalar.Angle, Scalar.Area, Scalar.Dimensionless, Scalar.Energy, Scalar.Force, Scalar.Frequency, Scalar.Length, Scalar.Mass, Scalar.Power, Scalar.Pressure, Scalar.Speed, Scalar.Temperature, Scalar.Time, Scalar.Volume
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final javax.measure.Unit<Q>
The unit of measurement specified by the user.private final double
The value specified by the user, in unit ofderivedUnit
.private final javax.measure.UnitConverter
Converter from the system unit to the unit of this quantity.private static final long
For cross-version compatibility. -
Constructor Summary
ConstructorsConstructorDescriptionDerivedScalar
(double value, javax.measure.Unit<Q> unit, javax.measure.Unit<Q> systemUnit, javax.measure.UnitConverter toSystem) Creates a new scalar for the given value.DerivedScalar
(DerivedScalar<Q> origin, double value) Creates a new scalar resulting from an arithmetic operation performed on the given scalar. -
Method Summary
Modifier and TypeMethodDescription(package private) javax.measure.Quantity<Q>
Creates a new quantity of same type than this quantity but with a different value.final double
Returns the value specified at construction time.final float
Returns the value casted to a single-precision floating point number.(package private) final javax.measure.Unit<Q>
Returns the system unit of measurement.final javax.measure.Unit<Q>
getUnit()
Returns the unit of measurement specified at construction time.final long
Returns the value rounded to nearest integer.final javax.measure.Quantity<Q>
Converts this quantity to another unit of measurement.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
derivedValue
private final double derivedValueThe value specified by the user, in unit ofderivedUnit
. Could be computed form super-class value, but nevertheless stored for avoiding rounding errors. -
derivedUnit
The unit of measurement specified by the user. The relationship between this unit and its system unit (stored in super-class) is something more complex than a scale factor, otherwise we would not need thisDerivedScalar
. -
fromSystem
private final javax.measure.UnitConverter fromSystemConverter from the system unit to the unit of this quantity.
-
-
Constructor Details
-
DerivedScalar
DerivedScalar(double value, javax.measure.Unit<Q> unit, javax.measure.Unit<Q> systemUnit, javax.measure.UnitConverter toSystem) Creates a new scalar for the given value.- Parameters:
toSystem
- converter fromunit
to the system unit.
-
DerivedScalar
DerivedScalar(DerivedScalar<Q> origin, double value) Creates a new scalar resulting from an arithmetic operation performed on the given scalar. The arithmetic operation result is in the same unit than the original scalar.- Parameters:
value
- the arithmetic result in system unit.
-
-
Method Details
-
create
Creates a new quantity of same type than this quantity but with a different value. The unit of measurement shall be the same than the system unit of this quantity. Implementation in subclasses should be like below: -
getSystemUnit
Returns the system unit of measurement. -
getUnit
Returns the unit of measurement specified at construction time. -
doubleValue
public final double doubleValue()Returns the value specified at construction time.- Overrides:
doubleValue
in classScalar<Q extends javax.measure.Quantity<Q>>
-
floatValue
public final float floatValue()Returns the value casted to a single-precision floating point number.- Overrides:
floatValue
in classScalar<Q extends javax.measure.Quantity<Q>>
-
longValue
public final long longValue()Returns the value rounded to nearest integer.Double.NaN
are casted to 0 and values out oflong
range are clamped to minimal or maximal representable numbers oflong
type. -
to
Converts this quantity to another unit of measurement.
-