Class 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 use
     ObjectOuputStream 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
    • 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 interface java.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 interface java.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 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.
        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 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.
        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 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.
        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 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.
        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 class java.lang.Object