1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.search.api.request;
20
21 import static java.util.Objects.requireNonNull;
22
23
24
25
26 public abstract class BooleanQuery extends Query {
27 private final Query left;
28
29 private final Query right;
30
31 protected BooleanQuery(Query left, String op, Query right) {
32 super(op);
33 this.left = requireNonNull(left);
34 this.right = requireNonNull(right);
35 }
36
37
38
39
40 public Query getLeft() {
41 return left;
42 }
43
44
45
46
47 public Query getRight() {
48 return right;
49 }
50
51 @Override
52 public String toString() {
53 return getLeft() + " " + getValue() + " " + getRight();
54 }
55
56 public static final class And extends BooleanQuery {
57 private And(Query left, Query right) {
58 super(left, "AND", right);
59 }
60 }
61
62
63
64
65
66 public static BooleanQuery and(Query left, Query... rights) {
67 if (rights.length == 0) {
68 throw new IllegalArgumentException("one or more on right needed");
69 }
70 BooleanQuery result = null;
71 for (Query right : rights) {
72 result = new And(result == null ? left : result, right);
73 }
74 return result;
75 }
76 }