Skip to content

Commit e6eef01

Browse files
committed
List value conditions do not expect null values
1 parent 450526f commit e6eef01

File tree

8 files changed

+31
-56
lines changed

8 files changed

+31
-56
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
import java.util.stream.Collectors;
2424
import java.util.stream.Stream;
2525

26-
import org.jspecify.annotations.Nullable;
27-
2826
public abstract class AbstractListValueCondition<T> implements VisitableCondition<T> {
29-
protected final Collection<@Nullable T> values;
27+
protected final Collection<T> values;
3028

31-
protected AbstractListValueCondition(Collection<@Nullable T> values) {
29+
protected AbstractListValueCondition(Collection<T> values) {
3230
this.values = Objects.requireNonNull(values);
3331
}
3432

35-
public final Stream<@Nullable T> values() {
33+
public final Stream<T> values() {
3634
return values.stream();
3735
}
3836

@@ -46,18 +44,18 @@ public <R> R accept(ConditionVisitor<T, R> visitor) {
4644
return visitor.visit(this);
4745
}
4846

49-
private <R> Collection<R> applyMapper(Function<? super @Nullable T, ? extends @Nullable R> mapper) {
47+
private <R> Collection<R> applyMapper(Function<? super T, ? extends R> mapper) {
5048
Objects.requireNonNull(mapper);
5149
return values.stream().map(mapper).collect(Collectors.toList());
5250
}
5351

54-
private Collection<T> applyFilter(Predicate<? super @Nullable T> predicate) {
52+
private Collection<T> applyFilter(Predicate<? super T> predicate) {
5553
Objects.requireNonNull(predicate);
5654
return values.stream().filter(predicate).toList();
5755
}
5856

59-
protected <S extends AbstractListValueCondition<T>> S filterSupport(Predicate<? super @Nullable T> predicate,
60-
Function<Collection<@Nullable T>, S> constructor, S self, Supplier<S> emptySupplier) {
57+
protected <S extends AbstractListValueCondition<T>> S filterSupport(Predicate<? super T> predicate,
58+
Function<Collection<T>, S> constructor, S self, Supplier<S> emptySupplier) {
6159
if (isEmpty()) {
6260
return self;
6361
} else {
@@ -66,9 +64,8 @@ protected <S extends AbstractListValueCondition<T>> S filterSupport(Predicate<?
6664
}
6765
}
6866

69-
protected <R, S extends AbstractListValueCondition<R>> S mapSupport(
70-
Function<? super @Nullable T, ? extends @Nullable R> mapper,
71-
Function<Collection<@Nullable R>, S> constructor, Supplier<S> emptySupplier) {
67+
protected <R, S extends AbstractListValueCondition<R>> S mapSupport(Function<? super T, ? extends R> mapper,
68+
Function<Collection<R>, S> constructor, Supplier<S> emptySupplier) {
7269
if (isEmpty()) {
7370
return emptySupplier.get();
7471
} else {
@@ -84,7 +81,7 @@ protected <R, S extends AbstractListValueCondition<R>> S mapSupport(
8481
*
8582
* @return a new condition with filtered values if renderable, otherwise an empty condition
8683
*/
87-
public abstract AbstractListValueCondition<T> filter(Predicate<? super @Nullable T> predicate);
84+
public abstract AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
8885

8986
public abstract String operator();
9087
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,11 +914,11 @@ static IsNotLikeCaseInsensitive isNotLikeCaseInsensitiveWhenPresent(Supplier<@Nu
914914
return isNotLikeCaseInsensitiveWhenPresent(valueSupplier.get());
915915
}
916916

917-
static IsInCaseInsensitive isInCaseInsensitive(@Nullable String... values) {
917+
static IsInCaseInsensitive isInCaseInsensitive(String... values) {
918918
return IsInCaseInsensitive.of(values);
919919
}
920920

921-
static IsInCaseInsensitive isInCaseInsensitive(Collection<@Nullable String> values) {
921+
static IsInCaseInsensitive isInCaseInsensitive(Collection<String> values) {
922922
return IsInCaseInsensitive.of(values);
923923
}
924924

@@ -931,11 +931,11 @@ static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(
931931
return values == null ? IsInCaseInsensitiveWhenPresent.empty() : IsInCaseInsensitiveWhenPresent.of(values);
932932
}
933933

934-
static IsNotInCaseInsensitive isNotInCaseInsensitive(@Nullable String... values) {
934+
static IsNotInCaseInsensitive isNotInCaseInsensitive(String... values) {
935935
return IsNotInCaseInsensitive.of(values);
936936
}
937937

938-
static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection<@Nullable String> values) {
938+
static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection<String> values) {
939939
return IsNotInCaseInsensitive.of(values);
940940
}
941941

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import java.util.function.Predicate;
2222
import java.util.function.UnaryOperator;
2323

24-
import org.jspecify.annotations.Nullable;
2524
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2625
import org.mybatis.dynamic.sql.render.RenderingContext;
27-
import org.mybatis.dynamic.sql.util.StringUtilities;
2826
import org.mybatis.dynamic.sql.util.Validator;
2927

3028
public class IsInCaseInsensitive extends AbstractListValueCondition<String>
@@ -35,7 +33,7 @@ public static IsInCaseInsensitive empty() {
3533
return EMPTY;
3634
}
3735

38-
protected IsInCaseInsensitive(Collection<@Nullable String> values) {
36+
protected IsInCaseInsensitive(Collection<String> values) {
3937
super(values);
4038
}
4139

@@ -62,15 +60,15 @@ public IsInCaseInsensitive filter(Predicate<? super String> predicate) {
6260
* @param mapper a mapping function to apply to the values, if not empty
6361
* @return a new condition with mapped values if renderable, otherwise an empty condition
6462
*/
65-
public IsInCaseInsensitive map(UnaryOperator<@Nullable String> mapper) {
63+
public IsInCaseInsensitive map(UnaryOperator<String> mapper) {
6664
return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty);
6765
}
6866

69-
public static IsInCaseInsensitive of(@Nullable String... values) {
67+
public static IsInCaseInsensitive of(String... values) {
7068
return of(Arrays.asList(values));
7169
}
7270

73-
public static IsInCaseInsensitive of(Collection<@Nullable String> values) {
74-
return new IsInCaseInsensitive(values).map(StringUtilities::safelyUpperCase);
71+
public static IsInCaseInsensitive of(Collection<String> values) {
72+
return new IsInCaseInsensitive(values).map(String::toUpperCase);
7573
}
7674
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.jspecify.annotations.Nullable;
2525
import org.mybatis.dynamic.sql.AbstractListValueCondition;
26-
import org.mybatis.dynamic.sql.util.StringUtilities;
2726
import org.mybatis.dynamic.sql.util.Utilities;
2827

2928
public class IsInCaseInsensitiveWhenPresent extends AbstractListValueCondition<String>
@@ -57,7 +56,7 @@ public IsInCaseInsensitiveWhenPresent filter(Predicate<? super String> predicate
5756
* @param mapper a mapping function to apply to the values, if not empty
5857
* @return a new condition with mapped values if renderable, otherwise an empty condition
5958
*/
60-
public IsInCaseInsensitiveWhenPresent map(UnaryOperator<@Nullable String> mapper) {
59+
public IsInCaseInsensitiveWhenPresent map(UnaryOperator<String> mapper) {
6160
return mapSupport(mapper, IsInCaseInsensitiveWhenPresent::new, IsInCaseInsensitiveWhenPresent::empty);
6261
}
6362

@@ -66,6 +65,6 @@ public static IsInCaseInsensitiveWhenPresent of(@Nullable String... values) {
6665
}
6766

6867
public static IsInCaseInsensitiveWhenPresent of(Collection<@Nullable String> values) {
69-
return new IsInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase);
68+
return new IsInCaseInsensitiveWhenPresent(values).map(String::toUpperCase);
7069
}
7170
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import java.util.function.Predicate;
2222
import java.util.function.UnaryOperator;
2323

24-
import org.jspecify.annotations.Nullable;
2524
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2625
import org.mybatis.dynamic.sql.render.RenderingContext;
27-
import org.mybatis.dynamic.sql.util.StringUtilities;
2826
import org.mybatis.dynamic.sql.util.Validator;
2927

3028
public class IsNotInCaseInsensitive extends AbstractListValueCondition<String>
@@ -35,7 +33,7 @@ public static IsNotInCaseInsensitive empty() {
3533
return EMPTY;
3634
}
3735

38-
protected IsNotInCaseInsensitive(Collection<@Nullable String> values) {
36+
protected IsNotInCaseInsensitive(Collection<String> values) {
3937
super(values);
4038
}
4139

@@ -62,15 +60,15 @@ public IsNotInCaseInsensitive filter(Predicate<? super String> predicate) {
6260
* @param mapper a mapping function to apply to the values, if not empty
6361
* @return a new condition with mapped values if renderable, otherwise an empty condition
6462
*/
65-
public IsNotInCaseInsensitive map(UnaryOperator<@Nullable String> mapper) {
63+
public IsNotInCaseInsensitive map(UnaryOperator<String> mapper) {
6664
return mapSupport(mapper, IsNotInCaseInsensitive::new, IsNotInCaseInsensitive::empty);
6765
}
6866

69-
public static IsNotInCaseInsensitive of(@Nullable String... values) {
67+
public static IsNotInCaseInsensitive of(String... values) {
7068
return of(Arrays.asList(values));
7169
}
7270

73-
public static IsNotInCaseInsensitive of(Collection<@Nullable String> values) {
74-
return new IsNotInCaseInsensitive(values).map(StringUtilities::safelyUpperCase);
71+
public static IsNotInCaseInsensitive of(Collection<String> values) {
72+
return new IsNotInCaseInsensitive(values).map(String::toUpperCase);
7573
}
7674
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import org.jspecify.annotations.Nullable;
2525
import org.mybatis.dynamic.sql.AbstractListValueCondition;
26-
import org.mybatis.dynamic.sql.util.StringUtilities;
2726
import org.mybatis.dynamic.sql.util.Utilities;
2827

2928
public class IsNotInCaseInsensitiveWhenPresent extends AbstractListValueCondition<String>
@@ -57,7 +56,7 @@ public IsNotInCaseInsensitiveWhenPresent filter(Predicate<? super String> predic
5756
* @param mapper a mapping function to apply to the values, if not empty
5857
* @return a new condition with mapped values if renderable, otherwise an empty condition
5958
*/
60-
public IsNotInCaseInsensitiveWhenPresent map(UnaryOperator<@Nullable String> mapper) {
59+
public IsNotInCaseInsensitiveWhenPresent map(UnaryOperator<String> mapper) {
6160
return mapSupport(mapper, IsNotInCaseInsensitiveWhenPresent::new, IsNotInCaseInsensitiveWhenPresent::empty);
6261
}
6362

@@ -66,6 +65,6 @@ public static IsNotInCaseInsensitiveWhenPresent of(@Nullable String... values) {
6665
}
6766

6867
public static IsNotInCaseInsensitiveWhenPresent of(Collection<@Nullable String> values) {
69-
return new IsNotInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase);
68+
return new IsNotInCaseInsensitiveWhenPresent(values).map(String::toUpperCase);
7069
}
7170
}

src/main/java/org/mybatis/dynamic/sql/where/render/DefaultConditionVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ public FragmentAndParameters visit(AbstractColumnComparisonCondition<T> conditio
110110
.mapFragment(f -> condition.operator() + spaceBefore(f));
111111
}
112112

113-
private @Nullable Object convertValue(@Nullable T value) {
113+
private @Nullable Object convertValue(T value) {
114114
return column.convertParameterType(value);
115115
}
116116

117-
private FragmentAndParameters toFragmentAndParameters(@Nullable T value) {
117+
private FragmentAndParameters toFragmentAndParameters(T value) {
118118
RenderedParameterInfo parameterInfo = renderingContext.calculateParameterInfo(column);
119119
return FragmentAndParameters.withFragment(parameterInfo.renderedPlaceHolder())
120120
.withParameter(parameterInfo.parameterMapKey(), convertValue(value))

src/test/java/examples/animal/data/AnimalDataTest.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ void testInCaseSensitiveCondition() {
744744

745745
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
746746
.from(animalData)
747-
.where(animalName, isInCaseInsensitive("yellow-bellied marmot", "verbet", null))
747+
.where(animalName, isInCaseInsensitive("yellow-bellied marmot", "verbet"))
748748
.build()
749749
.render(RenderingStrategies.MYBATIS3);
750750

@@ -785,22 +785,6 @@ void testNotInCaseSensitiveCondition() {
785785
}
786786
}
787787

788-
@Test
789-
void testNotInCaseSensitiveConditionWithNull() {
790-
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
791-
AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
792-
793-
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
794-
.from(animalData)
795-
.where(animalName, isNotInCaseInsensitive((String)null))
796-
.build()
797-
.render(RenderingStrategies.MYBATIS3);
798-
799-
List<AnimalData> animals = mapper.selectMany(selectStatement);
800-
assertThat(animals).isEmpty();
801-
}
802-
}
803-
804788
@Test
805789
void testNotInConditionWithEventuallyEmptyList() {
806790
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {

0 commit comments

Comments
 (0)