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 import org.mybatis.dynamic.sql.util.StringUtilities;
29
30 public class IsInCaseInsensitiveWhenPresent<T> extends AbstractListValueCondition<T>
31 implements CaseInsensitiveRenderableCondition<T>, AbstractListValueCondition.Filterable<T>,
32 AbstractListValueCondition.Mappable<T> {
33 private static final IsInCaseInsensitiveWhenPresent<?> EMPTY =
34 new IsInCaseInsensitiveWhenPresent<>(Collections.emptyList());
35
36 public static <T> IsInCaseInsensitiveWhenPresent<T> empty() {
37 @SuppressWarnings("unchecked")
38 IsInCaseInsensitiveWhenPresent<T> t = (IsInCaseInsensitiveWhenPresent<T>) EMPTY;
39 return t;
40 }
41
42 protected IsInCaseInsensitiveWhenPresent(Collection<T> values) {
43 super(values.stream().filter(Objects::nonNull).map(StringUtilities::upperCaseIfPossible).toList());
44 }
45
46 @Override
47 public String operator() {
48 return "in";
49 }
50
51 @Override
52 public IsInCaseInsensitiveWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
53 return filterSupport(predicate, IsInCaseInsensitiveWhenPresent::new, this,
54 IsInCaseInsensitiveWhenPresent::empty);
55 }
56
57 @Override
58 public <R> IsInCaseInsensitiveWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
59 return mapSupport(mapper, IsInCaseInsensitiveWhenPresent::new, IsInCaseInsensitiveWhenPresent::empty);
60 }
61
62 @SafeVarargs
63 public static <T> IsInCaseInsensitiveWhenPresent<T> of(@Nullable T... values) {
64 return of(Arrays.asList(values));
65 }
66
67 public static <T> IsInCaseInsensitiveWhenPresent<T> of(@Nullable Collection<@Nullable T> values) {
68 if (values == null) {
69 return empty();
70 } else {
71 return new IsInCaseInsensitiveWhenPresent<>(values);
72 }
73 }
74 }