Skip to content

Commit 26c973a

Browse files
committed
Fully denote the nullability of filter and map methods.
Also fix al the tests that were, essentially, misuses of the library.
1 parent 37fa65f commit 26c973a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+315
-306
lines changed

src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.stream.Collectors;
2424
import java.util.stream.Stream;
2525

26+
import org.jspecify.annotations.NonNull;
2627
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
2728
import org.mybatis.dynamic.sql.render.RenderingContext;
2829
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
@@ -113,7 +114,7 @@ public interface Filterable<T> {
113114
* @return this condition if renderable and the value matches the predicate, otherwise a condition
114115
* that will not render.
115116
*/
116-
AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
117+
AbstractListValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
117118
}
118119

119120
/**
@@ -138,6 +139,6 @@ public interface Mappable<T> {
138139
* @return a new condition with the result of applying the mapper to the value of this condition,
139140
* if renderable, otherwise a condition that will not render.
140141
*/
141-
<R> AbstractListValueCondition<R> map(Function<? super T, ? extends R> mapper);
142+
<R> AbstractListValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
142143
}
143144
}

src/main/java/org/mybatis/dynamic/sql/AbstractSingleValueCondition.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.function.Predicate;
2222
import java.util.function.Supplier;
2323

24+
import org.jspecify.annotations.NonNull;
2425
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
2526
import org.mybatis.dynamic.sql.render.RenderingContext;
2627
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
@@ -88,7 +89,7 @@ public interface Filterable<T> {
8889
* @return this condition if renderable and the value matches the predicate, otherwise a condition
8990
* that will not render.
9091
*/
91-
AbstractSingleValueCondition<T> filter(Predicate<? super T> predicate);
92+
AbstractSingleValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
9293
}
9394

9495
/**
@@ -113,6 +114,6 @@ public interface Mappable<T> {
113114
* @return a new condition with the result of applying the mapper to the value of this condition,
114115
* if renderable, otherwise a condition that will not render.
115116
*/
116-
<R> AbstractSingleValueCondition<R> map(Function<? super T, ? extends R> mapper);
117+
<R> AbstractSingleValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
117118
}
118119
}

src/main/java/org/mybatis/dynamic/sql/AbstractTwoValueCondition.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.function.Predicate;
2424
import java.util.function.Supplier;
2525

26+
import org.jspecify.annotations.NonNull;
2627
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
2728
import org.mybatis.dynamic.sql.render.RenderingContext;
2829
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
@@ -110,7 +111,7 @@ public interface Filterable<T> {
110111
* @return this condition if renderable and the values match the predicate, otherwise a condition
111112
* that will not render.
112113
*/
113-
AbstractTwoValueCondition<T> filter(BiPredicate<? super T, ? super T> predicate);
114+
AbstractTwoValueCondition<T> filter(BiPredicate<? super @NonNull T, ? super @NonNull T> predicate);
114115

115116
/**
116117
* If renderable and both values match the predicate, returns this condition. Else returns a condition
@@ -121,7 +122,7 @@ public interface Filterable<T> {
121122
* @return this condition if renderable and the values match the predicate, otherwise a condition
122123
* that will not render.
123124
*/
124-
AbstractTwoValueCondition<T> filter(Predicate<? super T> predicate);
125+
AbstractTwoValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
125126
}
126127

127128
/**
@@ -147,8 +148,8 @@ public interface Mappable<T> {
147148
* @return a new condition with the result of applying the mappers to the values of this condition,
148149
* if renderable, otherwise a condition that will not render.
149150
*/
150-
<R> AbstractTwoValueCondition<R> map(Function<? super T, ? extends R> mapper1,
151-
Function<? super T, ? extends R> mapper2);
151+
<R> AbstractTwoValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper1,
152+
Function<? super @NonNull T, ? extends R> mapper2);
152153

153154
/**
154155
* If renderable, apply the mapping to both values and return a new condition with the new values. Else return a
@@ -159,6 +160,6 @@ <R> AbstractTwoValueCondition<R> map(Function<? super T, ? extends R> mapper1,
159160
* @return a new condition with the result of applying the mappers to the values of this condition,
160161
* if renderable, otherwise a condition that will not render.
161162
*/
162-
<R> AbstractTwoValueCondition<R> map(Function<? super T, ? extends R> mapper);
163+
<R> AbstractTwoValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
163164
}
164165
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetween.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
import java.util.function.Function;
2121
import java.util.function.Predicate;
2222

23+
import org.jspecify.annotations.NonNull;
2324
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2425

25-
public class IsBetween<T> extends AbstractTwoValueCondition<T>
26+
public class IsBetween<T> extends AbstractTwoValueCondition<@NonNull T>
2627
implements AbstractTwoValueCondition.Filterable<T>, AbstractTwoValueCondition.Mappable<T> {
2728
private static final IsBetween<?> EMPTY = new IsBetween<Object>(-1, -1) {
2829
@Override
@@ -62,22 +63,23 @@ public String operator2() {
6263
}
6364

6465
@Override
65-
public IsBetween<T> filter(BiPredicate<? super T, ? super T> predicate) {
66+
public IsBetween<T> filter(BiPredicate<? super @NonNull T, ? super @NonNull T> predicate) {
6667
return filterSupport(predicate, IsBetween::empty, this);
6768
}
6869

6970
@Override
70-
public IsBetween<T> filter(Predicate<? super T> predicate) {
71+
public IsBetween<T> filter(Predicate<? super @NonNull T> predicate) {
7172
return filterSupport(predicate, IsBetween::empty, this);
7273
}
7374

7475
@Override
75-
public <R> IsBetween<R> map(Function<? super T, ? extends R> mapper1, Function<? super T, ? extends R> mapper2) {
76+
public <R> IsBetween<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper1,
77+
Function<? super @NonNull T, ? extends @NonNull R> mapper2) {
7678
return mapSupport(mapper1, mapper2, IsBetween::new, IsBetween::empty);
7779
}
7880

7981
@Override
80-
public <R> IsBetween<R> map(Function<? super T, ? extends R> mapper) {
82+
public <R> IsBetween<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
8183
return map(mapper, mapper);
8284
}
8385

src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetweenWhenPresent.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.function.Function;
2121
import java.util.function.Predicate;
2222

23+
import org.jspecify.annotations.NonNull;
2324
import org.jspecify.annotations.Nullable;
2425
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2526

@@ -63,23 +64,23 @@ public String operator2() {
6364
}
6465

6566
@Override
66-
public IsBetweenWhenPresent<T> filter(BiPredicate<? super T, ? super T> predicate) {
67+
public IsBetweenWhenPresent<T> filter(BiPredicate<? super @NonNull T, ? super @NonNull T> predicate) {
6768
return filterSupport(predicate, IsBetweenWhenPresent::empty, this);
6869
}
6970

7071
@Override
71-
public IsBetweenWhenPresent<T> filter(Predicate<? super T> predicate) {
72+
public IsBetweenWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
7273
return filterSupport(predicate, IsBetweenWhenPresent::empty, this);
7374
}
7475

7576
@Override
76-
public <R> IsBetweenWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper1,
77-
Function<? super T, ? extends @Nullable R> mapper2) {
77+
public <R> IsBetweenWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper1,
78+
Function<? super @NonNull T, ? extends @Nullable R> mapper2) {
7879
return mapSupport(mapper1, mapper2, IsBetweenWhenPresent::of, IsBetweenWhenPresent::empty);
7980
}
8081

8182
@Override
82-
public <R> IsBetweenWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper) {
83+
public <R> IsBetweenWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
8384
return map(mapper, mapper);
8485
}
8586

src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualTo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.Function;
2020
import java.util.function.Predicate;
2121

22+
import org.jspecify.annotations.NonNull;
2223
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2324

2425
public class IsEqualTo<T> extends AbstractSingleValueCondition<T>
@@ -56,12 +57,12 @@ public static <T> IsEqualTo<T> of(T value) {
5657
}
5758

5859
@Override
59-
public IsEqualTo<T> filter(Predicate<? super T> predicate) {
60+
public IsEqualTo<T> filter(Predicate<? super @NonNull T> predicate) {
6061
return filterSupport(predicate, IsEqualTo::empty, this);
6162
}
6263

6364
@Override
64-
public <R> IsEqualTo<R> map(Function<? super T, ? extends R> mapper) {
65+
public <R> IsEqualTo<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
6566
return mapSupport(mapper, IsEqualTo::new, IsEqualTo::empty);
6667
}
6768
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualToWhenPresent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.Function;
2020
import java.util.function.Predicate;
2121

22+
import org.jspecify.annotations.NonNull;
2223
import org.jspecify.annotations.Nullable;
2324
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2425

@@ -61,12 +62,12 @@ public static <T> IsEqualToWhenPresent<T> of(@Nullable T value) {
6162
}
6263

6364
@Override
64-
public IsEqualToWhenPresent<T> filter(Predicate<? super T> predicate) {
65+
public IsEqualToWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
6566
return filterSupport(predicate, IsEqualToWhenPresent::empty, this);
6667
}
6768

6869
@Override
69-
public <R> IsEqualToWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper) {
70+
public <R> IsEqualToWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
7071
return mapSupport(mapper, IsEqualToWhenPresent::of, IsEqualToWhenPresent::empty);
7172
}
7273
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThan.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.Function;
2020
import java.util.function.Predicate;
2121

22+
import org.jspecify.annotations.NonNull;
2223
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2324

2425
public class IsGreaterThan<T> extends AbstractSingleValueCondition<T>
@@ -55,12 +56,12 @@ public static <T> IsGreaterThan<T> of(T value) {
5556
}
5657

5758
@Override
58-
public IsGreaterThan<T> filter(Predicate<? super T> predicate) {
59+
public IsGreaterThan<T> filter(Predicate<? super @NonNull T> predicate) {
5960
return filterSupport(predicate, IsGreaterThan::empty, this);
6061
}
6162

6263
@Override
63-
public <R> IsGreaterThan<R> map(Function<? super T, ? extends R> mapper) {
64+
public <R> IsGreaterThan<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
6465
return mapSupport(mapper, IsGreaterThan::new, IsGreaterThan::empty);
6566
}
6667
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualTo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.Function;
2020
import java.util.function.Predicate;
2121

22+
import org.jspecify.annotations.NonNull;
2223
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2324

2425
public class IsGreaterThanOrEqualTo<T> extends AbstractSingleValueCondition<T>
@@ -55,12 +56,12 @@ public static <T> IsGreaterThanOrEqualTo<T> of(T value) {
5556
}
5657

5758
@Override
58-
public IsGreaterThanOrEqualTo<T> filter(Predicate<? super T> predicate) {
59+
public IsGreaterThanOrEqualTo<T> filter(Predicate<? super @NonNull T> predicate) {
5960
return filterSupport(predicate, IsGreaterThanOrEqualTo::empty, this);
6061
}
6162

6263
@Override
63-
public <R> IsGreaterThanOrEqualTo<R> map(Function<? super T, ? extends R> mapper) {
64+
public <R> IsGreaterThanOrEqualTo<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
6465
return mapSupport(mapper, IsGreaterThanOrEqualTo::new, IsGreaterThanOrEqualTo::empty);
6566
}
6667
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualToWhenPresent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.Function;
2020
import java.util.function.Predicate;
2121

22+
import org.jspecify.annotations.NonNull;
2223
import org.jspecify.annotations.Nullable;
2324
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2425

@@ -60,12 +61,12 @@ public static <T> IsGreaterThanOrEqualToWhenPresent<T> of(@Nullable T value) {
6061
}
6162

6263
@Override
63-
public IsGreaterThanOrEqualToWhenPresent<T> filter(Predicate<? super T> predicate) {
64+
public IsGreaterThanOrEqualToWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
6465
return filterSupport(predicate, IsGreaterThanOrEqualToWhenPresent::empty, this);
6566
}
6667

6768
@Override
68-
public <R> IsGreaterThanOrEqualToWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper) {
69+
public <R> IsGreaterThanOrEqualToWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
6970
return mapSupport(mapper, IsGreaterThanOrEqualToWhenPresent::of, IsGreaterThanOrEqualToWhenPresent::empty);
7071
}
7172
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanWhenPresent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.function.Function;
2020
import java.util.function.Predicate;
2121

22+
import org.jspecify.annotations.NonNull;
2223
import org.jspecify.annotations.Nullable;
2324
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2425

@@ -60,12 +61,12 @@ public static <T> IsGreaterThanWhenPresent<T> of(@Nullable T value) {
6061
}
6162

6263
@Override
63-
public IsGreaterThanWhenPresent<T> filter(Predicate<? super T> predicate) {
64+
public IsGreaterThanWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
6465
return filterSupport(predicate, IsGreaterThanWhenPresent::empty, this);
6566
}
6667

6768
@Override
68-
public <R> IsGreaterThanWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper) {
69+
public <R> IsGreaterThanWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
6970
return mapSupport(mapper, IsGreaterThanWhenPresent::of, IsGreaterThanWhenPresent::empty);
7071
}
7172
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.function.Function;
2222
import java.util.function.Predicate;
2323

24+
import org.jspecify.annotations.NonNull;
2425
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2526
import org.mybatis.dynamic.sql.render.RenderingContext;
2627
import org.mybatis.dynamic.sql.util.Validator;
@@ -51,12 +52,12 @@ public String operator() {
5152
}
5253

5354
@Override
54-
public IsIn<T> filter(Predicate<? super T> predicate) {
55+
public IsIn<T> filter(Predicate<? super @NonNull T> predicate) {
5556
return filterSupport(predicate, IsIn::new, this, IsIn::empty);
5657
}
5758

5859
@Override
59-
public <R> IsIn<R> map(Function<? super T, ? extends R> mapper) {
60+
public <R> IsIn<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
6061
return mapSupport(mapper, IsIn::new, IsIn::empty);
6162
}
6263

src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitive.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.function.Function;
2222
import java.util.function.Predicate;
2323

24+
import org.jspecify.annotations.NonNull;
2425
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2526
import org.mybatis.dynamic.sql.render.RenderingContext;
2627
import org.mybatis.dynamic.sql.util.StringUtilities;
@@ -53,12 +54,12 @@ public String operator() {
5354
}
5455

5556
@Override
56-
public IsInCaseInsensitive<T> filter(Predicate<? super T> predicate) {
57+
public IsInCaseInsensitive<T> filter(Predicate<? super @NonNull T> predicate) {
5758
return filterSupport(predicate, IsInCaseInsensitive::new, this, IsInCaseInsensitive::empty);
5859
}
5960

6061
@Override
61-
public <R> IsInCaseInsensitive<R> map(Function<? super T, ? extends R> mapper) {
62+
public <R> IsInCaseInsensitive<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
6263
return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty);
6364
}
6465

src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Objects;
2323
import java.util.function.Predicate;
2424

25+
import org.jspecify.annotations.NonNull;
2526
import org.jspecify.annotations.Nullable;
2627
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2728
import org.mybatis.dynamic.sql.util.StringUtilities;
@@ -48,13 +49,13 @@ public String operator() {
4849
}
4950

5051
@Override
51-
public IsInCaseInsensitiveWhenPresent<T> filter(Predicate<? super T> predicate) {
52+
public IsInCaseInsensitiveWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
5253
return filterSupport(predicate, IsInCaseInsensitiveWhenPresent::new, this,
5354
IsInCaseInsensitiveWhenPresent::empty);
5455
}
5556

5657
@Override
57-
public <R> IsInCaseInsensitiveWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper) {
58+
public <R> IsInCaseInsensitiveWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
5859
return mapSupport(mapper, IsInCaseInsensitiveWhenPresent::new, IsInCaseInsensitiveWhenPresent::empty);
5960
}
6061

@@ -64,7 +65,7 @@ public static <T> IsInCaseInsensitiveWhenPresent<T> of(@Nullable T... values) {
6465
}
6566

6667
public static <T> IsInCaseInsensitiveWhenPresent<T> of(@Nullable Collection<@Nullable T> values) {
67-
if (values == null || values.isEmpty()) {
68+
if (values == null) {
6869
return empty();
6970
} else {
7071
return new IsInCaseInsensitiveWhenPresent<>(values);

0 commit comments

Comments
 (0)