Skip to content

Commit 5c62e85

Browse files
committed
Update nullability specs
IntelliJ has fixed quite a few nullability inspection bugs - updating accordingly
1 parent a828741 commit 5c62e85

File tree

69 files changed

+599
-146
lines changed

Some content is hidden

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

69 files changed

+599
-146
lines changed

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

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

26-
import org.jspecify.annotations.NonNull;
2726
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
2827
import org.mybatis.dynamic.sql.render.RenderingContext;
2928
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
@@ -114,7 +113,7 @@ public interface Filterable<T> {
114113
* @return this condition if renderable and the value matches the predicate, otherwise a condition
115114
* that will not render.
116115
*/
117-
AbstractListValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
116+
AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
118117
}
119118

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

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

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

24-
import org.jspecify.annotations.NonNull;
2524
import org.mybatis.dynamic.sql.render.RenderedParameterInfo;
2625
import org.mybatis.dynamic.sql.render.RenderingContext;
2726
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
@@ -89,7 +88,7 @@ public interface Filterable<T> {
8988
* @return this condition if renderable and the value matches the predicate, otherwise a condition
9089
* that will not render.
9190
*/
92-
AbstractSingleValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
91+
AbstractSingleValueCondition<T> filter(Predicate<? super T> predicate);
9392
}
9493

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

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

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

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

116115
/**
117116
* If renderable and both values match the predicate, returns this condition. Else returns a condition
@@ -122,7 +121,7 @@ public interface Filterable<T> {
122121
* @return this condition if renderable and the values match the predicate, otherwise a condition
123122
* that will not render.
124123
*/
125-
AbstractTwoValueCondition<T> filter(Predicate<? super @NonNull T> predicate);
124+
AbstractTwoValueCondition<T> filter(Predicate<? super T> predicate);
126125
}
127126

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

154153
/**
155154
* If renderable, apply the mapping to both values and return a new condition with the new values. Else return a
@@ -160,6 +159,6 @@ <R> AbstractTwoValueCondition<R> map(Function<? super @NonNull T, ? extends R> m
160159
* @return a new condition with the result of applying the mappers to the values of this condition,
161160
* if renderable, otherwise a condition that will not render.
162161
*/
163-
<R> AbstractTwoValueCondition<R> map(Function<? super @NonNull T, ? extends R> mapper);
162+
<R> AbstractTwoValueCondition<R> map(Function<? super T, ? extends R> mapper);
164163
}
165164
}

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

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

24-
import org.jspecify.annotations.NonNull;
2524
import org.jspecify.annotations.Nullable;
2625
import org.mybatis.dynamic.sql.delete.DeleteDSL;
2726
import org.mybatis.dynamic.sql.delete.DeleteModel;
@@ -782,11 +781,11 @@ static <T> IsLessThanOrEqualToWhenPresent<T> isLessThanOrEqualToWhenPresent(Supp
782781
}
783782

784783
@SafeVarargs
785-
static <T> IsIn<T> isIn(@NonNull T... values) {
784+
static <T> IsIn<T> isIn(T... values) {
786785
return IsIn.of(values);
787786
}
788787

789-
static <T> IsIn<T> isIn(Collection<@NonNull T> values) {
788+
static <T> IsIn<T> isIn(Collection<T> values) {
790789
return IsIn.of(values);
791790
}
792791

@@ -804,11 +803,11 @@ static <T> IsInWhenPresent<T> isInWhenPresent(@Nullable Collection<@Nullable T>
804803
}
805804

806805
@SafeVarargs
807-
static <T> IsNotIn<T> isNotIn(@NonNull T... values) {
806+
static <T> IsNotIn<T> isNotIn(T... values) {
808807
return IsNotIn.of(values);
809808
}
810809

811-
static <T> IsNotIn<T> isNotIn(Collection<@NonNull T> values) {
810+
static <T> IsNotIn<T> isNotIn(Collection<T> values) {
812811
return IsNotIn.of(values);
813812
}
814813

@@ -829,7 +828,7 @@ static <T> IsBetween.Builder<T> isBetween(T value1) {
829828
return IsBetween.isBetween(value1);
830829
}
831830

832-
static <T> IsBetween.Builder<T> isBetween(Supplier<@NonNull T> valueSupplier1) {
831+
static <T> IsBetween.Builder<T> isBetween(Supplier<T> valueSupplier1) {
833832
return isBetween(valueSupplier1.get());
834833
}
835834

@@ -845,7 +844,7 @@ static <T> IsNotBetween.Builder<T> isNotBetween(T value1) {
845844
return IsNotBetween.isNotBetween(value1);
846845
}
847846

848-
static <T> IsNotBetween.Builder<T> isNotBetween(Supplier<@NonNull T> valueSupplier1) {
847+
static <T> IsNotBetween.Builder<T> isNotBetween(Supplier<T> valueSupplier1) {
849848
return isNotBetween(valueSupplier1.get());
850849
}
851850

src/main/java/org/mybatis/dynamic/sql/util/Utilities.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@
1515
*/
1616
package org.mybatis.dynamic.sql.util;
1717

18+
import java.util.Collection;
19+
import java.util.Objects;
20+
import java.util.stream.Stream;
21+
1822
import org.jspecify.annotations.Nullable;
1923

2024
public interface Utilities {
2125
static long safelyUnbox(@Nullable Long l) {
2226
return l == null ? 0 : l;
2327
}
28+
29+
static <T> Collection<T> filterNulls(Collection<@Nullable T> values) {
30+
// this method helps IntelliJ understand intended nullability
31+
Stream<T> st = values.stream().filter(Objects::nonNull);
32+
return st.toList();
33+
}
2434
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import java.util.function.Supplier;
1919

20-
import org.jspecify.annotations.NonNull;
21-
2220
/**
2321
* Utility class supporting the "and" part of a between condition. This class supports builders, so it is mutable.
2422
*
@@ -40,7 +38,7 @@ public R and(T value2) {
4038
return build(value2);
4139
}
4240

43-
public R and(Supplier<@NonNull T> valueSupplier2) {
41+
public R and(Supplier<T> valueSupplier2) {
4442
return and(valueSupplier2.get());
4543
}
4644

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

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

23-
import org.jspecify.annotations.NonNull;
2423
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2524

26-
public class IsBetween<T> extends AbstractTwoValueCondition<@NonNull T>
25+
public class IsBetween<T> extends AbstractTwoValueCondition<T>
2726
implements AbstractTwoValueCondition.Filterable<T>, AbstractTwoValueCondition.Mappable<T> {
2827
private static final IsBetween<?> EMPTY = new IsBetween<Object>(-1, -1) {
2928
@Override
@@ -63,23 +62,23 @@ public String operator2() {
6362
}
6463

6564
@Override
66-
public IsBetween<T> filter(BiPredicate<? super @NonNull T, ? super @NonNull T> predicate) {
65+
public IsBetween<T> filter(BiPredicate<? super T, ? super T> predicate) {
6766
return filterSupport(predicate, IsBetween::empty, this);
6867
}
6968

7069
@Override
71-
public IsBetween<T> filter(Predicate<? super @NonNull T> predicate) {
70+
public IsBetween<T> filter(Predicate<? super T> predicate) {
7271
return filterSupport(predicate, IsBetween::empty, this);
7372
}
7473

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

8180
@Override
82-
public <R> IsBetween<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
81+
public <R> IsBetween<R> map(Function<? super T, ? extends R> mapper) {
8382
return map(mapper, mapper);
8483
}
8584

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

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

23-
import org.jspecify.annotations.NonNull;
2423
import org.jspecify.annotations.Nullable;
2524
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2625

@@ -64,23 +63,23 @@ public String operator2() {
6463
}
6564

6665
@Override
67-
public IsBetweenWhenPresent<T> filter(BiPredicate<? super @NonNull T, ? super @NonNull T> predicate) {
66+
public IsBetweenWhenPresent<T> filter(BiPredicate<? super T, ? super T> predicate) {
6867
return filterSupport(predicate, IsBetweenWhenPresent::empty, this);
6968
}
7069

7170
@Override
72-
public IsBetweenWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
71+
public IsBetweenWhenPresent<T> filter(Predicate<? super T> predicate) {
7372
return filterSupport(predicate, IsBetweenWhenPresent::empty, this);
7473
}
7574

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

8281
@Override
83-
public <R> IsBetweenWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
82+
public <R> IsBetweenWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper) {
8483
return map(mapper, mapper);
8584
}
8685

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

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

22-
import org.jspecify.annotations.NonNull;
2322
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2423

2524
public class IsEqualTo<T> extends AbstractSingleValueCondition<T>
@@ -57,12 +56,12 @@ public static <T> IsEqualTo<T> of(T value) {
5756
}
5857

5958
@Override
60-
public IsEqualTo<T> filter(Predicate<? super @NonNull T> predicate) {
59+
public IsEqualTo<T> filter(Predicate<? super T> predicate) {
6160
return filterSupport(predicate, IsEqualTo::empty, this);
6261
}
6362

6463
@Override
65-
public <R> IsEqualTo<R> map(Function<? super @NonNull T, ? extends @NonNull R> mapper) {
64+
public <R> IsEqualTo<R> map(Function<? super T, ? extends R> mapper) {
6665
return mapSupport(mapper, IsEqualTo::new, IsEqualTo::empty);
6766
}
6867
}

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

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

22-
import org.jspecify.annotations.NonNull;
2322
import org.jspecify.annotations.Nullable;
2423
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2524

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

6463
@Override
65-
public IsEqualToWhenPresent<T> filter(Predicate<? super @NonNull T> predicate) {
64+
public IsEqualToWhenPresent<T> filter(Predicate<? super T> predicate) {
6665
return filterSupport(predicate, IsEqualToWhenPresent::empty, this);
6766
}
6867

6968
@Override
70-
public <R> IsEqualToWhenPresent<R> map(Function<? super @NonNull T, ? extends @Nullable R> mapper) {
69+
public <R> IsEqualToWhenPresent<R> map(Function<? super T, ? extends @Nullable R> mapper) {
7170
return mapSupport(mapper, IsEqualToWhenPresent::of, IsEqualToWhenPresent::empty);
7271
}
7372
}

0 commit comments

Comments
 (0)