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

torand / FasterSQL / 12893661530

21 Jan 2025 06:40PM UTC coverage: 50.829%. Remained the same
12893661530

push

github

torand
refactor: rename expression -> condition

104 of 304 branches covered (34.21%)

Branch coverage included in aggregate %.

81 of 211 new or added lines in 24 files covered. (38.39%)

3 existing lines in 2 files now uncovered.

601 of 1083 relevant lines covered (55.49%)

2.91 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/condition/OptionalCondition.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.condition;
17

18
import io.github.torand.fastersql.condition.logical.LogicalConditions;
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 OptionalCondition {
29
    private final Condition condition;
30

31
    public static OptionalCondition of(Condition condition) {
NEW
32
        requireNonNull(condition, "condition");
×
NEW
33
        return new OptionalCondition(condition);
×
34
    }
35

36
    public static OptionalCondition ofNullable(Condition condition) {
37
        return new OptionalCondition(condition);
5✔
38
    }
39

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

44
    private OptionalCondition(Condition condition) {
2✔
45
        this.condition = condition;
3✔
46
    }
1✔
47

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

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

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

61
    public OptionalCondition or(Condition other) {
NEW
62
        requireNonNull(other, "other");
×
63

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

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

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

95
    public OptionalCondition and(Condition other) {
NEW
96
        requireNonNull(other, "other");
×
97

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

105
    public static Collection<Condition> unwrap(OptionalCondition... maybeConditions) {
106
        return streamSafely(maybeConditions).flatMap(OptionalCondition::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