Q
- The type of the quantity measured by this unit.public interface Unit<Q extends Quantity<Q>>
It is helpful to think of instances of this class as recording the history
by which they are created. Thus, for example, the string "g/kg"
(which
is a dimensionless unit) would result from invoking the method toString()
on a unit that was created by dividing a gram unit by a kilogram unit.
This interface supports the multiplication of offsets units. The result is usually a unit not convertible to its system unit. Such units may appear in derivative quantities. For example Celsius per meter is an unit of gradient, which is common in atmospheric and oceanographic research.
Units raised at non-integral powers are not supported. For example,
LITRE.root(2)
raises an ArithmeticException
, but
HECTARE.root(2)
returns HECTOMETRE
(100 metres).
Unit instances shall be immutable.
Modifier and Type | Method and Description |
---|---|
Unit<Q> |
alternate(String symbol)
Returns a system unit equivalent to this unscaled standard unit but used
in expressions to distinguish between quantities of a different nature
but of the same dimensions.
|
<T extends Quantity<T>> |
asType(Class<T> type)
Casts this unit to a parameterized unit of specified nature or throw a
ClassCastException if the dimension of the specified quantity
and this unit's dimension do not match. |
Unit<Q> |
divide(double divisor)
Returns the result of dividing this unit by an approximate divisor.
|
Unit<?> |
divide(Unit<?> divisor)
Returns the quotient of this unit with the one specified.
|
UnitConverter |
getConverterTo(Unit<Q> that)
Returns a converter of numeric values from this unit to another unit of same type.
|
UnitConverter |
getConverterToAny(Unit<?> that)
Returns a converter from this unit to the specified unit of type unknown.
|
Dimension |
getDimension()
Returns the dimension of this unit.
|
String |
getName()
Returns the name (if any) of this unit.
|
Map<? extends Unit<?>,Integer> |
getProductUnits()
Returns the base units and their exponent whose product is this unit,
or
null if this unit is a base unit (not a product of existing units). |
String |
getSymbol()
Returns the symbol (if any) of this unit.
|
Unit<Q> |
getSystemUnit()
Returns the unscaled system unit from which this unit is derived.
|
Unit<?> |
inverse()
Returns the inverse of this unit.
|
boolean |
isCompatible(Unit<?> that)
Indicates if this unit is compatible with the unit specified.
|
Unit<Q> |
multiply(double multiplier)
Returns the result of multiplying this unit by the specified factor.
|
Unit<?> |
multiply(Unit<?> multiplier)
Returns the product of this unit with the one specified.
|
Unit<?> |
pow(int n)
Returns a unit equals to this unit raised to an exponent.
|
Unit<?> |
root(int n)
Returns a unit equals to the given root of this unit.
|
Unit<Q> |
shift(double offset)
Returns the result of setting the origin of the scale of measurement to the given value.
|
String |
toString()
Returns a string representation of this unit.
|
Unit<Q> |
transform(UnitConverter converter)
Returns the unit derived from this unit using the specified converter.
|
String getSymbol()
null
if this unit has no specific symbol associated with.null
if this unit has not
specific symbol associated with (e.g. product of units).toString()
,
UnitFormat
String getName()
null
if this unit has no specific name associated with.null
if this unit has not
specific name associated with (e.g. product of units).toString()
,
UnitFormat
Dimension getDimension()
u1
and u2
are compatible if and only if
u1.getDimension().equals(u2.getDimension())
.isCompatible(Unit)
Unit<Q> getSystemUnit()
Because the system unit is unique by quantity type, it can be be used to identify the quantity given the unit. For example:
[code] static boolean isAngularSpeed(Unit> unit) { return unit.getSystemUnit().equals(RADIAN.divide(SECOND)); } assert isAngularSpeed(REVOLUTION.divide(MINUTE)); // Returns true. [/code]this
if this unit is a system unit.Map<? extends Unit<?>,Integer> getProductUnits()
null
if this unit is a base unit (not a product of existing units).boolean isCompatible(Unit<?> that)
ONE
is a dimensionless unit):
[code]
RADIAN.equals(ONE) == false
RADIAN.isCompatible(ONE) == true
[/code]that
- the other unit to compare for compatibility.this.getDimension().equals(that.getDimension())
getDimension()
<T extends Quantity<T>> Unit<T> asType(Class<T> type) throws ClassCastException
ClassCastException
if the dimension of the specified quantity
and this unit's dimension do not match. For example:
[code]
UnitT
- The type of the quantity measured by the unit.type
- the quantity class identifying the nature of the unit.ClassCastException
- if the dimension of this unit is different
from the specified quantity dimension.UnitConverter getConverterTo(Unit<Q> that) throws UnconvertibleException
getConverterToAny(Unit)
without
raising checked exception.that
- the unit of same type to which to convert the numeric values.that
unit.UnconvertibleException
- if a converter cannot be constructed.getConverterToAny(Unit)
UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException
To convert to a unit having the same parameterized type,
getConverterTo(Unit)
is preferred (no checked exception raised).
that
- the unit to which to convert the numeric values.that
unit.IncommensurableException
- if this unit is not
compatible with that
unit.UnconvertibleException
- if a converter cannot be constructed.getConverterTo(Unit)
,
isCompatible(Unit)
Unit<Q> alternate(String symbol)
Examples of alternate units:
[code] Unitsymbol
- the new symbol for the alternate unit.UnsupportedOperationException
- if this unit is not an unscaled standard unit.IllegalArgumentException
- if the specified symbol is already
associated to a different unit.Unit<Q> shift(double offset)
offset
- the offset added (expressed in this unit).Unit<Q> multiply(double multiplier)
multiplier
- the multiplierUnit<?> multiply(Unit<?> multiplier)
multiplier
- the unit multiplier.this * multiplier
Unit<Q> divide(double divisor)
divisor
- the divisor value.Unit<?> divide(Unit<?> divisor)
divisor
- the unit divisor.this / divisor
Unit<?> root(int n)
n
- the root's order.ArithmeticException
- if n == 0
or if this operation
would result in an unit with a fractional exponent.Unit<?> pow(int n)
n
- the exponent.String toString()
toString
in class Object
getSymbol()
Unit<Q> transform(UnitConverter converter)
Unit DECIBEL = Unit.ONE.transform(
new LogConverter(10).inverse().concatenate(
new RationalConverter(1, 10)));
operation
- the converter from the transformed unit to this unit.Copyright © 2014 Jean-Marie Dautelle, Werner Keil, V2COM. All Rights Reserved.