Package uk.me.nxg.unity
Class UnitDefinition
- java.lang.Object
-
- uk.me.nxg.unity.UnitDefinition
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<UnitDefinition>
public class UnitDefinition extends java.lang.Object implements java.io.Serializable, java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(UnitDefinition o)
java.lang.String
description()
Further remarks about this unit, or other commentsDimensions
dimensions()
The dimensions of this unit For example, the joule has dimensions ‘L^2 M T^-2’.boolean
equals(java.lang.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.java.lang.String
getURI()
The Kind of this unit, named by a URIint
hashCode()
java.lang.String
label()
A label for this unit, for example ‘Meter’.java.lang.String
latexForm()
A LaTeX version of the unit symbol, if there is one definedjava.lang.String
name()
The (human-readable) name of this unit, for example ‘Metre’ or ‘Second’java.lang.String
toString()
Produces a representation of this unit as a string, combining the name of the unit and a URI referring to it unambiguously.java.lang.String
type()
A label for the type of this unit, as a QUDT (or similar) ‘quantity’ URI.
-
-
-
Method Detail
-
name
public java.lang.String name()
The (human-readable) name of this unit, for example ‘Metre’ or ‘Second’- Returns:
- a string unit name (not null)
-
label
public java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 ofSyntax
- 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 interfacejava.lang.Comparable<UnitDefinition>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.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, useUnitExpr.toString()
. If you wish to get a human-readable representation of the unit, then usegetRepresentation(uk.me.nxg.unity.Syntax)
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the unit
-
-