• 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

72.5
/src/main/java/io/github/torand/fastersql/function/singlerow/SingleRowFunctions.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.function.singlerow;
17

18
import io.github.torand.fastersql.expression.Expression;
19
import io.github.torand.fastersql.function.singlerow.cast.CastBuilder;
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.nonNull;
26
import static java.util.Objects.requireNonNull;
27

28
/**
29
 * Provides factory methods for single row functions.
30
 */
31
public final class SingleRowFunctions {
32
    private SingleRowFunctions() {}
33

34
    /**
35
     * Creates the UPPER function for a string expression.
36
     * @param expression the string expression.
37
     * @return the string function.
38
     */
39
    public static Upper upper(Expression expression) {
40
        return new Upper(expression, null);
6✔
41
    }
42

43
    /**
44
     * Creates the UPPER function for a string constant value.
45
     * @param constantValue the string value.
46
     * @return the string function.
47
     */
48
    public static Upper upper(String constantValue) {
49
        return upper($(constantValue));
×
50
    }
51

52
    /**
53
     * Creates the LOWER function for a string expression.
54
     * @param expression the string expression.
55
     * @return the string function.
56
     */
57
    public static Lower lower(Expression expression) {
58
        return new Lower(expression, null);
6✔
59
    }
60

61
    /**
62
     * Creates the LOWER function for a string constant value.
63
     * @param constantValue the string value.
64
     * @return the string function.
65
     */
66
    public static Lower lower(String constantValue) {
67
        return lower($(constantValue));
×
68
    }
69

70
    /**
71
     * Creates the TO_NUMBER function converting from a string expression to decimal number.
72
     * @param expression the string expression.
73
     * @param precision the total number of digits (including decimals).
74
     * @param scale the number of decimals.
75
     * @return the conversion function.
76
     */
77
    public static ToNumber toNumber(Expression expression, int precision, int scale) {
78
        return new ToNumber(expression, precision, scale, null);
×
79
    }
80

81
    /**
82
     * Creates the TO_NUMBER function converting from a string constant value to decimal number.
83
     * @param constantValue the string value.
84
     * @param precision the total number of digits (including decimals).
85
     * @param scale the number of decimals.
86
     * @return the conversion function.
87
     */
88
    public static ToNumber toNumber(String constantValue, int precision, int scale) {
89
        return toNumber($(constantValue), precision, scale);
×
90
    }
91

92
    /**
93
     * Creates the TO_NUMBER function converting from a string expression to integer.
94
     * @param expression the string expression.
95
     * @param precision the total number of digits.
96
     * @return the conversion function.
97
     */
98
    public static ToNumber toNumber(Expression expression, int precision) {
99
        return new ToNumber(expression, precision, 0, null);
8✔
100
    }
101

102
    /**
103
     * Creates the TO_NUMBER function converting from a string constant value to integer.
104
     * @param constantValue the string value.
105
     * @param precision the total number of digits.
106
     * @return the conversion function.
107
     */
108
    public static ToNumber toNumber(String constantValue, int precision) {
109
        return toNumber($(constantValue), precision);
×
110
    }
111

112
    /**
113
     * Creates the SUBSTRING function for a string expression.
114
     * @param expression the string expression.
115
     * @param startPos the substring start position, 1-based.
116
     * @param length the substring length.
117
     * @return the string function.
118
     */
119
    public static Substring substring(Expression expression, int startPos, int length) {
120
        return new Substring(expression, startPos, length, null);
8✔
121
    }
122

123
    /**
124
     * Creates the SUBSTRING function for a string constant value.
125
     * @param constantValue the string value.
126
     * @param startPos the substring start position, 1-based.
127
     * @param length the substring length.
128
     * @return the string function.
129
     */
130
    public static Substring substring(String constantValue, int startPos, int length) {
131
        return substring($(constantValue), startPos, length);
×
132
    }
133

134
    /**
135
     * Creates the TO_CHAR function converting from a timestamp/number expression to string.
136
     * @param expression the timestamp or number expression.
137
     * @param format the format specifier.
138
     * @return the conversion function.
139
     */
140
    public static ToChar toChar(Expression expression, String format) {
141
        return new ToChar(expression, format, null);
7✔
142
    }
143

144
    /**
145
     * Creates the CONCAT function for two or more string expressions.
146
     * @param expression1 the first string expression.
147
     * @param expression2 the second string expression.
148
     * @param otherExpressions the additional string expressions.
149
     * @return the string function.
150
     */
151
    public static Concat concat(Expression expression1, Expression expression2, Expression... otherExpressions) {
152
        List<Expression> expressions = new ArrayList<>();
4✔
153
        expressions.add(requireNonNull(expression1, "First expression is null"));
7✔
154
        expressions.add(requireNonNull(expression2, "Second expression is null"));
7✔
155
        if (nonNull(otherExpressions)) {
3!
156
            expressions.addAll(List.of(otherExpressions));
5✔
157
        }
158

159
        return new Concat(expressions, null);
6✔
160
    }
161

162
    /**
163
     * Creates the LENGTH function for a string expression.
164
     * @param expression the string expression.
165
     * @return the string function.
166
     */
167
    public static Length length(Expression expression) {
168
        return new Length(expression, null);
6✔
169
    }
170

171
    /**
172
     * Creates the LENGTH function for a string constant value.
173
     * @param constantValue the string value.
174
     * @return the string function.
175
     */
176
    public static Length length(String constantValue) {
177
        return length($(constantValue));
×
178
    }
179

180
    /**
181
     * Creates the ROUND function for a numeric expression.
182
     * @param expression the numeric expression.
183
     * @return the numeric function.
184
     */
185
    public static Round round(Expression expression) {
186
        return new Round(expression, null);
6✔
187
    }
188

189
    /**
190
     * Creates the ROUND function for a numeric constant value.
191
     * @param constantValue the numeric value.
192
     * @return the numeric function.
193
     */
194
    public static Round round(Number constantValue) {
195
        return round($(constantValue));
×
196
    }
197

198
    /**
199
     * Creates the ABS function for a numeric expression.
200
     * @param expression the numeric expression.
201
     * @return the numeric function.
202
     */
203
    public static Abs abs(Expression expression) {
204
        return new Abs(expression, null);
6✔
205
    }
206

207
    /**
208
     * Creates the ABS function for a numeric constant value.
209
     * @param constantValue the numeric value.
210
     * @return the numeric function.
211
     */
212
    public static Abs abs(Number constantValue) {
213
        return abs($(constantValue));
4✔
214
    }
215

216
    /**
217
     * Creates the CEIL function for a numeric expression.
218
     * @param expression the numeric expression.
219
     * @return the numeric function.
220
     */
221
    public static Ceil ceil(Expression expression) {
222
        return new Ceil(expression, null);
6✔
223
    }
224

225
    /**
226
     * Creates the CEIL function for a numeric constant value.
227
     * @param constantValue the numeric value.
228
     * @return the numeric function.
229
     */
230
    public static Ceil ceil(Number constantValue) {
231
        return ceil($(constantValue));
×
232
    }
233

234
    /**
235
     * Creates the FLOOR function for a numeric expression.
236
     * @param expression the numeric expression.
237
     * @return the numeric function.
238
     */
239
    public static Floor floor(Expression expression) {
240
        return new Floor(expression, null);
6✔
241
    }
242

243
    /**
244
     * Creates the FLOOR function for a numeric constant value.
245
     * @param constantValue the numeric value.
246
     * @return the numeric function.
247
     */
248
    public static Floor floor(Number constantValue) {
249
        return floor($(constantValue));
×
250
    }
251

252
    /**
253
     * Creates the LN (natural logarithm) function for a numeric expression.
254
     * @param expression the numeric expression.
255
     * @return the numeric function.
256
     */
257
    public static Ln ln(Expression expression) {
258
        return new Ln(expression, null);
6✔
259
    }
260

261
    /**
262
     * Creates the LN (natural logarithm) function for a numeric constant value.
263
     * @param constantValue the numeric value.
264
     * @return the numeric function.
265
     */
266
    public static Ln ln(Number constantValue) {
267
        return ln($(constantValue));
4✔
268
    }
269

270
    /**
271
     * Creates the EXP (natural exponential) function for a numeric expression.
272
     * @param expression the numeric expression.
273
     * @return the numeric function.
274
     */
275
    public static Exp exp(Expression expression) {
276
        return new Exp(expression, null);
6✔
277
    }
278

279
    /**
280
     * Creates the EXP (natural exponential) function for a numeric constant value.
281
     * @param constantValue the numeric value.
282
     * @return the numeric function.
283
     */
284
    public static Exp exp(Number constantValue) {
285
        return exp($(constantValue));
4✔
286
    }
287

288
    /**
289
     * Creates the SQRT (square root) function for a numeric expression.
290
     * @param expression the numeric expression.
291
     * @return the numeric function.
292
     */
293
    public static Sqrt sqrt(Expression expression) {
294
        return new Sqrt(expression, null);
6✔
295
    }
296

297
    /**
298
     * Creates the SQRT (square root) function for a numeric constant value.
299
     * @param constantValue the numeric value.
300
     * @return the numeric function.
301
     */
302
    public static Sqrt sqrt(Number constantValue) {
303
        return sqrt($(constantValue));
4✔
304
    }
305

306
    /**
307
     * Creates the POW (exponentiation) function for a numeric expression.
308
     * @param base the numeric base expression.
309
     * @param exponent the numeric exponent expression.
310
     * @return the numeric function.
311
     */
312
    public static Power pow(Expression base, Expression exponent) {
313
        return new Power(base, exponent, null);
7✔
314
    }
315

316
    /**
317
     * Creates the POW (exponentiation) function for a numeric expression with constant value exponent.
318
     * @param base the numeric base expression.
319
     * @param exponent the numeric exponent value.
320
     * @return the numeric function.
321
     */
322
    public static Power pow(Expression base, Number exponent) {
323
        return pow(base, $(exponent));
5✔
324
    }
325

326
    /**
327
     * Creates the CAST function for an expression.
328
     * @param expression the expression.
329
     * @return the CAST function builder.
330
     */
331
    public static CastBuilder cast(Expression expression) {
332
        return new CastBuilder(expression);
5✔
333
    }
334

335
    /**
336
     * Creates the CAST function for a constant value.
337
     * @param value the constant value.
338
     * @return the CAST function builder.
339
     */
340
    public static CastBuilder cast(String value) {
341
        return cast($(value));
4✔
342
    }
343

344
    /**
345
     * Creates the CAST function for a constant value.
346
     * @param value the constant value.
347
     * @return the CAST function builder.
348
     */
349
    public static CastBuilder cast(Number value) {
350
        return cast($(value));
4✔
351
    }
352
}
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