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

mybatis / mybatis-dynamic-sql / #1521

15 Nov 2023 11:38AM CUT coverage: 100.0%. Remained the same
#1521

push

github

web-flow
Merge pull request #697 from mybatis/renovate/testcontainers-java-monorepo

Update testcontainers-java monorepo to v1.19.2

4517 of 4517 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-2023 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
public abstract class AbstractListValueCondition<T> implements VisitableCondition<T> {
27
    protected final Collection<T> values;
28

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

33
    public final <R> Stream<R> mapValues(Function<T, R> mapper) {
34
        return values.stream().map(mapper);
1✔
35
    }
36

37
    @Override
38
    public boolean shouldRender() {
39
        return !values.isEmpty();
1✔
40
    }
41

42
    @Override
43
    public <R> R accept(ConditionVisitor<T, R> visitor) {
44
        return visitor.visit(this);
1✔
45
    }
46

47
    private <R> Collection<R> applyMapper(Function<? super T, ? extends R> mapper) {
48
        Objects.requireNonNull(mapper);
1✔
49
        return values.stream().map(mapper).collect(Collectors.toList());
1✔
50
    }
51

52
    private Collection<T> applyFilter(Predicate<? super T> predicate) {
53
        Objects.requireNonNull(predicate);
1✔
54
        return values.stream().filter(predicate).collect(Collectors.toList());
1✔
55
    }
56

57
    protected <S extends AbstractListValueCondition<T>> S filterSupport(Predicate<? super T> predicate,
58
            Function<Collection<T>, S> constructor, S self, Supplier<S> emptySupplier) {
59
        if (shouldRender()) {
1✔
60
            Collection<T> filtered = applyFilter(predicate);
1✔
61
            return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered);
1✔
62
        } else {
63
            return self;
1✔
64
        }
65
    }
66

67
    protected <R, S extends AbstractListValueCondition<R>> S mapSupport(Function<? super T, ? extends R> mapper,
68
            Function<Collection<R>, S> constructor, Supplier<S> emptySupplier) {
69
        if (shouldRender()) {
1✔
70
            return constructor.apply(applyMapper(mapper));
1✔
71
        } else {
72
            return emptySupplier.get();
1✔
73
        }
74
    }
75

76
    /**
77
     * If renderable, apply the predicate to each value in the list and return a new condition with the filtered values.
78
     *     Else returns a condition that will not render (this). If all values are filtered out of the value
79
     *     list, then the condition will not render.
80
     *
81
     * @param predicate
82
     *            predicate applied to the values, if renderable
83
     *
84
     * @return a new condition with filtered values if renderable, otherwise a condition that will not render.
85
     */
86
    public abstract AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
87

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