com.rubecula.jquantity
Class JQuantityPresentation

java.lang.Object
  |
  +--com.rubecula.util.Presentation
        |
        +--com.rubecula.jquantity.JQuantityPresentation
All Implemented Interfaces:
Auditable, Identifiable

public class JQuantityPresentation
extends Presentation
implements Identifiable

This class is a string-component representation of a JQuantity.

Version:
$Revision: 1.1 $
Author:
Robin Hillyard

Field Summary
(package private) static java.lang.String _PresentableClass
          This string defines the class which will be used to parse JQuantityPresentations.
 
Fields inherited from class com.rubecula.util.Presentation
$empty, $Stars
 
Constructor Summary
JQuantityPresentation()
          Empty constructor to create an undefine JQuantityPresentation.
JQuantityPresentation(java.lang.String identifier, NumberPresentation real, NumberPresentation imag, java.lang.String units)
          Primary constructor to create an identified, possibly complex, JQuantityPresentation, optionally with defined Units.
JQuantityPresentation(java.lang.String identifier, java.lang.String real)
          Secondary constructor to create an identified, JQuantityPresentation, optionally with defined Units.
JQuantityPresentation(java.lang.String identifier, java.lang.String real, java.lang.String units)
          Secondary constructor to create an identified, JQuantityPresentation, optionally with defined Units.
JQuantityPresentation(java.lang.String identifier, java.lang.String real, java.lang.String imag, java.lang.String units)
          Secondary constructor to create an identified, possibly complex, JQuantityPresentation, optionally with defined Units.
 
Method Summary
 java.lang.String audit(java.lang.String label)
          Method to return a detailed string from an arithmetical object for debugging purposes.
 java.lang.String getIdentifier()
          Method to get the specific identifier for an object.
 NumberPresentation getImag()
           
 NumberPresentation getReal()
           
 java.lang.String getUnitsPart()
           
static void main(java.lang.String[] args)
          Main method for testing this class.
 Presentable parse()
          Convert Presentation x into a Presentable object.
 void setIdentifier(java.lang.String identifier)
          Method to set a specific identifier to an object.
 Presentation setValue(java.lang.String source)
          Fix the value of this Presentation according to the given string s.
 java.lang.String toString(int width)
          Render this Presentation as a String within the width specified.
static JQuantityPresentation valueOf(java.lang.String string)
          Factory method to create a JQuantityPresentation from a String.
 
Methods inherited from class com.rubecula.util.Presentation
audit, audit, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_PresentableClass

static java.lang.String _PresentableClass
This string defines the class which will be used to parse JQuantityPresentations. Note: Currently the value is "com.rubecula.jquantity.Quantity".

Constructor Detail

JQuantityPresentation

public JQuantityPresentation(java.lang.String identifier,
                             NumberPresentation real,
                             NumberPresentation imag,
                             java.lang.String units)
Primary constructor to create an identified, possibly complex, JQuantityPresentation, optionally with defined Units.

Parameters:
identifier - a String to be used to identify this presentation.
real - a NumberPresentation representing the real part of this presentation.
imag - a NumberPresentation representing the imaginary part of this presentation.
units - a String to represent the units (may be "").

JQuantityPresentation

public JQuantityPresentation(java.lang.String identifier,
                             java.lang.String real,
                             java.lang.String imag,
                             java.lang.String units)
                      throws PresentationException
Secondary constructor to create an identified, possibly complex, JQuantityPresentation, optionally with defined Units.

Parameters:
identifier - a String to be used to identify this presentation.
real - a string representing the real part of this presentation.
imag - a string representing the imaginary part of this presentation.
units - a String to represent the units (may be "").
Throws:
PresentationException

JQuantityPresentation

public JQuantityPresentation(java.lang.String identifier,
                             java.lang.String real,
                             java.lang.String units)
                      throws PresentationException
Secondary constructor to create an identified, JQuantityPresentation, optionally with defined Units.

Parameters:
identifier - a String to be used to identify this presentation.
real - a String representing the real part of this presentation (see ValuePresentation).
units - a String to represent the units (or null).
Throws:
PresentationException

JQuantityPresentation

public JQuantityPresentation(java.lang.String identifier,
                             java.lang.String real)
                      throws PresentationException
Secondary constructor to create an identified, JQuantityPresentation, optionally with defined Units.

Parameters:
identifier - a String to be used to identify this presentation.
real - a String representing the real part of this presentation (see ValuePresentation).
Throws:
PresentationException

JQuantityPresentation

public JQuantityPresentation()
Empty constructor to create an undefine JQuantityPresentation.

Method Detail

valueOf

public static JQuantityPresentation valueOf(java.lang.String string)
                                     throws PresentationException
Factory method to create a JQuantityPresentation from a String.

Parameters:
string - the string from which to create the JQuantityPresentation.
Returns:
the new JQuantityPresentation.
Throws:
PresentationException

parse

public Presentable parse()
Convert Presentation x into a Presentable object.
Note that this method must be an instance method since it is defined in the Presentable interface, but really it would like to be a class method, i.e. we never actually reference this.

Specified by:
parse in class Presentation
Returns:
an appropriate instance of Presentable.

setValue

public Presentation setValue(java.lang.String source)
                      throws PresentationException
Fix the value of this Presentation according to the given string s. The details of what is created will vary according to the implementer and the string itself.

Parameters:
source - the string representing all aspects of this value. The format of the string is:
[Identifier ':'] ValuePresentation ['i' ValuePresentation ] ['@' Units]
where:
Identifier
represents a string which will be used when the Presentation is audited;
ValuePresentation
represents a
Returns:
a newly-minted JQuantityPresentation with value defined by source.
Throws:
PresentationException
See Also:
either the (required) real part or the (optional) imaginary part.
Units
the name of the Units

toString

public java.lang.String toString(int width)
Render this Presentation as a String within the width specified.

Specified by:
toString in class Presentation
Parameters:
width - the max. number of characters within which to output the presentation.
Returns:
a representation (rendering) of this Presentation.

setIdentifier

public void setIdentifier(java.lang.String identifier)
Method to set a specific identifier to an object.

Specified by:
setIdentifier in interface Identifiable
Parameters:
identifier - String: the identifier to associate with the object

getIdentifier

public java.lang.String getIdentifier()
Method to get the specific identifier for an object.

Specified by:
getIdentifier in interface Auditable
Returns:
"<" value ">"

audit

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

Specified by:
audit in interface Auditable
Parameters:
label - String: the label to associate with the data
Returns:
the detailed string.

getReal

public NumberPresentation getReal()
Returns:
the String representing the integer part, derived directly from the original string.

getImag

public NumberPresentation getImag()
Returns:
the String representing the integer part, derived directly from the original string.

getUnitsPart

public java.lang.String getUnitsPart()
Returns:
the String representing the integer part, derived directly from the original string.

main

public static void main(java.lang.String[] args)
Main method for testing this class.

Parameters:
args - String[] : the command line options.