uk.me.nxg.unity
Class UnitExpr

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

public class UnitExpr
extends Object

A parsed unit expression.


Method Summary
 boolean allUnitsRecognised(String syntax)
          Indicates whether the parsed expression is composed only of recognised units, in the sense of OneUnit.isRecognisedUnit(java.lang.String).
 boolean allUnitsRecommended(String syntax)
          Indicates whether the parsed expression is composed only of recommended units, in the sense of OneUnit.isRecommendedUnit(java.lang.String).
 boolean allUsageConstraintsSatisfied(String syntax)
          Indicates whether the expression is being used in a way which satisfies any usage constraints, in the sense of OneUnit.satisfiesUsageConstraints(java.lang.String).
 List<OneUnit> asList()
          Return a representation of the parsed expression as a list of OneUnits.
 double getFactor()
          Obtain the factor multiplying this expression
 double getLogFactor()
          Obtain the base-10 log of the factor multiplying this expression
 OneUnit getUnit(String reqUnit)
          Returns the unit with the given base-unit.
 boolean isFullyConformant(String syntax)
          Indicates whether the expression is fully conformant with the appropriate recommendations.
 String toDebugString()
          Format the unit expression as a string, in some sort of canonical/unambiguous form.
 String toString()
          Produces a string representation of the unit expression, in a form suitable for display
 String toString(String syntax)
          Produces a string representation of the unit expression, in a format appropriate to the given syntax.
 String toString(String syntax, Locale locale)
          Produces a string representation of the unit expression, in a format appropriate to the given syntax, and with output respecting the conventions of the given locale.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getLogFactor

public double getLogFactor()
Obtain the base-10 log of the factor multiplying this expression


getFactor

public double getFactor()
Obtain the factor multiplying this expression


asList

public List<OneUnit> asList()
Return a representation of the parsed expression as a list of OneUnits.


getUnit

public OneUnit getUnit(String reqUnit)
Returns the unit with the given base-unit. If there is more than one known abbreviation for a unit (as is the case for "pixel" and "pix"), either may be used, irrespective of which one appeared in the originally parsed string.

Parameters:
reqUnit - the string representation of a base unit we're to find, such as "m"
Returns:
the OneUnit representing the presence of this unit in the expression, or null if the unit is not present

allUnitsRecommended

public boolean allUnitsRecommended(String syntax)
Indicates whether the parsed expression is composed only of recommended units, in the sense of OneUnit.isRecommendedUnit(java.lang.String). Recommended units are units which are both recognised and not deprecated.

Parameters:
syntax - the syntax with respect to which the units should be checked

allUnitsRecognised

public boolean allUnitsRecognised(String syntax)
Indicates whether the parsed expression is composed only of recognised units, in the sense of OneUnit.isRecognisedUnit(java.lang.String). That is, an expression composed of only non-deprecated and unknown units has no deprecated units.

Parameters:
syntax - the syntax with respect to which the units should be checked

allUsageConstraintsSatisfied

public boolean allUsageConstraintsSatisfied(String syntax)
Indicates whether the expression is being used in a way which satisfies any usage constraints, in the sense of OneUnit.satisfiesUsageConstraints(java.lang.String). 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

isFullyConformant

public boolean isFullyConformant(String syntax)
Indicates whether the expression is fully conformant with the appropriate recommendations. That is, all units are recommended, and are being used in a way which is conformant with any usage constraints.

Parameters:
syntax - one of the syntaxes of UnitParser

toString

public String toString()
Produces a string representation of the unit expression, in a form suitable for display

Overrides:
toString in class Object

toString

public String toString(String syntax)
                throws UnitParserException
Produces a string representation of the unit expression, in a format appropriate to the given syntax. The syntaxes are those of UnitParser. The output is locale-independent (which in practice means it is in the java.text.Locale.US locale).

Parameters:
syntax - the syntax to generate
Throws:
UnitParserException

toString

public String toString(String syntax,
                       Locale locale)
                throws UnitParserException
Produces a string representation of the unit expression, in a format appropriate to the given syntax, and with output respecting the conventions of the given locale. The syntaxes are those of UnitParser. If locale is null, the output is locale-independent (which in practice means it is in the java.text.Locale.US locale); note that this is distinct from the process's default locale.

Parameters:
syntax - the syntax to generate
locale - the locale to use, or null to use a 'no-locale' locale
Throws:
UnitParserException

toDebugString

public String toDebugString()
Format the unit expression as a string, in some sort of canonical/unambiguous form. The format of the output is unspecified: the toString() method is generally preferred as a way of formatting expressions.