Class QuantityType<T extends javax.measure.Quantity<T>>

    • Field Detail

      • ZERO

        public static final QuantityType<javax.measure.quantity.Dimensionless> ZERO
      • ONE

        public static final QuantityType<javax.measure.quantity.Dimensionless> ONE
    • Constructor Detail

      • QuantityType

        public QuantityType()
        Creates a dimensionless QuantityType with scalar 0 and unit AbstractUnit.ONE. A default constructor is needed by ItemUpdater.receiveUpdate(org.openhab.core.items.events.ItemStateEvent))
      • QuantityType

        public QuantityType​(String value)
        Creates a new QuantityType with the given value. The value may contain a unit. The specific Quantity is obtained by NumberDelimiterQuantityFormat.parse(CharSequence). The English locale is used to determine (decimal/grouping) separator characters.
        Parameters:
        value - the non null value representing a quantity with an optional unit.
        Throws:
        NumberFormatException - when a quantity without a unit could not be parsed
        IllegalArgumentException - when a quantity with a unit could not be parsed
      • QuantityType

        public QuantityType​(String value,
                            Locale locale)
        Creates a new QuantityType with the given value. The value may contain a unit. The specific Quantity is obtained by NumberDelimiterQuantityFormat.parse(CharSequence).
        Parameters:
        value - the non null value representing a quantity with an optional unit.
        locale - the locale used to determine (decimal/grouping) separator characters.
        Throws:
        NumberFormatException - when a quantity without a unit could not be parsed
        IllegalArgumentException - when a quantity with a unit could not be parsed
      • QuantityType

        public QuantityType​(Number value,
                            javax.measure.Unit<T> unit)
        Creates a new QuantityType with the given value and Unit.
        Parameters:
        value - the non null measurement value.
        unit - the non null measurement unit.
    • Method Detail

      • valueOf

        public static <T extends javax.measure.Quantity<T>> QuantityType<T> valueOf​(double value,
                                                                                    javax.measure.Unit<T> unit)
        Static access to QuantityType#QuantityType(double, Unit).
        Parameters:
        value - the non null measurement value.
        unit - the non null measurement unit.
        Returns:
        a new QuantityType
      • equals

        public boolean equals​(@Nullable Object obj)
        Overrides:
        equals in class Object
      • getUnit

        public javax.measure.Unit<T> getUnit()
      • getDimension

        public javax.measure.Dimension getDimension()
      • toUnit

        public @Nullable QuantityType<T> toUnit​(javax.measure.Unit<?> targetUnit)
        Convert this QuantityType to a new QuantityType using the given target unit.
        Parameters:
        targetUnit - the unit to which this QuantityType will be converted to.
        Returns:
        the new QuantityType in the given Unit or null in case of an error.
      • toInvertibleUnit

        public @Nullable QuantityType<?> toInvertibleUnit​(javax.measure.Unit<?> targetUnit)
        Convert this QuantityType to a new QuantityType using the given target unit. Implicit conversions using inverse units are allowed (i.e. mired <=> Kelvin). This may change the dimension.
        Parameters:
        targetUnit - the unit to which this QuantityType will be converted to.
        Returns:
        the new QuantityType in the given Unit or null in case of an erro.
      • toInvertibleUnit

        public @Nullable QuantityType<?> toInvertibleUnit​(String targetUnit)
      • toUnitRelative

        public @Nullable QuantityType<T> toUnitRelative​(javax.measure.Unit<T> targetUnit)
        Convert this QuantityType to a new QuantityType using the given target unit. Similar to toUnit(javax.measure.Unit<?>), except that it treats the values as relative instead of absolute. This means that any offsets in the conversion of absolute values are ignored. This is useful when your quantity represents a delta, and not necessarily a measured value itself. For example, 32 °F, when converted with toUnit to Celsius, it will become 0 °C. But when converted with toUnitRelative, it will become 17.8 °C.
        Parameters:
        targetUnit - the unit to which this QuantityType will be converted to.
        Returns:
        the new QuantityType in the given Unit or null in case of an error.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • format

        public String format​(String pattern)
        Description copied from interface: Type
        Formats the value of this type according to a pattern (see Formatter).
        Specified by:
        format in interface Type
        Parameters:
        pattern - the pattern to use
        Returns:
        the formatted string
      • intValue

        public int intValue()
        Specified by:
        intValue in class Number
      • longValue

        public long longValue()
        Specified by:
        longValue in class Number
      • floatValue

        public float floatValue()
        Specified by:
        floatValue in class Number
      • doubleValue

        public double doubleValue()
        Specified by:
        doubleValue in class Number
      • toFullString

        public String toFullString()
        Description copied from interface: Type
        Get a string representation that contains the whole internal representation of the type.

        The returned string could be consumed by the static 'valueOf(String)' method of the respective type to build a new type that is equal to this type.

        Specified by:
        toFullString in interface Type
        Returns:
        a full string representation of the type to be consumed by 'valueOf(String)'
      • as

        public <U extends State> @Nullable U as​(@Nullable Class<U> target)
        Description copied from interface: State
        Convert this State's value into another type
        Specified by:
        as in interface State
        Parameters:
        target - the desired State type
        Returns:
        the State's value in the given type's representation, or null if the conversion was not possible
      • negate

        public QuantityType<T> negate()
        Negates the value of this QuantityType leaving its unit untouched.
        Returns:
        the negated value of this QuantityType.
      • divide

        public QuantityType<?> divide​(BigDecimal value)
        Divide this QuantityType by the given value.
        Parameters:
        value - the value this QuantityType should be divided by.
        Returns:
        the quotient from this QuantityType and the given value.
      • offset

        public QuantityType<T> offset​(QuantityType<T> offset,
                                      javax.measure.Unit<T> unit)
        Apply a given offset to this QuantityType
        Parameters:
        offset - the offset to apply
        Returns:
        changed QuantityType by offset
      • inverse

        public QuantityType<?> inverse()
        Return the reciprocal of this QuantityType.
        Returns:
        a QuantityType with both the value and unit reciprocated