Skip to content

Package: PredicateFactory$In

PredicateFactory$In

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.model.query.criteria;
19:
20: import java.util.Collection;
21:
22: public interface PredicateFactory {
23:
24: /**
25: * Create a conjunction of the given boolean expressions.
26: * @param x boolean expression
27: * @param y boolean expression
28: * @return and predicate
29: */
30: Predicate and(Expression<Boolean> x, Expression<Boolean> y);
31:
32: /**
33: * Create a conjunction of the given restriction predicates. A conjunction of zero predicates is true.
34: * @param restrictions zero or more restriction predicates
35: * @return and predicate
36: */
37: Predicate and(Predicate... restrictions);
38:
39: /**
40: * Create a disjunction of the given boolean expressions.
41: * @param x boolean expression
42: * @param y boolean expression
43: * @return or predicate
44: */
45: Predicate or(Expression<Boolean> x, Expression<Boolean> y);
46:
47: /**
48: * Create a disjunction of the given restriction predicates. A disjunction of zero predicates is false.
49: * @param restrictions zero or more restriction predicates
50: * @return or predicate
51: */
52: Predicate or(Predicate... restrictions);
53:
54: /**
55: * Create a predicate for testing the arguments for equality.
56: * @param x expression
57: * @param y expression
58: * @return equality predicate
59: */
60: Predicate equal(Expression<?> x, Expression<?> y);
61:
62: /**
63: * Create a predicate for testing the arguments for equality.
64: * @param x expression
65: * @param y object
66: * @return equality predicate
67: */
68: Predicate equal(Expression<?> x, Object y);
69:
70: /**
71: * Create a predicate for testing the arguments for equality.
72: * @param x expression
73: * @param y string
74: * @param languageTag string
75: * @return equality predicate
76: */
77: Predicate equal(Expression<?> x, String y, String languageTag);
78:
79: /**
80: * Create a predicate for testing the arguments for inequality.
81: * @param x expression
82: * @param y expression
83: * @return inequality predicate
84: */
85: Predicate notEqual(Expression<?> x, Expression<?> y);
86:
87: /**
88: * Create a predicate for testing the arguments for inequality.
89: * @param x expression
90: * @param y object
91: * @return inequality predicate
92: */
93: Predicate notEqual(Expression<?> x, Object y);
94:
95: /**
96: * Create a predicate for testing whether the first argument is greater than the second.
97: * @param x expression
98: * @param y expression
99: * @return greaterThan predicate
100: */
101: <Y extends Comparable<? super Y>> Predicate greaterThan(Expression<? extends Y> x, Expression<? extends Y> y);
102:
103: /**
104: * Create a predicate for testing whether the first argument is greater than the second.
105: * @param x expression
106: * @param y value
107: * @return greaterThan predicate
108: */
109: <Y extends Comparable<? super Y>> Predicate greaterThan(Expression<? extends Y> x, Y y);
110:
111: /**
112: * Create a predicate for testing whether the first argument is greater than or equal to the second.
113: * @param x expression
114: * @param y expression
115: * @return greaterThanOrEqual predicate
116: */
117: <Y extends Comparable<? super Y>> Predicate greaterThanOrEqual(Expression<? extends Y> x,
118: Expression<? extends Y> y);
119:
120: /**
121: * Create a predicate for testing whether the first argument is greater than or equal to the second.
122: * @param x expression
123: * @param y value
124: * @return greaterThanOrEqual predicate
125: */
126: <Y extends Comparable<? super Y>> Predicate greaterThanOrEqual(Expression<? extends Y> x, Y y);
127:
128: /**
129: * Create a predicate for testing whether the first argument is less than the second.
130: * @param x expression
131: * @param y expression
132: * @return lessThan predicate
133: */
134: <Y extends Comparable<? super Y>> Predicate lessThan(Expression<? extends Y> x, Expression<? extends Y> y);
135:
136: /**
137: * Create a predicate for testing whether the first argument is less than the second.
138: * @param x expression
139: * @param y value
140: * @return lessThan predicate
141: */
142: <Y extends Comparable<? super Y>> Predicate lessThan(Expression<? extends Y> x, Y y);
143:
144: /**
145: * Create a predicate for testing whether the first argument is less than or equal to the second.
146: * @param x expression
147: * @param y expression
148: * @return lessThanOrEqual predicate
149: */
150: <Y extends Comparable<? super Y>> Predicate lessThanOrEqual(Expression<? extends Y> x, Expression<? extends Y> y);
151:
152: /**
153: * Create a predicate for testing whether the first argument is less than or equal to the second.
154: * @param x expression
155: * @param y value
156: * @return lessThanOrEqual predicate
157: */
158: <Y extends Comparable<? super Y>> Predicate lessThanOrEqual(Expression<? extends Y> x, Y y);
159:
160: /**
161: * Create a predicate for testing whether the expression satisfies the given pattern.
162: * @param x string expression
163: * @param pattern string expression
164: * @return like predicate
165: */
166: Predicate like(Expression<String> x, Expression<String> pattern);
167:
168: /**
169: * Create a predicate for testing whether the expression satisfies the given pattern.
170: * @param x string expression
171: * @param pattern string
172: * @return like predicate
173: */
174: Predicate like(Expression<String> x, String pattern);
175:
176: /**
177: * Create a predicate for testing whether the expression does not satisfy the given pattern.
178: * @param x string expression
179: * @param pattern string expression
180: * @return like predicate
181: */
182: Predicate notLike(Expression<String> x, Expression<String> pattern);
183:
184: /**
185: * Create a predicate for testing whether the expression does not satisfy the given pattern.
186: * @param x string expression
187: * @param pattern string
188: * @return like predicate
189: */
190: Predicate notLike(Expression<String> x, String pattern);
191:
192: /**
193: * Creates a predicate that tests whether an element is a member of a collection.
194: *
195: * If the collection is empty, the predicate will be false.
196: * @param elem Element
197: * @param collection Expression
198: * @return is-member predicate
199: */
200: <E, C extends Collection<E>> Predicate isMember(E elem, Expression<C> collection);
201:
202: /**
203: * Creates a predicate that tests whether an element is not a member of a collection.
204: *
205: * If the collection is empty, the predicate will be true.
206: * @param elem Element
207: * @param collection Expression
208: * @return is-member predicate
209: */
210: <E, C extends Collection<E>> Predicate isNotMember(E elem, Expression<C> collection);
211:
212: /**
213: * Create a negation of the given restriction.
214: * @param restriction restriction expression
215: * @return not predicate
216: */
217: Predicate not(Expression<Boolean> restriction);
218:
219: /**
220: * Create predicate to test whether given expression is contained in a list of values.
221: * @param expression - to be tested against list of values
222: * @return in predicate
223: */
224: <T> PredicateFactory.In<T> in(Expression<? extends T> expression);
225:
226: /**
227: * Create predicate to test whether given expression is not contained in a list of values.
228: * @param expression - to be tested against list of values
229: * @return not in predicate
230: */
231: <T> In<T> notIn(Expression<? extends T> expression);
232:
233: /**
234: * Interface used to build in predicates.
235: * @param <T>
236: */
237: interface In<T> extends Predicate {
238:
239: /**
240: * Return the expression to be tested against the list of values.
241: * @return expression
242: */
243: Expression<T> getExpression();
244:
245: /**
246: * Add to list of values to be tested against.
247: * @param value - value
248: * @return in predicate
249: */
250: PredicateFactory.In<T> value(T value);
251: }
252: }