The class represents units founded on the seven SI base units for seven base quantities assumed to be mutually independent.
For all physics units, unit conversions are symmetrical:
u1.getConverterTo(u2).equals(u2.getConverterTo(u1).inverse()).
Non-physical units (e.g. currency units) for which conversion is not
symmetrical should have their own separate class hierarchy and are considered
distinct (e.g. financial units), although they can always be combined with
physics units (e.g. "€/Kg", "$/h").
| Modifier and Type | Class and Description |
|---|---|
| protected static class | AbstractUnit.
Utility class for number comparison and equality |
| Modifier and Type | Field and Description |
|---|---|
| private String | name
Holds the name. |
| public static final Unit | ONE
Holds the dimensionless unit |
| protected Quantity. | scale
Holds the measurement scale |
| private static final long | |
| private String | symbol
Holds the symbol. |
| protected static final transient Map | SYMBOL_TO_UNIT
Holds the unique symbols collection (base units or alternate units). |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public final Unit | alternate(String
the new symbol for the alternate unit. newSymbol)Implements javax. 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. |
| public final Unit | |
| public final <T extends Quantity | asType(Class<T>
the quantity class identifying the nature of the unit. type)Implements javax. 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 (regardless whether or not the dimensions are independent or not). |
| public int | Returns: a negative integer, zero, or a positive integer as this unit is less than, equal to, or greater than the specified unit.the object to be compared. that)Implements java. Compares this unit to the specified unit. |
| private int | |
| public Unit | divide(double
the divisor value. divisor)Implements javax. Returns the result of dividing this unit by an approximate divisor. |
| public final Unit | Returns: this unit divided by the specified divisor.the divisor value. divisor)Implements javax. Returns the result of dividing this unit by the specified divisor. |
| public final Unit | Returns: this.multiply(that.inverse())the unit divisor. that)Implements javax. Returns the quotient of this unit with the one specified. |
| public abstract boolean | equals(Object
the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| protected Type | |
| public abstract Map | getBaseUnits()
Redeclares javax. Returns the base units and their exponent whose product is this unit, or |
| public final UnitConverter | getConverterTo(Unit<Q>
the unit of same type to which to convert the numeric values. that)Implements javax. Returns a converter of numeric values from this unit to another unit of same type. |
| public final UnitConverter | Returns: the converter from this unit tothat unit in the given scale.the unit of same type to which to convert the numeric values. that, Quantity.the measurement scale. scaleReturns a converter of numeric values from this unit to another unit of same type. |
| public final UnitConverter | getConverterToAny(Unit<?>
the unit to which to convert the numeric values. that)Implements javax. Returns a converter from this unit to the specified unit of type unknown. |
| public final UnitConverter | Returns: the converter fromthis unit to that unit using the given scale.the unit to which to convert the numeric values. that, Quantity.the measurement scale. scaleReturns a converter from this unit to the specified unit of type unknown in the given scale. |
| public abstract Dimension | |
| public String | getName()
Implements javax. Returns the name (if any) of this unit. |
| public String | getSymbol()
Implements javax. Returns the symbol (if any) of this unit. |
| public abstract UnitConverter | Returns: getConverterTo(this.toSystemUnit())Returns the converter from this unit to its unscaled |
| public final Unit | Returns: the unscaled metric unit from which this unit is derived.Implements javax. Returns the system unit (unscaled SI unit) from which this unit is derived. |
| public abstract int | |
| protected final UnitConverter | |
| private final boolean | |
| public final Unit | Returns: 1 / thisImplements javax. Returns the inverse of this physical unit. |
| public final boolean | Returns: true if this unit and that unit have the same
fundamental dimension according to the current dimensional model;
false otherwise.the other unit. that)Implements javax. Indicates if this unit is compatible with the unit specified. |
| public boolean | isEquivalentTo(Unit<Q>
the that)Unit<Q> to be compared with this instance.Implements javax. Indicates if this unit represents the same quantity than the given unit, ignoring name and symbols. |
| public boolean | Returns: equals(toSystemUnit())Indicates if this unit belongs to the set of coherent SI units (unscaled SI units). |
| public final Unit | multiply(Number
the multiplier factor)Implements javax. Returns the result of multiplying this unit by the specified factor. |
| public Unit | multiply(double
the multiplier multiplier)Implements javax. Returns the result of multiplying this unit by the specified factor. |
| public final Unit | Returns: this * thatthe physical unit multiplicand. that)Implements javax. Returns the product of this physical unit with the one specified. |
| public static Unit | Returns: SimpleUnitFormat.getInstance().parse(csq)the character sequence to parse. charSequence)Returns the abstract unit represented by the specified characters as per default format. |
| public Unit | Returns: the result of raising this unit to the exponent.the exponent. n)Implements javax. Returns a unit equals to this unit raised to an exponent. |
| public Unit | prefix(Prefix
the prefix to apply on this unit. prefix)Implements javax. Returns a new unit equal to this unit prefixed by the specified |
| public final Unit | Returns: the result of taking the given root of this unit.the root's order. n)Implements javax. Returns a unit equals to the given root of this unit. |
| protected void | |
| protected void | |
| public final Unit | shift(Number
the offset added (expressed in this unit). offset)Implements javax. Returns the result of setting the origin of the scale of measurement to the given value. |
| public Unit | shift(double
the offset added (expressed in this unit). offset)Implements javax. Returns the result of setting the origin of the scale of measurement to the given value. |
| public String | Returns: SimpleUnitFormat.getInstance().format(this)Overrides java. Implements javax. Returns the standard representation of this physics unit. |
| protected abstract Unit | Returns: the unscaled metric unit from which this unit is derived.Returns the unscaled |
| public final Unit | transform(UnitConverter
the converter from the transformed unit to this unit. operation)Implements javax. Returns the unit derived from this unit using the specified converter. |
| name | back to summary |
|---|---|
| private String name Holds the name. | |
| ONE | back to summary |
|---|---|
| public static final Unit<Dimensionless> ONE Holds the dimensionless unit | |
| scale | back to summary |
|---|---|
| protected Quantity. Holds the measurement scale | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| symbol | back to summary |
|---|---|
| private String symbol Holds the symbol. | |
| SYMBOL_TO_UNIT | back to summary |
|---|---|
| protected static final transient Map<String, Unit<?>> SYMBOL_TO_UNIT Holds the unique symbols collection (base units or alternate units). | |
| AbstractUnit | back to summary |
|---|---|
| protected AbstractUnit() Default constructor. | |
| AbstractUnit | back to summary |
|---|---|
| protected AbstractUnit(String symbol) Constructor setting a symbol.
| |
| alternate | back to summary |
|---|---|
| public final Unit Implements javax. Doc from javax. 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);
| |
| annotate | back to summary |
|---|---|
| public final Unit Annotates the specified unit. Annotation does not change the unit semantic.
Annotations are often written between curly braces behind units. For
example: | |
| asType | back to summary |
|---|---|
| public final <T extends Quantity Implements javax. 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 (regardless whether or not the dimensions are independent or not).
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(Unit<Q> that) Implements java. Compares this unit to the specified unit. The default implementation compares the name and symbol of both this unit and the specified unit, giving precedence to the symbol.
| |
| compareToWithPossibleNullValues | back to summary |
|---|---|
| private int compareToWithPossibleNullValues(String a, String b) | |
| divide | back to summary |
|---|---|
| public Unit Implements javax. Doc from javax. Returns the result of dividing this unit by an approximate divisor. For example: | |
| divide | back to summary |
|---|---|
| public final Unit Implements javax. Returns the result of dividing this unit by the specified divisor. If the factor is an integer value, the division is exact. For example:
| |
| divide | back to summary |
|---|---|
| public final Unit Implements javax. Returns the quotient of this unit with the one specified. | |
| equals | back to summary |
|---|---|
| public abstract boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| getActualType | back to summary |
|---|---|
| protected Type getActualType() | |
| getBaseUnits | back to summary |
|---|---|
| public abstract Map Redeclares javax. Doc from javax. Returns the base units and their exponent whose product is this unit, or | |
| getConverterTo | back to summary |
|---|---|
| public final UnitConverter getConverterTo(Unit<Q> that) throws UnconvertibleException Implements javax. Doc from javax. Returns a converter of numeric values from this unit to another unit of same type. This method performs the same work as
| |
| getConverterTo | back to summary |
|---|---|
| public final UnitConverter getConverterTo(Unit<Q> that, Quantity. 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 final UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException Implements javax. Doc from javax. 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,
| |
| getConverterToAny | back to summary |
|---|---|
| public final UnitConverter getConverterToAny(Unit<?> that, Quantity. Returns a converter from this unit to the specified unit of type unknown in the given scale. 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 abstract Dimension getDimension() Redeclares javax. Doc from javax. Returns the dimension of this unit. Two units | |
| getName | back to summary |
|---|---|
| public String getName() Implements javax. Doc from javax. Returns the name (if any) of this unit. This method returns
| |
| getSymbol | back to summary |
|---|---|
| public String getSymbol() Implements javax. Doc from javax. Returns the symbol (if any) of this unit. This method returns
| |
| getSystemConverter | back to summary |
|---|---|
| public abstract UnitConverter getSystemConverter() Returns the converter from this unit to its unscaled
| |
| getSystemUnit | back to summary |
|---|---|
| public final Unit Implements javax. Returns the system unit (unscaled SI unit) from which this unit is derived.
They can be be used to identify a quantity given the unit. For example: | |
| hashCode | back to summary |
|---|---|
| public abstract int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| internalGetConverterTo | back to summary |
|---|---|
| protected final UnitConverter internalGetConverterTo(Unit<Q> that, boolean useEquals) throws UnconvertibleException | |
| internalIsCompatible | back to summary |
|---|---|
| private final boolean internalIsCompatible(Unit<?> that, boolean checkEquals) Internal helper for isCompatible | |
| inverse | back to summary |
|---|---|
| public final Unit Implements javax. Returns the inverse of this physical unit. | |
| isCompatible | back to summary |
|---|---|
| public final boolean isCompatible(Unit<?> that) Implements javax. Indicates if this unit is compatible with the unit specified. To be compatible both units must be physics units having the same fundamental dimension. | |
| isEquivalentTo | back to summary |
|---|---|
| public boolean isEquivalentTo(Unit<Q> that) Implements javax. Doc from javax. 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 | |
| isSystemUnit | back to summary |
|---|---|
| public boolean isSystemUnit() Indicates if this unit belongs to the set of coherent SI units (unscaled SI units). The base and coherent derived units of the SI form a coherent set, designated the set of coherent SI units. The word coherent is used here in the following sense: when coherent units are used, equations between the numerical values of quantities take exactly the same form as the equations between the quantities themselves. Thus if only units from a coherent set are used, conversion factors between units are never required.
| |
| multiply | back to summary |
|---|---|
| public final Unit Implements javax. Doc from javax. 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 Implements javax. Doc from javax. Returns the result of multiplying this unit by the specified factor. For example: | |
| multiply | back to summary |
|---|---|
| public final Unit Implements javax. Returns the product of this physical unit with the one specified. | |
| parse | back to summary |
|---|---|
| public static Unit Returns the abstract unit represented by the specified characters as per
default format.
Locale-sensitive unit parsing could be handled using Note The standard format supports dimensionless
units.
| |
| pow | back to summary |
|---|---|
| public Unit Implements javax. Returns a unit equals to this unit raised to an exponent. | |
| prefix | back to summary |
|---|---|
| public Unit Implements javax. Doc from javax. Returns a new unit equal to this unit prefixed by the specified | |
| root | back to summary |
|---|---|
| public final Unit Implements javax. Returns a unit equals to the given root of this unit.
| |
| setName | back to summary |
|---|---|
| protected void setName(String name) | |
| setSymbol | back to summary |
|---|---|
| protected void setSymbol(String s) | |
| shift | back to summary |
|---|---|
| public final Unit Implements javax. Doc from javax. 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 Implements javax. Doc from javax. 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() Overrides java. Implements javax. Returns the standard representation of this physics unit. The string produced
for a given unit is always the same; it is not affected by the locale. It can
be used as a canonical string representation for exchanging units, or as a
key for a Hashtable, etc.
Locale-sensitive unit parsing could be handled using | |
| toSystemUnit | back to summary |
|---|---|
| protected abstract Unit Returns the unscaled
| |
| transform | back to summary |
|---|---|
| public final Unit Implements javax. Doc from javax. 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)));
| |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static boolean |
| Equalizer | back to summary |
|---|---|
| protected Equalizer() | |
| areEqual | back to summary |
|---|---|
| public static boolean areEqual(Unit<Q extends Quantity<Q>> u1, Unit<Q extends Quantity<Q>> u2) Indicates if this unit is considered equals to the specified object. order).
| |