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

torand / FasterSQL / 13316820294

13 Feb 2025 08:49PM UTC coverage: 56.762% (+11.0%) from 45.739%
13316820294

push

github

web-flow
Merge pull request #8 from torand/testcontainers

feat: misc additions

143 of 336 branches covered (42.56%)

Branch coverage included in aggregate %.

97 of 171 new or added lines in 34 files covered. (56.73%)

6 existing lines in 6 files now uncovered.

772 of 1276 relevant lines covered (60.5%)

3.21 hits per line

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

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

18
import io.github.torand.fastersql.Context;
19
import io.github.torand.fastersql.Field;
20
import io.github.torand.fastersql.expression.Expression;
21
import io.github.torand.fastersql.projection.Projection;
22

23
import java.util.Random;
24
import java.util.stream.Stream;
25

26
import static io.github.torand.fastersql.util.contract.Requires.require;
27
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
28
import static io.github.torand.fastersql.util.lang.StringHelper.nonBlank;
29
import static java.util.Objects.requireNonNull;
30

31
public class ToNumber implements SingleRowFunction {
32
    private final Expression expression;
33
    private final int precision;
34
    private final int scale;
35
    private final String alias;
36

37
    ToNumber(Expression expression, int precision, int scale, String alias) {
×
38
        require(() -> precision >= 1, "precision must be 1 or greater");
×
39
        require(() -> scale >= 0, "scale must be 0 or greater");
×
40
        require(() -> scale <= precision, "scale must be less than or equal to precision");
×
41

42
        this.expression = requireNonNull(expression, "No expression specified");
×
43
        this.alias = nonBlank(alias) ? alias : defaultAlias();
×
44
        this.precision = precision;
×
45
        this.scale = scale;
×
46
    }
×
47

48
    // Sql
49

50
    @Override
51
    public String sql(Context context) {
52
        return context.getDialect().formatToNumberFunction(expression.sql(context), precision, scale);
×
53
    }
54

55
    @Override
56
    public Stream<Object> params(Context context) {
NEW
57
        return expression.params(context);
×
58
    }
59

60
    // Projection
61

62
    @Override
63
    public Projection as(String alias) {
64
        requireNonBlank(alias, "No alias specified");
×
65
        return new ToNumber(expression, precision, scale, alias);
×
66
    }
67

68
    @Override
69
    public String alias() {
70
        return alias;
×
71
    }
72

73
    // Expression
74

75
    @Override
76
    public Stream<Field> fieldRefs() {
77
        return expression.fieldRefs();
×
78
    }
79

80
    private String defaultAlias() {
81
        return "TO_NUMBER_" + new Random().nextInt(999) + 1;
×
82
    }
83
}
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