1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.dynamic.sql.where.condition;
17
18 import java.util.Arrays;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.Objects;
22 import java.util.function.Function;
23 import java.util.function.Predicate;
24
25 import org.jspecify.annotations.NonNull;
26 import org.jspecify.annotations.Nullable;
27 import org.mybatis.dynamic.sql.AbstractListValueCondition;
28
29 public class IsInWhenPresent<T> extends AbstractListValueCondition<T>
30 implements AbstractListValueCondition.Filterable<T>, AbstractListValueCondition.Mappable<T> {
31 private static final IsInWhenPresent<?> EMPTY = new IsInWhenPresent<>(Collections.emptyList());
32
33 public static <T> IsInWhenPresent<T> empty() {
34 @SuppressWarnings("unchecked")
35 IsInWhenPresent<T> t = (IsInWhenPresent<T>) EMPTY;
36 return t;
37 }
38
39 protected IsInWhenPresent(Collection<T> values) {
40 super(values.stream().filter(Objects::nonNull).toList());
41 }
42
43 @Override
44 public String operator() {
45 return "in";
46 }
47
48 @Override
49 public IsInWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
50 return filterSupport(predicate, IsInWhenPresent::new, this, IsInWhenPresent::empty);
51 }
52
53 @Override
54 public <R> IsInWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
55 return mapSupport(mapper, IsInWhenPresent::of, IsInWhenPresent::empty);
56 }
57
58 @SafeVarargs
59 public static <T> IsInWhenPresent<T> of(@Nullable T... values) {
60 return of(Arrays.asList(values));
61 }
62
63 public static <T> IsInWhenPresent<T> of(@Nullable Collection<@Nullable T> values) {
64 if (values == null) {
65 return empty();
66 } else {
67 return new IsInWhenPresent<>(values);
68 }
69 }
70 }