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.NoSuchElementException;
19 import java.util.function.Function;
20 import java.util.function.Predicate;
21
22 import org.jspecify.annotations.NonNull;
23 import org.jspecify.annotations.Nullable;
24 import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
25 import org.mybatis.dynamic.sql.util.StringUtilities;
26
27 public class IsNotLikeCaseInsensitiveWhenPresent<T> extends AbstractSingleValueCondition<T>
28 implements CaseInsensitiveRenderableCondition<T>, AbstractSingleValueCondition.Filterable<T>,
29 AbstractSingleValueCondition.Mappable<T> {
30 private static final IsNotLikeCaseInsensitiveWhenPresent<?> EMPTY =
31 new IsNotLikeCaseInsensitiveWhenPresent<>("") {
32 @Override
33 public String value() {
34 throw new NoSuchElementException("No value present");
35 }
36
37 @Override
38 public boolean isEmpty() {
39 return true;
40 }
41 };
42
43 public static <T> IsNotLikeCaseInsensitiveWhenPresent<T> empty() {
44 @SuppressWarnings("unchecked")
45 IsNotLikeCaseInsensitiveWhenPresent<T> t = (IsNotLikeCaseInsensitiveWhenPresent<T>) EMPTY;
46 return t;
47 }
48
49 protected IsNotLikeCaseInsensitiveWhenPresent(T value) {
50 super(StringUtilities.upperCaseIfPossible(value));
51 }
52
53 @Override
54 public String operator() {
55 return "not like";
56 }
57
58 @Override
59 public IsNotLikeCaseInsensitiveWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
60 return filterSupport(predicate, IsNotLikeCaseInsensitiveWhenPresent::empty, this);
61 }
62
63 @Override
64 public <R> IsNotLikeCaseInsensitiveWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
65 return mapSupport(mapper, IsNotLikeCaseInsensitiveWhenPresent::of, IsNotLikeCaseInsensitiveWhenPresent::empty);
66 }
67
68 public static <T> IsNotLikeCaseInsensitiveWhenPresent<T> of(@Nullable T value) {
69 if (value == null) {
70 return empty();
71 } else {
72 return new IsNotLikeCaseInsensitiveWhenPresent<>(value);
73 }
74 }
75 }