1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.graph.query.model;
25
26 import net.jcip.annotations.Immutable;
27 import org.modeshape.common.util.CheckArg;
28
29 /**
30 * A constraint that negates another constraint.
31 */
32 @Immutable
33 public class Not extends Constraint {
34 private static final long serialVersionUID = 1L;
35
36 private final Constraint constraint;
37
38 /**
39 * Create a constraint that negates another constraint.
40 *
41 * @param constraint the constraint that is being negated
42 * @throws IllegalArgumentException if the supplied constraint is null
43 */
44 public Not( Constraint constraint ) {
45 CheckArg.isNotNull(constraint, "constraint");
46 this.constraint = constraint;
47 }
48
49 /**
50 * The constraint being negated.
51 *
52 * @return the constraint; never null
53 */
54 public final Constraint getConstraint() {
55 return constraint;
56 }
57
58 /**
59 * {@inheritDoc}
60 *
61 * @see java.lang.Object#toString()
62 */
63 @Override
64 public String toString() {
65 return Visitors.readable(this);
66 }
67
68 /**
69 * {@inheritDoc}
70 *
71 * @see java.lang.Object#hashCode()
72 */
73 @Override
74 public int hashCode() {
75 return getConstraint().hashCode();
76 }
77
78 /**
79 * {@inheritDoc}
80 *
81 * @see java.lang.Object#equals(java.lang.Object)
82 */
83 @Override
84 public boolean equals( Object obj ) {
85 if (obj == this) return true;
86 if (obj instanceof Not) {
87 Not that = (Not)obj;
88 return this.constraint.equals(that.constraint);
89 }
90 return false;
91 }
92
93 /**
94 * {@inheritDoc}
95 *
96 * @see org.modeshape.graph.query.model.Visitable#accept(org.modeshape.graph.query.model.Visitor)
97 */
98 public void accept( Visitor visitor ) {
99 visitor.visit(this);
100 }
101 }