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