com.rubecula.jquantity
Class SymbolicPresentation

java.lang.Object
  extended bycom.rubecula.util.Presentation
      extended bycom.rubecula.jquantity.SymbolicPresentation
All Implemented Interfaces:
Auditable, Documentable, Identifiable

public class SymbolicPresentation
extends Presentation
implements Documentable

Class to model the presentation of symbolic text, for example in a mathematical formula.

Since:
V_0_2
Version:
$Revision: 1.24 $ // TODO This is somewhat simplistic. Could be made more useful. // TODO This should not directly refer to Value.
Author:
Robin Hillyard

Field Summary
(package private) static java.lang.String _PresentableClass
          This string defines the class which will be used to parse JQuantityPresentations.
private  java.util.Vector _Presentations
          List of component presentations, some of which may be pure Strings.
static java.lang.String $E
          The symbolic representation of e (base of natural logarithms) - i.e. the letter e alone.
static java.lang.String $I
          The symbolic representation of i - i.e. the square root of -1.
static java.lang.String $Infinity
          The symbolic representation of infinity.
static java.lang.String $Pi
          The symbolic representation of pi - i.e. the greek letter.
 
Fields inherited from class com.rubecula.util.Presentation
_Appearance, $empty, $Stars
 
Constructor Summary
  SymbolicPresentation()
          Secondary constructor to create an empty SymbolicPresentation.
  SymbolicPresentation(Presentation presentation)
          Secondary constructor.
  SymbolicPresentation(Presentation presentation1, Presentation presentation2)
          Secondary constructor.
  SymbolicPresentation(Presentation presentation1, java.lang.String presentation2)
          Secondary constructor.
  SymbolicPresentation(java.lang.String string)
          Secondary constructor.
protected SymbolicPresentation(java.util.Vector presentations)
          Primary constructor.
 
Method Summary
 void add(java.lang.Object o)
          Add a Presentation or String to this SymbolicPresentation
 java.lang.String audit(java.lang.String label)
          Method to return a detailed string from an object for debugging purposes.
 AttrMap getAttributes()
          Return the attributes with which this presentation was created, or at least the best guess.
 java.lang.String getIdentifier()
          Method to get the specific identifier for an object.
private static Presentable GetPresentable(java.lang.Object component)
           
 java.lang.String getPresentableClass()
          Method to get the name of the corresponding Presentable class for this Presentation.
protected  boolean isOperator(java.lang.String string)
           
 java.util.Iterator iterator()
           
private  int length()
          Method to get the lengthwise dimension of this presentation.
static void main(java.lang.String[] args)
          Main method for testing this class.
private static Presentable parseStringComponent(java.lang.String component)
          Method to parse this text presentation and create a new Presentable object.
 void refineStructure(java.lang.Object token)
          This method is used to discover serial-type delimiters and create an appropriate structure.
 void refineStructure(java.lang.Object tokenStart, java.lang.Object tokenEnd)
          This method is used to discover open/close delimiter pairs and create an appropriate structure.
 void render(StylishWriteable doc)
          This method is used to render this object in the context of a StylishWriteable doc.
 void replace(int index, java.lang.Object o)
           
protected static void testPresentation(java.io.PrintStream out, Presentation presentation, java.lang.String label)
           
 java.lang.String toString(int width)
          Render this Presentation as a String within the width specified.
 
Methods inherited from class com.rubecula.util.Presentation
audit, audit, parse, toString, updateAppearance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

$Pi

public static final java.lang.String $Pi
The symbolic representation of pi - i.e. the greek letter.

See Also:
Constant Field Values

$I

public static final java.lang.String $I
The symbolic representation of i - i.e. the square root of -1.

See Also:
Constant Field Values

$E

public static final java.lang.String $E
The symbolic representation of e (base of natural logarithms) - i.e. the letter e alone.

See Also:
Constant Field Values

$Infinity

public static final java.lang.String $Infinity
The symbolic representation of infinity.

See Also:
Constant Field Values

_Presentations

private java.util.Vector _Presentations
List of component presentations, some of which may be pure Strings.


_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". // TODO Change value to "com.rubecula.jquantity.JQuantity".

Constructor Detail

SymbolicPresentation

protected SymbolicPresentation(java.util.Vector presentations)
Primary constructor.

Parameters:
presentations - the vector of presentations.

SymbolicPresentation

public SymbolicPresentation()
Secondary constructor to create an empty SymbolicPresentation.


SymbolicPresentation

public SymbolicPresentation(Presentation presentation)
Secondary constructor.

Parameters:
presentation - the initial presentation for this new SymbolicPresentation.

SymbolicPresentation

public SymbolicPresentation(Presentation presentation1,
                            Presentation presentation2)
Secondary constructor.

Parameters:
presentation1 - the initial presentation for this new SymbolicPresentation.
presentation2 - the second presentation for this new SymbolicPresentation.

SymbolicPresentation

public SymbolicPresentation(Presentation presentation1,
                            java.lang.String presentation2)
Secondary constructor.

Parameters:
presentation1 - the initial presentation for this new SymbolicPresentation.
presentation2 - the second presentation for this new SymbolicPresentation.

SymbolicPresentation

public SymbolicPresentation(java.lang.String string)
Secondary constructor.

Parameters:
string - the text for the one (simple) presentation.
Method Detail

testPresentation

protected static void testPresentation(java.io.PrintStream out,
                                       Presentation presentation,
                                       java.lang.String label)

main

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

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

getAttributes

public AttrMap getAttributes()
                      throws PresentationException
Return the attributes with which this presentation was created, or at least the best guess.

Specified by:
getAttributes in class Presentation
Returns:
a map of attributes used to render this Presentation. Currently returns an empty map.
Throws:
PresentationException

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.
Throws:
PresentationException - if the presentation cannot be rendered within the given width. // TODO make this more sophisticated. Currently it just concatenates the presentations. // TODO deal more properly with the case where we ignore non-trailing "1" presentations. // TODO in particular, we want to add more structure including spacing between elements.

audit

public java.lang.String audit(java.lang.String label)
Description copied from interface: Auditable
Method to return a detailed string from an object for debugging purposes.

Specified by:
audit in interface Auditable
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.

getPresentableClass

public java.lang.String getPresentableClass()
Method to get the name of the corresponding Presentable class for this Presentation.

Specified by:
getPresentableClass in class Presentation
Returns:
_PresentableClass.

getIdentifier

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

Specified by:
getIdentifier in interface Identifiable
Returns:
the text itself.

render

public void render(StylishWriteable doc)
Description copied from interface: Documentable
This method is used to render this object in the context of a StylishWriteable doc.

Specified by:
render in interface Documentable
Parameters:
doc - the document in which to render this object.

parseStringComponent

private static Presentable parseStringComponent(java.lang.String component)
                                         throws PresentationException
Method to parse this text presentation and create a new Presentable object.

Parameters:
component - a string representation of a Value.
Returns:
a Presentable object of class Value.
Throws:
PresentationException - if the symbolic presentation cannot be parsed.

isOperator

protected boolean isOperator(java.lang.String string)

length

private int length()
Method to get the lengthwise dimension of this presentation. Note that it correctly deals with unicode characters.

Returns:
the length of the presentation.

add

public void add(java.lang.Object o)
         throws PresentationException
Add a Presentation or String to this SymbolicPresentation

Parameters:
o - the Presentation or String to be added.
Throws:
PresentationException - if o is not a Presentation or String.

replace

public void replace(int index,
                    java.lang.Object o)
             throws PresentationException
Throws:
PresentationException

refineStructure

public void refineStructure(java.lang.Object tokenStart,
                            java.lang.Object tokenEnd)
                     throws PresentationException
This method is used to discover open/close delimiter pairs and create an appropriate structure. Note that we never create an extra nesting level for a single element.

Parameters:
tokenStart - the opening token
tokenEnd - the closing token // TODO Note that it cannot deal with nested delimiters of the same type. That has to be fixed, obviously.
Throws:
PresentationException

refineStructure

public void refineStructure(java.lang.Object token)
                     throws PresentationException
This method is used to discover serial-type delimiters and create an appropriate structure. Note that we never create an extra nesting level for a single element.

Parameters:
token - the token
Throws:
PresentationException

iterator

public java.util.Iterator iterator()

GetPresentable

private static Presentable GetPresentable(java.lang.Object component)
                                   throws PresentationException
Throws:
PresentationException