001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.server.xdbm.search.evaluator; 021 022 023import org.apache.directory.api.ldap.model.entry.Entry; 024import org.apache.directory.api.ldap.model.exception.LdapException; 025import org.apache.directory.api.ldap.model.filter.ExprNode; 026import org.apache.directory.api.ldap.model.filter.NotNode; 027import org.apache.directory.server.core.api.partition.PartitionTxn; 028import org.apache.directory.server.xdbm.IndexEntry; 029import org.apache.directory.server.xdbm.search.Evaluator; 030 031 032/** 033 * An Evaluator for logical negation (NOT) expressions. 034 * 035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 036 */ 037public class NotEvaluator implements Evaluator<NotNode> 038{ 039 /** The ExprNode to evaluate */ 040 private final NotNode node; 041 042 /** The Evaluator to use for the inner Node */ 043 private final Evaluator<? extends ExprNode> childEvaluator; 044 045 046 /** 047 * Creates a new NotEvaluator 048 * 049 * @param node The NotNode 050 * @param childEvaluator The included evaluator 051 */ 052 public NotEvaluator( NotNode node, Evaluator<? extends ExprNode> childEvaluator ) 053 { 054 this.node = node; 055 this.childEvaluator = childEvaluator; 056 } 057 058 059 /** 060 * {@inheritDoc} 061 */ 062 @Override 063 public boolean evaluate( Entry entry ) throws LdapException 064 { 065 return !childEvaluator.evaluate( entry ); 066 } 067 068 069 /** 070 * {@inheritDoc} 071 */ 072 @Override 073 public boolean evaluate( PartitionTxn partitionTxn, IndexEntry<?, String> indexEntry ) throws LdapException 074 { 075 return !childEvaluator.evaluate( partitionTxn, indexEntry ); 076 } 077 078 079 /** 080 * {@inheritDoc} 081 */ 082 @Override 083 public NotNode getExpression() 084 { 085 return node; 086 } 087 088 089 /** 090 * @see Object#toString() 091 */ 092 public String toString( String tabs ) 093 { 094 StringBuilder sb = new StringBuilder(); 095 096 sb.append( tabs ).append( "NotEvaluator : " ).append( node ).append( '\n' ); 097 098 sb.append( childEvaluator.toString( tabs + " " ) ); 099 100 return sb.toString(); 101 } 102 103 104 /** 105 * @see Object#toString() 106 */ 107 public String toString() 108 { 109 return toString( "" ); 110 } 111}