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

class DerivedScalar<Q extends javax.measure.Quantity<Q>> extends Scalar<Q>
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
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • derivedValue

      private final double derivedValue
      The value specified by the user, in unit of derivedUnit. Could be computed form super-class value, but nevertheless stored for avoiding rounding errors.
    • derivedUnit

      private final javax.measure.Unit<Q extends javax.measure.Quantity<Q>> 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 this DerivedScalar.
    • fromSystem

      private final javax.measure.UnitConverter fromSystem
      Converter 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 from unit 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

      javax.measure.Quantity<Q> create(double newValue, javax.measure.Unit<Q> newUnit)
      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:
      Overrides:
      create in class Scalar<Q extends javax.measure.Quantity<Q>>
      See Also:
    • getSystemUnit

      final javax.measure.Unit<Q> getSystemUnit()
      Returns the system unit of measurement.
    • getUnit

      public final javax.measure.Unit<Q> getUnit()
      Returns the unit of measurement specified at construction time.
      Specified by:
      getUnit in interface javax.measure.Quantity<Q extends javax.measure.Quantity<Q>>
      Overrides:
      getUnit in class Scalar<Q extends javax.measure.Quantity<Q>>
    • doubleValue

      public final double doubleValue()
      Returns the value specified at construction time.
      Overrides:
      doubleValue in class Scalar<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 class Scalar<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 of long range are clamped to minimal or maximal representable numbers of long type.
      Overrides:
      longValue in class Scalar<Q extends javax.measure.Quantity<Q>>
    • to

      public final javax.measure.Quantity<Q> to(javax.measure.Unit<Q> newUnit)
      Converts this quantity to another unit of measurement.
      Specified by:
      to in interface javax.measure.Quantity<Q extends javax.measure.Quantity<Q>>
      Overrides:
      to in class Scalar<Q extends javax.measure.Quantity<Q>>