Top Description Inners Fields Constructors Methods
tech.units.indriya

public abstract Class AbstractUnit<Q extends Quantity<Q>>

extends Object
implements Unit<Q extends Quantity<Q>>, Comparable<Unit<Q extends Quantity<Q>>>, PrefixOperator<Q extends Quantity<Q>>, Nameable, Serializable, SymbolSupplier
Class Inheritance
All Implemented Interfaces
tech.uom.lib.common.function.SymbolSupplier, java.io.Serializable, tech.uom.lib.common.function.Nameable, tech.uom.lib.common.function.PrefixOperator, java.lang.Comparable, javax.measure.Unit
Known Direct Subclasses
tech.units.indriya.unit.AlternateUnit, tech.units.indriya.unit.AnnotatedUnit, tech.units.indriya.unit.BaseUnit, tech.units.indriya.unit.ProductUnit, tech.units.indriya.unit.TransformedUnit
Static Imports
javax.measure.Quantity.Scale.ABSOLUTE, org.apiguardian.api.API.Status.EXPERIMENTAL

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").

Authors
Jean-Marie Dautelle, Werner Keil
Since
1.0
Version
4.1, October 4, 2024
See Also
Wikipedia: International System of Units

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
AbstractUnit.Equalizer

Utility class for number comparison and equality

Field Summary

Modifier and TypeField and Description
private String
name

Holds the name.

public static final Unit<Dimensionless>
ONE

Holds the dimensionless unit ONE.

protected Quantity.Scale
scale

Holds the measurement scale

private static final long
private String
symbol

Holds the symbol.

protected static final transient Map<String, Unit<?>>
SYMBOL_TO_UNIT

Holds the unique symbols collection (base units or alternate units).

Constructor Summary

AccessConstructor and Description
protected
AbstractUnit()

Default constructor.

protected
AbstractUnit(String
the unit symbol.
symbol
)

Constructor setting a symbol.

Method Summary

Modifier and TypeMethod and Description
public final Unit<Q>
alternate(String
the new symbol for the alternate unit.
newSymbol
)

Implements javax.measure.Unit.alternate.

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<Q>

Returns:

the annotated unit.
annotate
(String
the unit annotation.
annotation
)

Annotates the specified unit.

public final <T extends Quantity<T>> Unit<T>
asType(Class<T>
the quantity class identifying the nature of the unit.
type
)

Implements javax.measure.Unit.asType.

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.
compareTo
(Unit<Q>
the object to be compared.
that
)

Implements java.lang.Comparable.compareTo.

Compares this unit to the specified unit.

private int
public Unit<Q>
divide(double
the divisor value.
divisor
)

Implements javax.measure.Unit.divide.

Returns the result of dividing this unit by an approximate divisor.

public final Unit<Q>

Returns:

this unit divided by the specified divisor.
divide
(Number
the divisor value.
divisor
)

Implements javax.measure.Unit.divide.

Returns the result of dividing this unit by the specified divisor.

public final Unit<?>

Returns:

this.multiply(that.inverse())
divide
(Unit<?>
the unit divisor.
that
)

Implements javax.measure.Unit.divide.

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.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

protected Type
public abstract Map<? extends Unit<?>, Integer>
getBaseUnits()

Redeclares javax.measure.Unit.getBaseUnits.

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).

public final UnitConverter
getConverterTo(Unit<Q>
the unit of same type to which to convert the numeric values.
that
)

Implements javax.measure.Unit.getConverterTo.

Returns a converter of numeric values from this unit to another unit of same type.

public final UnitConverter

Returns:

the converter from this unit to that unit in the given scale.
getConverterTo
(Unit<Q>
the unit of same type to which to convert the numeric values.
that
,
Quantity.Scale
the measurement scale.
scale
)

Returns 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.measure.Unit.getConverterToAny.

Returns a converter from this unit to the specified unit of type unknown.

public final UnitConverter

Returns:

the converter from this unit to that unit using the given scale.
getConverterToAny
(Unit<?>
the unit to which to convert the numeric values.
that
,
Quantity.Scale
the measurement scale.
scale
)

Returns a converter from this unit to the specified unit of type unknown in the given scale.

public abstract Dimension
getDimension()

Redeclares javax.measure.Unit.getDimension.

Returns the dimension of this unit.

public String
getName()

Implements javax.measure.Unit.getName, tech.uom.lib.common.function.Nameable.getName.

Returns the name (if any) of this unit.

public String
public abstract UnitConverter

Returns:

getConverterTo(this.toSystemUnit())
getSystemConverter
()

Returns the converter from this unit to its unscaled System Unit unit.

public final Unit<Q>

Returns:

the unscaled metric unit from which this unit is derived.
getSystemUnit
()

Implements javax.measure.Unit.getSystemUnit.

Returns the system unit (unscaled SI unit) from which this unit is derived.

public abstract int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

protected final UnitConverter
internalGetConverterTo(Unit<Q> that, boolean useEquals)

private final boolean
internalIsCompatible(Unit<?> that, boolean checkEquals)

Internal helper for isCompatible

public final Unit<?>

Returns:

1 / this
inverse
()

Implements javax.measure.Unit.inverse.

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.
isCompatible
(Unit<?>
the other unit.
that
)

Implements javax.measure.Unit.isCompatible.

Indicates if this unit is compatible with the unit specified.

public boolean
isEquivalentTo(Unit<Q>
the Unit<Q> to be compared with this instance.
that
)

Implements javax.measure.Unit.isEquivalentTo.

Indicates if this unit represents the same quantity than the given unit, ignoring name and symbols.

public boolean

Returns:

equals(toSystemUnit())
isSystemUnit
()

Indicates if this unit belongs to the set of coherent SI units (unscaled SI units).

public final Unit<Q>
multiply(Number
the multiplier
factor
)

Implements javax.measure.Unit.multiply.

Returns the result of multiplying this unit by the specified factor.

public Unit<Q>
multiply(double
the multiplier
multiplier
)

Implements javax.measure.Unit.multiply.

Returns the result of multiplying this unit by the specified factor.

public final Unit<?>

Returns:

this * that
multiply
(Unit<?>
the physical unit multiplicand.
that
)

Implements javax.measure.Unit.multiply.

Returns the product of this physical unit with the one specified.

public static Unit<?>

Returns:

SimpleUnitFormat.getInstance().parse(csq)
parse
(CharSequence
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.
pow
(int
the exponent.
n
)

Implements javax.measure.Unit.pow.

Returns a unit equals to this unit raised to an exponent.

public Unit<Q>
prefix(Prefix
the prefix to apply on this unit.
prefix
)

Implements javax.measure.Unit.prefix, tech.uom.lib.common.function.PrefixOperator.prefix.

Returns a new unit equal to this unit prefixed by the specified prefix.

public final Unit<?>

Returns:

the result of taking the given root of this unit.
root
(int
the root's order.
n
)

Implements javax.measure.Unit.root.

Returns a unit equals to the given root of this unit.

protected void
protected void
public final Unit<Q>
shift(Number
the offset added (expressed in this unit).
offset
)

Implements javax.measure.Unit.shift.

Returns the result of setting the origin of the scale of measurement to the given value.

public Unit<Q>
shift(double
the offset added (expressed in this unit).
offset
)

Implements javax.measure.Unit.shift.

Returns the result of setting the origin of the scale of measurement to the given value.

public String

Returns:

SimpleUnitFormat.getInstance().format(this)
toString
()

Overrides java.lang.Object.toString.

Implements javax.measure.Unit.toString.

Returns the standard representation of this physics unit.

protected abstract Unit<Q>

Returns:

the unscaled metric unit from which this unit is derived.
toSystemUnit
()

Returns the unscaled SI unit from which this unit is derived.

public final Unit<Q>
transform(UnitConverter
the converter from the transformed unit to this unit.
operation
)

Implements javax.measure.Unit.transform.

Returns the unit derived from this unit using the specified converter.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

nameback to summary
private String name

Holds the name.

ONEback to summary
public static final Unit<Dimensionless> ONE

Holds the dimensionless unit ONE.

See Also
Wikipedia: Natural Units - Choosing constants to normalize, Units of Dimension One
scaleback to summary
protected Quantity.Scale scale

Holds the measurement scale

serialVersionUIDback to summary
private static final long serialVersionUID
symbolback to summary
private String symbol

Holds the symbol.

SYMBOL_TO_UNITback to summary
protected static final transient Map<String, Unit<?>> SYMBOL_TO_UNIT

Holds the unique symbols collection (base units or alternate units).

Constructor Detail

AbstractUnitback to summary
protected AbstractUnit()

Default constructor.

AbstractUnitback to summary
protected AbstractUnit(String symbol)

Constructor setting a symbol.

Parameters
symbol:String

the unit symbol.

Method Detail

alternateback to summary
public final Unit<Q> alternate(String newSymbol)

Implements javax.measure.Unit.alternate.

Doc from javax.measure.Unit.alternate.

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);
Unit<Force> NEWTON = METRE.multiply(KILOGRAM).divide(SECOND.pow(2)).alternate("N").asType(Force.class);
Unit<Pressure> PASCAL = NEWTON.divide(METRE.pow(2)).alternate("Pa").asType(Pressure.class);
Parameters
newSymbol:String

the new symbol for the alternate unit.

Returns:Unit<Q>

the alternate unit.

Annotations
@Override
annotateback to summary
public final Unit<Q> annotate(String annotation)

Annotates the specified unit. Annotation does not change the unit semantic. Annotations are often written between curly braces behind units. For example:
Unit PERCENT_VOL = ((AbstractUnit)Units.PERCENT).annotate("vol"); // "%{vol}" Unit KG_TOTAL = ((AbstractUnit)Units.KILOGRAM).annotate("total"); // "kg{total}" Unit RED_BLOOD_CELLS = ((AbstractUnit)Units.ONE).annotate("RBC"); // "{RBC}" Note: Annotation of system units are not considered themselves as system units.

Parameters
annotation:String

the unit annotation.

Returns:Unit<Q>

the annotated unit.

asTypeback to summary
public final <T extends Quantity<T>> Unit<T> asType(Class<T> type)

Implements javax.measure.Unit.asType.

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).

Parameters
<T>

Doc from javax.measure.Unit.asType. The type of the quantity measured by the unit.

type:Class<T>

the quantity class identifying the nature of the unit.

Returns:Unit<T>

Doc from javax.measure.Unit.asType.

this unit parameterized with the specified type.

Annotations
@SuppressWarnings:unchecked
@Override
Exceptions
ClassCastException:
if the dimension of this unit is different from the SI dimension of the specified type.
See Also
Units#getUnit(Class)
compareToback to summary
public int compareTo(Unit<Q> that)

Implements java.lang.Comparable.compareTo.

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.

Parameters
that:Unit<Q>

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this unit is less than, equal to, or greater than the specified unit.

Annotations
@Override
compareToWithPossibleNullValuesback to summary
private int compareToWithPossibleNullValues(String a, String b)
divideback to summary
public Unit<Q> divide(double divisor)

Implements javax.measure.Unit.divide.

Doc from javax.measure.Unit.divide.

Returns the result of dividing this unit by an approximate divisor. For example:
GRAM = KILOGRAM.divide(1000d);

Parameters
divisor:double

the divisor value.

Returns:Unit<Q>

this unit divided by the specified divisor.

Annotations
@Override
divideback to summary
public final Unit<Q> divide(Number divisor)

Implements javax.measure.Unit.divide.

Returns the result of dividing this unit by the specified divisor. If the factor is an integer value, the division is exact. For example:


   QUART = GALLON_LIQUID_US.divide(4); // Exact definition.

Parameters
divisor:Number

the divisor value.

Returns:Unit<Q>

this unit divided by the specified divisor.

Annotations
@Override
divideback to summary
public final Unit<?> divide(Unit<?> that)

Implements javax.measure.Unit.divide.

Returns the quotient of this unit with the one specified.

Parameters
that:Unit<?>

the unit divisor.

Returns:Unit<?>

this.multiply(that.inverse())

Annotations
@Override
equalsback to summary
public abstract boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

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.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getActualTypeback to summary
protected Type getActualType()
getBaseUnitsback to summary
public abstract Map<? extends Unit<?>, Integer> getBaseUnits()

Redeclares javax.measure.Unit.getBaseUnits.

Doc from javax.measure.Unit.getBaseUnits.

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).

Returns:Map<? extends Unit<?>, Integer>

the base units and their exponent making up this unit.

Annotations
@Override
getConverterToback to summary
public final UnitConverter getConverterTo(Unit<Q> that) throws UnconvertibleException

Implements javax.measure.Unit.getConverterTo.

Doc from javax.measure.Unit.getConverterTo.

Returns a converter of numeric values from this unit to another unit of same type. This method performs the same work as getConverterToAny(Unit) without raising checked exception.

Parameters
that:Unit<Q>

the unit of same type to which to convert the numeric values.

Returns:UnitConverter

the converter from this unit to that unit.

Annotations
@Override
Exceptions
UnconvertibleException:
if a converter cannot be constructed.
getConverterToback to summary
public final UnitConverter getConverterTo(Unit<Q> that, Quantity.Scale scale) 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(Unit) without raising checked exception.

Parameters
that:Unit<Q>

the unit of same type to which to convert the numeric values.

scale:Quantity.Scale

the measurement scale.

Returns:UnitConverter

the converter from this unit to that unit in the given scale.

Annotations
@API
status:EXPERIMENTAL
Exceptions
UnconvertibleException:
if a converter cannot be constructed.
See Also
getConverterToAny(Unit)
getConverterToAnyback to summary
public final UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException

Implements javax.measure.Unit.getConverterToAny.

Doc from javax.measure.Unit.getConverterToAny.

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, getConverterTo(Unit) is preferred (no checked exception raised).

Parameters
that:Unit<?>

the unit to which to convert the numeric values.

Returns:UnitConverter

the converter from this unit to that unit.

Annotations
@Override
Exceptions
IncommensurableException:
if this unit is not compatible with that unit.
UnconvertibleException:
if a converter cannot be constructed.
getConverterToAnyback to summary
public final UnitConverter getConverterToAny(Unit<?> that, Quantity.Scale scale) throws IncommensurableException, UnconvertibleException

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, getConverterTo(Unit, Scale) is preferred (no checked exception raised).

Parameters
that:Unit<?>

the unit to which to convert the numeric values.

scale:Quantity.Scale

the measurement scale.

Returns:UnitConverter

the converter from this unit to that unit using the given scale.

Annotations
@API
status:EXPERIMENTAL
@SuppressWarnings:rawtypes
Exceptions
IncommensurableException:
if this unit is not compatible with that.
UnconvertibleException:
if a converter cannot be constructed.
See Also
getConverterTo(Unit), isCompatible(Unit)
getDimensionback to summary
public abstract Dimension getDimension()

Redeclares javax.measure.Unit.getDimension.

Doc from javax.measure.Unit.getDimension.

Returns the dimension of this unit. Two units u1 and u2 are compatible if and only if u1.getDimension().equals(u2.getDimension()).

Returns:Dimension

the dimension of this unit.

Annotations
@Override
getNameback to summary
public String getName()

Implements javax.measure.Unit.getName, tech.uom.lib.common.function.Nameable.getName.

Doc from javax.measure.Unit.getName.

Returns the name (if any) of this unit. This method returns null if this unit has no specific name associated with.

Returns:String

this unit name, or null if this unit has not specific name associated with (e.g. product of units).

getSymbolback to summary
public String getSymbol()

Implements javax.measure.Unit.getSymbol, tech.uom.lib.common.function.SymbolSupplier.getSymbol.

Doc from javax.measure.Unit.getSymbol.

Returns the symbol (if any) of this unit. This method returns null if this unit has no specific symbol associated with.

Returns:String

this unit symbol, or null if this unit has not specific symbol associated with (e.g. product of units).

getSystemConverterback to summary
public abstract UnitConverter getSystemConverter()

Returns the converter from this unit to its unscaled System Unit unit.

Returns:UnitConverter

getConverterTo(this.toSystemUnit())

See Also
toSystemUnit
getSystemUnitback to summary
public final Unit<Q> getSystemUnit()

Implements javax.measure.Unit.getSystemUnit.

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:
static boolean isAngularVelocity(AbstractUnit unit) {
  return unit.getSystemUnit().equals(RADIAN.divide(SECOND));
}
assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.

Returns:Unit<Q>

the unscaled metric unit from which this unit is derived.

Annotations
@Override
hashCodeback to summary
public abstract int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
internalGetConverterToback to summary
protected final UnitConverter internalGetConverterTo(Unit<Q> that, boolean useEquals) throws UnconvertibleException
internalIsCompatibleback to summary
private final boolean internalIsCompatible(Unit<?> that, boolean checkEquals)

Internal helper for isCompatible

inverseback to summary
public final Unit<?> inverse()

Implements javax.measure.Unit.inverse.

Returns the inverse of this physical unit.

Returns:Unit<?>

1 / this

Annotations
@Override
isCompatibleback to summary
public final boolean isCompatible(Unit<?> that)

Implements javax.measure.Unit.isCompatible.

Indicates if this unit is compatible with the unit specified. To be compatible both units must be physics units having the same fundamental dimension.

Parameters
that:Unit<?>

the other unit.

Returns:boolean

true if this unit and that unit have the same fundamental dimension according to the current dimensional model; false otherwise.

Annotations
@Override
isEquivalentToback to summary
public boolean isEquivalentTo(Unit<Q> that)

Implements javax.measure.Unit.isEquivalentTo.

Doc from javax.measure.Unit.isEquivalentTo.

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 isCompatible(Unit) an equivalence check requires both units to be strictly type-compatible, because it makes no sense to compare e.g. gram and mm for equivalence. By contrast, the compatibility check can works across different quantity types.

Parameters
that:Unit<Q>

the Unit<Q> to be compared with this instance.

Returns:boolean

true if that ≡ this.

Annotations
@Override
isSystemUnitback 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.

Returns:boolean

equals(toSystemUnit())

multiplyback to summary
public final Unit<Q> multiply(Number factor)

Implements javax.measure.Unit.multiply.

Doc from javax.measure.Unit.multiply.

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:
FOOT = METRE.multiply(3048).divide(10000); // Exact definition.
ELECTRON_MASS = KILOGRAM.multiply(9.10938188e-31); // Approximation.

Parameters
factor:Number

the multiplier

Returns:Unit<Q>

this unit scaled by the specified multiplier.

Annotations
@Override
multiplyback to summary
public Unit<Q> multiply(double multiplier)

Implements javax.measure.Unit.multiply.

Doc from javax.measure.Unit.multiply.

Returns the result of multiplying this unit by the specified factor. For example:
FOOT = METRE.multiply(3048).divide(10000); // Exact definition.
ELECTRON_MASS = KILOGRAM.multiply(9.10938188e-31); // Approximation.

Parameters
multiplier:double

the multiplier

Returns:Unit<Q>

this unit scaled by the specified multiplier.

Annotations
@Override
multiplyback to summary
public final Unit<?> multiply(Unit<?> that)

Implements javax.measure.Unit.multiply.

Returns the product of this physical unit with the one specified.

Parameters
that:Unit<?>

the physical unit multiplicand.

Returns:Unit<?>

this * that

parseback to summary
public static Unit<?> parse(CharSequence charSequence)

Returns the abstract unit represented by the specified characters as per default format. Locale-sensitive unit parsing could be handled using LocalUnitFormat in subclasses of AbstractUnit.

Note

The standard format supports dimensionless units. AbstractUnit PERCENT = AbstractUnit.parse("100").inverse().asType(Dimensionless.class);

Parameters
charSequence:CharSequence

the character sequence to parse.

Returns:Unit<?>

SimpleUnitFormat.getInstance().parse(csq)

Exceptions
MeasurementParseException:
if the specified character sequence cannot be correctly parsed (e.g. not UCUM compliant).
powback to summary
public Unit<?> pow(int n)

Implements javax.measure.Unit.pow.

Returns a unit equals to this unit raised to an exponent.

Parameters
n:int

the exponent.

Returns:Unit<?>

the result of raising this unit to the exponent.

Annotations
@Override
prefixback to summary
public Unit<Q> prefix(Prefix prefix)

Implements javax.measure.Unit.prefix, tech.uom.lib.common.function.PrefixOperator.prefix.

Doc from javax.measure.Unit.prefix.

Returns a new unit equal to this unit prefixed by the specified prefix.

Parameters
prefix:Prefix

the prefix to apply on this unit.

Returns:Unit<Q>

the unit with the given prefix applied.

Annotations
@Override
rootback to summary
public final Unit<?> root(int n)

Implements javax.measure.Unit.root.

Returns a unit equals to the given root of this unit.

Parameters
n:int

the root's order.

Returns:Unit<?>

the result of taking the given root of this unit.

Annotations
@Override
Exceptions
ArithmeticException:
if n == 0 or if this operation would result in an unit with a fractional exponent.
setNameback to summary
protected void setName(String name)
setSymbolback to summary
protected void setSymbol(String s)
shiftback to summary
public final Unit<Q> shift(Number offset)

Implements javax.measure.Unit.shift.

Doc from javax.measure.Unit.shift.

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:
CELSIUS = KELVIN.shift(273.15); creates a new unit where 0°C (the origin of the new unit) is equals to 273.15 K. Converting from the old unit to the new one is equivalent to subtracting the offset to the value in the old unit.

Parameters
offset:Number

the offset added (expressed in this unit).

Returns:Unit<Q>

this unit offset by the specified value.

Annotations
@Override
shiftback to summary
public Unit<Q> shift(double offset)

Implements javax.measure.Unit.shift.

Doc from javax.measure.Unit.shift.

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:
CELSIUS = KELVIN.shift(273.15); creates a new unit where 0°C (the origin of the new unit) is equals to 273.15 K. Converting from the old unit to the new one is equivalent to subtracting the offset to the value in the old unit.

Parameters
offset:double

the offset added (expressed in this unit).

Returns:Unit<Q>

this unit offset by the specified value.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements javax.measure.Unit.toString.

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 LocalUnitFormat in subclasses of AbstractUnit.

Returns:String

SimpleUnitFormat.getInstance().format(this)

Annotations
@Override
toSystemUnitback to summary
protected abstract Unit<Q> toSystemUnit()

Returns the unscaled SI unit from which this unit is derived. The SI unit can be be used to identify a quantity given the unit. For example: static boolean isAngularVelocity(AbstractUnit unit) { return unit.toSystemUnit().equals(RADIAN.divide(SECOND)); } assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.

Returns:Unit<Q>

the unscaled metric unit from which this unit is derived.

transformback to summary
public final Unit<Q> transform(UnitConverter operation)

Implements javax.measure.Unit.transform.

Doc from javax.measure.Unit.transform.

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)));
Parameters
operation:UnitConverter

the converter from the transformed unit to this unit.

Returns:Unit<Q>

the unit after the specified transformation.

Annotations
@Override
tech.units.indriya back to summary

protected final Class AbstractUnit.Equalizer

extends Object
Class Inheritance

Utility class for number comparison and equality

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if this and obj are considered equal; falseotherwise.
areEqual
(Unit<Q extends Quantity<Q>> u1, Unit<Q extends Quantity<Q>> u2)

Indicates if this unit is considered equals to the specified object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Equalizerback to summary
protected Equalizer()

Method Detail

areEqualback 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).

Returns:boolean

true if this and obj are considered equal; falseotherwise.