Class Unit
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 Unit object with undefined exponents.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UnitThe electric current unit ampere (A)private static final intprivate static final Unit[]An array containing all units defined.static final UnitThe electric charge unit coulomb (C).static final UnitThe luminous intensity unit candela (cd)private static final intstatic final UnitThe capacitance unit farad (F).static final UnitThe absorbed dose unit gray (Gy).static final UnitThe frequency unit hertz (Hz).static final UnitThe energy unit joule (J).static final UnitThe temperature unit kelvin (K)private static final intstatic final UnitThe catalytic activity unit katal (kat).static final UnitThe mass unit kilogram (kg)private static final intstatic final UnitThe illuminance unit lux (lx).static final UnitThe length unit meter (m)static final UnitThe speed unit meter per second (m/s)static final UnitThe acceleration unit meter per second squared (m/s2)private static final intstatic final UnitThe area unit square meter (m2)static final UnitThe volume unit cubic meter (m3)private static final longstatic final UnitThe amount of substance unit mole (mol)private static final intstatic final UnitThe force unit newton (N).private final Stringstatic final UnitThe electric resistance unit ohm.static final UnitThe pressure unit pascal (Pa).static final UnitThe angle unit radians (rad)private static final intstatic final UnitThe time unit second (s)static final UnitThe electric conductance unit siemens (S).private static final intstatic final UnitThe magnetic flux density unit tesla (T).private final longstatic final UnitNo Unit (Unity)private static final longstatic final UnitThe electric potential difference unit volt (V).static final UnitThe power unit watt (W).static final UnitThe magnetic flux unit weber (Wb).private static final longprivate static final intprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) UnitReturns a newUnitthat is the addition of thisUnitand theUnitspecified.private static voidaddSIname(int si, String name, StringBuilder numerator, StringBuilder denominator) private static 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) UnitReturns a newUnitthat is the division of thisUnitand theUnitspecifiedbooleanChecks 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 booleanChecks whether the unit has a special type, i.e.(package private) UnitReturns a newUnitthat is the multiplication of thisUnitand theUnitspecified(package private) UnitReturns a newUnitthat is the subtraction between thisUnitand theUnitspecified.toString()Returns aStringobject representing theUnit
-
Field Details
-
UNITY
private static final long UNITY -
ZERO
private static final long ZERO- See Also:
-
MASK
private static final long MASK- See Also:
-
m_SHIFT
private static final int m_SHIFT- See Also:
-
s_SHIFT
private static final int s_SHIFT- See Also:
-
kg_SHIFT
private static final int kg_SHIFT- See Also:
-
K_SHIFT
private static final int K_SHIFT- See Also:
-
A_SHIFT
private static final int A_SHIFT- See Also:
-
mol_SHIFT
private static final int mol_SHIFT- See Also:
-
cd_SHIFT
private static final int cd_SHIFT- See Also:
-
rad_SHIFT
private static final int rad_SHIFT- See Also:
-
x_SHIFT
private static final int x_SHIFT- See Also:
-
x_MASK
private static final long x_MASK- See Also:
-
unity
No Unit (Unity) -
m
The length unit meter (m) -
s
The time unit second (s) -
kg
The mass unit kilogram (kg) -
K
The temperature unit kelvin (K) -
A
The electric current unit ampere (A) -
mol
The amount of substance unit mole (mol) -
cd
The luminous intensity unit candela (cd) -
m_s
The speed unit meter per second (m/s) -
m_s2
The acceleration unit meter per second squared (m/s2) -
m2
The area unit square meter (m2) -
m3
The volume unit cubic meter (m3) -
Hz
The frequency unit hertz (Hz).hertz is expressed in SI units as 1/s
-
N
The force unit newton (N).N is expressed in SI units as m·kg/s2
-
Pa
The pressure unit pascal (Pa).Pa is equal to N/m2 or is expressed in SI units as kg/m·s2
-
J
The energy unit joule (J).joule is equal to N·m or is expressed in SI units as m2·kg/s2
-
W
The power unit watt (W).watt is equal to J/s or is expressed in SI units as m2·kg/s3
-
C
The electric charge unit coulomb (C).coulomb is expressed in SI units as s·A
-
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
The capacitance unit farad (F).farad is equal to C/V or is expressed in SI units as s4·A2/m2·kg
-
Ohm
The electric resistance unit ohm.ohm is equal to V/A or is expressed in SI units as m2·kg/s3·A2
-
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
The magnetic flux unit weber (Wb).weber is equal to V·s or is expressed in SI units as m2·kg/s2·A
-
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
The illuminance unit lux (lx).lux is expressed in SI units as cd/m2
-
Gy
The absorbed dose unit gray (Gy).Gy is equal to J/kg or is expressed in SI units as m2/s2
-
kat
The catalytic activity unit katal (kat).katal is expressed in SI units as mol/s
-
rad
The angle unit radians (rad) -
allUnits
An array containing all units defined. The first seven items must be m, s, kg, K, A, mol, cd, rad in this order! -
base
-
name
-
type
private final long type
-
-
Constructor Details
-
Unit
Creates a newUnitinstance.- Parameters:
name- the name of theUnittype- the type of theUnit
-
-
Method Details
-
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
Checks whether thisUnitobject is equal to the specifiedUnitobject. TheUnitobjects are considered equal if their exponents are equal. -
hashCode
public int hashCode()Returns the hash code for this object. -
mul
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:
RuntimeException- if bothUnits are special- See Also:
-
div
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:
RuntimeException- if bothUnits are special- See Also:
-
add
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:
RuntimeException- if the twoUnits are not the same
-
sub
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:
RuntimeException- if theUnitspecified is not the same as thisUnit
-
find
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
Returns aStringobject representing theUnit -
computeName
-
addSIname
private static void addSIname(int si, String name, StringBuilder numerator, 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.
-