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