public class Unit extends Object implements 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.
Modifier and Type | Field and Description |
---|---|
static Unit |
AMPERE
Ampere unit.
|
static Unit |
ARC_MINUTE
Arc minute unit.
|
static Unit |
ARC_SECOND
Arc second unit.
|
static Unit |
BAR
Bar unit.
|
static Unit |
COULOMB
Coulomb unit.
|
static Unit |
DAY
Day unit.
|
static Unit |
DEGREE
Degree unit.
|
static Unit |
EARTH_RADII
Earth Radii used as Bstar unit in CCSDS OMM.
|
static Unit |
GRAM
Gram unit.
|
static Unit |
HERTZ
Hertz unit.
|
static Unit |
HOUR
Hour unit.
|
static Unit |
JOULE
Joule unit.
|
static Unit |
KILOGRAM
Kilogram unit.
|
static Unit |
KILOMETRE
Kilometre unit.
|
static Unit |
METRE
Metre unit.
|
static Unit |
MINUTE
Minute unit.
|
static Unit |
NEWTON
Newton unit.
|
static Unit |
NONE
No unit.
|
static Unit |
OHM
Ohm unit.
|
static Unit |
ONE
Dimensionless unit.
|
static Unit |
PASCAL
Pascal unit.
|
static Unit |
PERCENT
Percentage unit.
|
static Unit |
RADIAN
Radian unit.
|
static Unit |
REVOLUTION
Revolution unit.
|
static Unit |
SECOND
Second unit.
|
static Unit |
SOLAR_FLUX_UNIT
Solar Flux Unit.
|
static Unit |
TESLA
tesla unit.
|
static Unit |
TOTAL_ELECTRON_CONTENT_UNIT
Total Electron Content Unit.
|
static Unit |
VOLT
Volt unit.
|
static Unit |
WATT
Watt unit.
|
static Unit |
YEAR
Julian year unit.
|
Constructor and Description |
---|
Unit(String name,
double scale,
Fraction mass,
Fraction length,
Fraction time,
Fraction current,
Fraction angle)
Simple constructor.
|
Modifier and Type | Method and Description |
---|---|
Unit |
alias(String newName)
Create an alias for a unit.
|
Unit |
divide(String newName,
Unit other)
Create quotient of units.
|
boolean |
equals(Object unit)
Check if the instance represents the same unit as another instance.
|
double |
fromSI(double value)
Convert a value from SI units.
|
double |
fromSI(Double value)
Convert a value from SI units.
|
Fraction |
getAngle()
Get the angle exponent.
|
Fraction |
getCurrent()
Get the current exponent.
|
Fraction |
getLength()
Get the length exponent.
|
Fraction |
getMass()
Get the mass exponent.
|
String |
getName()
Get the name of the unit.
|
double |
getScale()
Get the scaling factor to SI units.
|
Fraction |
getTime()
Get the time exponent.
|
int |
hashCode()
Get a hashcode for this unit.
|
Unit |
multiply(String newName,
Unit other)
Create product of units.
|
static Unit |
parse(String unitSpecification)
Parse a unit.
|
Unit |
power(String newName,
Fraction exponent)
Create power of unit.
|
boolean |
sameDimension(Unit other)
Check if a unit has the same dimension as another unit.
|
Unit |
sameDimensionSI()
Create the SI unit with same dimension.
|
Unit |
scale(String newName,
double factor)
Scale a unit.
|
Unit |
sqrt(String newName)
Create root of unit.
|
double |
toSI(double value)
Convert a value to SI units.
|
double |
toSI(Double value)
Convert a value to SI units.
|
String |
toString() |
public static final Unit NONE
public static final Unit ONE
public static final Unit PERCENT
public static final Unit SECOND
public static final Unit MINUTE
public static final Unit HOUR
public static final Unit DAY
public static final Unit YEAR
public static final Unit HERTZ
public static final Unit METRE
public static final Unit KILOMETRE
public static final Unit KILOGRAM
public static final Unit GRAM
public static final Unit AMPERE
public static final Unit RADIAN
public static final Unit DEGREE
public static final Unit ARC_MINUTE
public static final Unit ARC_SECOND
public static final Unit REVOLUTION
public static final Unit NEWTON
public static final Unit PASCAL
public static final Unit BAR
public static final Unit JOULE
public static final Unit WATT
public static final Unit COULOMB
public static final Unit VOLT
public static final Unit OHM
public static final Unit TESLA
public static final Unit SOLAR_FLUX_UNIT
public static final Unit TOTAL_ELECTRON_CONTENT_UNIT
public static final Unit EARTH_RADII
public Unit(String name, double scale, Fraction mass, Fraction length, Fraction time, Fraction current, Fraction angle)
name
- name of the unitscale
- scaling factor to SI unitsmass
- mass exponentlength
- length exponenttime
- time exponentcurrent
- current exponentangle
- angle exponentpublic String getName()
public double getScale()
public Fraction getMass()
public Fraction getLength()
public Fraction getTime()
public Fraction getCurrent()
public Fraction getAngle()
public boolean sameDimension(Unit other)
other
- other unit to check againstpublic Unit sameDimensionSI()
public Unit alias(String newName)
newName
- name of the new unitpublic Unit scale(String newName, double factor)
newName
- name of the new unitfactor
- scaling factorpublic Unit power(String newName, Fraction exponent)
newName
- name of the new unitexponent
- exponent to applypublic Unit sqrt(String newName)
newName
- name of the new unitpublic Unit multiply(String newName, Unit other)
newName
- name of the new unitother
- unit to multiply withpublic Unit divide(String newName, Unit other)
newName
- name of the new unitother
- unit to divide withpublic double toSI(double value)
value
- value instance unitpublic double toSI(Double value)
value
- value instance unitpublic double fromSI(double value)
value
- value SI unitpublic double fromSI(Double value)
value
- value SI unitpublic static Unit parse(String unitSpecification)
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.
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).
Exponents can be specified in different ways:
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²
unitSpecification
- unit specification to parsepublic boolean equals(Object unit)
The name is not considered so aliases are considered equal.
public int hashCode()
Copyright © 2002-2022 CS GROUP. All rights reserved.