Class BranchNormalizedVisitor
- java.lang.Object
-
- org.apache.directory.api.ldap.model.filter.BranchNormalizedVisitor
-
- All Implemented Interfaces:
FilterVisitor
public class BranchNormalizedVisitor extends Object implements FilterVisitor
Visitor which traverses a filter tree while normalizing the branch node order. Filter expressions can change the order of expressions in branch nodes without effecting the logical meaning of the expression. This visitor orders the children of expression tree branch nodes consistantly. It is really useful for comparing expression trees which may be altered for performance or altered because of codec idiosyncracies: for example the SNACC4J codec uses a hashmap to store expressions in a sequence which rearranges the order of children based on object hashcodes. We need this visitor to remove such inconsitancies in order hence normalizing the branch node's child order.- Author:
- Apache Directory Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classBranchNormalizedVisitor.NodeComparator
-
Constructor Summary
Constructors Constructor Description BranchNormalizedVisitor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanVisit(ExprNode node)Checks to see if a node can be visited.static StringgetNormalizedFilter(ExprNode filter)Normalizes a filter expression to a canonical representation while retaining logical meaning of the expression.static StringgetNormalizedFilter(SchemaManager schemaManager, String filter)Normalizes a filter expression to a canonical representation while retaining logical meaning of the expression.List<ExprNode>getOrder(BranchNode node, List<ExprNode> children)Get the array of children to visit sequentially to determine the order of child visitations.booleanisPrefix()Determines whether the visitation order is prefix or postfix.Objectvisit(ExprNode node)Visits a filter expression AST using a specific visitation order.
-
-
-
Method Detail
-
visit
public Object visit(ExprNode node)
Description copied from interface:FilterVisitorVisits a filter expression AST using a specific visitation order.- Specified by:
visitin interfaceFilterVisitor- Parameters:
node- the node to visit- Returns:
- node the resulting modified node
-
canVisit
public boolean canVisit(ExprNode node)
Checks to see if a node can be visited.- Specified by:
canVisitin interfaceFilterVisitor- Parameters:
node- the node to be visited- Returns:
- whether or node the node should be visited
-
isPrefix
public boolean isPrefix()
Determines whether the visitation order is prefix or postfix.- Specified by:
isPrefixin interfaceFilterVisitor- Returns:
- true if the visitation is in prefix order, false otherwise.
-
getOrder
public List<ExprNode> getOrder(BranchNode node, List<ExprNode> children)
Get the array of children to visit sequentially to determine the order of child visitations. Some children may not be returned at all if canVisit() returns false on them.- Specified by:
getOrderin interfaceFilterVisitor- Parameters:
node- the parent branch nodechildren- the child node array- Returns:
- the new reordered array of children
-
getNormalizedFilter
public static String getNormalizedFilter(SchemaManager schemaManager, String filter) throws ParseException
Normalizes a filter expression to a canonical representation while retaining logical meaning of the expression.- Parameters:
schemaManager- The SchemaManagerfilter- the filter to normalize- Returns:
- the normalized version of the filter
- Throws:
ParseException- if the filter is malformed
-
-