Serializable
, Comparable<Q>
, javax.measure.Unit<Q>
, ComparableUnit<Q>
, tech.uom.lib.common.function.Nameable
, tech.uom.lib.common.function.PrefixOperator<Q>
, tech.uom.lib.common.function.SymbolSupplier
AlternateUnit
, AnnotatedUnit
, BaseUnit
, ProductUnit
, TransformedUnit
public abstract class AbstractUnit<Q extends javax.measure.Quantity<Q>> extends Object implements ComparableUnit<Q>, tech.uom.lib.common.function.Nameable, tech.uom.lib.common.function.PrefixOperator<Q>, tech.uom.lib.common.function.SymbolSupplier
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 | Description |
---|---|---|
protected static class |
AbstractUnit.Equalizer |
Utility class for number comparison and equality
|
Modifier and Type | Field | Description |
---|---|---|
protected String |
name |
Holds the name.
|
static javax.measure.Unit<javax.measure.quantity.Dimensionless> |
ONE |
Holds the dimensionless unit
ONE . |
protected static Map<String,javax.measure.Unit<?>> |
SYMBOL_TO_UNIT |
Holds the unique symbols collection (base units or alternate units).
|
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractUnit() |
Default constructor.
|
protected |
AbstractUnit(String symbol) |
Constructor setting a symbol.
|
Modifier and Type | Method | Description |
---|---|---|
javax.measure.Unit<Q> |
alternate(String newSymbol) |
|
javax.measure.Unit<Q> |
annotate(String annotation) |
Annotates the specified unit.
|
<T extends javax.measure.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 (regardless whether or not the dimensions are
independent or not).
|
int |
compareTo(javax.measure.Unit<Q> that) |
Compares this unit to the specified unit.
|
javax.measure.Unit<Q> |
divide(double divisor) |
|
javax.measure.Unit<Q> |
divide(Number divisor) |
Returns the result of dividing this unit by the specified divisor.
|
javax.measure.Unit<?> |
divide(javax.measure.Unit<?> that) |
Returns the quotient of this unit with the one specified.
|
protected javax.measure.Unit<?> |
divide(ComparableUnit<?> that) |
Returns the quotient of this physical unit with the one specified.
|
abstract boolean |
equals(Object obj) |
|
protected Type |
getActualType() |
|
abstract Map<? extends javax.measure.Unit<?>,Integer> |
getBaseUnits() |
|
javax.measure.UnitConverter |
getConverterTo(javax.measure.Unit<Q> that) |
|
javax.measure.UnitConverter |
getConverterToAny(javax.measure.Unit<?> that) |
|
abstract javax.measure.Dimension |
getDimension() |
|
String |
getName() |
|
String |
getSymbol() |
|
javax.measure.Unit<Q> |
getSystemUnit() |
Returns the system unit (unscaled SI unit) from which this unit is derived.
|
abstract int |
hashCode() |
|
protected javax.measure.UnitConverter |
internalGetConverterTo(javax.measure.Unit<Q> that,
boolean useEquals) |
|
javax.measure.Unit<?> |
inverse() |
Returns the inverse of this physical unit.
|
boolean |
isCompatible(javax.measure.Unit<?> that) |
Indicates if this unit is compatible with the unit specified.
|
boolean |
isEquivalentTo(javax.measure.Unit<Q> that) |
Compares two instances of
Unit<Q> , doing the conversion of unit if necessary. |
boolean |
isSystemUnit() |
Indicates if this unit belongs to the set of coherent SI units (unscaled SI
units).
|
javax.measure.Unit<Q> |
multiply(double multiplier) |
|
javax.measure.Unit<Q> |
multiply(Number factor) |
|
javax.measure.Unit<?> |
multiply(javax.measure.Unit<?> that) |
Returns the product of this unit with the one specified.
|
protected javax.measure.Unit<?> |
multiply(ComparableUnit<?> that) |
Returns the product of this physical unit with the one specified.
|
static javax.measure.Unit<?> |
parse(CharSequence charSequence) |
Returns the abstract unit represented by the specified characters as per
default format.
|
javax.measure.Unit<?> |
pow(int n) |
Returns a unit equals to this unit raised to an exponent.
|
javax.measure.Unit<Q> |
prefix(javax.measure.Prefix prefix) |
|
javax.measure.Unit<?> |
root(int n) |
Returns a unit equals to the given root of this unit.
|
protected void |
setName(String name) |
|
protected void |
setSymbol(String s) |
|
javax.measure.Unit<Q> |
shift(double offset) |
|
javax.measure.Unit<Q> |
shift(Number offset) |
|
String |
toString() |
Returns the standard representation of this physics unit.
|
protected abstract javax.measure.Unit<Q> |
toSystemUnit() |
Returns the unscaled
SI unit from which this unit is derived. |
javax.measure.Unit<Q> |
transform(javax.measure.UnitConverter operation) |
getSystemConverter
public static final javax.measure.Unit<javax.measure.quantity.Dimensionless> ONE
ONE
.protected static final transient Map<String,javax.measure.Unit<?>> SYMBOL_TO_UNIT
protected AbstractUnit()
protected AbstractUnit(String symbol)
symbol
- the unit symbol.protected Type getActualType()
public boolean isSystemUnit()
isSystemUnit
in interface ComparableUnit<Q extends javax.measure.Quantity<Q>>
equals(toSystemUnit())
protected abstract javax.measure.Unit<Q> toSystemUnit()
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.
public final javax.measure.Unit<Q> annotate(String annotation)
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.annotation
- the unit annotation.public static javax.measure.Unit<?> parse(CharSequence charSequence)
LocalUnitFormat
in subclasses of AbstractUnit.
Note: The standard format supports dimensionless
units. AbstractUnit
charSequence
- the character sequence to parse.SimpleUnitFormat.getInstance().parse(csq, new ParsePosition(0))
javax.measure.format.MeasurementParseException
- if the specified character sequence cannot
be correctly parsed (e.g. not UCUM
compliant).public String toString()
LocalUnitFormat
in subclasses of AbstractUnit.public final javax.measure.Unit<Q> getSystemUnit()
static boolean isAngularVelocity(AbstractUnit> unit) {
return unit.getSystemUnit().equals(RADIAN.divide(SECOND));
}
assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.
getSystemUnit
in interface ComparableUnit<Q extends javax.measure.Quantity<Q>>
getSystemUnit
in interface javax.measure.Unit<Q extends javax.measure.Quantity<Q>>
public final boolean isCompatible(javax.measure.Unit<?> that)
public final <T extends javax.measure.Quantity<T>> ComparableUnit<T> asType(Class<T> type)
asType
in interface javax.measure.Unit<Q extends javax.measure.Quantity<Q>>
type
- the quantity class identifying the nature of the unit.ClassCastException
- if the dimension of this unit is different from
the SI dimension of the specified type.AbstractSystemOfUnits.getUnit(Class)
public abstract Map<? extends javax.measure.Unit<?>,Integer> getBaseUnits()
public abstract javax.measure.Dimension getDimension()
public final javax.measure.UnitConverter getConverterTo(javax.measure.Unit<Q> that) throws javax.measure.UnconvertibleException
public final javax.measure.UnitConverter getConverterToAny(javax.measure.Unit<?> that) throws javax.measure.IncommensurableException, javax.measure.UnconvertibleException
protected final javax.measure.UnitConverter internalGetConverterTo(javax.measure.Unit<Q> that, boolean useEquals) throws javax.measure.UnconvertibleException
javax.measure.UnconvertibleException
public final javax.measure.Unit<?> multiply(javax.measure.Unit<?> that)
Note: If the specified unit (that) is not a physical unit, then
that.multiply(this)
is returned.
protected final javax.measure.Unit<?> multiply(ComparableUnit<?> that)
that
- the physical unit multiplicand.this * that
public final javax.measure.Unit<?> inverse()
public final javax.measure.Unit<Q> divide(Number divisor)
QUART = GALLON_LIQUID_US.divide(4); // Exact definition.
public final javax.measure.Unit<?> divide(javax.measure.Unit<?> that)
protected final javax.measure.Unit<?> divide(ComparableUnit<?> that)
that
- the physical unit divisor.this.multiply(that.inverse())
public final javax.measure.Unit<?> root(int n)
root
in interface javax.measure.Unit<Q extends javax.measure.Quantity<Q>>
n
- the root's order.ArithmeticException
- if n == 0
or if this operation would
result in an unit with a fractional exponent.public javax.measure.Unit<?> pow(int n)
public int compareTo(javax.measure.Unit<Q> that)
compareTo
in interface Comparable<Q extends javax.measure.Quantity<Q>>
public boolean isEquivalentTo(javax.measure.Unit<Q> that)
ComparableUnit
Unit<Q>
, doing the conversion of unit if necessary.isEquivalentTo
in interface ComparableUnit<Q extends javax.measure.Quantity<Q>>
that
- the Unit<Q>
to be compared with this instance.true
if that < this
.Copyright © 2005–2020 Units of Measurement project. All rights reserved.