|
JScience v2.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.physics.units.Unit<Q>
public abstract class Unit<Q extends Quantity>
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<Dimensionless> |
ONE
Holds the dimensionless unit ONE. |
| Method Summary | ||
|---|---|---|
Unit<Q> |
alias(java.lang.String alias)
Attaches a system-wide alias to this unit. |
|
|
alternate(java.lang.String symbol)
Returns a unit compatible to this unit except it uses the specified symbol. |
|
CompoundUnit<Q> |
compound(Unit<Q> subunit)
Returns the combination of this unit with the specified sub-unit. |
|
|
divide(Unit that)
Returns the quotient of this unit with the one specified. |
|
boolean |
equals(java.lang.Object that)
Indicates if this unit is equal to the object specified. |
|
protected abstract boolean |
equalsImpl(java.lang.Object that)
Indicates if the specified unit can be considered equals to the one specified (for unicity purpose). |
|
Unit<? super Q> |
getBaseUnits()
Returns the base unit or product of base units this
unit is derived from. |
|
Converter |
getConverterTo(Unit that)
Returns a converter of numeric values from this unit to another unit. |
|
Dimension |
getDimension()
Returns the local dimension
of this unit. |
|
protected static
|
getInstance(Unit<Q> template)
This method returns an Unit from the collection
identified by the specified template; if such units does not
exists the specified template is added to the unit collection
and returned. |
|
static java.util.Set<Unit> |
getInstances()
Returns a read-only/thread safe set of the currently-defined units. |
|
Unit<? super Q> |
getParentUnit()
Returns the unit this unit is derived from. |
|
protected abstract Unit<? super Q> |
getParentUnitImpl()
Returns the parent units this unit is derived from. |
|
int |
hashCode()
Returns the hash code value for this unit. |
|
protected abstract int |
hashCodeImpl()
Returns the hash code for this unit (calculated only once as units are unique). |
|
|
inverse()
Returns the inverse of this unit. |
|
boolean |
isCompatible(Unit that)
Indicates if this unit is compatible with the unit specified. |
|
Unit<Q> |
label(java.lang.String label)
Attaches a system-wide label to the specified unit. |
|
Unit<Q> |
plus(double offset)
Returns the result of adding an offset to this unit. |
|
|
pow(int n)
Returns a unit equals to this unit raised to an exponent. |
|
protected java.lang.Object |
readResolve()
Overrides readResolve() to ensure that deserialization
maintains unit's unicity. |
|
|
root(int n)
Returns a unit equals to the given root of this unit. |
|
Unit<Q> |
times(double scale)
Returns the result of multiplying this unit by a scale factor. |
|
|
times(Unit that)
Returns the product of this unit with the one specified. |
|
Converter |
toBaseUnits()
Returns the converter from this unit to its base units. |
|
Converter |
toParentUnit()
Returns the converter from this unit to its parent unit. |
|
protected abstract Converter |
toParentUnitImpl()
Returns the converter to the parent unit. |
|
java.lang.String |
toString()
Returns the standard String representation of this unit. |
|
Text |
toText()
Returns the textual representation of this unit. |
|
Unit<Q> |
transform(Converter operation)
Returns the unit derived from this unit using the specified converter. |
|
static Unit |
valueOf(java.lang.CharSequence csq)
Returns a unit instance that is defined from the specified character sequence. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Unit<Dimensionless> ONE
ONE.
| Method Detail |
|---|
protected abstract int hashCodeImpl()
protected abstract boolean equalsImpl(java.lang.Object that)
true if this unit is considered equal to
that unit; false otherwise.protected abstract Unit<? super Q> getParentUnitImpl()
this if this unit is
a base unit or a product of base units.protected abstract Converter toParentUnitImpl()
getParentUnitImpl()public final Unit<? super Q> getParentUnit()
Note: Having the same parent unit is not sufficient to ensure that a converter exists between the two units (e.g. °C/m and K/m).
this if this unit is
a base unit or a product of base units.public final Converter toParentUnit()
this.getConverterTo(this.getParentUnit())public final Unit<? super Q> getBaseUnits()
base unit or product of base units this
unit is derived from.
Note: Having the same base units is not sufficient to ensure that a converter exists between the two units (e.g. °C/m and K/m).
public final Converter toBaseUnits()
this.getConverterTo(this.getBaseUnits())public final boolean isCompatible(Unit that)
RADIAN.equals(ONE) == false
RADIAN.isCompatible(ONE) == true.
that - the other unit.
this.getDimension() == that.getDimension()public final Dimension getDimension()
local dimension
of this unit.
BaseUnit.setDimension(org.jscience.physics.units.Dimension, org.jscience.physics.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 <T extends Q> org.jscience.physics.units.AlternateUnit<T> alternate(java.lang.String symbol)
Unit<Angle> RADIAN = Unit.ONE.alternate("rad");
Unit<Force> NEWTON = METER.multiply(KILOGRAM).divide(SECOND.pow(2)).alternate("N");
Unit<Pressure> PASCAL = NEWTON.divide(METER.pow(2)).alternate("Pa");
Any unit having the specified symbol as label loses its label
(symbols and labels cannot conflict).
symbol - the unique symbol for the alternate unit.
AlternateUnit.getInstance(symbol, this)
java.lang.IllegalArgumentException - if the specified symbol is currently
a symbol associated to a different unit.public final CompoundUnit<Q> compound(Unit<Q> subunit)
HOUR_MINUTE = NonSI.HOUR.compound(NonSI.MINUTE);
DEGREE_MINUTE_SECOND_ANGLE = NonSI.DEGREE_ANGLE.compound(
NonSI.DEGREE_MINUTE).compound(NonSI.SECOND_ANGLE);
subunit - the sub-unit to combine with this unit.
CompoundUnit.getInstance(this, subUnit)public final Unit<Q> transform(Converter operation)
Unit>Dimensionless> DECIBEL = Unit.ONE.transform(
new LogConverter(10).inverse().concatenate(
new MultiplyConverter(0.1))).label("dB");
operation - the converter from the transformed unit to this unit.
public final Unit<Q> plus(double offset)
offset - the offset added (expressed in this unit,
e.g. CELSIUS = KELVIN.plus(273.15)).
this.transform(new AddConverter(offset))public final Unit<Q> times(double scale)
scale - the scale factor
(e.g. KILOMETER = METER.multiply(1000)).
this.transform(new MultiplyConverter(scale))public final <Q extends Quantity> Unit<Q> times(Unit that)
that - the unit multiplicand.
this * thatpublic final <Q extends Quantity> Unit<Q> inverse()
1 / thispublic final <Q extends Quantity> Unit<Q> divide(Unit that)
that - the unit divisor.
this / thatpublic final <Q extends Quantity> Unit<Q> root(int n)
n - the root's order.
java.lang.ArithmeticException - if n == 0.public final <Q extends Quantity> Unit<Q> pow(int n)
n - the exponent.
public Unit<Q> label(java.lang.String label)
aliases). For example:
DAY.multiply(365).label("year");
Unit FOOT = METER.multiply(0.3048).label("ft");
label - the new label for this unit or null
to detache the previous label (if any).
java.lang.IllegalArgumentException - if the specified label is a known
symbol (base unit or alternate unit).public Unit<Q> alias(java.lang.String alias)
METER.multiply(0.3048).alias("foot");
METER.multiply(0.3048).alias("feet");
METER.alias("meter");
METER.alias("metre");
alias - the alias being attached to this unit.
java.lang.IllegalArgumentException - if the specified alias is a known
symbol (base unit / alternate unit) or a currently associated
label.public static Unit valueOf(java.lang.CharSequence csq)
ProductUnit), then the corresponding
unit is created if not already defined.
Examples of valid entries (all for meters per second squared) are:
csq - the character sequence to parse.
UnitFormat.current().parse(csq)
java.lang.IllegalArgumentException - if the specified character sequence
cannot be correctly parsed (e.g. symbol unknown).UnitFormat.current()public static java.util.Set<Unit> getInstances()
public Text toText()
UnitFormatpublic final java.lang.String toString()
String representation of this unit.
toString in class java.lang.ObjecttoText().toString();protected static <Q extends Quantity> Unit<Q> getInstance(Unit<Q> template)
Unit from the collection
identified by the specified template; if such units does not
exists the specified template is added to the unit collection
and returned.
template - the unit template for comparison.
java.lang.IllegalArgumentException - if the template uses an intrinsic
symbol already taken by a different unit.equalsImpl(Object)public final boolean equals(java.lang.Object that)
== to test for equality.
equals in class java.lang.Objectthat - the object to compare for equality.
this == thatpublic final int hashCode()
hashCode in class java.lang.Objectprotected java.lang.Object readResolve()
readResolve() to ensure that deserialization
maintains unit's unicity.
|
JScience v2.0 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||