Class Unit
- java.lang.Object
-
- org.osgi.util.measurement.Unit
-
public class Unit extends java.lang.ObjectA unit system for measurements. This class contains definitions of the most common SI units.This class only support exponents for the base SI units in the range -64 to +63. Any operation which produces an exponent outside of this range will result in a
Unitobject with undefined exponents.
-
-
Field Summary
Fields Modifier and Type Field Description static UnitAThe electric current unit ampere (A)private static intA_SHIFTprivate static Unit[]allUnitsAn array containing all units defined.private static java.util.Map<Unit,Unit>basestatic UnitCThe electric charge unit coulomb (C).static UnitcdThe luminous intensity unit candela (cd)private static intcd_SHIFTstatic UnitFThe capacitance unit farad (F).static UnitGyThe absorbed dose unit gray (Gy).static UnitHzThe frequency unit hertz (Hz).static UnitJThe energy unit joule (J).static UnitKThe temperature unit kelvin (K)private static intK_SHIFTstatic UnitkatThe catalytic activity unit katal (kat).static UnitkgThe mass unit kilogram (kg)private static intkg_SHIFTstatic UnitlxThe illuminance unit lux (lx).static UnitmThe length unit meter (m)static Unitm_sThe speed unit meter per second (m/s)static Unitm_s2The acceleration unit meter per second squared (m/s2)private static intm_SHIFTstatic Unitm2The area unit square meter (m2)static Unitm3The volume unit cubic meter (m3)private static longMASKstatic UnitmolThe amount of substance unit mole (mol)private static intmol_SHIFTstatic UnitNThe force unit newton (N).private java.lang.Stringnamestatic UnitOhmThe electric resistance unit ohm.static UnitPaThe pressure unit pascal (Pa).static UnitradThe angle unit radians (rad)private static intrad_SHIFTstatic UnitsThe time unit second (s)static UnitSThe electric conductance unit siemens (S).private static ints_SHIFTstatic UnitTThe magnetic flux density unit tesla (T).private longtypestatic UnitunityNo Unit (Unity)private static longUNITYstatic UnitVThe electric potential difference unit volt (V).static UnitWThe power unit watt (W).static UnitWbThe magnetic flux unit weber (Wb).private static longx_MASKprivate static intx_SHIFTprivate static longZERO
-
Constructor Summary
Constructors Modifier Constructor Description privateUnit(java.lang.String name, long type)Creates a newUnitinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) Unitadd(Unit that)Returns a newUnitthat is the addition of thisUnitand theUnitspecified.private static voidaddSIname(int si, java.lang.String name, java.lang.StringBuilder numerator, java.lang.StringBuilder denominator)private static java.lang.StringcomputeName(long type)private static longcreateType(int _x, int _rad, int _cd, int _mol, int _A, int _K, int _kg, int _s, int _m)Create a type field from the base SI unit exponent values.(package private) Unitdiv(Unit that)Returns a newUnitthat is the division of thisUnitand theUnitspecifiedbooleanequals(java.lang.Object obj)Checks whether thisUnitobject is equal to the specifiedUnitobject.(package private) static Unitfind(long type)Finds aUnitbased on a type.inthashCode()Returns the hash code for this object.private booleanisSpecial()Checks whether the unit has a special type, i.e.(package private) Unitmul(Unit that)Returns a newUnitthat is the multiplication of thisUnitand theUnitspecified(package private) Unitsub(Unit that)Returns a newUnitthat is the subtraction between thisUnitand theUnitspecified.java.lang.StringtoString()Returns aStringobject representing theUnit
-
-
-
Field Detail
-
UNITY
private static final long UNITY
-
ZERO
private static final long ZERO
- See Also:
- Constant Field Values
-
MASK
private static final long MASK
- See Also:
- Constant Field Values
-
m_SHIFT
private static final int m_SHIFT
- See Also:
- Constant Field Values
-
s_SHIFT
private static final int s_SHIFT
- See Also:
- Constant Field Values
-
kg_SHIFT
private static final int kg_SHIFT
- See Also:
- Constant Field Values
-
K_SHIFT
private static final int K_SHIFT
- See Also:
- Constant Field Values
-
A_SHIFT
private static final int A_SHIFT
- See Also:
- Constant Field Values
-
mol_SHIFT
private static final int mol_SHIFT
- See Also:
- Constant Field Values
-
cd_SHIFT
private static final int cd_SHIFT
- See Also:
- Constant Field Values
-
rad_SHIFT
private static final int rad_SHIFT
- See Also:
- Constant Field Values
-
x_SHIFT
private static final int x_SHIFT
- See Also:
- Constant Field Values
-
x_MASK
private static final long x_MASK
- See Also:
- Constant Field Values
-
unity
public static final Unit unity
No Unit (Unity)
-
m
public static final Unit m
The length unit meter (m)
-
s
public static final Unit s
The time unit second (s)
-
kg
public static final Unit kg
The mass unit kilogram (kg)
-
K
public static final Unit K
The temperature unit kelvin (K)
-
A
public static final Unit A
The electric current unit ampere (A)
-
mol
public static final Unit mol
The amount of substance unit mole (mol)
-
cd
public static final Unit cd
The luminous intensity unit candela (cd)
-
m_s
public static final Unit m_s
The speed unit meter per second (m/s)
-
m_s2
public static final Unit m_s2
The acceleration unit meter per second squared (m/s2)
-
m2
public static final Unit m2
The area unit square meter (m2)
-
m3
public static final Unit m3
The volume unit cubic meter (m3)
-
Hz
public static final Unit Hz
The frequency unit hertz (Hz).hertz is expressed in SI units as 1/s
-
N
public static final Unit N
The force unit newton (N).N is expressed in SI units as m·kg/s2
-
Pa
public static final Unit Pa
The pressure unit pascal (Pa).Pa is equal to N/m2 or is expressed in SI units as kg/m·s2
-
J
public static final Unit J
The energy unit joule (J).joule is equal to N·m or is expressed in SI units as m2·kg/s2
-
W
public static final Unit W
The power unit watt (W).watt is equal to J/s or is expressed in SI units as m2·kg/s3
-
C
public static final Unit C
The electric charge unit coulomb (C).coulomb is expressed in SI units as s·A
-
V
public static final Unit V
The electric potential difference unit volt (V).volt is equal to W/A or is expressed in SI units as m2·kg/s3·A
-
F
public static final Unit F
The capacitance unit farad (F).farad is equal to C/V or is expressed in SI units as s4·A2/m2·kg
-
Ohm
public static final Unit Ohm
The electric resistance unit ohm.ohm is equal to V/A or is expressed in SI units as m2·kg/s3·A2
-
S
public static final Unit S
The electric conductance unit siemens (S).siemens is equal to A/V or is expressed in SI units as s3·A2/m2·kg
-
Wb
public static final Unit Wb
The magnetic flux unit weber (Wb).weber is equal to V·s or is expressed in SI units as m2·kg/s2·A
-
T
public static final Unit T
The magnetic flux density unit tesla (T).tesla is equal to Wb/m2 or is expressed in SI units as kg/s2·A
-
lx
public static final Unit lx
The illuminance unit lux (lx).lux is expressed in SI units as cd/m2
-
Gy
public static final Unit Gy
The absorbed dose unit gray (Gy).Gy is equal to J/kg or is expressed in SI units as m2/s2
-
kat
public static final Unit kat
The catalytic activity unit katal (kat).katal is expressed in SI units as mol/s
-
rad
public static final Unit rad
The angle unit radians (rad)
-
allUnits
private static final Unit[] allUnits
An array containing all units defined. The first seven items must be m, s, kg, K, A, mol, cd, rad in this order!
-
name
private final java.lang.String name
-
type
private final long type
-
-
Method Detail
-
createType
private static long createType(int _x, int _rad, int _cd, int _mol, int _A, int _K, int _kg, int _s, int _m)Create a type field from the base SI unit exponent values.
-
equals
public boolean equals(java.lang.Object obj)
Checks whether thisUnitobject is equal to the specifiedUnitobject. TheUnitobjects are considered equal if their exponents are equal.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- theUnitobject that should be checked for equality- Returns:
- true if the specified
Unitobject is equal to thisUnitobject.
-
hashCode
public int hashCode()
Returns the hash code for this object.- Overrides:
hashCodein classjava.lang.Object- Returns:
- This object's hash code.
-
mul
Unit mul(Unit that)
Returns a newUnitthat is the multiplication of thisUnitand theUnitspecified- Parameters:
that- theUnitthat will be multiplied with thisUnit- Returns:
- a new
Unitthat is the multiplication of thisUnitand theUnitspecified - Throws:
java.lang.RuntimeException- if bothUnits are special- See Also:
isSpecial()
-
div
Unit div(Unit that)
Returns a newUnitthat is the division of thisUnitand theUnitspecified- Parameters:
that- theUnitthat thisUnitwill be divided with- Returns:
- a new
Unitthat is the division of thisUnitand theUnitspecified - Throws:
java.lang.RuntimeException- if bothUnits are special- See Also:
isSpecial()
-
add
Unit add(Unit that)
Returns a newUnitthat is the addition of thisUnitand theUnitspecified.- Parameters:
that- theUnitthat should be added to thisUnit- Returns:
- a new
Unitthat is the addition of thisUnitand theUnitspecified. - Throws:
java.lang.RuntimeException- if the twoUnits are not the same
-
sub
Unit sub(Unit that)
Returns a newUnitthat is the subtraction between thisUnitand theUnitspecified.- Parameters:
that- theUnitthat will be subtracted from thisUnit- Returns:
- a new
Unitthat is the subtraction between thisUnitand theUnitspecified. - Throws:
java.lang.RuntimeException- if theUnitspecified is not the same as thisUnit
-
find
static Unit find(long type)
Finds aUnitbased on a type. If theUnitis not found, it will be created and added to the list of all units under a null name.- Parameters:
type- the type of theUnitto find- Returns:
- the
Unit
-
toString
public java.lang.String toString()
Returns aStringobject representing theUnit- Overrides:
toStringin classjava.lang.Object- Returns:
- A
Stringobject representing theUnit
-
computeName
private static java.lang.String computeName(long type)
-
addSIname
private static void addSIname(int si, java.lang.String name, java.lang.StringBuilder numerator, java.lang.StringBuilder denominator)
-
isSpecial
private boolean isSpecial()
Checks whether the unit has a special type, i.e. not a SI unit.- Returns:
- true if the type is special, otherwise false.
-
-