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