herschel.share.unit
U - Class that extends this classpublic abstract class Unit<U extends Unit<U>> extends java.lang.Object implements java.io.Externalizable, java.lang.Comparable<Unit<?>>
Each unit is identified by an unique name. Alternatively, it may have a different dialog name, to be displayed in GUI dialogs.
The unit name may have any ASCII printable character (the ones from hexadecimal 20 to 7F). Spaces are only allowed if any sub-string is meaningful by its own. For example:
"arcsec" is a correct name.
"arc sec" is not a correct name (arc is not a unit).
"km s-1" is a correct name.
"km/s" is a correct name.
"km / s" is not a correct name (/ is not a unit).
"deg" is a correct name.
"°" is not a
correct name (non-ASCII character).
Click on the methods for more information about the functionality they provide, including usage samples.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MICRO
Micro prefix with the greek letter µ
|
static java.lang.String |
SQUARE
Superscript 2: ²
|
| Modifier and Type | Method and Description |
|---|---|
Unit<?> |
__div__(Unit<?> other)
Jython only: wrapper for abbreviated access to divide.
|
Unit<?> |
__mul__(Unit<?> other)
Jython only: wrapper for abbreviated access to multiply.
|
Unit<?> |
__pow__(int n)
Jython only: wrapper for abbreviated access to power.
|
Unit<U> |
atto()
Returns the derived Unit having the 10-18 prefix, atto (a).
|
Unit<U> |
centi()
Returns the derived Unit having the 10-2 prefix, centi (c).
|
static java.lang.String |
checkName(java.lang.String name)
Checks whether the name contains only printable ASCII characters or a
µ character.
|
int |
compareTo(Unit<?> other)
Compares units by their name.
|
Unit<U> |
deci()
Returns the derived Unit having the 10-1 prefix, deci (d).
|
Unit<U> |
deka()
Returns the derived Unit having the 10 prefix, deka (da).
|
Unit<?> |
divide(Unit<?> other)
Returns a unit equals to this unit divided by another unit.
|
boolean |
equals(java.lang.Object o)
Informs whether this unit is equal to another object.
|
Unit<U> |
exa()
Returns the derived Unit having the 1018 prefix, exa (E).
|
Unit<U> |
femto()
Returns the derived Unit having the 10-15 prefix, femto (f).
|
U |
getAsSI()
Returns this unit as an SI unit.
|
Unit<U> |
getAtto()
Returns the derived Unit having the 10-18 prefix, atto (a).
|
Unit<U> |
getCenti()
Returns the derived Unit having the 10-2 prefix, centi (c).
|
Unit<U> |
getDeci()
Returns the derived Unit having the 10-1 prefix, deci (d).
|
Unit<U> |
getDeka()
Returns the derived Unit having the 10 prefix, deka (da).
|
java.lang.String |
getDialogName()
Returns the unit in string short format for displaying in a dialog.
|
Unit<U> |
getExa()
Returns the derived Unit having the 1018 prefix, exa (E).
|
Unit<U> |
getFemto()
Returns the derived Unit having the 10-15 prefix, femto (f).
|
Unit<U> |
getGiga()
Returns the derived Unit having the 109 prefix, giga (G).
|
Unit<U> |
getHecto()
Returns the derived Unit having the 102 prefix, hecto (h).
|
UnitImpl |
getImpl()
There is no need to call this method by the users.
|
Unit<U> |
getKilo()
Returns the derived Unit having the 103 prefix, kilo (k).
|
Unit<U> |
getMega()
Returns the derived Unit having the 106 prefix, mega (M).
|
Unit<U> |
getMicro()
Returns the derived Unit having the 10-6 prefix, micro (µ).
|
Unit<U> |
getMilli()
Returns the derived Unit having the 10-3 prefix, milli (m).
|
java.lang.String |
getName()
Returns the unit in string ASCII short format.
|
Unit<U> |
getNano()
Returns the derived Unit having the 10-9 prefix, nano (n).
|
Unit<U> |
getPeta()
Returns the derived Unit having the 1015 prefix, peta (P).
|
Unit<U> |
getPico()
Returns the derived Unit having the 10-12 prefix, pico (p).
|
Unit<U> |
getTera()
Returns the derived Unit having the 1012 prefix, tera (T).
|
double |
getToSI()
Returns the conversion factor from the unit to the corresponding SI unit.
|
double |
getValue(double value,
Unit<?> other)
Returns the value given in the current unit, expressed in the new unit, which must be compatible with this one.
|
Unit<U> |
giga()
Returns the derived Unit having the 109 prefix, giga (G).
|
Unit<U> |
hecto()
Returns the derived Unit having the 102 prefix, hecto (h).
|
Unit<?> |
inverse()
Returns the inverse of this unit.
|
boolean |
isCompatible(Unit<?> other)
Informs whether this unit is compatible with another unit,
that is, if they have the same dimensions.
|
boolean |
isEquivalent(Unit<?> other)
Informs whether this unit is equivalent to another unit,
that is, if they are compatible
and the conversion factor from this unit to the other one is 1.
|
boolean |
isKnown()
Informs whether this unit is known.
|
Unit<U> |
kilo()
Returns the derived Unit having the 103 prefix, kilo (k).
|
Unit<U> |
mega()
Returns the derived Unit having the 106 prefix, mega (M).
|
Unit<U> |
micro()
Returns the derived Unit having the 10-6 prefix, micro (µ).
|
Unit<U> |
milli()
Returns the derived Unit having the 10-3 prefix, milli (m).
|
Unit<U> |
multiply(double factor,
java.lang.String name)
Returns the result of multiplying this unit by an approximate factor.
|
Unit<U> |
multiply(long factor,
java.lang.String name)
Returns the result of multiplying this unit by an exact factor.
|
Unit<?> |
multiply(Unit<?> other)
Returns a unit equals to this unit times another unit.
|
Unit<U> |
nano()
Returns the derived Unit having the 10-9 prefix, nano (n).
|
Unit<U> |
peta()
Returns the derived Unit having the 1015 prefix, peta (P).
|
Unit<U> |
pico()
Returns the derived Unit having the 10-12 prefix, pico (p).
|
Unit<?> |
power(int n)
Returns a unit equals to this unit raised to an exponent.
|
void |
readExternal(java.io.ObjectInput in)
Used for the serialization mechanism.
|
Unit<?> |
root(int n)
Returns a unit equals to the given root of this unit.
|
Unit<U> |
tera()
Returns the derived Unit having the 1012 prefix, tera (T).
|
double |
to(Unit<?> other)
Returns the conversion factor from this unit to other unit.
|
java.lang.String |
toString()
Returns a string representation of the unit.
|
void |
writeExternal(java.io.ObjectOutput out)
Used for the serialization mechanism.
|
public static final java.lang.String MICRO
public static final java.lang.String SQUARE
public static java.lang.String checkName(java.lang.String name)
name - Unit name to checkjava.lang.NullPointerException - If the name is null.java.lang.IllegalArgumentException - If the name contains any non 7-bit
printable ASCII character different than µ, it is empty, or it has
only spaces.public final Unit<?> __mul__(Unit<?> other)
Example:
SQUARE_METERS = Length.METERS * Length.METERS
Not to be used by Java-code developers!
multiply(Unit)public final Unit<?> __div__(Unit<?> other)
Example:
PASCAL = Force.NEWTONS / SQUARE_METERS
Not to be used by Java-code developers!
divide(Unit)public final Unit<?> __pow__(int n)
Example:
SQUARE_METERS = Length.METERS**2
Not to be used by Java-code developers!
power(int)public final double to(Unit<?> other)
Note that it has sense only for units with a linear relationship.
For a more general way of converting values from one unit to another, prefer getValue(double, herschel.share.unit.Unit>)
or use a UnitConverter.
Example:
Java
double degrees = 2.0;
double minutes = degrees * Angle.DEGREES.to(Angle.MINUTES_ARC);
System.out.println(minutes); // 120.0
Jython
degrees = 2.0
minutes = degrees * Angle.DEGREES.to(Angle.MINUTES_ARC)
print minutes # 120.0
other - Unit to which we want to know the conversion factor.IncompatibleUnitException - if the given unit is not compatible with this one.java.lang.UnsupportedOperationException - if called on an unknown unit.getValue(double, Unit),
getAsSI(),
getToSI()public final double getToSI()
Note that it has sense only for units with a linear relationship.
For a more general way of converting values to its SI representation, prefer getAsSI().
Example:
Java
System.out.println(Length.ANGSTROMS.getToSI()); // 1.0E-10
Jython
print Length.ANGSTROMS.toSI # 1.0E-10
java.lang.UnsupportedOperationException - if called on an unknown unit.getValue(double, Unit),
getAsSI(),
to(Unit)public final U getAsSI()
Examples:
Angle.DEGREES.getAsSI() => Angle.RADIANS
Speed.KILOMETERS_PER_HOUR.getAsSI() => Speed.METERS_PER_SECOND
Unit.parse("mV cm-1").getAsSI() => CompositeUnit("V m-1")
NOTE: Be aware that, for some units, the result may not be the
corresponding expected SI unit, but an equivalent composite one.
For instance, Pressure.BARS.getAsSI() may return
Pressure.PASCALS, CompositeUnit("kg m-1 s-2")
or even CompositeUnit("N s-2").
See equals(Object) for more information about the difference
between equal and equivalent units.
java.lang.UnsupportedOperationException - if called on an unknown unitgetValue(double, Unit),
getToSI(),
to(Unit)public final double getValue(double value,
Unit<?> other)
For a more general way of converting values between units, see UnitConverter.
Example:
Java
double degrees = 2.0;
double minutes = Angle.DEGREES.getValue(degrees, Angle.MINUTES_ARC);
System.out.println(minutes); // 120.0
Jython
degrees = 2.0
minutes = Angle.DEGREES.getValue(degrees, Angle.MINUTES_ARC)
print minutes # 120.0
value - Value in the current unit to be converted to the other unit.other - The returned value is expressed in this given unit.java.lang.NullPointerException - if the other unit is nullIncompatibleUnitException - if the other unit is not compatible with this onejava.lang.UnsupportedOperationException - if called on an unknown unitgetAsSI(),
getToSI(),
to(Unit),
isCompatible(Unit),
UnitConverterpublic final java.lang.String getName()
Examples:
WaveNumber.RECIPROCAL_METERS→ m-1Speed.KILOMETERS_PER_SECOND→ km s-1Length.MICROMETERS→ micrometerLength.ANGSTROMS→ angstromAngle.SECONDS_ARC→ arcsecELECTRON_VOLTS→ eVTemperature.CELSIUS→ degC
public final java.lang.String getDialogName()
Examples:
WaveNumber.RECIPROCAL_METERS→ m-1Speed.KILOMETERS_PER_SECOND→ km/sLength.MICROMETERS→ µmLength.ANGSTROMS→ ÅAngle.SECONDS_ARC→ "ELECTRON_VOLTS→ eVTemperature.CELSIUS→ °C
Note:
The actual dialog names for composite units may depend on the underlying implementation.
public final boolean isKnown()
multiply or
divide, derivations of the unit through prefix methods like
kilo or centi, checks against other units like
isEquivalent or isCompatible, etc. are allowed.
UnsupportedOperationException if any of those methods is
tried to be used.true if it is a known unit, false
otherwise.public final boolean isCompatible(Unit<?> other)
Example:
Unit DYNES = Unit.parse("g cm s-2");
Force.NEWTONS.equals(DYNES) == false, and
Force.NEWTONS.isEquivalent(DYNES) == false, but
Force.NEWTONS.isCompatible(DYNES) == true.
other - Unit to check compatibility withjava.lang.UnsupportedOperationException - if called on an unknown unitpublic final boolean isEquivalent(Unit<?> other)
Example:
Unit.parse("kg m s-2").equals(Force.NEWTONS) == false, but
Unit.parse("kg m s-2").isEquivalent(Force.NEWTONS) == true.
java.lang.UnsupportedOperationException - if called on an unknown unit.public final Unit<U> multiply(long factor, java.lang.String name)
factor - Exact factor to multiply with this unitname - Name to be assigned to the resulting unitjava.lang.UnsupportedOperationException - if called on an unknown unitpublic final Unit<U> multiply(double factor, java.lang.String name)
factor - Approximate factor to multiply with this unit (double is not exact)name - Name to be assigned to the resulting unitjava.lang.UnsupportedOperationException - if called on an unknown unitpublic final Unit<?> multiply(Unit<?> other)
java.lang.UnsupportedOperationException - if called on an unknown unit.public final Unit<?> divide(Unit<?> other)
java.lang.UnsupportedOperationException - if called on an unknown unit.public final Unit<?> power(int n)
java.lang.UnsupportedOperationException - if called on an unknown unit.public final Unit<?> root(int n)
java.lang.UnsupportedOperationException - if called on an unknown unit.public final Unit<?> inverse()
java.lang.UnsupportedOperationException - if called on an unknown unit.public final Unit<U> exa()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> peta()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> tera()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> giga()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> mega()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> kilo()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> hecto()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> deka()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> deci()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> centi()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> milli()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> micro()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> nano()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> pico()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> femto()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> atto()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getExa()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getPeta()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getTera()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getGiga()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getMega()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getKilo()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getHecto()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getDeka()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getDeci()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getCenti()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getMilli()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getMicro()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getNano()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getPico()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getFemto()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final Unit<U> getAtto()
java.lang.UnsupportedOperationException - if it is a product unit or an
unknown unit.public final UnitImpl getImpl()
Gets the unit implementation. If it is null, it creates a specific one for this unit.
public java.lang.String toString()
toString in class java.lang.Objectpublic final boolean equals(java.lang.Object o)
A unit is considered equal to another object if it is also a
Unit, and both units' implementations are equal.
Note that equivalent units are not ensured to be equal. Examples:
Length.METERS.equals(Unit.parse("m"))→ trueEnergy.JOULES.equals(Unit.parse("J"))→ trueEnergy.JOULES.equals(Unit.parse("N m"))→ false
For this reason, prefer using isEquivalent(Unit)
rather than equals when comparing units.
equals in class java.lang.Objectpublic final int compareTo(Unit<?> other)
compareTo in interface java.lang.Comparable<Unit<?>>public final void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
readExternal in interface java.io.Externalizablejava.io.IOExceptionjava.lang.ClassNotFoundExceptionExternalizable.readExternal(java.io.ObjectInput)public final void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
writeExternal in interface java.io.Externalizablejava.io.IOExceptionExternalizable.writeExternal(java.io.ObjectOutput)