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

torand / FasterSQL / 12970217277

26 Jan 2025 01:31AM UTC coverage: 49.458%. Remained the same
12970217277

push

github

torand
refactor: condition -> predicate

108 of 322 branches covered (33.54%)

Branch coverage included in aggregate %.

58 of 137 new or added lines in 12 files covered. (42.34%)

3 existing lines in 2 files now uncovered.

622 of 1154 relevant lines covered (53.9%)

2.85 hits per line

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

14.29
/src/main/java/io/github/torand/fastersql/predicate/OptionalPredicate.java
1
/*
2
 * Copyright (c) 2024 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.predicate.compound.CompoundPredicates;
19

20
import java.util.Collection;
21
import java.util.stream.Stream;
22

23
import static io.github.torand.fastersql.util.collection.CollectionHelper.streamSafely;
24
import static io.github.torand.fastersql.util.contract.Requires.precondition;
25
import static java.util.Objects.nonNull;
26
import static java.util.Objects.requireNonNull;
27

28
public class OptionalPredicate {
29
    private final Predicate predicate;
30

31
    public static OptionalPredicate of(Predicate predicate) {
NEW
32
        requireNonNull(predicate, "Predicate not specified");
×
NEW
33
        return new OptionalPredicate(predicate);
×
34
    }
35

36
    public static OptionalPredicate ofNullable(Predicate predicate) {
37
        return new OptionalPredicate(predicate);
5✔
38
    }
39

40
    public static OptionalPredicate empty() {
NEW
41
        return new OptionalPredicate(null);
×
42
    }
43

44
    private OptionalPredicate(Predicate predicate) {
2✔
45
        this.predicate = predicate;
3✔
46
    }
1✔
47

48
    public boolean isPresent() {
NEW
49
        return nonNull(predicate);
×
50
    }
51

52
    public Predicate get() {
NEW
53
        precondition(() -> nonNull(predicate), "Predicate is not present");
×
NEW
54
        return predicate;
×
55
    }
56

57
    public Stream<Predicate> stream() {
58
        return nonNull(predicate) ? Stream.of(predicate) : Stream.empty();
10✔
59
    }
60

61
    public OptionalPredicate or(Predicate other) {
NEW
62
        requireNonNull(other, "other");
×
63

NEW
64
        if (nonNull(this.predicate)) {
×
NEW
65
            return new OptionalPredicate(CompoundPredicates.or(this.predicate, other));
×
66
        } else {
NEW
67
            return new OptionalPredicate(other);
×
68
        }
69
    }
70

71
    public OptionalPredicate or(OptionalPredicate other) {
NEW
72
        if (nonNull(this.predicate) && nonNull(other.predicate)) {
×
NEW
73
            return new OptionalPredicate(CompoundPredicates.or(this.predicate, other.predicate));
×
NEW
74
        } else if (nonNull(this.predicate)) {
×
NEW
75
            return new OptionalPredicate(this.predicate);
×
NEW
76
        } else if (nonNull(other.predicate)) {
×
NEW
77
            return new OptionalPredicate(other.predicate);
×
78
        } else {
NEW
79
            return new OptionalPredicate(null);
×
80
        }
81
    }
82

83
    public OptionalPredicate and(OptionalPredicate other) {
NEW
84
        if (nonNull(this.predicate) && nonNull(other.predicate)) {
×
NEW
85
            return new OptionalPredicate(CompoundPredicates.and(this.predicate, other.predicate));
×
NEW
86
        } else if (nonNull(this.predicate)) {
×
NEW
87
            return new OptionalPredicate(this.predicate);
×
NEW
88
        } else if (nonNull(other.predicate)) {
×
NEW
89
            return new OptionalPredicate(other.predicate);
×
90
        } else {
NEW
91
            return new OptionalPredicate(null);
×
92
        }
93
    }
94

95
    public OptionalPredicate and(Predicate other) {
NEW
96
        requireNonNull(other, "other");
×
97

NEW
98
        if (nonNull(this.predicate)) {
×
NEW
99
            return new OptionalPredicate(CompoundPredicates.and(this.predicate, other));
×
100
        } else {
NEW
101
            return new OptionalPredicate(other);
×
102
        }
103
    }
104

105
    public static Collection<Predicate> unwrap(OptionalPredicate... maybePredicates) {
106
        return streamSafely(maybePredicates).flatMap(OptionalPredicate::stream).toList();
6✔
107
    }
108
}
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