Package org.xcsp.common.predicates
Class XNodeLeaf<V extends IVar>
- java.lang.Object
-
- org.xcsp.common.predicates.XNode<V>
-
- org.xcsp.common.predicates.XNodeLeaf<V>
-
- All Implemented Interfaces:
Comparable<XNode<V>>
public final class XNodeLeaf<V extends IVar> extends XNode<V>
The class used for representing a leaf node in a syntactic tree.- Author:
- Christophe Lecoutre
-
-
Constructor Summary
Constructors Constructor Description XNodeLeaf(Types.TypeExpr type, Object... value)
Builds a leaf node for a syntactic tree, with the specified type and the specified value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description XNode<V>
abstraction(List<Object> args, boolean abstractIntegers, boolean multiOccurrences)
Returns a new tree representing an abstraction of the tree rooted by this node.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.XNode<V>
canonization()
Returns a new tree, equivalent to the tree rooted by this node, and in canonical form.int
compareTo(XNode<V> obj)
XNode<V>
concretization(Object[] args)
Returns a new tree representing a concretization of the tree rooted by this node.boolean
equals(Object obj)
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, ornull
otherwise.int
maxParameterNumber()
Returns the maximum value of a parameter number in the tree rooted by this node, or -1 if there is none.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 functionXNode<V>
replacePartiallyParameters(Object[] valueParameters)
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.int
size()
Returns the size of the tree rooted by this node, i.e., the number of nodes it contains.String
toFunctionalExpression(Object[] argsForConcretization)
Returns a string denoting the functional expression of the tree rooted by this node.String
toPostfixExpression(IVar[] scopeForAbstraction)
Returns a string denoting the post-fixed expression of the tree rooted by this node.-
Methods inherited from class org.xcsp.common.predicates.XNode
allNodesSuchThat, ariop, arity, arrayOfVals, arrayOfVars, collectVarsToSet, exactlyVars, getType, listOfVals, listOfVars, logop, longLeaf, node, node, node, node, node, node, node, possibleValues, relop, specialLeaf, toString, unalop, val, var, vars
-
-
-
-
Constructor Detail
-
XNodeLeaf
public XNodeLeaf(Types.TypeExpr type, Object... value)
Builds a leaf node for a syntactic tree, with the specified type and the specified value.
-
-
Method Detail
-
size
public int size()
Description copied from class:XNode
Returns the size of the tree rooted by this node, i.e., the number of nodes it contains.
-
maxParameterNumber
public int maxParameterNumber()
Description copied from class:XNode
Returns the maximum value of a parameter number in the tree rooted by this node, or -1 if there is none.- Specified by:
maxParameterNumber
in classXNode<V extends IVar>
- Returns:
- the maximum value of a parameter number in the tree rooted by this node, or -1
-
canonization
public XNode<V> canonization()
Description copied from class:XNode
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 inTypeExpr
is used. Some simplifications are also performed; for example,not(eq(x,y))
becomesne(x,y)
.- Specified by:
canonization
in classXNode<V extends IVar>
- Returns:
- a new tree, equivalent to the tree rooted by this node, and in canonical form
-
abstraction
public XNode<V> abstraction(List<Object> args, boolean abstractIntegers, boolean multiOccurrences)
Description copied from class:XNode
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.- Specified by:
abstraction
in classXNode<V extends IVar>
- Parameters:
args
- a list that is updated by adding the objects (variables, and possibly integers) that are abstracted (replaced by parameters)abstractIntegers
- iftrue
, encountered integers are also abstractedmultiOccurrences
- iftrue
, 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 XNode<V> concretization(Object[] args)
Description copied from class:XNode
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.- Specified by:
concretization
in classXNode<V extends IVar>
- 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
-
replaceSymbols
public XNode<V> replaceSymbols(Map<String,Integer> mapOfSymbols)
Description copied from class:XNode
Returns a new tree, obtained from the tree rooted by this node by replacing symbols with integers, as defined by the specified map.- Specified by:
replaceSymbols
in classXNode<V extends IVar>
- 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 XNode<V> replaceLeafValues(java.util.function.Function<Object,Object> f)
Description copied from class:XNode
a new tree, obtained from the tree rooted by this node by replacing values of leaves, as defined by the specified function- Specified by:
replaceLeafValues
in classXNode<V extends IVar>
- 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 XNode<V> replacePartiallyParameters(Object[] valueParameters)
- Specified by:
replacePartiallyParameters
in classXNode<V extends IVar>
-
firstNodeSuchThat
public XNode<V> firstNodeSuchThat(java.util.function.Predicate<XNode<V>> p)
Description copied from class:XNode
Returns the first node accepted by the specified predicate in the tree rooted by this node, ornull
otherwise.- Specified by:
firstNodeSuchThat
in classXNode<V extends IVar>
- Parameters:
p
- a predicate to be applied on nodes- Returns:
- the first node accepted by the specified predicate
-
allNodesSuchThat
public LinkedList<XNode<V>> allNodesSuchThat(java.util.function.Predicate<XNode<V>> p, LinkedList<XNode<V>> list)
Description copied from class:XNode
Adds to the specified list all nodes accepted by the specified predicate in the tree rooted by this node. The specifies list is returned.- Specified by:
allNodesSuchThat
in classXNode<V extends IVar>
- Parameters:
p
- a predicate to be applied on nodeslist
- 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
-
toPostfixExpression
public String toPostfixExpression(IVar[] scopeForAbstraction)
Description copied from class:XNode
Returns a string denoting the post-fixed expression of the tree rooted by this node. If the specified array is notnull
, variables that are present in the tree are replaced by their parameterized forms%i
.- Specified by:
toPostfixExpression
in classXNode<V extends IVar>
- Parameters:
scopeForAbstraction
- if notnull
, 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 String toFunctionalExpression(Object[] argsForConcretization)
Description copied from class:XNode
Returns a string denoting the functional expression of the tree rooted by this node. If the specified array is notnull
, parameters that are present in the tree are replaced by their corresponding arguments.- Specified by:
toFunctionalExpression
in classXNode<V extends IVar>
- Parameters:
argsForConcretization
- if notnull
, 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
-
-