com.rubecula.jquantity
Class FlatUnit

java.lang.Object
  extended bycom.rubecula.util.Item
      extended bycom.rubecula.jquantity.BaseUnit
          extended bycom.rubecula.jquantity.FlatUnit
All Implemented Interfaces:
com.rubecula.util.Auditable, Comparable, com.rubecula.util.Identifiable, Measurable, com.rubecula.util.Presentable, Serializable

public class FlatUnit
extends BaseUnit

The public class FlatUnit is used to describe a Measurable which has been flattened out so that all its dimensions and its scale are readily apparent.

Version:
$Revision: 1.4 $
Author:
Robin Hillyard
See Also:
Serialized Form

Field Summary
private  Dimensions _Dimensions
          The Dimensions corresponding to this flattened unit.
private  Rational _Scale
          The scale of this flattened unit.
 
Fields inherited from class com.rubecula.util.Item
JQUANTITY_TEST
 
Constructor Summary
(package private) FlatUnit(Dimensions dimensions, Rational scale)
          Primary constructor to create a FlatUnit.
(package private) FlatUnit(Measurable other)
          Constructor to copy another Measurable.
 
Method Summary
 String audit(String label)
          Method to return a detailed string from an object for debugging purposes.
 BaseUnit flatten()
          Method to reduce a Units tree to a single flattened version.
 Dimensions getDimensions()
          Method to return the dimensions of this Measurable.
 String getIdentifier()
           
 UnitsName getName()
           
 Rational getOffset()
          Method to return the offset of this Measurable.
 Rational getScale()
          Method to return the scale of this Measurable.
 SystemFlag getSystem()
           
 boolean isEqual(Measurable other)
          Method to determine if this BaseUnit is equivalent to that Measurable.
 boolean isInSystem(int sysIndex)
          Method to determine if this Measurable is in a certain system of units.
 boolean isNumber()
          Method to determine if this is dimensionless (i.e. unitless).
static void main(String[] args)
           
 com.rubecula.util.Presentable makePresentableInstance(com.rubecula.util.Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
 com.rubecula.util.Presentation present(com.rubecula.util.AttrMap attributes)
          Convert this Presentable object into a Presentation, according to the set of attributes provided.
 String toString()
           
 
Methods inherited from class com.rubecula.jquantity.BaseUnit
isParallel, isParallelInSystem
 
Methods inherited from class com.rubecula.util.Item
audit, audit, compareTo, Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, Wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_Dimensions

private Dimensions _Dimensions
The Dimensions corresponding to this flattened unit.


_Scale

private Rational _Scale
The scale of this flattened unit.

Constructor Detail

FlatUnit

FlatUnit(Dimensions dimensions,
         Rational scale)
Primary constructor to create a FlatUnit.

Parameters:
dimensions - the Dimensions to use.
scale - the scale to use.

FlatUnit

FlatUnit(Measurable other)
   throws JQuantityException
Constructor to copy another Measurable.

Parameters:
other - that other Measurable.
Throws:
JQuantityException
Method Detail

getName

public UnitsName getName()

getSystem

public SystemFlag getSystem()

getDimensions

public Dimensions getDimensions()
Method to return the dimensions of this Measurable.

Returns:
the Dimensions.

getScale

public Rational getScale()
Method to return the scale of this Measurable.

Returns:
the scale.

getOffset

public Rational getOffset()
Method to return the offset of this Measurable.

Returns:
the offset, usually $0.

isInSystem

public boolean isInSystem(int sysIndex)
Method to determine if this Measurable is in a certain system of units.

Overrides:
isInSystem in class BaseUnit
Parameters:
sysIndex - the index of the units system.
Returns:
true of this Measurable belongs to System defined by sysIndex.

flatten

public BaseUnit flatten()
                 throws JQuantityException
Method to reduce a Units tree to a single flattened version.

Returns:
the equivalent FlatUnit.
Throws:
JQuantityException

isNumber

public boolean isNumber()
Method to determine if this is dimensionless (i.e. unitless).

Specified by:
isNumber in interface Measurable
Overrides:
isNumber in class BaseUnit
Returns:
true if not in any System.

getIdentifier

public final String getIdentifier()

isEqual

public boolean isEqual(Measurable other)
Description copied from class: BaseUnit
Method to determine if this BaseUnit is equivalent to that Measurable.

Overrides:
isEqual in class BaseUnit
Parameters:
other - the Measurable to compare.
Returns:
true if isParallel(other) and if their respective scales and offsets are equal.

toString

public String toString()

audit

public String audit(String label)
Method to return a detailed string from an object for debugging purposes.

Parameters:
label - the label to associate with the data. If label is non-null, a more detailed audit will be returned (this normally occurs only at the top level).
Returns:
the detailed string.

present

public com.rubecula.util.Presentation present(com.rubecula.util.AttrMap attributes)
                                       throws com.rubecula.util.PresentationException
Convert this Presentable object into a Presentation, according to the set of attributes provided.

Parameters:
attributes - a map of the attributes desired for the construction of the new presentation (may be empty).
Returns:
an appropriate instance of Presentation.
Throws:
com.rubecula.util.PresentationException - in case of parsing error.

makePresentableInstance

public com.rubecula.util.Presentable makePresentableInstance(com.rubecula.util.Presentation presentation)
                                                      throws com.rubecula.util.PresentationException
Instance method to convert a Presentation into a Presentable. Ideally, this would be a class method, but such a method cannot be defined in an interface. Nor can it be defined in an abstract class with the intention of overriding it in a subclass. Polymorphism just doesn't work that way.
Therefore, the present value (as in fields) of the instance is essentially ignored - only the methods are important.

Parameters:
presentation - of a number to be converted into a Presentable number.
Returns:
a number in the form of a Presentable.
Throws:
com.rubecula.util.PresentationException - in case of parsing error.

main

public static void main(String[] args)