Package com.singularsys.jep.walkers

# Class SerializableExpression

java.lang.Object
com.singularsys.jep.walkers.PostfixTreeWalker
com.singularsys.jep.walkers.SerializableExpression

All Implemented Interfaces:
  `Externalizable`, `Serializable`

public class SerializableExpression extends PostfixTreeWalker implements Externalizable
A serializable representation of an expression. To serialize an expression use

     ObjectOutputStream oos = ...;
     SerializableExpression se = new SerializableExpression(node);
     oos.writeObject(se);

To deserialize use

     ObjectInputStream ois = ...;
     SerializableExpression se = (SerializableExpression) ois.readObject();
     Node n = se.toNode(jep);

Since Jep 4.0 this class will serialize any Hooks added to the nodes (see `Node.HookKey`). Expressions serialized in older versions of Jep can still be read by the Jep 4.0 version of this class. Expressions serialized by this version can be read by older version, provide no hooks are set. The `HookRemover` class can be used to remove any hooks.

See Also:
  - Serialized Form

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `SerializableExpression.Constant`
  An element representing a constant value.
  `static interface`
  `SerializableExpression.Element`
  interface used in internal representation of expression
  `static class`
  `SerializableExpression.Function`
  An element representing a function.
  `static class`
  `SerializableExpression.Operator`
  An element representing an operator.
  `static class`
  `SerializableExpression.Variable`
  An element representing a variable.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SerializableExpression()`
  Constructor used by the serializable mechanism.
  `SerializableExpression(Node node)`
  Construct a SerializableExpression from a given node

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Iterator<SerializableExpression.Element>`
  `iterator()`
  Returns an iterator for the reverse polish representation of the expression.
  `final void`
  `readExternal(ObjectInput ois)`
  `final Node`
  `toNode(Jep j)`
  Convert to a node in a given context.
  `String`
  `toString()`
  `protected void`
  `visit(ASTConstant node, int nchildren, int depth)`
  Visit a constant node
  `protected void`
  `visit(ASTFunNode node, int nchildren, int depth)`
  Visit a function node
  `protected void`
  `visit(ASTOpNode node, int nchildren, int depth)`
  Visit an operator node
  `protected void`
  `visit(ASTVarNode node, int nchildren, int depth)`
  Visit a variable node
  `final void`
  `writeExternal(ObjectOutput out)`
  Write a serialized version of the node to a stream.
  `static void`
  `writeHooks(ObjectOutput oos, Map<Node.HookKey,Object> hooks)`

  ### Methods inherited from class com.singularsys.jep.walkers.PostfixTreeWalker

  `suppressExaminingChildren, walk, walkSubEquations`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### SerializableExpression

    public SerializableExpression(Node node) throws JepException
    Construct a SerializableExpression from a given node
    Parameters:
      `node` - root node of the expression to serialize
    Throws:
      `JepException`

  - ### SerializableExpression

    public SerializableExpression()
    Constructor used by the serializable mechanism. Not for normal use.

- ## Method Details

  - ### toNode

    public final Node toNode(Jep j) throws JepException
    Convert to a node in a given context. Variable, function and operator nodes will refer to the corresponding object in the jep instance.
    Parameters:
      `j` - Jep instance specifying the context
    Returns:
      root node of the expression
    Throws:
      `JepException`

  - ### writeExternal

    public final void writeExternal(ObjectOutput out) throws IOException
    Write a serialized version of the node to a stream.
    Specified by:
      `writeExternal` in interface `Externalizable`
    Parameters:
      `out` - the stream to write to.
    Throws:
      `IOException`

  - ### readExternal

    public final void readExternal(ObjectInput ois) throws IOException, ClassNotFoundException
    Specified by:
      `readExternal` in interface `Externalizable`
    Throws:
      `IOException`
      `ClassNotFoundException`

  - ### visit

    protected void visit(ASTFunNode node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit a function node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### visit

    protected void visit(ASTOpNode node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit an operator node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### visit

    protected void visit(ASTVarNode node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit a variable node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### visit

    protected void visit(ASTConstant node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit a constant node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### iterator

    public Iterator<SerializableExpression.Element> iterator()
    Returns an iterator for the reverse polish representation of the expression. This iterator is unmodifiable.

  - ### writeHooks

    public static void writeHooks(ObjectOutput oos, Map<Node.HookKey,Object> hooks) throws IOException
    Throws:
      `IOException`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`