public abstract class AbstractUnit<Q extends javax.measure.Quantity<Q>>
extends java.lang.Object
implements javax.measure.Unit<Q>, java.lang.Comparable<javax.measure.Unit<Q>>, java.io.Serializable
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 | Field and Description |
---|---|
protected java.lang.String |
name
Holds the name.
|
static javax.measure.Unit<javax.measure.quantity.Dimensionless> |
ONE
Holds the dimensionless unit
ONE . |
private static long |
serialVersionUID |
private java.lang.String |
symbol
Holds the symbol.
|
protected static java.util.Map<java.lang.String,javax.measure.Unit<?>> |
SYMBOL_TO_UNIT
Holds the unique symbols collection (base units or alternate units).
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractUnit()
DefaultQuantityFactory constructor.
|
Modifier and Type | Method and Description |
---|---|
javax.measure.Unit<Q> |
alternate(java.lang.String symbol) |
AnnotatedUnit<Q> |
annotate(java.lang.String annotation)
Annotates the specified unit.
|
<T extends javax.measure.Quantity<T>> |
asType(java.lang.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<?> |
divide(AbstractUnit<?> that)
Returns the quotient of this physical unit with the one specified.
|
AbstractUnit<Q> |
divide(double divisor)
Returns the result of dividing this unit by the specifified divisor.
|
javax.measure.Unit<?> |
divide(javax.measure.Unit<?> that)
Returns the quotient of this unit with the one specified.
|
abstract boolean |
equals(java.lang.Object that) |
protected java.lang.reflect.Type |
getActualType() |
abstract java.util.Map<? extends javax.measure.Unit<?>,java.lang.Integer> |
getBaseUnits() |
javax.measure.UnitConverter |
getConverterTo(javax.measure.Unit<Q> that) |
javax.measure.UnitConverter |
getConverterToAny(javax.measure.Unit<?> that) |
abstract javax.measure.Dimension |
getDimension() |
java.lang.String |
getName() |
java.lang.String |
getSymbol() |
abstract javax.measure.UnitConverter |
getSystemConverter()
Returns the converter from this unit to its unscaled
System Unit unit. |
AbstractUnit<Q> |
getSystemUnit()
Returns the system unit (unscaled SI unit) from which this unit is derived.
|
abstract int |
hashCode() |
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.
|
private static boolean |
isLongValue(double value) |
boolean |
isSystemUnit()
Indicates if this unit belongs to the set of coherent SI units (unscaled SI units).
|
javax.measure.Unit<?> |
multiply(AbstractUnit<?> that)
Returns the product of this physical unit with the one specified.
|
AbstractUnit<Q> |
multiply(double factor) |
javax.measure.Unit<?> |
multiply(javax.measure.Unit<?> that)
Returns the product of this unit with the one specified.
|
static javax.measure.Unit<?> |
parse(java.lang.CharSequence charSequence)
Returns the abstract unit represented by the specified characters as per standard UCUM format.
|
javax.measure.Unit<?> |
pow(int n)
Returns a unit equals to this unit raised to an exponent.
|
javax.measure.Unit<?> |
root(int n)
Returns a unit equals to the given root of this unit.
|
protected void |
setName(java.lang.String name) |
protected void |
setSymbol(java.lang.String s) |
AbstractUnit<Q> |
shift(double offset) |
java.lang.String |
toString()
Returns the standard representation of this physics unit.
|
protected abstract AbstractUnit<Q> |
toSystemUnit()
Returns the unscaled
SI unit from which this unit is derived. |
AbstractUnit<Q> |
transform(javax.measure.UnitConverter operation) |
private static final long serialVersionUID
public static final javax.measure.Unit<javax.measure.quantity.Dimensionless> ONE
ONE
.protected java.lang.String name
private java.lang.String symbol
protected static final java.util.Map<java.lang.String,javax.measure.Unit<?>> SYMBOL_TO_UNIT
protected java.lang.reflect.Type getActualType()
public boolean isSystemUnit()
equals(toSystemUnit())
protected abstract AbstractUnit<Q> toSystemUnit()
SI
unit from which this unit is derived.
They SI unit can be be used to identify a quantity given the unit. For example:[code] static boolean isAngularVelocity(AbstractUnit> unit) {
return unit.toSI().equals(RADIAN.divide(SECOND)); } assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true. [/code]public abstract javax.measure.UnitConverter getSystemConverter()
System Unit
unit.getConverterTo(this.toSystemUnit())
#toSI
public AnnotatedUnit<Q> annotate(java.lang.String annotation)
annotation
- the unit annotation.public static javax.measure.Unit<?> parse(java.lang.CharSequence charSequence)
org.unitsofmeasurement.service.UnitFormatService
or for non-OSGi
applications the LocalUnitFormat
utility class.
Note: The standard format supports dimensionless units.[code] AbstractUnit
charSequence
- the character sequence to parse.UCUMFormat.getCaseSensitiveInstance().parse(csq, new ParsePosition(0))
ParserException
- if the specified character sequence cannot be correctly parsed (e.g. not UCUM compliant).public java.lang.String toString()
org.unitsofmeasurement.service.UnitFormat
service.public final AbstractUnit<Q> getSystemUnit()
public final boolean isCompatible(javax.measure.Unit<?> that)
public final <T extends javax.measure.Quantity<T>> AbstractUnit<T> asType(java.lang.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.java.lang.ClassCastException
- if the dimension of this unit is different from the SI dimension of the specified type.AbstractSystemOfUnits.getUnit(Class)
public abstract java.util.Map<? extends javax.measure.Unit<?>,java.lang.Integer> getBaseUnits()
public abstract javax.measure.Dimension getDimension()
protected void setName(java.lang.String name)
public java.lang.String getName()
public java.lang.String getSymbol()
protected void setSymbol(java.lang.String s)
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
public final javax.measure.Unit<Q> alternate(java.lang.String symbol)
public final AbstractUnit<Q> transform(javax.measure.UnitConverter operation)
public final AbstractUnit<Q> shift(double offset)
public final AbstractUnit<Q> multiply(double factor)
private static boolean isLongValue(double value)
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.
public final javax.measure.Unit<?> multiply(AbstractUnit<?> that)
that
- the physical unit multiplicand.this * that
public final javax.measure.Unit<?> inverse()
public final AbstractUnit<Q> divide(double divisor)
QUART = GALLON_LIQUID_US.divide(4); // Exact definition.
public final javax.measure.Unit<?> divide(javax.measure.Unit<?> that)
public final javax.measure.Unit<?> divide(AbstractUnit<?> 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.java.lang.ArithmeticException
- if n == 0
or if this operation would result in an unit with a fractional exponent.public final javax.measure.Unit<?> pow(int n)
public int compareTo(javax.measure.Unit<Q> that)
public abstract int hashCode()
hashCode
in class java.lang.Object
public abstract boolean equals(java.lang.Object that)
equals
in class java.lang.Object