Skip to content

Package: PredicateFactory

PredicateFactory

Coverage

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