// - NOT
if ( node instanceof NotNode )
{
// Manage the NOT
ExprNode child = node.getFirstChild();
ExprNode result = ( ExprNode ) visit( child );
if ( result == null )
{
return null;
}
else if ( result instanceof BranchNode )
{
List<ExprNode> newChildren = new ArrayList<ExprNode>( 1 );
newChildren.add( result );
node.setChildren( newChildren );
return node;
}
else if ( result instanceof LeafNode )
{
List<ExprNode> newChildren = new ArrayList<ExprNode>( 1 );
newChildren.add( result );
node.setChildren( newChildren );
return node;
}
}
else
{
// Manage AND and OR nodes.
BranchNode branchNode = node;
List<ExprNode> children = node.getChildren();
// For AND and OR, we may have more than one children.
// We may have to remove some of them, so let's create
// a new handler to store the correct nodes.
List<ExprNode> newChildren = new ArrayList<ExprNode>( children.size() );
// Now, iterate through all the children
for ( int i = 0; i < children.size(); i++ )
{
ExprNode child = children.get( i );
ExprNode result = ( ExprNode ) visit( child );
if ( result != null )
{
// As the node is correct, add it to the children
// list.