• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torand / FasterSQL / 16990059345

15 Aug 2025 12:34PM UTC coverage: 66.782% (-6.6%) from 73.399%
16990059345

push

github

torand
chore: access central snapshots

294 of 598 branches covered (49.16%)

Branch coverage included in aggregate %.

1638 of 2295 relevant lines covered (71.37%)

3.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.13
/src/main/java/io/github/torand/fastersql/predicate/LeftOperand.java
1
/*
2
 * Copyright (c) 2024-2025 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.fastersql.predicate;
17

18
import io.github.torand.fastersql.expression.Expression;
19
import io.github.torand.fastersql.predicate.comparison.ComparisonPredicates;
20
import io.github.torand.fastersql.sql.Sql;
21
import io.github.torand.fastersql.statement.SelectStatement;
22
import io.github.torand.fastersql.subquery.ExpressionSubquery;
23

24
import java.util.Collection;
25
import java.util.Optional;
26

27
import static io.github.torand.fastersql.predicate.compound.CompoundPredicates.not;
28
import static io.github.torand.javacommons.contract.Requires.requireNonEmpty;
29
import static java.util.Arrays.asList;
30
import static java.util.Objects.requireNonNull;
31

32
/**
33
 * Defines the left operand of an expression.
34
 */
35
public interface LeftOperand extends Sql {
36

37
    /**
38
     * Creates an equivalence predicate from this left operand and the specified constant value.
39
     * @param value the constant value.
40
     * @return the predicate.
41
     */
42
    default Predicate eq(Object value) {
43
        return ComparisonPredicates.eq(this, value);
4✔
44
    }
45

46
    /**
47
     * Creates an optional equivalence predicate from this left operand and the specified optional value.
48
     * @param value the optional value.
49
     * @return the optional predicate.
50
     */
51
    default OptionalPredicate eq(Optional<?> value) {
52
        requireNonNull(value, "No value specified");
4✔
53
        return OptionalPredicate.ofNullable(value.map(v -> ComparisonPredicates.eq(this, v)).orElse(null));
13✔
54
    }
55

56
    /**
57
     * Creates an equivalence predicate from this left operand and the specified expression.
58
     * @param expression the expression.
59
     * @return the predicate.
60
     */
61
    default Predicate eq(Expression expression) {
62
        return ComparisonPredicates.eq(this, expression);
4✔
63
    }
64

65
    /**
66
     * Creates an equivalence predicate from this left operand and the specified subquery.
67
     * @param query the subquery.
68
     * @return the predicate.
69
     */
70

71
    default Predicate eq(SelectStatement query) {
72
        return ComparisonPredicates.eq(this, new ExpressionSubquery(query));
7✔
73
    }
74

75

76
    /**
77
     * Creates a non-equivalence predicate from this left operand and the specified constant value.
78
     * @param value the constant value.
79
     * @return the predicate.
80
     */
81
    default Predicate ne(Object value) {
82
        return ComparisonPredicates.ne(this, value);
4✔
83
    }
84

85
    /**
86
     * Creates an optional non-equivalence predicate from this left operand and the specified optional value.
87
     * @param value the optional value.
88
     * @return the optional predicate.
89
     */
90
    default OptionalPredicate ne(Optional<?> value) {
91
        requireNonNull(value, "No value specified");
×
92
        return OptionalPredicate.ofNullable(value.map(v -> ComparisonPredicates.ne(this, v)).orElse(null));
×
93
    }
94

95
    /**
96
     * Creates a non-equivalence predicate from this left operand and the specified expression.
97
     * @param expression the expression.
98
     * @return the predicate.
99
     */
100
    default Predicate ne(Expression expression) {
101
        return ComparisonPredicates.ne(this, expression);
×
102
    }
103

104
    /**
105
     * Creates a non-equivalence predicate from this left operand and the specified subquery.
106
     * @param query the subquery.
107
     * @return the predicate.
108
     */
109
    default Predicate ne(SelectStatement query) {
110
        return ComparisonPredicates.ne(this, new ExpressionSubquery(query));
×
111
    }
112

113
    /**
114
     * Creates a 'less than' predicate from this left operand and the specified constant value.
115
     * @param value the constant value.
116
     * @return the predicate.
117
     */
118
    default Predicate lt(Object value) {
119
        return ComparisonPredicates.lt(this, value);
4✔
120
    }
121

122
    /**
123
     * Creates an optional 'less than' predicate from this left operand and the specified optional value.
124
     * @param value the optional value.
125
     * @return the optional predicate.
126
     */
127
    default OptionalPredicate lt(Optional<?> value) {
128
        requireNonNull(value, "No value specified");
×
129
        return OptionalPredicate.ofNullable(value.map(v -> ComparisonPredicates.lt(this, v)).orElse(null));
×
130
    }
131

132
    /**
133
     * Creates a 'less than' predicate from this left operand and the specified expression.
134
     * @param expression the expression.
135
     * @return the predicate.
136
     */
137
    default Predicate lt(Expression expression) {
138
        return ComparisonPredicates.lt(this, expression);
×
139
    }
140

141
    /**
142
     * Creates a 'less than' predicate from this left operand and the specified subquery.
143
     * @param query the subquery.
144
     * @return the predicate.
145
     */
146
    default Predicate lt(SelectStatement query) {
147
        return ComparisonPredicates.lt(this, new ExpressionSubquery(query));
×
148
    }
149

150
    /**
151
     * Creates a 'less than or equal' predicate from this left operand and the specified constant value.
152
     * @param value the constant value.
153
     * @return the predicate.
154
     */
155
    default Predicate le(Object value) {
156
        return ComparisonPredicates.le(this, value);
4✔
157
    }
158

159
    /**
160
     * Creates an optional 'less than or equal' predicate from this left operand and the specified optional value.
161
     * @param value the optional value.
162
     * @return the optional predicate.
163
     */
164
    default OptionalPredicate le(Optional<?> value) {
165
        requireNonNull(value, "No value specified");
×
166
        return OptionalPredicate.ofNullable(value.map(v -> ComparisonPredicates.le(this, v)).orElse(null));
×
167
    }
168

169
    /**
170
     * Creates a 'less than or equal' predicate from this left operand and the specified expression.
171
     * @param expression the expression.
172
     * @return the predicate.
173
     */
174
    default Predicate le(Expression expression) {
175
        return ComparisonPredicates.le(this, expression);
×
176
    }
177

178
    /**
179
     * Creates a 'less than or equal' predicate from this left operand and the specified subquery.
180
     * @param query the subquery.
181
     * @return the predicate.
182
     */
183
    default Predicate le(SelectStatement query) {
184
        return ComparisonPredicates.le(this, new ExpressionSubquery(query));
×
185
    }
186

187
    /**
188
     * Creates a 'greater than' predicate from this left operand and the specified constant value.
189
     * @param value the constant value.
190
     * @return the predicate.
191
     */
192
    default Predicate gt(Object value) {
193
        return ComparisonPredicates.gt(this, value);
4✔
194
    }
195

196
    /**
197
     * Creates an optional 'greater than' predicate from this left operand and the specified optional value.
198
     * @param value the optional value.
199
     * @return the optional predicate.
200
     */
201
    default OptionalPredicate gt(Optional<?> value) {
202
        requireNonNull(value, "No value specified");
×
203
        return OptionalPredicate.ofNullable(value.map(v -> ComparisonPredicates.gt(this, v)).orElse(null));
×
204
    }
205

206
    /**
207
     * Creates a 'greater than' predicate from this left operand and the specified expression.
208
     * @param expression the expression.
209
     * @return the predicate.
210
     */
211
    default Predicate gt(Expression expression) {
212
        return ComparisonPredicates.gt(this, expression);
4✔
213
    }
214

215
    /**
216
     * Creates a 'greater than' predicate from this left operand and the specified subquery.
217
     * @param query the subquery.
218
     * @return the predicate.
219
     */
220
    default Predicate gt(SelectStatement query) {
221
        return ComparisonPredicates.gt(this, new ExpressionSubquery(query));
×
222
    }
223

224
    /**
225
     * Creates a 'greater than or equal' predicate from this left operand and the specified constant value.
226
     * @param value the constant value.
227
     * @return the predicate.
228
     */
229
    default Predicate ge(Object value) {
230
        return ComparisonPredicates.ge(this, value);
×
231
    }
232

233
    /**
234
     * Creates an optional 'greater than or equal' predicate from this left operand and the specified optional value.
235
     * @param value the optional value.
236
     * @return the optional predicate.
237
     */
238
    default OptionalPredicate ge(Optional<?> value) {
239
        requireNonNull(value, "No value specified");
×
240
        return OptionalPredicate.ofNullable(value.map(v -> ComparisonPredicates.ge(this, v)).orElse(null));
×
241
    }
242

243
    /**
244
     * Creates a 'greater than or equal' predicate from this left operand and the specified expression.
245
     * @param expression the expression.
246
     * @return the predicate.
247
     */
248
    default Predicate ge(Expression expression) {
249
        return ComparisonPredicates.ge(this, expression);
×
250
    }
251

252
    /**
253
     * Creates a 'greater than or equal' predicate from this left operand and the specified subquery.
254
     * @param query the subquery.
255
     * @return the predicate.
256
     */
257
    default Predicate ge(SelectStatement query) {
258
        return ComparisonPredicates.ge(this, new ExpressionSubquery(query));
×
259
    }
260

261
    /**
262
     * Creates a 'between' predicate from this left operand and the specified lower and upper bound constant values.
263
     * @param lowerBound the lower bound constant value.
264
     * @param upperBound the upper bound constant value.
265
     * @return the predicate.
266
     */
267
    default Predicate between(Object lowerBound, Object upperBound) {
268
        return ComparisonPredicates.between(this, lowerBound, upperBound);
5✔
269
    }
270

271
    /**
272
     * Creates a 'between' predicate from this left operand and the specified lower and upper bound expressions.
273
     * @param lowerBound the lower bound expression.
274
     * @param upperBound the upper bound expression.
275
     * @return the predicate.
276
     */
277
    default Predicate between(Expression lowerBound, Expression upperBound) {
278
        return ComparisonPredicates.between(this, lowerBound, upperBound);
×
279
    }
280

281
    /**
282
     * Creates a 'not between' predicate from this left operand and the specified lower and upper bound constant values.
283
     * @param lowerBound the lower bound constant value.
284
     * @param upperBound the upper bound constant value.
285
     * @return the predicate.
286
     */
287
    default Predicate notBetween(Object lowerBound, Object upperBound) {
288
        return not(between(lowerBound, upperBound));
×
289
    }
290

291
    /**
292
     * Creates a 'not between' predicate from this left operand and the specified lower and upper bound expressions.
293
     * @param lowerBound the lower bound expression.
294
     * @param upperBound the upper bound expression.
295
     * @return the predicate.
296
     */
297
    default Predicate notBetween(Expression lowerBound, Expression upperBound) {
298
        return not(between(lowerBound, upperBound));
×
299
    }
300

301
    /**
302
     * Creates a 'member of set' predicate from this left operand and the specified array of constant values.
303
     * @param values the constant values.
304
     * @return the predicate.
305
     */
306
    default Predicate in(Object... values) {
307
        requireNonEmpty(values, "No values specified");
6✔
308
        if (values.length == 1) {
4!
309
            return ComparisonPredicates.eq(this, values[0]);
×
310
        } else {
311
            return Predicates.in(this, asList(values));
5✔
312
        }
313
    }
314

315
    /**
316
     * Creates a 'member of set' predicate from this left operand and the specified collection of constant values.
317
     * @param values the constant values.
318
     * @return the predicate.
319
     */
320
    default Predicate in(Collection<?> values) {
321
        requireNonEmpty(values, "No values specified");
×
322
        if (values.size() == 1) {
×
323
            return ComparisonPredicates.eq(this, values.iterator().next());
×
324
        } else {
325
            return Predicates.in(this, values);
×
326
        }
327
    }
328

329
    /**
330
     * Creates an optional 'member of set' predicate from this left operand and the specified optional collection of constant values.
331
     * @param values the optional constant values.
332
     * @return the optional predicate.
333
     */
334
    default OptionalPredicate in(Optional<? extends Collection<?>> values) {
335
        requireNonNull(values, "No values specified");
×
336
        return OptionalPredicate.ofNullable(values.map(v -> {
×
337
            if (v.size() == 1) {
×
338
                return ComparisonPredicates.eq(this, v.iterator().next());
×
339
            } else {
340
                return Predicates.in(this, v);
×
341
            }
342
        }).orElse(null));
×
343
    }
344

345
    /**
346
     * Creates a 'member of set' predicate from this left operand and the specified subquery.
347
     * @param query the subquery.
348
     * @return the predicate.
349
     */
350
    default Predicate in(SelectStatement query) {
351
        return Predicates.in(this, new ExpressionSubquery(query));
×
352
    }
353

354
    /**
355
     * Creates a 'not member of set' predicate from this left operand and the specified array of constant values.
356
     * @param values the constant values.
357
     * @return the predicate.
358
     */
359
    default Predicate notIn(Object... values) {
360
        return not(in(values));
×
361
    }
362

363
    /**
364
     * Creates a 'not member of set' predicate from this left operand and the specified collection of constant values.
365
     * @param values the constant values.
366
     * @return the predicate.
367
     */
368
    default Predicate notIn(Collection<?> values) {
369
        return not(in(values));
×
370
    }
371

372
    /**
373
     * Creates a 'not member of set' predicate from this left operand and the specified subquery.
374
     * @param query the subquery.
375
     * @return the predicate.
376
     */
377
    default Predicate notIn(SelectStatement query) {
378
        return not(in(query));
×
379
    }
380

381
    /**
382
     * Creates a pattern matching predicate from this left operand and the specified string pattern.
383
     * @param pattern the string pattern.
384
     * @return the predicate.
385
     */
386
    default Predicate like(String pattern) {
387
        return Predicates.like(this, pattern);
4✔
388
    }
389

390
    /**
391
     * Creates an optional pattern matching predicate from this left operand and the specified optional string pattern.
392
     * @param pattern the optional string pattern.
393
     * @return the optional predicate.
394
     */
395
    default OptionalPredicate like(Optional<String> pattern) {
396
        requireNonNull(pattern, "No pattern specified");
×
397
        return OptionalPredicate.ofNullable(pattern.map(p -> Predicates.like(this, p)).orElse(null));
×
398
    }
399

400
    /**
401
     * Creates a negated pattern matching predicate from this left operand and the specified string pattern.
402
     * @param pattern the string pattern.
403
     * @return the predicate.
404
     */
405
    default Predicate notLike(String pattern) {
406
        return not(like(pattern));
×
407
    }
408

409
    /**
410
     * Creates an 'is null' predicate from this left operand.
411
     * @return the predicate.
412
     */
413
    default Predicate isNull() {
414
        return Predicates.isNull(this);
3✔
415
    }
416

417
    /**
418
     * Creates an 'is not null' predicate from this left operand.
419
     * @return the predicate.
420
     */
421
    default Predicate isNotNull() {
422
        return not(isNull());
4✔
423
    }
424
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc