Skip to content

Commit 264bd8c

Browse files
committed
Deprecate the "withValueStreamOperations" method in favor of "then"
This is consistent with the "then" method on the other conditions. Naming things is hard.
1 parent 2143928 commit 264bd8c

File tree

7 files changed

+229
-26
lines changed

7 files changed

+229
-26
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424

2525
public abstract class AbstractListValueCondition<T> implements VisitableCondition<T> {
2626
protected Collection<T> values;
27-
protected UnaryOperator<Stream<T>> valueStreamOperations;
27+
protected UnaryOperator<Stream<T>> valueStreamTransformer;
2828

2929
protected AbstractListValueCondition(Collection<T> values) {
3030
this(values, UnaryOperator.identity());
3131
}
3232

33-
protected AbstractListValueCondition(Collection<T> values, UnaryOperator<Stream<T>> valueStreamOperations) {
33+
protected AbstractListValueCondition(Collection<T> values, UnaryOperator<Stream<T>> valueStreamTransformer) {
3434
this.values = new ArrayList<>(Objects.requireNonNull(values));
35-
this.valueStreamOperations = Objects.requireNonNull(valueStreamOperations);
35+
this.valueStreamTransformer = Objects.requireNonNull(valueStreamTransformer);
3636
}
3737

3838
public final <R> Stream<R> mapValues(Function<T, R> mapper) {
39-
return valueStreamOperations.apply(values.stream()).map(mapper);
39+
return valueStreamTransformer.apply(values.stream()).map(mapper);
4040
}
4141

4242
@Override

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
public class IsIn<T> extends AbstractListValueCondition<T> {
2828

29-
protected IsIn(Collection<T> values, UnaryOperator<Stream<T>> valueStreamOperations) {
30-
super(values, valueStreamOperations);
29+
protected IsIn(Collection<T> values, UnaryOperator<Stream<T>> valueStreamTransformer) {
30+
super(values, valueStreamTransformer);
3131
}
3232

3333
protected IsIn(Collection<T> values) {
@@ -40,8 +40,35 @@ public String renderCondition(String columnName, Stream<String> placeholders) {
4040
+ placeholders.collect(Collectors.joining(",", "in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
4141
}
4242

43-
public IsIn<T> withValueStreamOperations(UnaryOperator<Stream<T>> valueStreamOperations) {
44-
return new IsIn<>(values, valueStreamOperations);
43+
/**
44+
* This method allows you to modify the condition's values before they are placed into the parameter map.
45+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
46+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
47+
* values out of the stream, then the condition will not render.
48+
*
49+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
50+
* the values are placed in the parameter map
51+
* @return new condition with the specified transformer
52+
*/
53+
public IsIn<T> then(UnaryOperator<Stream<T>> valueStreamTransformer) {
54+
return new IsIn<>(values, valueStreamTransformer);
55+
}
56+
57+
/**
58+
* This method allows you to modify the condition's values before they are placed into the parameter map.
59+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
60+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
61+
* values out of the stream, then the condition will not render.
62+
*
63+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
64+
* the values are placed in the parameter map
65+
* @return new condition with the specified transformer
66+
*
67+
* @deprecated See {@link IsIn#then(UnaryOperator)}
68+
*/
69+
@Deprecated
70+
public IsIn<T> withValueStreamOperations(UnaryOperator<Stream<T>> valueStreamTransformer) {
71+
return then(valueStreamTransformer);
4572
}
4673

4774
public static <T> IsIn<T> of(Collection<T> values) {

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ protected IsInCaseInsensitive(Collection<String> values) {
2929
super(values, s -> s.map(StringUtilities::safelyUpperCase));
3030
}
3131

32-
protected IsInCaseInsensitive(Collection<String> values, UnaryOperator<Stream<String>> valueStreamOperations) {
33-
super(values, StringUtilities.upperCaseAfter(valueStreamOperations));
32+
protected IsInCaseInsensitive(Collection<String> values, UnaryOperator<Stream<String>> valueStreamTransformer) {
33+
super(values, StringUtilities.upperCaseAfter(valueStreamTransformer));
3434
}
3535

3636
@Override
@@ -39,8 +39,35 @@ public String renderCondition(String columnName, Stream<String> placeholders) {
3939
placeholders.collect(Collectors.joining(",", "in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
4040
}
4141

42-
public IsInCaseInsensitive withValueStreamOperations(UnaryOperator<Stream<String>> valueStreamOperations) {
43-
return new IsInCaseInsensitive(values, valueStreamOperations);
42+
/**
43+
* This method allows you to modify the condition's values before they are placed into the parameter map.
44+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
45+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
46+
* values out of the stream, then the condition will not render.
47+
*
48+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
49+
* the values are placed in the parameter map
50+
* @return new condition with the specified transformer
51+
*/
52+
public IsInCaseInsensitive then(UnaryOperator<Stream<String>> valueStreamTransformer) {
53+
return new IsInCaseInsensitive(values, valueStreamTransformer);
54+
}
55+
56+
/**
57+
* This method allows you to modify the condition's values before they are placed into the parameter map.
58+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
59+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
60+
* values out of the stream, then the condition will not render.
61+
*
62+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
63+
* the values are placed in the parameter map
64+
* @return new condition with the specified transformer
65+
*
66+
* @deprecated See {@link IsInCaseInsensitive#then(UnaryOperator)}
67+
*/
68+
@Deprecated
69+
public IsInCaseInsensitive withValueStreamOperations(UnaryOperator<Stream<String>> valueStreamTransformer) {
70+
return then(valueStreamTransformer);
4471
}
4572

4673
public static IsInCaseInsensitive of(Collection<String> values) {

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
public class IsNotIn<T> extends AbstractListValueCondition<T> {
2828

29-
protected IsNotIn(Collection<T> values, UnaryOperator<Stream<T>> valueStreamOperations) {
30-
super(values, valueStreamOperations);
29+
protected IsNotIn(Collection<T> values, UnaryOperator<Stream<T>> valueStreamTransformer) {
30+
super(values, valueStreamTransformer);
3131
}
3232

3333
protected IsNotIn(Collection<T> values) {
@@ -41,8 +41,35 @@ public String renderCondition(String columnName, Stream<String> placeholders) {
4141
Collectors.joining(",", "not in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
4242
}
4343

44-
public IsNotIn<T> withValueStreamOperations(UnaryOperator<Stream<T>> valueStreamOperations) {
45-
return new IsNotIn<>(values, valueStreamOperations);
44+
/**
45+
* This method allows you to modify the condition's values before they are placed into the parameter map.
46+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
47+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
48+
* values out of the stream, then the condition will not render.
49+
*
50+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
51+
* the values are placed in the parameter map
52+
* @return new condition with the specified transformer
53+
*/
54+
public IsNotIn<T> then(UnaryOperator<Stream<T>> valueStreamTransformer) {
55+
return new IsNotIn<>(values, valueStreamTransformer);
56+
}
57+
58+
/**
59+
* This method allows you to modify the condition's values before they are placed into the parameter map.
60+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
61+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
62+
* values out of the stream, then the condition will not render.
63+
*
64+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
65+
* the values are placed in the parameter map
66+
* @return new condition with the specified transformer
67+
*
68+
* @deprecated See {@link IsNotIn#then(UnaryOperator)}
69+
*/
70+
@Deprecated
71+
public IsNotIn<T> withValueStreamOperations(UnaryOperator<Stream<T>> valueStreamTransformer) {
72+
return then(valueStreamTransformer);
4673
}
4774

4875
public static <T> IsNotIn<T> of(Collection<T> values) {

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ protected IsNotInCaseInsensitive(Collection<String> values) {
2929
super(values, s -> s.map(StringUtilities::safelyUpperCase));
3030
}
3131

32-
protected IsNotInCaseInsensitive(Collection<String> values, UnaryOperator<Stream<String>> valueStreamOperations) {
33-
super(values, StringUtilities.upperCaseAfter(valueStreamOperations));
32+
protected IsNotInCaseInsensitive(Collection<String> values, UnaryOperator<Stream<String>> valueStreamTransformer) {
33+
super(values, StringUtilities.upperCaseAfter(valueStreamTransformer));
3434
}
3535

3636
@Override
@@ -40,8 +40,35 @@ public String renderCondition(String columnName, Stream<String> placeholders) {
4040
Collectors.joining(",", "not in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
4141
}
4242

43-
public IsNotInCaseInsensitive withValueStreamOperations(UnaryOperator<Stream<String>> valueStreamOperations) {
44-
return new IsNotInCaseInsensitive(values, valueStreamOperations);
43+
/**
44+
* This method allows you to modify the condition's values before they are placed into the parameter map.
45+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
46+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
47+
* values out of the stream, then the condition will not render.
48+
*
49+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
50+
* the values are placed in the parameter map
51+
* @return new condition with the specified transformer
52+
*/
53+
public IsNotInCaseInsensitive then(UnaryOperator<Stream<String>> valueStreamTransformer) {
54+
return new IsNotInCaseInsensitive(values, valueStreamTransformer);
55+
}
56+
57+
/**
58+
* This method allows you to modify the condition's values before they are placed into the parameter map.
59+
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
60+
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
61+
* values out of the stream, then the condition will not render.
62+
*
63+
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
64+
* the values are placed in the parameter map
65+
* @return new condition with the specified transformer
66+
*
67+
* @deprecated See {@link IsNotInCaseInsensitive#then(UnaryOperator)}
68+
*/
69+
@Deprecated
70+
public IsNotInCaseInsensitive withValueStreamOperations(UnaryOperator<Stream<String>> valueStreamTransformer) {
71+
return then(valueStreamTransformer);
4572
}
4673

4774
public static IsNotInCaseInsensitive of(Collection<String> values) {

src/site/markdown/docs/conditions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ The following table shows the different supplied In conditions and how they will
143143

144144
If none of these options meet your needs, there is an extension point where you can add your own filter and/or map conditions to the value stream. This gives you great flexibility to alter or filter the value list before the condition is rendered.
145145

146-
The extension point for modifying the value list is the method `withValueStreamOperations(UnaryOperator<Stream<T>>)`. This method accepts a `UnaryOperator<Stream<T>>` in which you can specify map and/or filter operations for the value stream. For example, suppose you wanted to code an "in" condition that accepted a list of strings, but you want to filter out any null or blank string, and you want to trim all strings. This can be accomplished with code like this:
146+
The extension point for modifying the value list is the method `then(UnaryOperator<Stream<T>>)`. This method accepts a `UnaryOperator<Stream<T>>` in which you can specify map and/or filter operations for the value stream. For example, suppose you wanted to code an "in" condition that accepted a list of strings, but you want to filter out any null or blank string, and you want to trim all strings. This can be accomplished with code like this:
147147

148148
```java
149149
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
150150
.from(animalData)
151151
.where(animalName, isIn(" Mouse", " ", null, "", "Musk shrew ")
152-
.withValueStreamOperations(s -> s.filter(Objects::nonNull)
152+
.then(s -> s.filter(Objects::nonNull)
153153
.map(String::trim)
154154
.filter(st -> !st.isEmpty())))
155155
.orderBy(id)

0 commit comments

Comments
 (0)