Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.singularsys.jep
Class PrintVisitor

    java.lang.Object
      com.singularsys.jep.PrintVisitor

All Implemented Interfaces:
  JepComponent, ParserVisitor, java.io.Serializable

    public class PrintVisitor

extends java.lang.Object
implements ParserVisitor, JepComponent

Prints an expression. Prints the expression with lots of brackets. `((-1.0)/sqrt((1.0-(x^2.0))))`. To use

     Jep j = ...; Node in = ...;
     j.print(in, "x");

Since:
  Dec 04 and NumberFormat object can be supplied to modify printing of numbers., 21 Dec 04 PrintVisitor can now cope with 3 or more arguments to + and *., 3.3 greater customisation now possible
Author:
  Rich Morris Created on 20-Jun-2003
See Also:
  `Jep.print(Node)`, `Jep.print(Node, PrintStream)`, `Jep.println(Node)`, `Jep.println(Node, PrintStream)`, `Jep.toString(Node)`, Serialized Form

Nested Class Summary
`static interface` | `PrintVisitor.PrintRulesI` This interface specifies the method needed to implement a special print rule.

Field Summary
`static int` | `COMPLEX_I` Print Complex as 3+2 i
`protected java.text.NumberFormat` | `format` The NumberFormat object used to print numbers.
`static int` | `FULL_BRACKET` All brackets are printed.
`protected int` | `mode` The current mode for printing.
`protected java.lang.StringBuffer` | `sb`

Constructor Summary
`PrintVisitor()` Creates a visitor to create and print string representations of an expression tree.

Method Summary
`void` | `addSpecialRule(Operator op, PrintVisitor.PrintRulesI rule)` Adds a special print rule to be added for a given operator.
`void` | `addSpecialRule(java.lang.String funName, PrintVisitor.PrintRulesI rule)` Adds a special print rule to be added for a given function.
`java.lang.String` | `addSpecialVarName(java.lang.String oldName, java.lang.String newName)` Allows a replacement for a specific variable name
`void` | `append(java.lang.String s)` Add a string to buffer.
`java.lang.String` | `formatValue(java.lang.Object val)` Returns a formatted version of the value.
`void` | `formatValue(java.lang.Object val, java.lang.StringBuffer sb1)` Appends a formatted versions of val to the string buffer.
`java.lang.String` | `getFunArgSep()` Get the string separating function arguments.
`java.lang.String` | `getFunLBracket()` Get the string for left bracket around function arguments.
`java.lang.String` | `getFunRBracket()` Get the string for right bracket around function arguments.
`java.lang.String` | `getLBracket()` Get the string for left brackets.
`JepComponent` | `getLightWeightInstance()` Gets a light-weight instance suitable for using in multiple threads.
`int` | `getMaxLen()`
`int` | `getMode()` Return the current print mode.
`boolean` | `getMode(int testmode)`
`java.lang.String` | `getRBracket()` Get the string for right brackets.
`void` | `init(Jep jep)` Initialize the component.
`void` | `print(Node node)` Prints on System.out.
`void` | `print(Node node, java.io.PrintStream out)` Prints the tree descending from node with lots of brackets or specified stream.
`void` | `printBrackets(Node node)` print a node surrounded by brackets.
`void` | `println(Node node)` Prints on System.out.
`void` | `println(Node node, java.io.PrintStream out)` Prints the tree descending from node with a newline at end.
`void` | `printNoBrackets(Node node)` print the node with no brackets.
`void` | `printWrap(java.lang.StringBuffer sb, java.io.PrintStream out)` Utility method to print a wrapped version of the output.
`void` | `setFunArgSep(java.lang.String functionArgSep)` Set the string separating function arguments.
`void` | `setFunLBracket(java.lang.String funLBracket)` Set the string for left bracket around function arguments.
`void` | `setFunRBracket(java.lang.String funRBracket)` Set the string for right bracket around function arguments.
`void` | `setLBracket(java.lang.String bracket)` Set the string for left brackets.
`void` | `setMaxLen(int i)` Sets the maximum length printed per line.
`void` | `setMode(int mode, boolean flag)` Set printing mode.
`void` | `setNumberFormat(java.text.NumberFormat format)`
`void` | `setRBracket(java.lang.String bracket)` Set the string for right brackets.
`java.lang.String` | `toString(Node node)` Returns a String representation of the equation.
`java.lang.Object` | `visit(ASTConstant node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTFunNode node, java.lang.Object data)` prints a standard function: fun(arg, arg)
`java.lang.Object` | `visit(ASTOpNode node, java.lang.Object data)`
`java.lang.Object` | `visit(ASTVarNode node, java.lang.Object data)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### FULL_BRACKET

    public static final int FULL_BRACKET

  All brackets are printed. Removes all ambiguity.

  See Also:
    Constant Field Values

### COMPLEX_I

    public static final int COMPLEX_I

  Print Complex as 3+2 i

  See Also:
    Constant Field Values

### sb

    protected transient java.lang.StringBuffer sb

### mode

    protected int mode

  The current mode for printing.

### format

    protected java.text.NumberFormat format

  The NumberFormat object used to print numbers.

Constructor Detail

### PrintVisitor

    public PrintVisitor()

  Creates a visitor to create and print string representations of an expression tree.

Method Detail

### init

    public void init(Jep jep)

  Description copied from interface: `JepComponent`
  Initialize the component. This methods is called whenever a component is added to Jep. Hence it allows components to keep track of the other components they may rely on.

  Specified by:
    `init` in interface `JepComponent`
  Parameters:
    `jep` - the current Jep instance

### print

    public void print(Node node,
                      java.io.PrintStream out)

  Prints the tree descending from node with lots of brackets or specified stream.

  See Also:
    `Jep.println(Node, PrintStream)`

### printWrap

    public void printWrap(java.lang.StringBuffer sb,
                          java.io.PrintStream out)

  Utility method to print a wrapped version of the output. Each line will be a maximum of maxLen characters wide with lines broken on

  Parameters:
    `sb` - the StringBuffer to print
    `out` - the output stream

### print

    public void print(Node node)

  Prints on System.out.

### println

    public void println(Node node,
                        java.io.PrintStream out)

  Prints the tree descending from node with a newline at end.

### println

    public void println(Node node)

  Prints on System.out.

### toString

    public java.lang.String toString(Node node)

  Returns a String representation of the equation.

### append

    public void append(java.lang.String s)

  Add a string to buffer. Classes implementing PrintRulesI should call this add the

### addSpecialRule

    public void addSpecialRule(Operator op,
                               PrintVisitor.PrintRulesI rule)

  Adds a special print rule to be added for a given operator.

  Parameters:
    `op` - the operator the rule applies to
    `rule` - the print rule to use

### addSpecialRule

    public void addSpecialRule(java.lang.String funName,
                               PrintVisitor.PrintRulesI rule)

  Adds a special print rule to be added for a given function.

  Parameters:
    `funName` - name of function
    `rule` - the print rule to use

### addSpecialVarName

    public java.lang.String addSpecialVarName(java.lang.String oldName,
                                              java.lang.String newName)

  Allows a replacement for a specific variable name

  Parameters:
    `oldName` - name of variable to replace
    `newName` - string to print as replacment

### printNoBrackets

    public void printNoBrackets(Node node)
                         throws JepException

  print the node with no brackets.

  Throws:
    `JepException`

### printBrackets

    public void printBrackets(Node node)
                       throws JepException

  print a node surrounded by brackets.

  Throws:
    `JepException`

### visit

    public java.lang.Object visit(ASTFunNode node,
                                  java.lang.Object data)
                           throws JepException

  prints a standard function: fun(arg, arg)

  Specified by:
    `visit` in interface `ParserVisitor`
  Throws:
    `JepException`

### visit

    public java.lang.Object visit(ASTOpNode node,
                                  java.lang.Object data)
                           throws JepException

  Specified by:
    `visit` in interface `ParserVisitor`
  Throws:
    `JepException`

### visit

    public java.lang.Object visit(ASTVarNode node,
                                  java.lang.Object data)
                           throws JepException

  Specified by:
    `visit` in interface `ParserVisitor`
  Throws:
    `JepException`

### visit

    public java.lang.Object visit(ASTConstant node,
                                  java.lang.Object data)
                           throws JepException

  Specified by:
    `visit` in interface `ParserVisitor`
  Throws:
    `JepException`

### formatValue

    public void formatValue(java.lang.Object val,
                            java.lang.StringBuffer sb1)

  Appends a formatted versions of val to the string buffer.

  Parameters:
    `val` - The value to format
    `sb1` - The StringBuffer to append to

### formatValue

    public java.lang.String formatValue(java.lang.Object val)

  Returns a formatted version of the value.

### getMode

    public int getMode()

  Return the current print mode.

### getMode

    public boolean getMode(int testmode)

### setMode

    public void setMode(int mode,
                        boolean flag)

  Set printing mode. In full bracket mode the brackets each element in the tree will be surrounded by brackets to indicate the tree structure. In the default mode, (full bracket off) the number of brackets is minimized so (x+y)+z will be printed as x+y+z.

  Parameters:
    `mode` - which flags to change, typically FULL_BRACKET
    `flag` - whether to switch this mode on or off

### setNumberFormat

    public void setNumberFormat(java.text.NumberFormat format)

### setMaxLen

    public void setMaxLen(int i)

  Sets the maximum length printed per line. If the value is not -1 then the string will be broken into chunks each of which is less than the max length.

  Parameters:
    `i` - the maximum length

### getMaxLen

    public int getMaxLen()

  Returns:
    the maximum length printed per line

### getLightWeightInstance

    public JepComponent getLightWeightInstance()

  Description copied from interface: `JepComponent`
  Gets a light-weight instance suitable for using in multiple threads.

  Specified by:
    `getLightWeightInstance` in interface `JepComponent`
  Returns:
    either an new instance, or 'this'.

### getLBracket

    public java.lang.String getLBracket()

  Get the string for left brackets.

### setLBracket

    public void setLBracket(java.lang.String bracket)

  Set the string for left brackets.

### getRBracket

    public java.lang.String getRBracket()

  Get the string for right brackets.

### setRBracket

    public void setRBracket(java.lang.String bracket)

  Set the string for right brackets.

### getFunLBracket

    public java.lang.String getFunLBracket()

  Get the string for left bracket around function arguments.

### setFunLBracket

    public void setFunLBracket(java.lang.String funLBracket)

  Set the string for left bracket around function arguments.

### getFunRBracket

    public java.lang.String getFunRBracket()

  Get the string for right bracket around function arguments.

### setFunRBracket

    public void setFunRBracket(java.lang.String funRBracket)

  Set the string for right bracket around function arguments.

### getFunArgSep

    public java.lang.String getFunArgSep()

  Get the string separating function arguments.

### setFunArgSep

    public void setFunArgSep(java.lang.String functionArgSep)

  Set the string separating function arguments.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008 Singular Systems http://www.singularsys.com/jep