Skip to content

Commit e52fa81

Browse files
committed
Define a map template method for list value
1 parent 1d41ea4 commit e52fa81

File tree

10 files changed

+105
-122
lines changed

10 files changed

+105
-122
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ protected <R, S extends AbstractListValueCondition<R>> S mapSupport(Function<? s
8383
*/
8484
public abstract AbstractListValueCondition<T> filter(Predicate<? super T> predicate);
8585

86+
/**
87+
* If not empty, apply the mapping to each value in the list return a new condition with the mapped values.
88+
* Else return an empty condition (this).
89+
*
90+
* @param mapper a mapping function to apply to the values, if not empty
91+
* @param <R> type of the new condition
92+
* @return a new condition with mapped values if renderable, otherwise an empty condition
93+
*/
94+
public abstract <R> AbstractListValueCondition<R> map(Function<? super T, ? extends R> mapper);
95+
8696
public abstract String operator();
8797

8898
@Override

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -915,36 +915,36 @@ static IsNotLikeCaseInsensitive<String> isNotLikeCaseInsensitiveWhenPresent(
915915
return isNotLikeCaseInsensitiveWhenPresent(valueSupplier.get());
916916
}
917917

918-
static IsInCaseInsensitive isInCaseInsensitive(String... values) {
918+
static IsInCaseInsensitive<String> isInCaseInsensitive(String... values) {
919919
return IsInCaseInsensitive.of(values);
920920
}
921921

922-
static IsInCaseInsensitive isInCaseInsensitive(Collection<String> values) {
922+
static IsInCaseInsensitive<String> isInCaseInsensitive(Collection<String> values) {
923923
return IsInCaseInsensitive.of(values);
924924
}
925925

926-
static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(@Nullable String... values) {
926+
static IsInCaseInsensitiveWhenPresent<String> isInCaseInsensitiveWhenPresent(@Nullable String... values) {
927927
return IsInCaseInsensitiveWhenPresent.of(values);
928928
}
929929

930-
static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(
930+
static IsInCaseInsensitiveWhenPresent<String> isInCaseInsensitiveWhenPresent(
931931
@Nullable Collection<@Nullable String> values) {
932932
return values == null ? IsInCaseInsensitiveWhenPresent.empty() : IsInCaseInsensitiveWhenPresent.of(values);
933933
}
934934

935-
static IsNotInCaseInsensitive isNotInCaseInsensitive(String... values) {
935+
static IsNotInCaseInsensitive<String> isNotInCaseInsensitive(String... values) {
936936
return IsNotInCaseInsensitive.of(values);
937937
}
938938

939-
static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection<String> values) {
939+
static IsNotInCaseInsensitive<String> isNotInCaseInsensitive(Collection<String> values) {
940940
return IsNotInCaseInsensitive.of(values);
941941
}
942942

943-
static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(@Nullable String... values) {
943+
static IsNotInCaseInsensitiveWhenPresent<String> isNotInCaseInsensitiveWhenPresent(@Nullable String... values) {
944944
return IsNotInCaseInsensitiveWhenPresent.of(values);
945945
}
946946

947-
static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(
947+
static IsNotInCaseInsensitiveWhenPresent<String> isNotInCaseInsensitiveWhenPresent(
948948
@Nullable Collection<@Nullable String> values) {
949949
return values == null ? IsNotInCaseInsensitiveWhenPresent.empty() :
950950
IsNotInCaseInsensitiveWhenPresent.of(values);

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ public IsIn<T> filter(Predicate<? super T> predicate) {
5454
return filterSupport(predicate, IsIn::new, this, IsIn::empty);
5555
}
5656

57-
/**
58-
* If not empty, apply the mapping to each value in the list return a new condition with the mapped values.
59-
* Else return an empty condition (this).
60-
*
61-
* @param mapper a mapping function to apply to the values, if not empty
62-
* @param <R> type of the new condition
63-
* @return a new condition with mapped values if renderable, otherwise an empty condition
64-
*/
57+
@Override
6558
public <R> IsIn<R> map(Function<? super T, ? extends R> mapper) {
6659
Function<Collection<R>, IsIn<R>> constructor = IsIn::new;
6760
return mapSupport(mapper, constructor, IsIn::empty);

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Collections;
21+
import java.util.function.Function;
2122
import java.util.function.Predicate;
22-
import java.util.function.UnaryOperator;
2323

2424
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2525
import org.mybatis.dynamic.sql.render.RenderingContext;
2626
import org.mybatis.dynamic.sql.util.StringUtilities;
2727
import org.mybatis.dynamic.sql.util.Validator;
2828

29-
public class IsInCaseInsensitive extends AbstractListValueCondition<String>
30-
implements CaseInsensitiveRenderableCondition<String> {
31-
private static final IsInCaseInsensitive EMPTY = new IsInCaseInsensitive(Collections.emptyList());
29+
public class IsInCaseInsensitive<T> extends AbstractListValueCondition<T>
30+
implements CaseInsensitiveRenderableCondition<T> {
31+
private static final IsInCaseInsensitive<?> EMPTY = new IsInCaseInsensitive<>(Collections.emptyList());
3232

33-
public static IsInCaseInsensitive empty() {
34-
return EMPTY;
33+
public static <T> IsInCaseInsensitive<T> empty() {
34+
@SuppressWarnings("unchecked")
35+
IsInCaseInsensitive<T> t = (IsInCaseInsensitive<T>) EMPTY;
36+
return t;
3537
}
3638

37-
protected IsInCaseInsensitive(Collection<String> values) {
39+
protected IsInCaseInsensitive(Collection<T> values) {
3840
super(values);
3941
}
4042

@@ -50,28 +52,22 @@ public String operator() {
5052
}
5153

5254
@Override
53-
public IsInCaseInsensitive filter(Predicate<? super String> predicate) {
55+
public IsInCaseInsensitive<T> filter(Predicate<? super T> predicate) {
5456
return filterSupport(predicate, IsInCaseInsensitive::new, this, IsInCaseInsensitive::empty);
5557
}
5658

57-
/**
58-
* If not empty, apply the mapping to each value in the list return a new condition with the mapped values.
59-
* Else return an empty condition (this).
60-
*
61-
* @param mapper a mapping function to apply to the values, if not empty
62-
* @return a new condition with mapped values if renderable, otherwise an empty condition
63-
*/
64-
public IsInCaseInsensitive map(UnaryOperator<String> mapper) {
59+
@Override
60+
public <R> IsInCaseInsensitive<R> map(Function<? super T, ? extends R> mapper) {
6561
return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty);
6662
}
6763

68-
public static IsInCaseInsensitive of(String... values) {
64+
public static IsInCaseInsensitive<String> of(String... values) {
6965
return of(Arrays.asList(values));
7066
}
7167

72-
public static IsInCaseInsensitive of(Collection<String> values) {
68+
public static IsInCaseInsensitive<String> of(Collection<String> values) {
7369
// Keep the null safe upper case utility for backwards compatibility
7470
//noinspection DataFlowIssue
75-
return new IsInCaseInsensitive(values).map(StringUtilities::safelyUpperCase);
71+
return new IsInCaseInsensitive<>(values).map(StringUtilities::safelyUpperCase);
7672
}
7773
}

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,26 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Collections;
21+
import java.util.function.Function;
2122
import java.util.function.Predicate;
22-
import java.util.function.UnaryOperator;
2323

2424
import org.jspecify.annotations.Nullable;
2525
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2626
import org.mybatis.dynamic.sql.util.StringUtilities;
2727
import org.mybatis.dynamic.sql.util.Utilities;
2828

29-
public class IsInCaseInsensitiveWhenPresent extends AbstractListValueCondition<String>
30-
implements CaseInsensitiveRenderableCondition<String> {
31-
private static final IsInCaseInsensitiveWhenPresent EMPTY =
32-
new IsInCaseInsensitiveWhenPresent(Collections.emptyList());
29+
public class IsInCaseInsensitiveWhenPresent<T> extends AbstractListValueCondition<T>
30+
implements CaseInsensitiveRenderableCondition<T> {
31+
private static final IsInCaseInsensitiveWhenPresent<?> EMPTY =
32+
new IsInCaseInsensitiveWhenPresent<>(Collections.emptyList());
3333

34-
public static IsInCaseInsensitiveWhenPresent empty() {
35-
return EMPTY;
34+
public static <T> IsInCaseInsensitiveWhenPresent<T> empty() {
35+
@SuppressWarnings("unchecked")
36+
IsInCaseInsensitiveWhenPresent<T> t = (IsInCaseInsensitiveWhenPresent<T>) EMPTY;
37+
return t;
3638
}
3739

38-
protected IsInCaseInsensitiveWhenPresent(Collection<@Nullable String> values) {
40+
protected IsInCaseInsensitiveWhenPresent(Collection<@Nullable T> values) {
3941
super(Utilities.removeNullElements(values));
4042
}
4143

@@ -45,29 +47,23 @@ public String operator() {
4547
}
4648

4749
@Override
48-
public IsInCaseInsensitiveWhenPresent filter(Predicate<? super String> predicate) {
50+
public IsInCaseInsensitiveWhenPresent<T> filter(Predicate<? super T> predicate) {
4951
return filterSupport(predicate, IsInCaseInsensitiveWhenPresent::new, this,
5052
IsInCaseInsensitiveWhenPresent::empty);
5153
}
5254

53-
/**
54-
* If not empty, apply the mapping to each value in the list return a new condition with the mapped values.
55-
* Else return an empty condition (this).
56-
*
57-
* @param mapper a mapping function to apply to the values, if not empty
58-
* @return a new condition with mapped values if renderable, otherwise an empty condition
59-
*/
60-
public IsInCaseInsensitiveWhenPresent map(UnaryOperator<String> mapper) {
55+
@Override
56+
public <R> IsInCaseInsensitiveWhenPresent<R> map(Function<? super T, ? extends R> mapper) {
6157
return mapSupport(mapper, IsInCaseInsensitiveWhenPresent::new, IsInCaseInsensitiveWhenPresent::empty);
6258
}
6359

64-
public static IsInCaseInsensitiveWhenPresent of(@Nullable String... values) {
60+
public static IsInCaseInsensitiveWhenPresent<String> of(@Nullable String... values) {
6561
return of(Arrays.asList(values));
6662
}
6763

68-
public static IsInCaseInsensitiveWhenPresent of(Collection<@Nullable String> values) {
64+
public static IsInCaseInsensitiveWhenPresent<String> of(Collection<@Nullable String> values) {
6965
// Keep the null safe upper case utility for backwards compatibility
7066
//noinspection DataFlowIssue
71-
return new IsInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase);
67+
return new IsInCaseInsensitiveWhenPresent<>(values).map(StringUtilities::safelyUpperCase);
7268
}
7369
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ public IsNotIn<T> filter(Predicate<? super T> predicate) {
5454
return filterSupport(predicate, IsNotIn::new, this, IsNotIn::empty);
5555
}
5656

57-
/**
58-
* If not empty, apply the mapping to each value in the list return a new condition with the mapped values.
59-
* Else return an empty condition (this).
60-
*
61-
* @param mapper a mapping function to apply to the values, if not empty
62-
* @param <R> type of the new condition
63-
* @return a new condition with mapped values if renderable, otherwise an empty condition
64-
*/
57+
@Override
6558
public <R> IsNotIn<R> map(Function<? super T, ? extends R> mapper) {
6659
Function<Collection<R>, IsNotIn<R>> constructor = IsNotIn::new;
6760
return mapSupport(mapper, constructor, IsNotIn::empty);

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Collections;
21+
import java.util.function.Function;
2122
import java.util.function.Predicate;
22-
import java.util.function.UnaryOperator;
2323

2424
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2525
import org.mybatis.dynamic.sql.render.RenderingContext;
2626
import org.mybatis.dynamic.sql.util.StringUtilities;
2727
import org.mybatis.dynamic.sql.util.Validator;
2828

29-
public class IsNotInCaseInsensitive extends AbstractListValueCondition<String>
30-
implements CaseInsensitiveRenderableCondition<String> {
31-
private static final IsNotInCaseInsensitive EMPTY = new IsNotInCaseInsensitive(Collections.emptyList());
29+
public class IsNotInCaseInsensitive<T> extends AbstractListValueCondition<T>
30+
implements CaseInsensitiveRenderableCondition<T> {
31+
private static final IsNotInCaseInsensitive<?> EMPTY = new IsNotInCaseInsensitive<>(Collections.emptyList());
3232

33-
public static IsNotInCaseInsensitive empty() {
34-
return EMPTY;
33+
public static <T> IsNotInCaseInsensitive<T> empty() {
34+
@SuppressWarnings("unchecked")
35+
IsNotInCaseInsensitive<T> t = (IsNotInCaseInsensitive<T>) EMPTY;
36+
return t;
3537
}
3638

37-
protected IsNotInCaseInsensitive(Collection<String> values) {
39+
protected IsNotInCaseInsensitive(Collection<T> values) {
3840
super(values);
3941
}
4042

@@ -50,28 +52,22 @@ public String operator() {
5052
}
5153

5254
@Override
53-
public IsNotInCaseInsensitive filter(Predicate<? super String> predicate) {
55+
public IsNotInCaseInsensitive<T> filter(Predicate<? super T> predicate) {
5456
return filterSupport(predicate, IsNotInCaseInsensitive::new, this, IsNotInCaseInsensitive::empty);
5557
}
5658

57-
/**
58-
* If not empty, apply the mapping to each value in the list return a new condition with the mapped values.
59-
* Else return an empty condition (this).
60-
*
61-
* @param mapper a mapping function to apply to the values, if not empty
62-
* @return a new condition with mapped values if renderable, otherwise an empty condition
63-
*/
64-
public IsNotInCaseInsensitive map(UnaryOperator<String> mapper) {
59+
@Override
60+
public <R> IsNotInCaseInsensitive<R> map(Function<? super T, ? extends R> mapper) {
6561
return mapSupport(mapper, IsNotInCaseInsensitive::new, IsNotInCaseInsensitive::empty);
6662
}
6763

68-
public static IsNotInCaseInsensitive of(String... values) {
64+
public static IsNotInCaseInsensitive<String> of(String... values) {
6965
return of(Arrays.asList(values));
7066
}
7167

72-
public static IsNotInCaseInsensitive of(Collection<String> values) {
68+
public static IsNotInCaseInsensitive<String> of(Collection<String> values) {
7369
// Keep the null safe upper case utility for backwards compatibility
7470
//noinspection DataFlowIssue
75-
return new IsNotInCaseInsensitive(values).map(StringUtilities::safelyUpperCase);
71+
return new IsNotInCaseInsensitive<>(values).map(StringUtilities::safelyUpperCase);
7672
}
7773
}

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,26 @@
1818
import java.util.Arrays;
1919
import java.util.Collection;
2020
import java.util.Collections;
21+
import java.util.function.Function;
2122
import java.util.function.Predicate;
22-
import java.util.function.UnaryOperator;
2323

2424
import org.jspecify.annotations.Nullable;
2525
import org.mybatis.dynamic.sql.AbstractListValueCondition;
2626
import org.mybatis.dynamic.sql.util.StringUtilities;
2727
import org.mybatis.dynamic.sql.util.Utilities;
2828

29-
public class IsNotInCaseInsensitiveWhenPresent extends AbstractListValueCondition<String>
30-
implements CaseInsensitiveRenderableCondition<String> {
31-
private static final IsNotInCaseInsensitiveWhenPresent EMPTY =
32-
new IsNotInCaseInsensitiveWhenPresent(Collections.emptyList());
29+
public class IsNotInCaseInsensitiveWhenPresent<T> extends AbstractListValueCondition<T>
30+
implements CaseInsensitiveRenderableCondition<T> {
31+
private static final IsNotInCaseInsensitiveWhenPresent<?> EMPTY =
32+
new IsNotInCaseInsensitiveWhenPresent<>(Collections.emptyList());
3333

34-
public static IsNotInCaseInsensitiveWhenPresent empty() {
35-
return EMPTY;
34+
public static <T> IsNotInCaseInsensitiveWhenPresent<T> empty() {
35+
@SuppressWarnings("unchecked")
36+
IsNotInCaseInsensitiveWhenPresent<T> t = (IsNotInCaseInsensitiveWhenPresent<T>) EMPTY;
37+
return t;
3638
}
3739

38-
protected IsNotInCaseInsensitiveWhenPresent(Collection<@Nullable String> values) {
40+
protected IsNotInCaseInsensitiveWhenPresent(Collection<@Nullable T> values) {
3941
super(Utilities.removeNullElements(values));
4042
}
4143

@@ -45,29 +47,23 @@ public String operator() {
4547
}
4648

4749
@Override
48-
public IsNotInCaseInsensitiveWhenPresent filter(Predicate<? super String> predicate) {
50+
public IsNotInCaseInsensitiveWhenPresent<T> filter(Predicate<? super T> predicate) {
4951
return filterSupport(predicate, IsNotInCaseInsensitiveWhenPresent::new,
5052
this, IsNotInCaseInsensitiveWhenPresent::empty);
5153
}
5254

53-
/**
54-
* If not empty, apply the mapping to each value in the list return a new condition with the mapped values.
55-
* Else return an empty condition (this).
56-
*
57-
* @param mapper a mapping function to apply to the values, if not empty
58-
* @return a new condition with mapped values if renderable, otherwise an empty condition
59-
*/
60-
public IsNotInCaseInsensitiveWhenPresent map(UnaryOperator<String> mapper) {
55+
@Override
56+
public <R> IsNotInCaseInsensitiveWhenPresent<R> map(Function<? super T, ? extends R> mapper) {
6157
return mapSupport(mapper, IsNotInCaseInsensitiveWhenPresent::new, IsNotInCaseInsensitiveWhenPresent::empty);
6258
}
6359

64-
public static IsNotInCaseInsensitiveWhenPresent of(@Nullable String... values) {
60+
public static IsNotInCaseInsensitiveWhenPresent<String> of(@Nullable String... values) {
6561
return of(Arrays.asList(values));
6662
}
6763

68-
public static IsNotInCaseInsensitiveWhenPresent of(Collection<@Nullable String> values) {
64+
public static IsNotInCaseInsensitiveWhenPresent<String> of(Collection<@Nullable String> values) {
6965
// Keep the null safe upper case utility for backwards compatibility
7066
//noinspection DataFlowIssue
71-
return new IsNotInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase);
67+
return new IsNotInCaseInsensitiveWhenPresent<>(values).map(StringUtilities::safelyUpperCase);
7268
}
7369
}

0 commit comments

Comments
 (0)