uk.me.nxg.unity
Class Dimensions

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

public class Dimensions
extends Object

A dimensions specification is a record of the measurement dimensions of a quantity.

This is derived from the QUDT framework of quantities, units and dimensions, although it is not necessary to be familiar with that framework in order to use the Dimensions class. The methods here are primarily intended to be used to query the dimensions of an existing object, but there is a parser to create new dimension quantities, should that be necessary.

The known dimensions are

SymbolNameSI base unit
UDimensionlessUnity
LLengthMetre
MMassKilogramme
TTimeSecond
IElectric currentAmpère
ΘThermodynamic temperatureKelvin
NAmount of substanceMole
JLuminous intensityCandela


Method Summary
 float[] exponents()
          Return the numerical dimensions of the quantities in the expression.
 String getUri()
          Return a URI naming one of the dimensions in the QUDT dimensions ontology.
 Dimensions multiply(Dimensions d)
          Respond with a Dimensions object which is the result of multiplying the dimensions of this object by the dimensions of another.
static Dimensions multiply(Iterable<Dimensions> dimlist)
          Multiplies several dimensions together, and returns a (new) object representing the dimensions of the result.
static Dimensions parse(String dimensionString)
          Parse a dimension string to produce a new dimension object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

multiply

public Dimensions multiply(Dimensions d)
Respond with a Dimensions object which is the result of multiplying the dimensions of this object by the dimensions of another. This will be a new object, if the resulting dimensions are different.


multiply

public static Dimensions multiply(Iterable<Dimensions> dimlist)
Multiplies several dimensions together, and returns a (new) object representing the dimensions of the result. If any of the Dimensions in the list are null, the result is null (and not an error)


getUri

public String getUri()
Return a URI naming one of the dimensions in the QUDT dimensions ontology. We construct this based on the dimensions of the current quantity, rather than looking it up, so it's possible to construct one which isn't actually listed there.


exponents

public float[] exponents()
Return the numerical dimensions of the quantities in the expression. The result is an array of the exponents of the base dimensions, in the order 'U', 'L', 'M', 'T', 'I', 'Θ', 'N', 'J'.


parse

public static Dimensions parse(String dimensionString)
                        throws UnitParserException
Parse a dimension string to produce a new dimension object. If the string is not parseable, throw an exception.

A dimensions string consists of a sequence of capital letter dimensions, and powers, for example "M L2T-2" for the dimensions of "kg m2 s-2". The dimensions are as discussed in the class overview above.

Since the domain is so restricted, the parsing can be very liberal, and everything which isn't a letter, or part of a number, is ignored (for example '^'). That means, by the way, that a string like 'ML2/T2' wouldn't have the same dimensions as the example above. If any letters appear which are not one of the known dimension letters, we throw an exception.

Parameters:
dimensionString - a string composed of a sequence of dimension letters and numbers
Throws:
UnitParserException - if the string is malformed