@Test public void testBranchNormalizedVisitor3() throws Exception { String filter = "(&(ou=Human Resources)(uid=akarasulu)"; filter += "(|(ou=Human Resources)(uid=akarasulu)))"; ExprNode ori = FilterParser.parse( filter ); ExprNode altered = FilterParser.parse( filter ); BranchNormalizedVisitor visitor = new BranchNormalizedVisitor(); visitor.visit( altered ); assertTrue( ori.toString().equals( altered.toString() ) ); }
@Override public Object visit( ExprNode node ) { if ( !( node instanceof BranchNode ) ) { return null; } BranchNode branch = ( BranchNode ) node; Comparator<ExprNode> nodeComparator = new NodeComparator(); Set<ExprNode> set = new TreeSet<>( nodeComparator ); List<ExprNode> children = branch.getChildren(); for ( ExprNode child : branch.getChildren() ) { if ( !child.isLeaf() ) { ExprNode newChild = ( ExprNode ) visit( child ); if ( newChild != null ) { set.add( newChild ); } } else { set.add( child ); } } children.clear(); children.addAll( set ); return branch; }
BranchNormalizedVisitor implements FilterVisitor { @Override public Object visit( ExprNode node ) { if ( !( node instanceof BranchNode ) ) { return null; } BranchNode branch = ( BranchNode ) node; Comparator<ExprNode> nodeComparator = new NodeComparator(); Set<ExprNode> set = new TreeSet<>( nodeComparator ); List<ExprNode> children = branch.getChildren(); for ( ExprNode child : branch.getChildren() ) { if ( !child.isLeaf() ) { ExprNode newChild = ( ExprNode ) visit( child ); if ( newChild != null ) { set.add( newChild ); } } else { set.add( child ); } } children.clear(); children.addAll( set ); return branch; } }
BranchNormalizedVisitor implements FilterVisitor { @Override public Object visit( ExprNode node ) { if ( !( node instanceof BranchNode ) ) { return null; } BranchNode branch = ( BranchNode ) node; Comparator<ExprNode> nodeComparator = new NodeComparator(); Set<ExprNode> set = new TreeSet<>( nodeComparator ); List<ExprNode> children = branch.getChildren(); for ( ExprNode child : branch.getChildren() ) { if ( !child.isLeaf() ) { ExprNode newChild = ( ExprNode ) visit( child ); if ( newChild != null ) { set.add( newChild ); } } else { set.add( child ); } } children.clear(); children.addAll( set ); return branch; }  }
BranchNormalizedVisitor implements FilterVisitor { @Override public Object visit( ExprNode node ) { if ( !( node instanceof BranchNode ) ) { return null; } BranchNode branch = ( BranchNode ) node; Comparator<ExprNode> nodeComparator = new NodeComparator(); Set<ExprNode> set = new TreeSet<>( nodeComparator ); List<ExprNode> children = branch.getChildren(); for ( ExprNode child : branch.getChildren() ) { if ( !child.isLeaf() ) { ExprNode newChild = ( ExprNode ) visit( child ); if ( newChild != null ) { set.add( newChild ); } } else { set.add( child ); } } children.clear(); children.addAll( set ); return branch; }  @Override Object visit( ExprNode node ); @Override boolean canVisit( ExprNode node ); @Override boolean isPrefix(); @Override List<ExprNode> getOrder( BranchNode node, List<ExprNode> children ); static String getNormalizedFilter( SchemaManager schemaManager, String filter ); static String getNormalizedFilter( ExprNode filter ); }
BranchNormalizedVisitor implements FilterVisitor { @Override public Object visit( ExprNode node ) { if ( !( node instanceof BranchNode ) ) { return null; } BranchNode branch = ( BranchNode ) node; Comparator<ExprNode> nodeComparator = new NodeComparator(); Set<ExprNode> set = new TreeSet<>( nodeComparator ); List<ExprNode> children = branch.getChildren(); for ( ExprNode child : branch.getChildren() ) { if ( !child.isLeaf() ) { ExprNode newChild = ( ExprNode ) visit( child ); if ( newChild != null ) { set.add( newChild ); } } else { set.add( child ); } } children.clear(); children.addAll( set ); return branch; }  @Override Object visit( ExprNode node ); @Override boolean canVisit( ExprNode node ); @Override boolean isPrefix(); @Override List<ExprNode> getOrder( BranchNode node, List<ExprNode> children ); static String getNormalizedFilter( SchemaManager schemaManager, String filter ); static String getNormalizedFilter( ExprNode filter );  }