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

torand / FasterSQL / 17194256933

24 Aug 2025 09:56PM UTC coverage: 68.417% (+0.3%) from 68.15%
17194256933

push

github

torand
refactor: sonar cloud issues

299 of 598 branches covered (50.0%)

Branch coverage included in aggregate %.

35 of 40 new or added lines in 6 files covered. (87.5%)

1 existing line in 1 file now uncovered.

1616 of 2201 relevant lines covered (73.42%)

4.01 hits per line

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

84.62
/src/main/java/io/github/torand/fastersql/expression/cases/SearchedCaseBuilder.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.expression.cases;
17

18
import io.github.torand.fastersql.expression.Expression;
19
import io.github.torand.fastersql.predicate.Predicate;
20

21
import java.util.ArrayList;
22
import java.util.List;
23

24
import static io.github.torand.fastersql.constant.Constants.$;
25
import static java.util.Objects.requireNonNull;
26

27
/**
28
 * Builder of searched CASE expressions.
29
 */
30
public class SearchedCaseBuilder {
31
    private final List<SearchedWhenThen> whenThenClauses = new ArrayList<>();
5✔
32
    private Expression elseExpression;
33

34
    SearchedCaseBuilder() {
2✔
35
    }
1✔
36

37
    /**
38
     * Creates a WHEN-THEN clause.
39
     * @param whenPredicate the WHEN predicate.
40
     * @return the WHEN-THEN builder.
41
     */
42
    public SearchedWhenThenBuilder when(Predicate whenPredicate) {
43
        requireNonNull(whenPredicate, "No when predicate specified");
4✔
44
        return new SearchedWhenThenBuilder(this, whenPredicate);
6✔
45
    }
46

47
    /**
48
     * Adds an ELSE clause.
49
     * @param elseExpression the ELSE expression.
50
     * @return the modified CASE expression.
51
     */
52
    public SearchedCaseBuilder else_(Expression elseExpression) {
53
        this.elseExpression = requireNonNull(elseExpression, "No else expression specified");
6✔
54
        return this;
2✔
55
    }
56

57
    /**
58
     * Adds an ELSE clause.
59
     * @param elseConstant the ELSE constant value.
60
     * @return the modified CASE expression.
61
     */
62
    public SearchedCaseBuilder else_(String elseConstant) {
63
        requireNonNull(elseConstant, "No else constant specified");
4✔
64
        return else_($(elseConstant));
5✔
65
    }
66

67
    /**
68
     * Adds an ELSE clause.
69
     * @param elseConstant the ELSE constant value.
70
     * @return the modified CASE expression.
71
     */
72
    public SearchedCaseBuilder else_(Number elseConstant) {
73
        requireNonNull(elseConstant, "No else constant specified");
×
74
        return else_($(elseConstant));
×
75
    }
76

77
    /**
78
     * Creates the searched CASE expression.
79
     * @return the searched CASE expression.
80
     */
81
    public SearchedCase end() {
82
        return new SearchedCase(whenThenClauses, elseExpression, null);
9✔
83
    }
84

85
    void addWhenThenClause(SearchedWhenThen whenThenClause) {
86
        requireNonNull(whenThenClause, "No when-then clause specified");
4✔
87
        this.whenThenClauses.add(whenThenClause);
5✔
88
    }
1✔
89

90
    /**
91
     * Builder of a WHEN-THEN clause in a searched CASE expression.
92
     */
93
    public static class SearchedWhenThenBuilder {
94
        private final SearchedCaseBuilder caseBuilder;
95
        private final Predicate whenPredicate;
96

97
        SearchedWhenThenBuilder(SearchedCaseBuilder caseBuilder, Predicate whenPredicate) {
2✔
98
            this.caseBuilder = requireNonNull(caseBuilder, "No case builder specified");
6✔
99
            this.whenPredicate = requireNonNull(whenPredicate, "No when predicate specified");
6✔
100
        }
1✔
101

102
        /**
103
         * Adds a WHEN-THEN clause.
104
         * @param thenExpression the THEN expression.
105
         * @return the modified CASE expression.
106
         */
107
        public SearchedCaseBuilder then(Expression thenExpression) {
108
            requireNonNull(thenExpression, "No then expression specified");
4✔
109
            caseBuilder.addWhenThenClause(new SearchedWhenThen(whenPredicate, thenExpression));
9✔
110
            return caseBuilder;
3✔
111
        }
112

113
        /**
114
         * Adds a WHEN-THEN clause.
115
         * @param thenConstant the THEN constant value.
116
         * @return the modified CASE expression.
117
         */
118
        public SearchedCaseBuilder then(String thenConstant) {
119
            requireNonNull(thenConstant, "No then constant specified");
4✔
120
            return then($(thenConstant));
5✔
121
        }
122

123
        /**
124
         * Adds a WHEN-THEN clause.
125
         * @param thenConstant the THEN constant value.
126
         * @return the modified CASE expression.
127
         */
128
        public SearchedCaseBuilder then(Number thenConstant) {
NEW
129
            requireNonNull(thenConstant, "No then constant specified");
×
NEW
130
            return then($(thenConstant));
×
131
        }
132
    }
133
}
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