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

torand / FasterSQL / 15071216480

16 May 2025 02:49PM UTC coverage: 69.877% (+2.4%) from 67.475%
15071216480

push

github

web-flow
Merge pull request #30 from torand/access-support

Access support

229 of 414 branches covered (55.31%)

Branch coverage included in aggregate %.

105 of 152 new or added lines in 26 files covered. (69.08%)

3 existing lines in 3 files now uncovered.

1193 of 1621 relevant lines covered (73.6%)

3.92 hits per line

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

78.79
/src/main/java/io/github/torand/fastersql/expression/arithmetic/Modulo.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.expression.arithmetic;
17

18
import io.github.torand.fastersql.Column;
19
import io.github.torand.fastersql.Context;
20
import io.github.torand.fastersql.alias.ColumnAlias;
21
import io.github.torand.fastersql.expression.Expression;
22
import io.github.torand.fastersql.order.OrderExpression;
23
import io.github.torand.fastersql.projection.Projection;
24

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

28
import static io.github.torand.fastersql.dialect.Capability.MODULO_OPERATOR;
29
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
30
import static io.github.torand.fastersql.util.lang.StringHelper.nonBlank;
31
import static java.util.Objects.requireNonNull;
32

33
/**
34
 * Implements the modulo (division remainder) expression.
35
 */
36
public class Modulo implements Expression, OrderExpression {
37
    private final Expression dividend;
38
    private final Expression divisor;
39
    private final ColumnAlias alias;
40

41
    Modulo(Expression dividend, Expression divisor, String alias) {
2✔
42
        this.dividend = requireNonNull(dividend, "No left operand (dividend) specified");
6✔
43
        this.divisor = requireNonNull(divisor, "No right operand (divisor) specified");
6✔
44
        this.alias = nonBlank(alias) ? new ColumnAlias(alias) : defaultAlias();
12✔
45
    }
1✔
46

47
    // Sql
48

49
    @Override
50
    public String sql(Context context) {
51
        if (context.getDialect().supports(MODULO_OPERATOR)) {
5✔
52
            String dividendSql = dividend.sql(context);
5✔
53
            if (dividend instanceof Addition || dividend instanceof Subtraction) {
8!
NEW
54
                dividendSql = "(" + dividendSql + ")";
×
55
            }
56

57
            String divisorSql = divisor.sql(context);
5✔
58
            if (divisor instanceof Addition || divisor instanceof Subtraction) {
8!
NEW
59
                divisorSql = "(" + divisorSql + ")";
×
60
            }
61

62
            return dividendSql + " % " + divisorSql;
4✔
63
        }
64

65
        return context.getDialect().formatModuloFunction(dividend.sql(context), divisor.sql(context));
12✔
66
    }
67

68
    @Override
69
    public Stream<Object> params(Context context) {
70
        return Stream.concat(dividend.params(context), divisor.params(context));
10✔
71
    }
72

73
    @Override
74
    public Stream<Column> columnRefs() {
75
        return Stream.concat(dividend.columnRefs(), divisor.columnRefs());
8✔
76
    }
77

78
    @Override
79
    public Stream<ColumnAlias> aliasRefs() {
NEW
80
        return Stream.concat(dividend.aliasRefs(), divisor.aliasRefs());
×
81
    }
82

83
    // Projection
84

85
    @Override
86
    public Projection as(String alias) {
87
        requireNonBlank(alias, "No alias specified");
6✔
88
        return new Modulo(dividend, divisor, alias);
9✔
89
    }
90

91
    @Override
92
    public Optional<ColumnAlias> alias() {
93
        return Optional.ofNullable(alias);
4✔
94
    }
95

96
    private ColumnAlias defaultAlias() {
97
        return ColumnAlias.generate("MODULO_");
3✔
98
    }
99
}
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