summaryrefslogtreecommitdiffstats
path: root/predicate-search-core/src/main/java/com/yahoo/document/predicate/Negation.java
diff options
context:
space:
mode:
Diffstat (limited to 'predicate-search-core/src/main/java/com/yahoo/document/predicate/Negation.java')
-rw-r--r--predicate-search-core/src/main/java/com/yahoo/document/predicate/Negation.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/predicate-search-core/src/main/java/com/yahoo/document/predicate/Negation.java b/predicate-search-core/src/main/java/com/yahoo/document/predicate/Negation.java
new file mode 100644
index 00000000000..c5a4cb802ee
--- /dev/null
+++ b/predicate-search-core/src/main/java/com/yahoo/document/predicate/Negation.java
@@ -0,0 +1,72 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.document.predicate;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
+ */
+public class Negation extends PredicateOperator {
+
+ private Predicate operand;
+
+ public Negation(Predicate operand) {
+ Objects.requireNonNull(operand, "operand");
+ this.operand = operand;
+ }
+
+ public Negation setOperand(Predicate operand) {
+ Objects.requireNonNull(operand, "operand");
+ this.operand = operand;
+ return this;
+ }
+
+ public Predicate getOperand() {
+ return operand;
+ }
+
+ @Override
+ public List<Predicate> getOperands() {
+ return java.util.Arrays.asList(operand);
+ }
+
+ @Override
+ public Negation clone() throws CloneNotSupportedException {
+ Negation obj = (Negation)super.clone();
+ obj.operand = operand.clone();
+ return obj;
+ }
+
+ @Override
+ public int hashCode() {
+ return operand.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof Negation)) {
+ return false;
+ }
+ Negation rhs = (Negation)obj;
+ if (!operand.equals(rhs.operand)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected void appendTo(StringBuilder out) {
+ if (operand instanceof FeatureSet) {
+ ((FeatureSet)operand).appendNegatedTo(out);
+ } else {
+ out.append("not (");
+ operand.appendTo(out);
+ out.append(')');
+ }
+ }
+
+}