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.NoSuchElementException;
19  import java.util.function.BiPredicate;
20  import java.util.function.Function;
21  import java.util.function.Predicate;
22  
23  import org.jspecify.annotations.NonNull;
24  import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
25  
26  public class IsNotBetween<T> extends AbstractTwoValueCondition<T>
27          implements AbstractTwoValueCondition.Filterable<T>, AbstractTwoValueCondition.Mappable<T> {
28      private static final IsNotBetween<?> EMPTY = new IsNotBetween<Object>(-1, -1) {
29          @Override
30          public Object value1() {
31              throw new NoSuchElementException("No value present"); //$NON-NLS-1$
32          }
33  
34          @Override
35          public Object value2() {
36              throw new NoSuchElementException("No value present"); //$NON-NLS-1$
37          }
38  
39          @Override
40          public boolean isEmpty() {
41              return true;
42          }
43      };
44  
45      public static <T> IsNotBetween<T> empty() {
46          @SuppressWarnings("unchecked")
47          IsNotBetween<T> t = (IsNotBetween<T>) EMPTY;
48          return t;
49      }
50  
51      protected IsNotBetween(T value1, T value2) {
52          super(value1, value2);
53      }
54  
55      @Override
56      public String operator1() {
57          return "not between"; //$NON-NLS-1$
58      }
59  
60      @Override
61      public String operator2() {
62          return "and"; //$NON-NLS-1$
63      }
64  
65      @Override
66      public IsNotBetween<T> filter(BiPredicate<? super @NonNull T, ? super @NonNull T> predicate) {
67          return filterSupport(predicate, IsNotBetween::empty, this);
68      }
69  
70      @Override
71      public IsNotBetween<T> filter(Predicate<? super @NonNull T> predicate) {
72          return filterSupport(predicate, IsNotBetween::empty, this);
73      }
74  
75      @Override
76      public <R> IsNotBetween<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper1,
77              Function<? super @NonNull T, ? extends @NonNull R> mapper2) {
78          return mapSupport(mapper1, mapper2, IsNotBetween::new, IsNotBetween::empty);
79      }
80  
81      @Override
82      public <R> IsNotBetween<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
83          return map(mapper, mapper);
84      }
85  
86      public static <T> Builder<T> isNotBetween(T value1) {
87          return new Builder<>(value1);
88      }
89  
90      public static class Builder<T> extends AndGatherer<T, IsNotBetween<T>> {
91  
92          private Builder(T value1) {
93              super(value1);
94          }
95  
96          @Override
97          protected IsNotBetween<T> build(T value2) {
98              return new IsNotBetween<>(value1, value2);
99          }
100     }
101 }