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