uk.me.nxg.unity
Class OneUnit

java.lang.Object
  extended by uk.me.nxg.unity.OneUnit

public class OneUnit
extends Object

A single unit. For example, the string "m s^-2" will result in two OneUnit instances, corresponding to "m" and "s^-2".


Method Summary
 String getBaseUnit()
          Returns the base unit for this string, in a default syntax
 String getBaseUnit(String syntaxName)
          Returns the base unit for this string, in the given syntax
 UnitDefinition getBaseUnitDefinition()
           
 double getExponent()
          Obtains the power the unit is raised to.
 double getPower()
          Returns the power to which this unit is raised.
 int getPrefix()
          Returns the prefix of the unit, as a base-ten log.
 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 unitString()
          Obtains the string form of the unit, including prefix, with a default syntax.
 String unitString(String syntaxName)
          Obtains the string form of the unit, including prefix, in the given syntax.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getPrefix

public int getPrefix()
Returns the prefix of the unit, as a base-ten log. Thus a prefix of "m", for "milli", would produce a prefix of -3.


getPower

public double getPower()
Returns the power to which this unit is raised. A unit of "mm^3" would return 3.0, and "m^(-1/2)" would return -0.5.


toString

public String toString()
Format this unit in some sort of canonical form. The form is unspecified. This should not generally be used for formatted output -- for that, it will generally be more appropriate to use UnitExpr.toString().

Overrides:
toString in class Object

unitString

public String unitString(String syntaxName)
Obtains the string form of the unit, including prefix, in the given syntax. That is, return 'mm' not 'm'.


getBaseUnitDefinition

public UnitDefinition getBaseUnitDefinition()

getBaseUnit

public String getBaseUnit()
Returns the base unit for this string, in a default syntax

Returns:
the base unit as, for example, "m" for metres

getBaseUnit

public String getBaseUnit(String syntaxName)
Returns the base unit for this string, in the given syntax

Parameters:
syntaxName - one of the syntaxes of UnitParser
Returns:
the base unit as, for example, "m" for metres

unitString

public String unitString()
Obtains the string form of the unit, including prefix, with a default syntax. That is, return 'mm' not 'm'.


getExponent

public double getExponent()
Obtains the power the unit is raised to. For example, for the unit 'mm^2', return 2.


isRecognisedUnit

public boolean isRecognisedUnit(String syntax)
Indicates whether the base unit is one of those recognised within the specification of the given syntax. In this context, "recognised" means "mentioned in the specification", so deprecated units count as recognised ones.

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).

Parameters:
syntax - one of the syntaxes of UnitParser
See Also:
isRecommendedUnit(java.lang.String)

isRecommendedUnit

public boolean isRecommendedUnit(String syntax)
Indicates whether the base unit is one of those recommended within the specification of the given syntax. In this context, "recommended" means "mentioned in the specification" and not deprecated.

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).

Parameters:
syntax - one of the syntaxes of UnitParser
See Also:
isRecognisedUnit(java.lang.String)

satisfiesUsageConstraints

public boolean satisfiesUsageConstraints(String syntax)
Indicates whether the unit is being used in a way which satisfies any usage constraints. Principally, this tests whether a unit which may not be used with SI prefixes was provided with a prefix, but there may be other constraints present.

An unrecognised unit has no constraints, and so will always satisfy them; this extends to units which are unrecognised in a particular syntax.

Parameters:
syntax - one of the syntaxes of UnitParser

toDebugString

public String toDebugString()
Write out the unit in a testable format. This is for debugging and testing.