}
}
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.
newChildren.add( result );
}
}
if ( ( branchNode instanceof AndNode ) && ( newChildren.size() != children.size() ) )
{
return null;
}
if ( newChildren.size() == 0 )
{
// No more children, return null
return null;
}
else if ( newChildren.size() == 1 )
{
// As we only have one child, return it
// to the caller.
return newChildren.get( 0 );
}
else
{
branchNode.setChildren( newChildren );
}
}
return node;
}