• 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

80.65
/src/main/java/io/github/torand/fastersql/expression/cases/SimpleCaseBuilder.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

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

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

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

34
    SimpleCaseBuilder(Expression caseExpression) {
2✔
35
        this.caseExpression = requireNonNull(caseExpression, "No case expression specified");
6✔
36
    }
1✔
37

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

48
   /**
49
     * Creates a WHEN-THEN clause.
50
     * @param whenConstant the WHEN constant value.
51
     * @return the WHEN-THEN builder.
52
     */
53
    public SimpleWhenThenBuilder when(String whenConstant) {
54
        requireNonNull(whenConstant, "No when constant specified");
4✔
55
        return when($(whenConstant));
5✔
56
    }
57

58
   /**
59
     * Creates a WHEN-THEN clause.
60
     * @param whenConstant the WHEN constant value.
61
     * @return the WHEN-THEN builder.
62
     */
63
    public SimpleWhenThenBuilder when(Number whenConstant) {
64
        requireNonNull(whenConstant, "No when constant specified");
×
65
        return when($(whenConstant));
×
66
    }
67

68
    /**
69
     * Adds an ELSE clause.
70
     * @param elseExpression the ELSE expression.
71
     * @return the modified CASE expression.
72
     */
73
    public SimpleCaseBuilder else_(Expression elseExpression) {
74
        this.elseExpression = requireNonNull(elseExpression, "No else expression specified");
6✔
75
        return this;
2✔
76
    }
77

78
    /**
79
     * Adds an ELSE clause.
80
     * @param elseConstant the ELSE constant value.
81
     * @return the modified CASE expression.
82
     */
83
    public SimpleCaseBuilder else_(String elseConstant) {
84
        requireNonNull(elseConstant, "No else constant specified");
4✔
85
        return else_($(elseConstant));
5✔
86
    }
87

88
    /**
89
     * Adds an ELSE clause.
90
     * @param elseConstant the ELSE constant value.
91
     * @return the modified CASE expression.
92
     */
93
    public SimpleCaseBuilder else_(Number elseConstant) {
94
        requireNonNull(elseConstant, "No else constant specified");
×
95
        return else_($(elseConstant));
×
96
    }
97

98
    /**
99
     * Creates the simple CASE expression.
100
     * @return the simple CASE expression.
101
     */
102
    public SimpleCase end() {
103
        return new SimpleCase(caseExpression, whenThenClauses, elseExpression, null);
11✔
104
    }
105

106
    void addWhenThenClause(SimpleWhenThen whenThenClause) {
107
        requireNonNull(whenThenClause, "No when-then clause specified");
4✔
108
        this.whenThenClauses.add(whenThenClause);
5✔
109
    }
1✔
110

111
    /**
112
     * Builder of a WHEN-THEN clause in a simple CASE expression.
113
     */
114
    public static class SimpleWhenThenBuilder {
115
        private final SimpleCaseBuilder caseBuilder;
116
        private final Expression whenExpression;
117

118
        SimpleWhenThenBuilder(SimpleCaseBuilder caseBuilder, Expression whenExpression) {
2✔
119
            this.caseBuilder = requireNonNull(caseBuilder, "No case builder specified");
6✔
120
            this.whenExpression = requireNonNull(whenExpression, "No when expression specified");
6✔
121
        }
1✔
122

123
        /**
124
         * Adds a WHEN-THEN clause.
125
         * @param thenExpression the THEN expression.
126
         * @return the modified CASE expression.
127
         */
128
        public SimpleCaseBuilder then(Expression thenExpression) {
129
            requireNonNull(thenExpression, "No then expression specified");
4✔
130
            caseBuilder.addWhenThenClause(new SimpleWhenThen(whenExpression, thenExpression));
9✔
131
            return caseBuilder;
3✔
132
        }
133

134
        /**
135
         * Adds a WHEN-THEN clause.
136
         * @param thenConstant the THEN constant value.
137
         * @return the modified CASE expression.
138
         */
139
        public SimpleCaseBuilder then(String thenConstant) {
140
            requireNonNull(thenConstant, "No then constant specified");
4✔
141
            return then($(thenConstant));
5✔
142
        }
143

144
        /**
145
         * Adds a WHEN-THEN clause.
146
         * @param thenConstant the THEN constant value.
147
         * @return the modified CASE expression.
148
         */
149
        public SimpleCaseBuilder then(Number thenConstant) {
NEW
150
            requireNonNull(thenConstant, "No then constant specified");
×
NEW
151
            return then($(thenConstant));
×
152
        }
153
    }
154
}
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