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