Class XNode<V extends IVar>

  • All Implemented Interfaces:
    Comparable<XNode<V>>
    Direct Known Subclasses:
    XNodeLeaf, XNodeParent

    public abstract class XNode<V extends IVar>
    extends Object
    implements Comparable<XNode<V>>
    This class is used for representing a node of a syntactic tree, which is built for functional expressions, and used especially with element <intension>. Subclasses of this class allow us to manage parent and leaf nodes.
    Author:
    Christophe Lecoutre
    • Field Detail

      • type

        public final Types.TypeExpr type
        The type of the node. For example, it can be ADD, NOT, or LONG.
      • sons

        public final XNode<V extends IVar>[] sons
        The sons (children) of the node. It is null if the node is a leaf.
    • Constructor Detail

      • XNode

        protected XNode​(Types.TypeExpr type,
                        XNode<V>[] sons)
        Builds a node for a syntactic tree, with the specified type and the specified sons (children).
        Parameters:
        type - the type of the node
        sons - the sons (children) of the node
    • Method Detail

      • longLeaf

        public static <V extends IVarXNodeLeaf<V> longLeaf​(long value)
      • getType

        public final Types.TypeExpr getType()
        Returns the type of the node. For example ADD, NOT, or LONG. Note that we need this method for language Scala.
        Returns:
        the type of the node
      • arity

        public final int arity()
        Returns the arity of this node, i.e., the number of sons.
        Returns:
        the arity of this node
      • size

        public abstract int size()
        Returns the size of the tree rooted by this node, i.e., the number of nodes it contains.
        Returns:
        the size of the tree rooted by this node
      • maxParameterNumber

        public abstract int maxParameterNumber()
        Returns the maximum value of a parameter number in the tree rooted by this node, or -1 if there is none.
        Returns:
        the maximum value of a parameter number in the tree rooted by this node, or -1
      • firstNodeSuchThat

        public abstract XNode<V> firstNodeSuchThat​(java.util.function.Predicate<XNode<V>> p)
        Returns the first node accepted by the specified predicate in the tree rooted by this node, or null otherwise.
        Parameters:
        p - a predicate to be applied on nodes
        Returns:
        the first node accepted by the specified predicate
      • allNodesSuchThat

        public abstract LinkedList<XNode<V>> allNodesSuchThat​(java.util.function.Predicate<XNode<V>> p,
                                                              LinkedList<XNode<V>> list)
        Adds to the specified list all nodes accepted by the specified predicate in the tree rooted by this node. The specifies list is returned.
        Parameters:
        p - a predicate to be applied on nodes
        list - a list in which nodes are added
        Returns:
        a list with all nodes accepted by the specified predicate in the tree rooted by this node
      • allNodesSuchThat

        public LinkedList<XNode<V>> allNodesSuchThat​(java.util.function.Predicate<XNode<V>> p)
        Returns a list containing all nodes accepted by the specified predicate in the tree rooted by this node. Nodes are added in infix manner.
        Parameters:
        p - a predicate to be applied on nodes
        Returns:
        a list with all nodes accepted by the specified predicate in the tree rooted by this node
      • listOfVars

        public final LinkedList<V> listOfVars()
        Builds a list with the sequence of variables encountered during a depth-first exploration of the tree rooted by this node. Multiple occurrences of the same variables are possible.
        Returns:
        the list of encountered variables during a depth-first exploration
      • listOfVals

        public final LinkedList<Long> listOfVals()
        Builds a list with the sequence of values (long integers) encountered during a depth-first exploration of the tree rooted by this node. Multiple occurrences of the same values are possible.
        Returns:
        the list of encountered values (integers) during a depth-first exploration
      • var

        public final V var​(int i)
        Returns the (i+1)th variable encountered while traversing (in a depth-first manner) the tree rooted by this node, or null if such variable does not exist.
        Parameters:
        i - the index, starting at 0, of a variable
        Returns:
        the (i+1)th variable encountered in the tree rooted by this node
      • val

        public final Integer val​(int i)
        Returns the (i+1)th value encountered while traversing (in a depth-first manner) the tree rooted by this node, or null if such value does not exist.
        Parameters:
        i - the index, starting at 0, of a value
        Returns:
        the (i+1)th value encountered in the tree rooted by this node
      • arrayOfVars

        public final V[] arrayOfVars()
        Returns the list of variables in the tree rooted by this node, in the order they are encountered, or null if there is none. Contrary to vars(), the same variables may occur several times.
        Returns:
        the list of variables in the order they are encountered
      • arrayOfVals

        public final int[] arrayOfVals()
        Returns the list of values (integers) in the tree rooted by this node, in the order they are encountered, or null if there is none. Of course, the same values may occur several times.
        Returns:
        the list of values (integers) in the order they are encountered
      • vars

        public final V[] vars()
        Returns the set of variables in the tree rooted by this node, in the order they are collected, or null if there is none.
        Returns:
        the set of variables in the tree rooted by this node, or null
      • exactlyVars

        public final boolean exactlyVars​(V[] t)
        Return true iff the sequence of variables (without duplicates) encountered in the tree rooted by this node is exactly the specified array.
        Parameters:
        t - an array of variables
        Returns:
        true iff the sequence of variables encountered in the tree rooted by this node is exactly the specified array
      • replaceSymbols

        public abstract XNode<V> replaceSymbols​(Map<String,​Integer> mapOfSymbols)
        Returns a new tree, obtained from the tree rooted by this node by replacing symbols with integers, as defined by the specified map.
        Parameters:
        mapOfSymbols - a map associating integers with strings (symbols)
        Returns:
        a new tree, obtained by replacing symbols with integers, as defined by the specified map
      • replaceLeafValues

        public abstract XNode<V> replaceLeafValues​(java.util.function.Function<Object,​Object> f)
        a new tree, obtained from the tree rooted by this node by replacing values of leaves, as defined by the specified function
        Parameters:
        f - a function mapping objects to objects
        Returns:
        a new tree, obtained by replacing values of leaves, as defined by the specified function
      • replacePartiallyParameters

        public abstract XNode<V> replacePartiallyParameters​(Object[] valueParameters)
      • canonization

        public abstract XNode<V> canonization()
        Returns a new tree, equivalent to the tree rooted by this node, and in canonical form. For example, commutative operators will take variables before integers as operands; actually, the total ordinal order over constants in TypeExpr is used. Some simplifications are also performed; for example, not(eq(x,y)) becomes ne(x,y).
        Returns:
        a new tree, equivalent to the tree rooted by this node, and in canonical form
      • abstraction

        public abstract XNode<V> abstraction​(List<Object> args,
                                             boolean abstractIntegers,
                                             boolean multiOccurrences)
        Returns a new tree representing an abstraction of the tree rooted by this node. Variables are replaced by parameters, and integers are also replaced by parameters (if the first specified Boolean is true). Occurrences of the same variables are replaced by the same parameter (if the second specified Boolean is true). Values replaced by parameters are added to the specified list.
        Parameters:
        args - a list that is updated by adding the objects (variables, and possibly integers) that are abstracted (replaced by parameters)
        abstractIntegers - if true, encountered integers are also abstracted
        multiOccurrences - if true, occurrences of the same variables are replaced by the same parameter
        Returns:
        a new tree representing an abstraction of the tree rooted by this node
      • concretization

        public abstract XNode<V> concretization​(Object[] args)
        Returns a new tree representing a concretization of the tree rooted by this node. Any parameter of value i is replaced by the ith object in the specified list of arguments.
        Parameters:
        args - the list of arguments to be used as values for the parameters that are present in the tree rooted by this node
        Returns:
        a new tree representing a concretization of the tree rooted by this node
      • toPostfixExpression

        public abstract String toPostfixExpression​(IVar[] scopeForAbstraction)
        Returns a string denoting the post-fixed expression of the tree rooted by this node. If the specified array is not null, variables that are present in the tree are replaced by their parameterized forms %i.
        Parameters:
        scopeForAbstraction - if not null, the scope on which an abstract post-fixed expression is built
        Returns:
        a string denoting the post-fixed expression of the tree rooted by this node.
      • toFunctionalExpression

        public abstract String toFunctionalExpression​(Object[] argsForConcretization)
        Returns a string denoting the functional expression of the tree rooted by this node. If the specified array is not null, parameters that are present in the tree are replaced by their corresponding arguments.
        Parameters:
        argsForConcretization - if not null, the list of arguments to be used as values for the parameters that are present in the tree rooted by this node
        Returns:
        a string denoting the functional expression of the tree rooted by this node
      • possibleValues

        public Object possibleValues()