Class QuantityType<T extends javax.measure.Quantity<T>>
- All Implemented Interfaces:
Serializable,Comparable<QuantityType<T>>,Command,PrimitiveType,State,Type
- Author:
- Gaël L'hopital - Initial contribution
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final QuantityType<javax.measure.quantity.Dimensionless> static final QuantityType<javax.measure.quantity.Dimensionless> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a dimensionlessQuantityTypewith scalar 0 and unitAbstractUnit.ONE.QuantityType(Number value, javax.measure.Unit<T> unit) Creates a newQuantityTypewith the given value andUnit.QuantityType(String value) Creates a newQuantityTypewith the given value.QuantityType(String value, Locale locale) Creates a newQuantityTypewith the given value. -
Method Summary
Modifier and TypeMethodDescriptionadd(QuantityType<T> state) Returns the sum of the givenQuantityTypewith this QuantityType.<U extends State>
@Nullable UConvert thisState's value into another typeintcompareTo(QuantityType<T> o) QuantityType<?> divide(BigDecimal value) Divide this QuantityType by the given value.QuantityType<?> divide(QuantityType<?> state) Divide this QuantityType by the givenQuantityType.doublebooleanfloatFormats the value of this type according to a pattern (seeFormatter).javax.measure.Dimensionjavax.measure.Unit<T> getUnit()inthashCode()intintValue()QuantityType<?> inverse()Return the reciprocal of this QuantityType.longQuantityType<?> multiply(BigDecimal value) Multiply thisQuantityTypeby the given value.QuantityType<?> multiply(QuantityType<?> state) Multiply this QuantityType by the givenQuantityType.negate()Negates the value of this QuantityType leaving its unit untouched.offset(QuantityType<T> offset, javax.measure.Unit<T> unit) Apply a given offset to this QuantityTypesubtract(QuantityType<T> state) Subtract the givenQuantityTypefrom this QuantityType.Get a string representation that contains the whole internal representation of the type.@Nullable QuantityType<?> toInvertibleUnit(String targetUnit) @Nullable QuantityType<?> toInvertibleUnit(javax.measure.Unit<?> targetUnit) Convert this QuantityType to a newQuantityTypeusing the given target unit.toString()@Nullable QuantityType<T> @Nullable QuantityType<T> toUnit(javax.measure.Unit<?> targetUnit) Convert this QuantityType to a newQuantityTypeusing the given target unit.@Nullable QuantityType<T> toUnitRelative(String targetUnit) @Nullable QuantityType<T> toUnitRelative(javax.measure.Unit<T> targetUnit) Convert this QuantityType to a newQuantityTypeusing the given target unit.static <T extends javax.measure.Quantity<T>>
QuantityType<T> valueOf(double value, javax.measure.Unit<T> unit) Static access toQuantityType(java.lang.Number,javax.measure.Unit<T>).static QuantityType<? extends javax.measure.Quantity<?>> Static access toQuantityType(String).Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
ZERO
-
ONE
-
-
Constructor Details
-
QuantityType
public QuantityType()Creates a dimensionlessQuantityTypewith scalar 0 and unitAbstractUnit.ONE. A default constructor is needed byItemUpdater.receiveUpdate(ItemStateEvent)) -
QuantityType
Creates a newQuantityTypewith the given value. The value may contain a unit. The specificQuantityis obtained byNumberDelimiterQuantityFormat.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 parsedIllegalArgumentException- when a quantity with a unit could not be parsed
-
QuantityType
Creates a newQuantityTypewith the given value. The value may contain a unit. The specificQuantityis obtained byNumberDelimiterQuantityFormat.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 parsedIllegalArgumentException- when a quantity with a unit could not be parsed
-
QuantityType
Creates a newQuantityTypewith the given value andUnit.- Parameters:
value- the non null measurement value.unit- the non null measurement unit.
-
-
Method Details
-
valueOf
public static <T extends javax.measure.Quantity<T>> QuantityType<T> valueOf(double value, javax.measure.Unit<T> unit) Static access toQuantityType(java.lang.Number,javax.measure.Unit<T>).- Parameters:
value- the non-null measurement value.unit- the non-null measurement unit.- Returns:
- a new
QuantityType
-
toString
-
valueOf
Static access toQuantityType(String).- Parameters:
value- the non null value representing a quantity with an optional unit- Returns:
- a new
QuantityType - Throws:
NumberFormatException- when a quantity without a unit could not be parsedIllegalArgumentException- when a quantity with a unit could not be parsed
-
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends javax.measure.Quantity<T>>
-
getUnit
-
getDimension
public javax.measure.Dimension getDimension() -
toUnit
Convert this QuantityType to a newQuantityTypeusing the given target unit.- Parameters:
targetUnit- the unit to which thisQuantityTypewill be converted to.- Returns:
- the new
QuantityTypein the givenUnitornullin case of an error.
-
toUnit
-
toInvertibleUnit
Convert this QuantityType to a newQuantityTypeusing the given target unit. Implicit conversions using inverse units are allowed (i.e.mired <=> Kelvin/Hertz <=> Second/Ohm <=> Siemens). This may change the dimension.This method converts the quantity from its actual unit to its respective system unit before converting to the inverse unit. This enables it to support not only conversions
mired <=> Kelvinbut also conversionsmired <=> Fahrenheitandmired <=> Celsius.Notes on units not yet implemented in openHAB:
- The optics unit
Dioptre(dpt/D) is the inverse of length (m-1); if it were added it would give correct results.- The optics unit
Kaiserfor wave number is also the inverse of length (cm-1); it is old and not commonly used, but if it were added it would NOT give correct results.- If you discover other units similar to
Kaiserabove: => Please inform openHAB maintainers.- Parameters:
targetUnit- the unit to which thisQuantityTypewill be converted to.- Returns:
- the new
QuantityTypein the givenUnitornullin case of an error.
- The optics unit
-
toInvertibleUnit
-
toUnitRelative
Convert this QuantityType to a newQuantityTypeusing the given target unit. Similar totoUnit(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 thisQuantityTypewill be converted to.- Returns:
- the new
QuantityTypein the givenUnitornullin case of an error.
-
toUnitRelative
-
toBigDecimal
-
hashCode
public int hashCode() -
format
Description copied from interface:TypeFormats the value of this type according to a pattern (seeFormatter). -
intValue
public int intValue() -
longValue
public long longValue() -
floatValue
public float floatValue()- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classNumber
-
toFullString
Description copied from interface:TypeGet 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:
toFullStringin interfaceType- Returns:
- a full string representation of the type to be consumed by 'valueOf(String)'
-
as
Description copied from interface:StateConvert thisState's value into another type -
add
Returns the sum of the givenQuantityTypewith this QuantityType.The result is an incremental addition where the operand is interpreted as an amount to be added based on the difference between its value converted to the unit of this instance and the zero point of the unit of this instance. So for example:
- Expression '
new QuantityType("20 °C").add(new QuantityType("30 °C")' gives '50 °C'- Expression '
new QuantityType("20 °C").add(new QuantityType("30 K")' gives '50 °C'- Expression '
new QuantityType("20 °C").add(new QuantityType("54 °F")' gives '50 °C'- Expression '
new QuantityType("20 K").add(new QuantityType("30 °C")' gives '50 K'- Expression '
new QuantityType("20 K").add(new QuantityType("30 K")' gives '50 K'- Expression '
new QuantityType("20 K").add(new QuantityType("54 °F")' gives '50 K'- Parameters:
state- theQuantityTypeto add to this QuantityType.- Returns:
- the sum of the given
QuantityTypewith this QuantityType.
- Expression '
-
negate
Negates the value of this QuantityType leaving its unit untouched.- Returns:
- the negated value of this QuantityType.
-
subtract
Subtract the givenQuantityTypefrom this QuantityType.The result is an incremental subtraction where the operand is interpreted as an amount to be subtracted based on the difference between its value converted to the unit of this instance and the zero point of the unit of this instance. So for example:
- Expression '
new QuantityType("50 °C").subtract(new QuantityType("30 °C")' gives '20 °C'- Expression '
new QuantityType("50 °C").subtract(new QuantityType("30 K")' gives '20 °C'- Expression '
new QuantityType("50 °C").subtract(new QuantityType("54 °F")' gives '20 °C'- Expression '
new QuantityType("50 K").subtract(new QuantityType("30 °C")' gives '20 K'- Expression '
new QuantityType("50 K").subtract(new QuantityType("30 K")' gives '20 K'- Expression '
new QuantityType("50 K").subtract(new QuantityType("54 °F")' gives '20 K'- Parameters:
state- theQuantityTypeto subtract from this QuantityType.- Returns:
- the difference by subtracting the given
QuantityTypefrom this QuantityType.
- Expression '
-
multiply
Multiply thisQuantityTypeby the given value.- Parameters:
value- the value thisQuantityTypeshould be multiplied with.- Returns:
- the product of the given value with this
QuantityType.
-
multiply
Multiply this QuantityType by the givenQuantityType.- Parameters:
state- theQuantityTypewith which this QuantityType should be multiplied with.- Returns:
- the product of the given
QuantityTypeand this QuantityType.
-
divide
Divide this QuantityType by the given value.- Parameters:
value- the value thisQuantityTypeshould be divided by.- Returns:
- the quotient from this QuantityType and the given value.
-
divide
Divide this QuantityType by the givenQuantityType.- Parameters:
state- theQuantityTypethis QuantityType should be divided by.- Returns:
- the quotient from this QuantityType and the given
QuantityType.
-
offset
Apply a given offset to this QuantityType- Parameters:
offset- the offset to apply- Returns:
- changed QuantityType by offset
-
inverse
Return the reciprocal of this QuantityType.- Returns:
- a QuantityType with both the value and unit reciprocated
-