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 |
|---|---|
| public Unit | |
| public < The type of the quantity measured by the unit. T extends Quantity | Returns: this unit parameterized with the specified type.the quantity class identifying the nature of the unit. type)Casts this unit to a parameterized unit of specified nature or throw a |
| public Unit | |
| public Unit | Returns: this unit divided by the specified divisor.the divisor value. divisor)Returns the result of dividing this unit by an approximate divisor. |
| public Unit | |
| public Map | Returns: the base units and their exponent making up this unit.Returns the base units and their exponent whose product is this unit, or |
| public UnitConverter | Returns: the converter from this unit tothat unit.the unit of same type to which to convert the numeric values. that)Returns a converter of numeric values from this unit to another unit of same type. |
| public UnitConverter | Returns: the converter from this unit tothat unit.the unit to which to convert the numeric values. that)Returns a converter from this unit to the specified unit of type unknown. |
| public Dimension | |
| public String | Returns: this unit name, ornull if this unit has not specific name associated with (e.g. product of units).Returns the name (if any) of this unit. |
| public String | Returns: this unit symbol, ornull if this unit has not specific symbol associated with (e.g. product of units).Returns the symbol (if any) of this unit. |
| public Unit | Returns: the system unit this unit is derived from, orthis if this unit is a system unit.Returns the unscaled system unit from which this unit is derived. |
| public Unit | |
| public boolean | Returns: this.getDimension().equals(that.getDimension())the other unit to compare for compatibility. that)Indicates if this unit is compatible with the unit specified. |
| public boolean | Returns: true if that ≡ this.the that)Unit<Q> to be compared with this instance.Indicates if this unit represents the same quantity than the given unit, ignoring name and symbols. |
| public Unit | |
| public Unit | Returns: this unit scaled by the specified multiplier.the multiplier multiplier)Returns the result of multiplying this unit by the specified factor. |
| public Unit | |
| public Unit | Returns: the result of raising this unit to the exponent.the exponent. n)Returns an unit raised to the n-th (integer) power of this unit. |
| public Unit | |
| public Unit | Returns: the n-th root of this unit.an integer giving the root's order as in 'n-th root' n)Returns an unit that is the n-th (integer) root of this unit. |
| public Unit | |
| public Unit | Returns: this unit offset by the specified value.the offset added (expressed in this unit). offset)Returns the result of setting the origin of the scale of measurement to the given value. |
| public String | Returns: the string representation of this unit.Returns a string representation of this unit. |
| public Unit | Returns: the unit after the specified transformation.the converter from the transformed unit to this unit. operation)Returns the unit derived from this unit using the specified converter. |
| alternate | back to summary |
|---|---|
| public Unit 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. Examples of alternate units:
Unit<Angle> RADIAN = ONE.alternate("rad").asType(Angle.class);
| |
| asType | back to summary |
|---|---|
| public <T extends Quantity Casts this unit to a parameterized unit of specified nature or throw a
| |
| divide | back to summary |
|---|---|
| public Unit Returns the result of dividing this unit by a divisor. If the factor is an integer value, the division is exact. For example: | |
| divide | back to summary |
|---|---|
| public Unit Returns the result of dividing this unit by an approximate divisor. For example:
| |
| divide | back to summary |
|---|---|
| public Unit Returns the quotient of this unit with the one specified. | |
| getBaseUnits | back to summary |
|---|---|
| public Map Returns the base units and their exponent whose product is this unit, or | |
| getConverterTo | back to summary |
|---|---|
| public UnitConverter getConverterTo(Unit<Q> that) throws UnconvertibleException Returns a converter of numeric values from this unit to another unit of same type. This method performs the same work as
| |
| getConverterToAny | back to summary |
|---|---|
| public UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException Returns a converter from this unit to the specified unit of type unknown. This method can be used when the quantity type of the specified unit is unknown at compile-time or when dimensional analysis allows for conversion between units of different type.
To convert to a unit having the same parameterized type,
| |
| getDimension | back to summary |
|---|---|
| public Dimension getDimension() Returns the dimension of this unit. Two units
| |
| getName | back to summary |
|---|---|
| public String getName() Returns the name (if any) of this unit. This method returns
| |
| getSymbol | back to summary |
|---|---|
| public String getSymbol() Returns the symbol (if any) of this unit. This method returns
| |
| getSystemUnit | back to summary |
|---|---|
| public Unit Returns the unscaled system unit from which this unit is derived. System units are either base units, alternate units or product of rational powers of system units. Because the system unit is unique by quantity type, it can be be used to identify the quantity given the unit. For example:
static boolean isAngularSpeed(Unit<?> unit) {
| |
| inverse | back to summary |
|---|---|
| public Unit Returns the reciprocal (multiplicative inverse) of this unit.
| |
| isCompatible | back to summary |
|---|---|
| public boolean isCompatible(Unit<?> that) Indicates if this unit is compatible with the unit specified. Units don't need to be equal to be compatible. For example (assuming
| |
| isEquivalentTo | back to summary |
|---|---|
| public boolean isEquivalentTo(Unit<Q> that) Indicates if this unit represents the same quantity than the given unit, ignoring name and symbols. Two units are equivalent if the conversion between them is identity.
Unlike
| |
| multiply | back to summary |
|---|---|
| public Unit Returns the result of multiplying this unit by the specified factor. If the factor is an integer value, the multiplication is exact
(recommended). For example: | |
| multiply | back to summary |
|---|---|
| public Unit Returns the result of multiplying this unit by the specified factor. For example:
| |
| multiply | back to summary |
|---|---|
| public Unit Returns the product of this unit with the one specified. | |
| pow | back to summary |
|---|---|
| public Unit Returns an unit raised to the n-th (integer) power of this unit. Equivalent to the mathematical expression
| |
| prefix | back to summary |
|---|---|
| public Unit Returns a new unit equal to this unit prefixed by the specified | |
| root | back to summary |
|---|---|
| public Unit Returns an unit that is the n-th (integer) root of this unit. Equivalent to the mathematical expression
| |
| shift | back to summary |
|---|---|
| public Unit Returns the result of setting the origin of the scale of measurement to the given value. The returned unit is convertible with all units that are
convertible with this unit. For example the following code: | |
| shift | back to summary |
|---|---|
| public Unit Returns the result of setting the origin of the scale of measurement to the given value. The returned unit is convertible with all units that are
convertible with this unit. For example the following code:
| |
| toString | back to summary |
|---|---|
| public String toString() Returns a string representation of this unit. The string representation may be the unit symbol, or may be some representation of product units, multiplication factor and offset if any. The string may be localized at implementation choice by the means of a particular device and platform.
| |
| transform | back to summary |
|---|---|
| public Unit Returns the unit derived from this unit using the specified converter. The converter does not need to be linear. For example:
Unit<Dimensionless> DECIBEL = Unit.ONE.transform(
new LogConverter(10).inverse().concatenate(
new RationalConverter(1, 10)));
| |