Package uk.me.nxg.unity

# Class UnitDefinition

java.lang.Object
uk.me.nxg.unity.UnitDefinition

All Implemented Interfaces:
  `Serializable`, `Comparable<UnitDefinition>`

public class UnitDefinition extends Object implements Serializable, Comparable<UnitDefinition>
Describes a unit.

A ‘unit’is a notion like ‘metre’, or ‘pixel’, and is not dependent on a particular syntax. The information here includes a readable name for a quantity (such as ‘Metre’ or ‘Julian year’), a URI uniquely naming it, and its dimensions.

The URI unique name is derived from the QUDT framework of quantities, units and dimensions, though it is not restricted to the set of units and quantities defined there.

The syntax-specific aspects of describing units concern how the unit is abbreviated, and indeed whether it is permitted or recommended in a particular syntax, and this is described by the class `UnitRepresentation`.

See Also:
  - Serialized Form

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(UnitDefinition o)`
`String`
`description()`
Further remarks about this unit, or other comments
`Dimensions`
`dimensions()`
The dimensions of this unit For example, the joule has dimensions ‘L^2 M T^-2’.
`boolean`
`equals(Object o)`
`UnitRepresentation`
`getRepresentation()`
Return a representation of this unit, from any syntax that knows of one.
`UnitRepresentation`
`getRepresentation(Syntax syntax)`
Return the syntax-specific information about this unit.
`String`
`getURI()`
The Kind of this unit, named by a URI
`int`
`hashCode()`
`String`
`label()`
A label for this unit, for example ‘Meter’.
`String`
`latexForm()`
A LaTeX version of the unit symbol, if there is one defined
`String`
`name()`
The (human-readable) name of this unit, for example ‘Metre’ or ‘Second’
`String`
`toString()`
Produces a representation of this unit as a string, combining the name of the unit and a URI referring to it unambiguously.
`String`
`type()`
A label for the type of this unit, as a QUDT (or similar) ‘quantity’ URI.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Method Details

### name

public String name()
The (human-readable) name of this unit, for example ‘Metre’ or ‘Second’

Returns:
  a string unit name (not null)

### label

public String label()
A label for this unit, for example ‘Meter’. It is (currently) formed from the URI of the unit, but this version of the library doesn't commit to the label being completely stable. This label will typically be the same as the name, but will not, for example, have spaces in it, and will not necessarily be spelled the same way. For example the URI for the metre has fragment `#Meter`, and that for the second `#SecondTime`.

Returns:
  a string denoting the unit, without spaces and expected to be unique (not null)

### type

public String type()
A label for the type of this unit, as a QUDT (or similar) ‘quantity’ URI. For example the metre and the light year are both ‘http://qudt.org/vocab/quantity#Length’

Returns:
  a string unit description (not null)

### description

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

Returns:
  comments about the unit, or null if there is nothing more to say

### latexForm

public String latexForm()
A LaTeX version of the unit symbol, if there is one defined

Returns:
  a string representation of the unit in LaTeX form, or null if there is no special form

### dimensions

public Dimensions dimensions()
The dimensions of this unit For example, the joule has dimensions ‘L^2 M T^-2’.

Returns:
  a Dimensions object representing the unit dimensions

### getURI

public String getURI()
The Kind of this unit, named by a URI

Returns:
  a string representing the unit's URI

### getRepresentation

public UnitRepresentation getRepresentation(Syntax 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.

Parameters:
  `syntax` - a non-null string name for the syntax, which should be one of the syntaxes of `Syntax`
Returns:
  the syntax details for this unit in this syntax, or null if the syntax is unknown

### getRepresentation

public UnitRepresentation getRepresentation()
Return a representation of this unit, from any syntax that knows of one. Since every known unit appears in at least one map, this will never return null.

Returns:
  a representation of this unit

### compareTo

public int compareTo(UnitDefinition o)

Specified by:
  `compareTo` in interface `Comparable<UnitDefinition>`

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()
Produces a representation of this unit as a string, combining the name of the unit and a URI referring to it unambiguously. This is occasionally useful, but not for formatting expressions into unit strings: for that, use `UnitExpr.toString()`. If you wish to get a human-readable representation of the unit, then use `getRepresentation(uk.me.nxg.unity.Syntax)`.

Overrides:
  `toString` in class `Object`
Returns:
  a string representation of the unit