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

torand / FasterSQL / 13316818541

13 Feb 2025 08:49PM UTC coverage: 56.762%. First build
13316818541

Pull #8

github

web-flow
Merge a7d313d14 into 1f252c094
Pull Request #8: 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%)

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

71.43
/src/main/java/io/github/torand/fastersql/function/singlerow/Substring.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 Substring implements SingleRowFunction {
32
    private final Expression expression;
33
    private final int startPos;
34
    private final int length;
35
    private final String alias;
36

37
    Substring(Expression expression, int startPos, int length, String alias) {
2✔
38
        require(() -> startPos >= 1, "startPos must be 1 or greater");
12!
39
        require(() -> length >= 1, "length must be 1 or greater");
12!
40

41
        this.expression = requireNonNull(expression, "No expression specified");
6✔
42
        this.alias = nonBlank(alias) ? alias : defaultAlias();
7!
43
        this.startPos = startPos;
3✔
44
        this.length = length;
3✔
45
    }
1✔
46

47
    // Sql
48

49
    @Override
50
    public String sql(Context context) {
51
        return context.getDialect().formatSubstringFunction(expression.sql(context), startPos, length);
12✔
52
    }
53

54
    @Override
55
    public Stream<Object> params(Context context) {
56
        return expression.params(context);
5✔
57
    }
58

59
    // Projection
60

61
    @Override
62
    public Projection as(String alias) {
63
        requireNonBlank(alias, "No alias specified");
×
NEW
64
        return new Substring(expression, length, startPos, alias);
×
65
    }
66

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

72
    // Expression
73

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

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