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

torand / FasterSQL / 17012572989

16 Aug 2025 08:26PM UTC coverage: 68.265% (-0.008%) from 68.273%
17012572989

push

github

torand
refactor: sonar cloud issues

299 of 598 branches covered (50.0%)

Branch coverage included in aggregate %.

33 of 47 new or added lines in 18 files covered. (70.21%)

1 existing line in 1 file now uncovered.

1680 of 2301 relevant lines covered (73.01%)

3.89 hits per line

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

75.0
/src/main/java/io/github/torand/fastersql/constant/GenericConstant.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.constant;
17

18
import io.github.torand.fastersql.alias.Alias;
19
import io.github.torand.fastersql.alias.ColumnAlias;
20
import io.github.torand.fastersql.model.Column;
21
import io.github.torand.fastersql.projection.Projection;
22
import io.github.torand.fastersql.sql.Context;
23

24
import java.util.Optional;
25
import java.util.stream.Stream;
26

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

31
/**
32
 * Represents a scalar value constant of any type.
33
 * @param <T> the value type.
34
 */
35
public class GenericConstant<T> implements Constant {
36
    private final T value;
37
    private final ColumnAlias alias;
38

39
    GenericConstant(T value, String alias) {
2✔
40
        this.value = requireNonNull(value, "Value is null. Use the NullValue constant instead.");
5✔
41
        this.alias = nonBlank(alias) ? new ColumnAlias(alias) : null;
11✔
42
    }
1✔
43

44
    // Sql
45

46
    @Override
47
    public String sql(Context context) {
48
        return "?";
2✔
49
    }
50

51
    @Override
52
    public Stream<Object> params(Context context) {
53
        return Stream.of(value);
4✔
54
    }
55

56
    @Override
57
    public Stream<Column> columnRefs() {
58
        return Stream.empty();
2✔
59
    }
60

61
    @Override
62
    public Stream<ColumnAlias> aliasRefs() {
63
        return Stream.empty();
×
64
    }
65

66
    // Projection
67

68
    @Override
69
    public Projection as(String alias) {
70
        requireNonBlank(alias, "No alias specified");
6✔
71
        return new GenericConstant<>(value, alias);
7✔
72
    }
73

74
    @Override
75
    public Optional<ColumnAlias> alias() {
76
        return Optional.ofNullable(alias);
4✔
77
    }
78

79
    // Constant
80

81
    @Override
82
    public T value() {
83
        return value;
×
84
    }
85

86
    @Override
87
    public Projection forColumn(Column column) {
88
        requireNonNull(column, "No column specified");
×
NEW
89
        return new GenericConstant<>(value, column.alias().map(Alias::name).orElse(null));
×
90
    }
91
}
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