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

mybatis / mybatis-dynamic-sql / #1703

16 Apr 2024 12:18AM CUT coverage: 100.0%. Remained the same
#1703

Pull #773

github

web-flow
Update dependency org.mybatis:mybatis-parent to v43
Pull Request #773: Update dependency org.mybatis:mybatis-parent to v43

152 of 152 branches covered (100.0%)

Branch coverage included in aggregate %.

4978 of 4978 relevant lines covered (100.0%)

1.0 hits per line

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

100.0
/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java
1
/*
2
 *    Copyright 2016-2024 the original author or authors.
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
 *       https://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 org.mybatis.dynamic.sql;
17

18
import java.util.Collection;
19
import java.util.Objects;
20
import java.util.function.Function;
21
import java.util.function.Predicate;
22
import java.util.function.Supplier;
23
import java.util.stream.Collectors;
24
import java.util.stream.Stream;
25

26
import org.mybatis.dynamic.sql.render.RenderingContext;
27

28
public abstract class AbstractListValueCondition<T> implements VisitableCondition<T> {
29
    protected final Collection<T> values;
30

31
    protected AbstractListValueCondition(Collection<T> values) {
1✔
32
        this.values = Objects.requireNonNull(values);
1✔
33
    }
1✔
34

35
    public final Stream<T> values() {
36
        return values.stream();
1✔
37
    }
38

39
    @Override
40
    public boolean isEmpty() {
41
        return values.isEmpty();
1✔
42
    }
43

44
    @Override
45
    public boolean shouldRender(RenderingContext renderingContext) {
46
        if (isEmpty()) {
1✔
47
            return renderingContext.isEmptyListConditionRenderingAllowed();
1✔
48
        } else {
49
            return true;
1✔
50
        }
51
    }
52

53
    @Override
54
    public <R> R accept(ConditionVisitor<T, R> visitor) {
55
        return visitor.visit(this);
1✔
56
    }
57

58
    private <R> Collection<R> applyMapper(Function<? super T, ? extends R> mapper) {
59
        Objects.requireNonNull(mapper);
1✔
60
        return values.stream().map(mapper).collect(Collectors.toList());
1✔
61
    }
62

63
    private Collection<T> applyFilter(Predicate<? super T> predicate) {
64
        Objects.requireNonNull(predicate);
1✔
65
        return values.stream().filter(predicate).collect(Collectors.toList());
1✔
66
    }
67

68
    protected <S extends AbstractListValueCondition<T>> S filterSupport(Predicate<? super T> predicate,
69
            Function<Collection<T>, S> constructor, S self, Supplier<S> emptySupplier) {
70
        if (isEmpty()) {
1✔
71
            return self;
1✔
72
        } else {
73
            Collection<T> filtered = applyFilter(predicate);
1✔
74
            return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered);
1✔
75
        }
76
    }
77

78
    protected <R, S extends AbstractListValueCondition<R>> S mapSupport(Function<? super T, ? extends R> mapper,
79
            Function<Collection<R>, S> constructor, Supplier<S> emptySupplier) {
80
        if (isEmpty()) {
1✔
81
            return emptySupplier.get();
1✔
82
        } else {
83
            return constructor.apply(applyMapper(mapper));
1✔
84
        }
85
    }
86

87
    /**
88
     * If renderable, apply the predicate to each value in the list and return a new condition with the filtered values.
89
     *     Else returns a condition that will not render (this). If all values are filtered out of the value
90
     *     list, then the condition will not render.
91
     *
92
     * @param predicate
93
     *            predicate applied to the values, if renderable
94
     *
95
     * @return a new condition with filtered values if renderable, otherwise a condition that will not render.
96
     */
97
    public abstract AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
98

99
    public abstract String operator();
100
}
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

© 2025 Coveralls, Inc