|
Java Units API Build 2004-02-06 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object Unit
This class represents a unit of physical quantity.
It is helpful to think of instances of this class as recording the
history by which they are created. Thus, for example, the string
"g/kg" (which is a dimensionless unit) would result from invoking
the method toString() on a unit that was created by dividing a
gram unit by a kilogram unit. Yet, "kg" divided by "kg" returns
ONE
and not "kg/kg" due to automatic unit factorization.
This class supports the multiplication of offsets units. The result is usually a unit not convertible to its system unit. Such units may appear in derivative quantities. For example °C/m is a unit of gradient, which is common in atmospheric and oceanographic research.
Units raised at rational powers are also supported. For example the cubic root of "liter" is a unit compatible with meter.
Instances of this class (and sub-classes) are immutable and unique.
Field Summary | |
static Unit |
ONE
Holds the dimensionless unit ONE . |
Method Summary | |
Unit |
add(double offset)
Returns the result of adding an offset to this unit. |
Unit |
alternate(String symbol)
Returns a unit compatible to this unit except it uses the specified symbol. |
StringBuffer |
appendTo(StringBuffer sb)
Appends the text representation of this Unit to the
StringBuffer argument. |
Unit |
divide(Unit that)
Returns the quotient of this unit with the one specified. |
abstract boolean |
equals(Object that)
Indicates if this unit is equal to the object specified. |
Converter |
getConverterTo(Unit that)
Returns a converter of numeric values from this unit to another unit. |
Unit |
getDimension()
Returns the units identifying the dimension of this unit. |
protected static Unit |
getInstance(Unit template)
This method returns an Unit from the collection equals to the
specified template. |
static Collection |
getInstances()
Returns a read-only list of the currently-defined units. |
abstract Unit |
getSystemUnit()
Returns the system unit for this unit. |
int |
hashCode()
Returns a hash code value for this unit. |
boolean |
isCompatible(Unit that)
Indicates if this unit is compatible with the unit specified. |
boolean |
isSystemUnit()
Indicates if this unit is a system unit. |
Unit |
multiply(double scale)
Returns the result of multiplying this unit by a scale factor. |
Unit |
multiply(Unit that)
Returns the product of this unit with the one specified. |
Unit |
pow(int n)
Returns a unit equals to this unit raised to an exponent. |
protected Object |
readResolve()
Overrides readResolve() to ensure that deserialization
maintains unit's unicity. |
Unit |
root(int n)
Returns a unit equals to the given root of this unit. |
static Unit |
searchSymbol(CharSequence symbol)
Retrieves a unit from its symbol. |
String |
toString()
Returns the standard String representation of this unit. |
static Unit |
valueOf(CharSequence chars)
Returns a unit instance that is defined from the specified character sequence. |
Methods inherited from class Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final Unit ONE
ONE
.
Method Detail |
public final boolean isCompatible(Unit that)
RADIAN.equals(ONE) == false
RADIAN.isCompatible(ONE) == true
.
that
- the other unit.
true
if both units have the same dimension;
false
otherwise.getDimension()
public final Unit getDimension()
BaseUnit.setDimension(javax.units.Unit, javax.units.Converter)
public final Converter getConverterTo(Unit that) throws ConversionException
that
- the unit to which to convert the numeric values.
that
unit.
ConversionException
- if the conveter cannot be constructed
(e.g. !this.isCompatible(that)
).public final boolean isSystemUnit()
true
if this unit is a system unit;
false
otherwise.getSystemUnit()
public abstract Unit getSystemUnit()
Note: Having the same system units is not sufficient to ensure that a converter exists between the two units (e.g. °C/m and K/m).
isSystemUnit()
public final Unit alternate(String symbol)
RADIAN = ONE.alternate("rad");
NEWTON = METER.multiply(KILOGRAM).divide(SECOND.pow(2)).alternate("N");
PASCAL = NEWTON.divide(METER.pow(2)).alternate("Pa");
symbol
- the unique symbol for the alternate unit.
IllegalArgumentException
- if the specified symbol is currently
associated to a different unit.
UnsupportedOperationException
- if the specified unit is not
a system unit.isSystemUnit()
public final Unit add(double offset)
offset
- the offset added (expressed in this unit,
e.g. CELSIUS = KELVIN.add(273.15)
).
this + offset
.public final Unit multiply(double scale)
scale
- the scale factor
(e.g. KILOMETER = METER.multiply(1000)
).
this * scale
public final Unit multiply(Unit that)
that
- the unit multiplicand.
this * that
public final Unit divide(Unit that)
that
- the unit divisor.
this / that
public final Unit root(int n)
n
- the root's order.
ArithmeticException
- if n == 0
.public final Unit pow(int n)
n
- the exponent.
public static Unit valueOf(CharSequence chars)
ProductUnit
), then the corresponding
unit is created if not already defined.
Examples of valid entries (all for meters per second squared) are:
UnitFormat.parseObject(java.lang.String, java.text.ParsePosition)
is
recommended.
chars
- the character sequence.
IllegalArgumentException
- if the specified character sequence
cannot be correctly parsed (e.g. symbol unknown).public static Collection getInstances()
public static Unit searchSymbol(CharSequence symbol)
Note: Unlike valueOf(CharSequence)
, this method does not
parse the given string (it does not raise an exception either
if the specified symbol is not yet defined).
symbol
- the symbol searched for.
null
if such unit cannot be found.public final String toString()
String
representation of this unit.
appendTo(new StringBuffer()).toString()
public final StringBuffer appendTo(StringBuffer sb)
Unit
to the
StringBuffer
argument. For better formatting control,
UnitFormat.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
is recommended.
sb
- the StrinBuffer
to append.
UnitFormat.getStandardInstance().format(this, sb, null)
UnitFormat.getStandardInstance()
public abstract boolean equals(Object that)
==
to test for equality.
that
- the object to compare for equality.
true
if this unit and the specified object are
considered equal; false
otherwise.public final int hashCode()
equals(java.lang.Object)
protected static Unit getInstance(Unit template)
Unit
from the collection equals to the
specified template. If the unit is not found, the specified template is
added to the collection and being returned. This method is typically used
by sub-classes to ensure unicity of Unit
instances.
template
- the unit template for comparaison.
UnsupportedOperationException
- if the template cannot be added to
the collection (e.g. symbol already taken by a different unit).equals(java.lang.Object)
protected Object readResolve()
readResolve()
to ensure that deserialization
maintains unit's unicity.
|
Java Units API Build 2004-02-06 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Symbols, terms and definitions | JSR-108 project |