001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.forgerock.opendj.config.conditions;
018
019import org.forgerock.opendj.config.AbstractManagedObjectDefinition;
020import org.forgerock.opendj.config.client.ManagedObject;
021import org.forgerock.opendj.config.client.ManagementContext;
022import org.forgerock.opendj.config.server.ConfigException;
023import org.forgerock.opendj.config.server.ServerManagedObject;
024import org.forgerock.opendj.ldap.LdapException;
025import org.forgerock.util.Reject;
026
027/**
028 * A condition which evaluates to <code>true</code> if the sub-condition is
029 * <code>false</code>, or <code>false</code> if the sub-condition is
030 * <code>true</code>.
031 */
032public final class NOTCondition implements Condition {
033
034    /** The single sub-condition. */
035    private final Condition condition;
036
037    /**
038     * Creates a new logical NOT condition with the provided sub-condition.
039     *
040     * @param condition
041     *            The sub-condition which will be inverted.
042     */
043    public NOTCondition(Condition condition) {
044        Reject.ifNull(condition);
045        this.condition = condition;
046    }
047
048    @Override
049    public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException {
050        return !condition.evaluate(context, managedObject);
051    }
052
053    @Override
054    public boolean evaluate(ServerManagedObject<?> managedObject) throws ConfigException {
055        return !condition.evaluate(managedObject);
056    }
057
058    @Override
059    public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception {
060        condition.initialize(d);
061    }
062
063}