public abstract class AbstractUnit<Q extends javax.measure.Quantity<Q>> extends Object implements javax.measure.Unit<Q>, Comparable<javax.measure.Unit<Q>>
The class represents units founded on the seven SI base units for seven base quantities assumed to be mutually independent.
For all physics units, units 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 String |
name
Holds the name.
|
static javax.measure.Unit<javax.measure.quantity.Dimensionless> |
ONE
Holds the dimensionless unit
ONE . |
Modifier | Constructor and Description |
---|---|
protected |
AbstractUnit()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
javax.measure.Unit<Q> |
alternate(String symbol) |
AnnotatedUnit<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)
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(Object that) |
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() |
abstract javax.measure.UnitConverter |
getSystemConverter()
Returns the converter from this unit to its unscaled
standard 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.
|
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.
|
javax.measure.Unit<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(CharSequence charSequence)
Returns the physics unit represented by the specified characters.
|
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(String name) |
protected void |
setSymbol(String s) |
javax.measure.Unit<Q> |
shift(double offset) |
String |
toString()
Returns the standard
String representation of this unit. |
protected abstract AbstractUnit<Q> |
toSystemUnit()
Returns the unscaled standard (SI) unit from which this unit is derived.
|
javax.measure.Unit<Q> |
transform(javax.measure.UnitConverter operation) |
public static final javax.measure.Unit<javax.measure.quantity.Dimensionless> ONE
ONE
.protected AbstractUnit()
public int compareTo(javax.measure.Unit<Q> that)
compareTo
in interface Comparable<javax.measure.Unit<Q extends javax.measure.Quantity<Q>>>
public boolean isSystemUnit()
equals(toSystemUnit())
protected abstract AbstractUnit<Q> toSystemUnit()
static boolean isAngularVelocity(AbstractUnit<?> unit) {
return unit.toSystemUnit().equals(RADIAN.divide(SECOND)); }
assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.
public abstract javax.measure.UnitConverter getSystemConverter()
standard
unit.getConverterTo(this.toSystemUnit())
toSystemUnit()
public AnnotatedUnit<Q> annotate(String annotation)
Unit<Volume> PERCENT_VOL =
Units.PERCENT.annotate("vol"); // "%{vol}" AbstractUnit<Mass> KG_TOTAL =
Units.KILOGRAM.annotate("total"); // "kg{total}" AbstractUnit<Dimensionless>
RED_BLOOD_CELLS = ONE.annotate("RBC"); // "{RBC}"
Note: Annotations of system units are not considered themselves as system units.annotation
- the unit annotation.public static javax.measure.Unit<?> parse(CharSequence charSequence)
UnitFormatService
or for non-OSGi applications instances of
SimpleUnitFormat
.
Note: The standard format supports dimensionless units. AbstractUnit<Dimensionless> PERCENT =
AbstractUnit.parse("100").inverse().asType(Dimensionless.class);
charSequence
- the character sequence to parse.SimpleUnitFormat.getInstance().parse(csq)
ParserException
- if the specified character sequence cannot be parsed correctly.public String toString()
String
representation of this 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 Map, Hashtable, etc.
Locale-sensitive unit parsing should be handled using the OSGi tec.units.ri.SimpleUnitFormat.service.UnitFormat
service (or
SimpleUnitFormat
for non-OSGi applications).public final AbstractUnit<Q> getSystemUnit()
public final boolean isCompatible(javax.measure.Unit<?> that)
public final <T extends javax.measure.Quantity<T>> javax.measure.Unit<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
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 javax.measure.Unit<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<?> 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 final javax.measure.Unit<?> pow(int n)
Copyright © 2005–2017 Jean-Marie Dautelle, Werner Keil, V2COM. All rights reserved.