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.function.Function;
22  import java.util.function.Predicate;
23  
24  import org.jspecify.annotations.NonNull;
25  import org.mybatis.dynamic.sql.AbstractListValueCondition;
26  import org.mybatis.dynamic.sql.render.RenderingContext;
27  import org.mybatis.dynamic.sql.util.StringUtilities;
28  import org.mybatis.dynamic.sql.util.Validator;
29  
30  public class IsNotInCaseInsensitive<T> extends AbstractListValueCondition<T>
31          implements CaseInsensitiveRenderableCondition<T>, AbstractListValueCondition.Filterable<T>,
32          AbstractListValueCondition.Mappable<T> {
33      private static final IsNotInCaseInsensitive<?> EMPTY = new IsNotInCaseInsensitive<>(Collections.emptyList());
34  
35      public static <T> IsNotInCaseInsensitive<T> empty() {
36          @SuppressWarnings("unchecked")
37          IsNotInCaseInsensitive<T> t = (IsNotInCaseInsensitive<T>) EMPTY;
38          return t;
39      }
40  
41      protected IsNotInCaseInsensitive(Collection<T> values) {
42          super(values.stream().map(StringUtilities::upperCaseIfPossible).toList());
43      }
44  
45      @Override
46      public boolean shouldRender(RenderingContext renderingContext) {
47          Validator.assertNotEmpty(values, "ERROR.44", "IsNotInCaseInsensitive"); //$NON-NLS-1$ //$NON-NLS-2$
48          return true;
49      }
50  
51      @Override
52      public String operator() {
53          return "not in"; //$NON-NLS-1$
54      }
55  
56      @Override
57      public IsNotInCaseInsensitive<T> filter(Predicate<? super @NonNull T> predicate) {
58          return filterSupport(predicate, IsNotInCaseInsensitive::new, this, IsNotInCaseInsensitive::empty);
59      }
60  
61      @Override
62      public <R> IsNotInCaseInsensitive<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
63          return mapSupport(mapper, IsNotInCaseInsensitive::new, IsNotInCaseInsensitive::empty);
64      }
65  
66      @SafeVarargs
67      public static <T> IsNotInCaseInsensitive<T> of(T... values) {
68          return of(Arrays.asList(values));
69      }
70  
71      public static <T> IsNotInCaseInsensitive<T> of(Collection<T> values) {
72          return new IsNotInCaseInsensitive<>(values);
73      }
74  }