uk.me.nxg.unity
Class UnitDefinition

java.lang.Object
  extended by uk.me.nxg.unity.UnitDefinition
All Implemented Interfaces:
Serializable

public class UnitDefinition
extends Object
implements Serializable

Describes a unit.

A 'unit' is a notion like 'metre', or 'pixel', and is not dependent on a particular syntax. The syntax-specific aspects of this (described by UnitDefinition.Syntax) are how the unit is abbreviated, and indeed whether it is permitted in that syntax.

See Also:
Serialized Form

Nested Class Summary
 class UnitDefinition.Syntax
          Describes the per-syntax information about a unit.
 
Constructor Summary
UnitDefinition(String name, String type, String notes, String latexForm)
           
 
Method Summary
 boolean addSyntax(String syntax, String abbrev, String syntaxSpec)
          Add a new syntax to this unit definition.
 UnitDefinition.Syntax getSyntax(String syntax)
          Return the syntax-specific information about this unit.
 Set<String> getSyntaxes()
          Produces a set of the syntax names for this unit
 String latexForm()
          A LaTeX version of the unit abbrev, or null if a syntax-specific abbrev should be used
 String name()
          The name of this unit, for example 'metre'
 String notes()
          Further remarks about this unit, or other comments
 String toString()
          Produces a representation of this unit as a string.
 String type()
          A description of the type of this unit, for example 'length'
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnitDefinition

public UnitDefinition(String name,
                      String type,
                      String notes,
                      String latexForm)
Method Detail

name

public String name()
The name of this unit, for example 'metre'


type

public String type()
A description of the type of this unit, for example 'length'


notes

public String notes()
Further remarks about this unit, or other comments


latexForm

public String latexForm()
A LaTeX version of the unit abbrev, or null if a syntax-specific abbrev should be used


getSyntax

public UnitDefinition.Syntax getSyntax(String syntax)
Return the syntax-specific information about this unit. Returns null if the syntax is unknown for this unit, meaning that the given syntax does not recognise this unit as a recommended one.

As a special case, if the syntax is given as null, then return any syntax (the caller is presumably scratching around for something to print).

Parameters:
syntax - a string name for the syntax, which should be one of the syntaxes of UnitParser, or null if we want any syntax at all
Returns:
the syntax details for this unit in this syntax, or null if the syntax is unknown

getSyntaxes

public Set<String> getSyntaxes()
Produces a set of the syntax names for this unit


toString

public String toString()
Produces a representation of this unit as a string. This should not generally be used for formatting expressions: for that, use UnitExpr.toString().

Overrides:
toString in class Object

addSyntax

public boolean addSyntax(String syntax,
                         String abbrev,
                         String syntaxSpec)
                  throws UnitParserException
Add a new syntax to this unit definition. The string describing the syntax can contain the characters '1', 's' or 'd' to indicate respectively that the syntax is permissible, that SI prefixes may be used with it, and that it is nonetheless deprecated. There may be more than one permissible name for a unit (for example, "pix" and "pixel" may both be legitimate names for pixels).

This is not generally useful for clients -- it is intended for use while building the package.

Parameters:
syntax - the syntax being updated (eg "fits")
abbrev - the permissible name for this unit in this syntax (eg "m" for metre)
syntaxSpec - a string describing the syntax
Throws:
UnitParserException - if the syntax is not a recognised one