Class Unit
- All Implemented Interfaces:
Serializable
This class is by no means a complete handling of units. For complete
support, look at libraries like UOM. This class handles only
time, length, mass and current dimensions, as well as angles (which are
dimensionless).
Instances of this class are immutable.
- Since:
- 11.0
- Author:
- Luc Maisonobe
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UnitAmpere unit.static final UnitArc minute unit.static final UnitArc second unit.static final UnitBar unit.static final UnitCoulomb unit.static final UnitCycle unit.static final UnitDay unit.static final UnitDegree unit.static final UnitEarth Radii used as Bstar unit in CCSDS OMM.static final UnitGram unit.static final UnitHertz unit.static final UnitHour unit.static final UnitJoule unit.static final UnitKilogram unit.static final UnitKilometre unit.static final UnitMetre unit.static final UnitMinute unit.static final UnitNewton unit.static final UnitNo unit.static final UnitOhm unit.static final UnitDimensionless unit.static final UnitPascal unit.static final UnitPercentage unit.static final UnitRadian unit.static final UnitRevolution unit.static final UnitSecond unit.static final UnitSolar Flux Unit.static final Unittesla unit.static final UnitTotal Electron Content Unit.static final UnitVolt unit.static final UnitWatt unit.static final UnitJulian year unit. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate an alias for a unit.Create quotient of units.static voidensureCompatible(String description, List<Unit> reference, boolean allowScaleDifferences, List<Unit> units) Ensure some units are compatible with reference units.booleanCheck if the instance represents the same unit as another instance.doublefromSI(double value) Convert a value from SI units.doubleConvert a value from SI units.<T extends CalculusFieldElement<T>>
TfromSI(T value) Convert a value from SI units.getAngle()Get the angle exponent.Get the current exponent.Get the length exponent.getMass()Get the mass exponent.getName()Get the name of the unit.doublegetScale()Get the scaling factor to SI units.getTime()Get the time exponent.inthashCode()Get a hashcode for this unit.Create product of units.static UnitParse a unit.Create power of unit.booleansameDimension(Unit other) Check if a unit has the same dimension as another unit.Create the SI unit with same dimension.Scale a unit.Create root of unit.doubletoSI(double value) Convert a value to SI units.doubleConvert a value to SI units.<T extends CalculusFieldElement<T>>
TtoSI(T value) Convert a value to SI units.toString()
-
Field Details
-
NONE
No unit. -
ONE
Dimensionless unit. -
CYCLE
Cycle unit.- Since:
- 13.0
-
PERCENT
Percentage unit. -
SECOND
Second unit. -
MINUTE
Minute unit. -
HOUR
Hour unit. -
DAY
Day unit. -
YEAR
Julian year unit.- See Also:
-
HERTZ
Hertz unit. -
METRE
Metre unit. -
KILOMETRE
Kilometre unit. -
KILOGRAM
Kilogram unit. -
GRAM
Gram unit. -
AMPERE
Ampere unit. -
RADIAN
Radian unit. -
DEGREE
Degree unit. -
ARC_MINUTE
Arc minute unit. -
ARC_SECOND
Arc second unit. -
REVOLUTION
Revolution unit. -
NEWTON
Newton unit. -
PASCAL
Pascal unit. -
BAR
Bar unit. -
JOULE
Joule unit. -
WATT
Watt unit. -
COULOMB
Coulomb unit. -
VOLT
Volt unit. -
OHM
Ohm unit. -
TESLA
tesla unit. -
SOLAR_FLUX_UNIT
Solar Flux Unit. -
TOTAL_ELECTRON_CONTENT_UNIT
Total Electron Content Unit. -
EARTH_RADII
Earth Radii used as Bstar unit in CCSDS OMM.
-
-
Constructor Details
-
Unit
public Unit(String name, double scale, Fraction mass, Fraction length, Fraction time, Fraction current, Fraction angle) Simple constructor.- Parameters:
name- name of the unitscale- scaling factor to SI unitsmass- mass exponentlength- length exponenttime- time exponentcurrent- current exponentangle- angle exponent
-
-
Method Details
-
getName
Get the name of the unit.- Returns:
- name of the unit
-
getScale
public double getScale()Get the scaling factor to SI units.- Returns:
- scaling factor to SI units
-
getMass
Get the mass exponent.- Returns:
- mass exponent
-
getLength
Get the length exponent.- Returns:
- length exponent
-
getTime
Get the time exponent.- Returns:
- time exponent
-
getCurrent
Get the current exponent.- Returns:
- current exponent
-
getAngle
Get the angle exponent.- Returns:
- angle exponent
-
sameDimension
Check if a unit has the same dimension as another unit.- Parameters:
other- other unit to check against- Returns:
- true if unit has the same dimension as the other unit
-
sameDimensionSI
Create the SI unit with same dimension.- Returns:
- a new unit, with same dimension as instance and scaling factor set to 1.0
-
ensureCompatible
public static void ensureCompatible(String description, List<Unit> reference, boolean allowScaleDifferences, List<Unit> units) Ensure some units are compatible with reference units.- Parameters:
description- description of the units list (for error message generation)reference- reference unitsallowScaleDifferences- if true, unit with same dimension but different scale (likeKILOMETREversusMETRE) are allowed, otherwise they will trigger an exceptionunits- units to check- Throws:
OrekitException- if units are not compatible (number of elements, dimensions or scaling)
-
alias
Create an alias for a unit.- Parameters:
newName- name of the new unit- Returns:
- a new unit representing same unit as the instance but with a different name
-
scale
Scale a unit.- Parameters:
newName- name of the new unitfactor- scaling factor- Returns:
- a new unit representing scale times the instance
-
power
Create power of unit.- Parameters:
newName- name of the new unitexponent- exponent to apply- Returns:
- a new unit representing the power of the instance
-
sqrt
Create root of unit.- Parameters:
newName- name of the new unit- Returns:
- a new unit representing the square root of the instance
-
multiply
Create product of units.- Parameters:
newName- name of the new unitother- unit to multiply with- Returns:
- a new unit representing the this times the other unit
-
divide
Create quotient of units.- Parameters:
newName- name of the new unitother- unit to divide with- Returns:
- a new unit representing the this divided by the other unit
-
toSI
public double toSI(double value) Convert a value to SI units.- Parameters:
value- value instance unit- Returns:
- value in SI units
-
toSI
Convert a value to SI units.- Parameters:
value- value instance unit- Returns:
- value in SI units
-
toSI
Convert a value to SI units.- Type Parameters:
T- type of the field elements- Parameters:
value- value instance unit- Returns:
- value in SI units
- Since:
- 12.1
-
fromSI
public double fromSI(double value) Convert a value from SI units.- Parameters:
value- value SI unit- Returns:
- value in instance units
-
fromSI
Convert a value from SI units.- Parameters:
value- value SI unit- Returns:
- value in instance units
-
fromSI
Convert a value from SI units.- Type Parameters:
T- type of the field elements- Parameters:
value- value SI unit- Returns:
- value in instance units
-
parse
Parse a unit.The grammar for unit specification allows chains units multiplication and division, as well as putting powers on units.
The symbols used for units are the SI units with some extensions.
- year
- the accepted non-SI unit for Julian year is "a" but we also accept "yr"
- day
- the accepted non-SI unit for day is "d" but we also accept "day"
- dimensionless
- both "1" and "#" (U+0023, NUMBER SIGN) are accepted
- mass
- "g" is the standard symbol, despite the unit is "kg" (it is the only unit that has a prefix in its name, so all multiples must be based on "g")
- degrees
- the base symbol for degrees is "°" (U+00B0, DEGREE SIGN), but we also accept "◦" (U+25E6, WHITE BULLET) and "deg"
- arcminute
- The base symbol for arcminute is "′" (U+2032, PRIME) but we also accept "'" (U+0027, APOSTROPHE)
- arcsecond
- The base symbol for arcsecond is "″" (U+2033, DOUBLE PRIME) but we also accept "''" (two occurrences of U+0027, APOSTROPHE), "\"" (U+0022, QUOTATION MARK) and "as"
All the SI prefix (from "y", yocto, to "Y", Yotta) are accepted, as well as integer prefixes. The standard symbol for micro 10⁻⁶ is "µ" (U+00B5, MICRO SIGN), but we also accept "μ" (U+03BC, GREEK SMALL LETTER MU). Beware that some combinations are forbidden, for example "Pa" is Pascal, not peta-years, and "as" is arcsecond for this parser, not atto-seconds, because many people in the space field use mas for milliarcseconds and µas for microarcseconds. Beware that prefixes are case-sensitive! Integer prefixes can be used to specify units like "30s", but only once at the beginning of the specification (i.e. "2rev/d²" is accepted, but "rev/(2d)²" is refused). Conforming with SI brochure "The International System of Units" (9th edition, 2019), each SI prefix is part of the unit and precedes the unit symbol without a separator (i.e. MHz is seen as one identifier).
- multiplication
- can specified with either "*" (U+002A, ASTERISK), "×" (U+00D7, MULTIPLICATION SIGN), "." (U+002E, FULL STOP) or "·" (U+00B7, MIDDLE DOT) as the operator
- division
- can be specified with either "/" (U+002F, SOLIDUS) or "⁄" (U+2044, FRACTION SLASH) as the operator
- powers
- can be specified either by
- prefixing with the unicode "√" (U+221A, SQUARE ROOT) character
- postfixing with "**", "^" or implicitly using unicode superscripts
Exponents can be specified in different ways:
- as an integer, as in "m^-2" or "m⁻²"
- directly as unicode characters for the few fractions that unicode supports, as in "Ω^⅞"
- as the special decimal value 0.5 which is used by CCSDS, as in "km**0.5"
- as a pair of parentheses surrounding two integers separated by a solidus or fraction slash, as in "Pa^(11/12)"
These rules mean all the following (silly) examples are parsed properly: MHz, km/√d, kg.m.s⁻¹, µas^⅖/(h**(2)×m)³, km/√(kg.s), km**0.5, 2rev/d²
- Parameters:
unitSpecification- unit specification to parse- Returns:
- parsed unit
-
equals
Check if the instance represents the same unit as another instance.The name is not considered so aliases are considered equal.
-
hashCode
public int hashCode()Get a hashcode for this unit. -
toString
-