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

torand / FasterSQL / 12970556809

26 Jan 2025 02:19AM UTC coverage: 46.173% (-1.0%) from 47.188%
12970556809

push

github

torand
feat: support decimal number constants

108 of 332 branches covered (32.53%)

Branch coverage included in aggregate %.

1 of 29 new or added lines in 2 files covered. (3.45%)

1 existing line in 1 file now uncovered.

622 of 1249 relevant lines covered (49.8%)

2.63 hits per line

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

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

18
import java.math.BigDecimal;
19
import java.math.BigInteger;
20
import java.util.UUID;
21

22
import static java.util.Objects.isNull;
23

24
public final class Constants {
25

26
    private Constants() {}
27

28
    public static Constant constant(Object value) {
29
        if (isNull(value)) {
3!
30
            return nullValue();
×
31
        }
32

33
        if (value instanceof String string) {
6!
34
            return constant(string);
3✔
35
        }
36

NEW
37
        if (value instanceof Integer integer) {
×
38
            return constant(Long.valueOf(integer));
×
39
        }
40

NEW
41
        if (value instanceof Long longValue) {
×
42
            return constant(longValue);
×
43
        }
44

NEW
45
        if (value instanceof BigInteger biginteger) {
×
NEW
46
            return constant(biginteger.longValue());
×
47
        }
48

NEW
49
        if (value instanceof Float floatValue) {
×
NEW
50
            return constant(Double.valueOf(floatValue));
×
51
        }
52

NEW
53
        if (value instanceof Double doubleValue) {
×
NEW
54
            return constant(doubleValue);
×
55
        }
56

NEW
57
        if (value instanceof BigDecimal bigdecimal) {
×
NEW
58
            return constant(bigdecimal.doubleValue());
×
59
        }
60

NEW
61
        if (value instanceof UUID uuid) {
×
62
            return constant(uuid);
×
63
        }
64

NEW
65
        if (value instanceof Enum enumValue) {
×
UNCOV
66
            return constant(enumValue);
×
67
        }
68

69
        throw new IllegalArgumentException("Unsupported constant type: " + value.getClass());
×
70
    }
71

72
    public static Constant constant(UUID value) {
73
        if (isNull(value)) {
×
74
            return nullValue();
×
75
        }
76
        return new StringConstant(value.toString(), null);
×
77
    }
78

79
    public static Constant constant(Enum<? extends Enum<?>> value) {
80
        if (isNull(value)) {
×
81
            return nullValue();
×
82
        }
83
        return new StringConstant(value.name(), null);
×
84
    }
85

86
    public static Constant constant(String value) {
87
        if (isNull(value)) {
3!
88
            return nullValue();
×
89
        }
90
        return new StringConstant(value, null);
6✔
91
    }
92

93
    public static Constant constant(Long value) {
94
        if (isNull(value)) {
3!
95
            return nullValue();
×
96
        }
97
        return new IntegerConstant(value, null);
6✔
98
    }
99

100
    public static Constant constant(Double value) {
NEW
101
        if (isNull(value)) {
×
NEW
102
            return nullValue();
×
103
        }
NEW
104
        return new DecimalConstant(value, null);
×
105
    }
106

107
    public static Constant nullValue() {
108
        return new NullConstant(null);
5✔
109
    }
110
}
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