|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.me.nxg.unity.OneUnit
uk.me.nxg.unity.SimpleUnit
public class SimpleUnit
A single simple unit. This is represented as a prefix, a base unit and an exponent. For example, the string "mm s^-2" will result in two SimpleUnit instances, one of which will have a base unit of "m" and a prefix power of -3, and the other of which will have a base unit of "s" and an exponent of -2.
This represents the abstract unit, shorn of the symbols which were parsed to obtain it. Thus if, in some odd syntax, the symbol 'x' were used to denote metres, then the SimpleUnit instance which resulted would be the same as the OneUnit which resulted from a more conventional syntax.
Also, there is a potential ambiguity if a symbol is recognised
in one syntax, but not in another. Thus if the string 'erg' were
parsed in a syntax which didn't recognise that, then it would be
stored as just that, an unrecognised symbol, not associated with
the UnitDefinition
for the erg.
The class's instances are immutable.
Method Summary | |
---|---|
boolean |
equals(Object o)
Two units are equal if they have the same power, units and exponent. |
UnitDefinition |
getBaseUnitDefinition()
Returns the known base unit. |
String |
getBaseUnitName()
Returns the name of this unit. |
String |
getBaseUnitString()
Returns the base unit string, which will only be non-null if this unit was an unrecognised one. |
Dimensions |
getDimensions()
Return the dimensions of the unit, if it is a recognised one. |
int |
getPrefix()
Returns the prefix of the unit, as a base-ten log. |
int |
hashCode()
|
boolean |
isRecognisedUnit(String syntax)
Indicates whether the base unit is one of those recognised within the specification of the given syntax. |
boolean |
isRecommendedUnit(String syntax)
Indicates whether the base unit is one of those recommended within the specification of the given syntax. |
boolean |
satisfiesUsageConstraints(String syntax)
Indicates whether the unit is being used in a way which satisfies any usage constraints. |
String |
toDebugString()
Write out the unit in a testable format. |
String |
toString()
Format this unit in some sort of canonical form. |
String |
toString(String syntax)
Format this unit in some sort of canonical form appropriate to the given syntax. |
String |
unitString()
Obtains the string form of the unit, including prefix, with a default syntax. |
String |
unitString(String syntaxName)
Obtains the string representation of the unit, including prefix, in the given syntax. |
Methods inherited from class uk.me.nxg.unity.OneUnit |
---|
getExponent |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public int getPrefix()
getPrefix
in class OneUnit
public String toString()
OneUnit
UnitExpr.toString()
.
toString
in class OneUnit
public String toString(String syntax)
OneUnit
UnitExpr.toString()
.
toString
in class OneUnit
public String unitString(String syntaxName) throws UnitParserException
OneUnit
unitString
in class OneUnit
syntaxName
- one of the syntaxes of UnitParser
UnitParserException
- if the syntax is unrecognisedpublic UnitDefinition getBaseUnitDefinition()
OneUnit
OneUnit.getBaseUnitString()
will not.
Note that the 'base unit' is simply the unit without the prefix, and doesn't refer to the fundamental SI base units. Thus in the expression "MW", it is 'W', Watt, that is the base unit.
getBaseUnitDefinition
in class OneUnit
public String getBaseUnitName()
OneUnit
getBaseUnitName
in class OneUnit
public String getBaseUnitString()
OneUnit
getBaseUnitString
in class OneUnit
public Dimensions getDimensions()
OneUnit
getDimensions
in class OneUnit
public String unitString()
The default syntax is (currently) the syntax with which this unit was originally read.
public boolean isRecognisedUnit(String syntax)
OneUnit
Note that this checks that the unit is a recommended one: we don't (currently) check whether the abbreviation that got us here is a recommended one (for example, "pixel" is a valid FITS/CDS name for pixels, and "pix" is a FITS and OGIP one).
isRecognisedUnit
in class OneUnit
syntax
- one of the syntaxes of UnitParser
OneUnit.isRecommendedUnit(java.lang.String)
public boolean isRecommendedUnit(String syntax)
OneUnit
Note that this checks that the unit is a recommended one: we don't (currently) check whether the abbreviation that got us here is a recommended one (for example, "pixel" is a valid FITS/CDS name for pixels, and "pix" is a FITS and OGIP one).
isRecommendedUnit
in class OneUnit
syntax
- one of the syntaxes of UnitParser
OneUnit.isRecognisedUnit(java.lang.String)
public boolean satisfiesUsageConstraints(String syntax)
OneUnit
An unrecognised unit has no constraints, and so will always satisfy them; this extends to units which are unrecognised in a particular syntax.
satisfiesUsageConstraints
in class OneUnit
syntax
- one of the syntaxes of UnitParser
public String toDebugString()
OneUnit
toDebugString
in class OneUnit
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |