001/*****************************************************************************
002 * Copyright (C) PicoContainer Organization. All rights reserved.            *
003 * ------------------------------------------------------------------------- *
004 * The software in this package is published under the terms of the BSD      *
005 * style license a copy of which has been included with this distribution in *
006 * the LICENSE.txt file.                                                     *
007 *****************************************************************************/
008
009package org.picocontainer.gems.constraints;
010
011import org.picocontainer.ComponentAdapter;
012import org.picocontainer.PicoVisitor;
013
014/**
015 * Inverts the logical sense of the given constraint.
016 *
017 * @author Nick Sieger
018 */
019@SuppressWarnings("serial")
020public final class Not extends AbstractConstraint {
021
022        private final Constraint constraint;
023
024    /**
025     * Creates a new <code>Not</code> instance.
026     * @param con a <code>Constraint</code> value
027     */
028    public Not(final Constraint con) {
029        this.constraint = con;
030    }
031
032    @Override
033        public boolean evaluate(final ComponentAdapter comp) {
034        return ! constraint.evaluate(comp);
035    }
036
037    @Override
038        public void accept(final PicoVisitor visitor) {
039        super.accept(visitor);
040        constraint.accept(visitor);
041    }
042}