Package com.singularsys.jep.walkers
Class SerializableExpression
- java.lang.Object
-
- com.singularsys.jep.walkers.PostfixTreeWalker
-
- com.singularsys.jep.walkers.SerializableExpression
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
public class SerializableExpression extends PostfixTreeWalker implements java.io.Externalizable
A serializable representation of an expression. To serialize an expression useObjectOuputStream oos = ...; SerializableExpression se = new SerializableExpression(node); oos.writeObject(se);
To deserialize useObjectInputStream 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 (seeNode.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. TheHookRemover
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
static interface
SerializableExpression.Element
interface used in internal representation of expressionstatic class
SerializableExpression.Function
static class
SerializableExpression.Operator
static class
SerializableExpression.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<SerializableExpression.Element>
iterator()
Returns an iterator for the reverse polish representation of the expression.void
readExternal(java.io.ObjectInput ois)
Node
toNode(Jep j)
Convert to a node in a given context.java.lang.String
toString()
protected void
visit(ASTConstant node, int nchildren, int depth)
Visit a constant nodeprotected void
visit(ASTFunNode node, int nchildren, int depth)
Visit a function nodeprotected void
visit(ASTOpNode node, int nchildren, int depth)
Visit an operator nodeprotected void
visit(ASTVarNode node, int nchildren, int depth)
Visit a variable nodevoid
writeExternal(java.io.ObjectOutput out)
Write a serialized version of the node to a stream.static void
writeHooks(java.io.ObjectOutput oos, java.util.Map<Node.HookKey,java.lang.Object> hooks)
-
Methods inherited from class com.singularsys.jep.walkers.PostfixTreeWalker
supressExaminingChildren, walk, walkSubEquations
-
-
-
-
Constructor Detail
-
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 Detail
-
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(java.io.ObjectOutput out) throws java.io.IOException
Write a serialized version of the node to a stream.- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Parameters:
out
- the stream to write to.- Throws:
java.io.IOException
-
readExternal
public final void readExternal(java.io.ObjectInput ois) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
visit
protected void visit(ASTFunNode node, int nchildren, int depth) throws JepException
Description copied from class:PostfixTreeWalker
Visit a function node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.- Throws:
JepException
-
visit
protected void visit(ASTOpNode node, int nchildren, int depth) throws JepException
Description copied from class:PostfixTreeWalker
Visit an operator node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.- Throws:
JepException
-
visit
protected void visit(ASTVarNode node, int nchildren, int depth) throws JepException
Description copied from class:PostfixTreeWalker
Visit a variable node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.- Throws:
JepException
-
visit
protected void visit(ASTConstant node, int nchildren, int depth) throws JepException
Description copied from class:PostfixTreeWalker
Visit a constant node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.- Throws:
JepException
-
iterator
public java.util.Iterator<SerializableExpression.Element> iterator()
Returns an iterator for the reverse polish representation of the expression. This iterator is unmodifiable.
-
writeHooks
public static void writeHooks(java.io.ObjectOutput oos, java.util.Map<Node.HookKey,java.lang.Object> hooks) throws java.io.IOException
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-