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

torand / FasterSQL / 16524838515

25 Jul 2025 02:47PM UTC coverage: 72.942% (+0.1%) from 72.847%
16524838515

push

github

torand
feat: add support for the negate operator

233 of 378 branches covered (61.64%)

Branch coverage included in aggregate %.

15 of 16 new or added lines in 2 files covered. (93.75%)

1282 of 1699 relevant lines covered (75.46%)

3.98 hits per line

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

80.95
/src/main/java/io/github/torand/fastersql/expression/arithmetic/Negate.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.alias.ColumnAlias;
19
import io.github.torand.fastersql.expression.Expression;
20
import io.github.torand.fastersql.model.Column;
21
import io.github.torand.fastersql.order.OrderExpression;
22
import io.github.torand.fastersql.projection.Projection;
23
import io.github.torand.fastersql.sql.Context;
24

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

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

32
/**
33
 * Implements the negate numerical function.
34
 */
35
public class Negate implements Expression, OrderExpression {
36
    private final Expression expression;
37
    private final ColumnAlias alias;
38

39
    Negate(Expression expression, String alias) {
2✔
40
        this.expression = requireNonNull(expression, "No expression specified");
6✔
41
        this.alias = nonBlank(alias) ? new ColumnAlias(alias) : defaultAlias();
12✔
42
    }
1✔
43

44
    // Sql
45

46
    @Override
47
    public String sql(Context context) {
48
        String exprSql = expression.sql(context);
5✔
49
        if (expression instanceof Addition || expression instanceof Subtraction) {
4!
50
            exprSql = "(" + exprSql + ")";
3✔
51
        }
52

53
        return "-" + exprSql;
3✔
54
    }
55

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

61
    @Override
62
    public Stream<Column> columnRefs() {
63
        return expression.columnRefs();
4✔
64
    }
65

66
    @Override
67
    public Stream<ColumnAlias> aliasRefs() {
NEW
68
        return expression.aliasRefs();
×
69
    }
70

71
    // Projection
72

73
    @Override
74
    public Projection as(String alias) {
75
        requireNonBlank(alias, "No alias specified");
6✔
76
        return new Negate(expression, alias);
7✔
77
    }
78

79
    @Override
80
    public Optional<ColumnAlias> alias() {
81
        return Optional.ofNullable(alias);
4✔
82
    }
83

84
    private ColumnAlias defaultAlias() {
85
        return ColumnAlias.generate("NEG_");
3✔
86
    }
87
}
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