Skip to content

Commit 60872ac

Browse files
authored
Merge pull request #435 from jeffgbutler/remove-deprecations
Remove deprecated "when" and "then" methods
2 parents b28ca54 + f23e7f1 commit 60872ac

29 files changed

+191
-630
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
1111
we did not support the grouping of criteria at the beginning of a where clause or the beginning of an and/or
1212
condition. Adding this support required significant refactoring, but that should be transparent to most users.
1313
([#434](https://github.com/mybatis/mybatis-dynamic-sql/pull/434))
14+
2. Remove deprecated "when" and "then" methods on all conditions. The methods have been replaced by more appropriately
15+
named "filter" and "map" methods that function as expected for method chaining.
16+
([#435](https://github.com/mybatis/mybatis-dynamic-sql/pull/435))
1417

1518
## Release 1.3.1 - December 18, 2021
1619

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
3-
Copyright 2016-2021 the original author or authors.
3+
Copyright 2016-2022 the original author or authors.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.

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

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.util.function.BiPredicate;
2020
import java.util.function.Function;
2121
import java.util.function.Predicate;
22-
import java.util.function.UnaryOperator;
2322

2423
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2524

@@ -46,35 +45,6 @@ public String renderCondition(String columnName, String placeholder1, String pla
4645
return columnName + " between " + placeholder1 + " and " + placeholder2; //$NON-NLS-1$ //$NON-NLS-2$
4746
}
4847

49-
/**
50-
* If renderable and the values match the predicate, returns this condition. Else returns a condition
51-
* that will not render.
52-
*
53-
* @deprecated replaced by {@link IsBetween#filter(BiPredicate)}
54-
* @param predicate predicate applied to the values, if renderable
55-
* @return this condition if renderable and the values match the predicate, otherwise a condition
56-
* that will not render.
57-
*/
58-
@Deprecated
59-
public IsBetween<T> when(BiPredicate<T, T> predicate) {
60-
return filter(predicate);
61-
}
62-
63-
/**
64-
* If renderable, apply the mappings to the values and return a new condition with the new values. Else return a
65-
* condition that will not render (this).
66-
*
67-
* @deprecated replaced by {@link IsBetween#map(Function, Function)}
68-
* @param mapper1 a mapping function to apply to the first value, if renderable
69-
* @param mapper2 a mapping function to apply to the second value, if renderable
70-
* @return a new condition with the result of applying the mappers to the values of this condition,
71-
* if renderable, otherwise a condition that will not render.
72-
*/
73-
@Deprecated
74-
public IsBetween<T> then(UnaryOperator<T> mapper1, UnaryOperator<T> mapper2) {
75-
return map(mapper1, mapper2);
76-
}
77-
7848
@Override
7949
public IsBetween<T> filter(BiPredicate<? super T, ? super T> predicate) {
8050
return filterSupport(predicate, IsBetween::empty, this);

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717

1818
import java.util.function.Function;
1919
import java.util.function.Predicate;
20-
import java.util.function.UnaryOperator;
2120

2221
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2322

@@ -49,34 +48,6 @@ public static <T> IsEqualTo<T> of(T value) {
4948
return new IsEqualTo<>(value);
5049
}
5150

52-
/**
53-
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
54-
* that will not render.
55-
*
56-
* @deprecated replaced by {@link IsEqualTo#filter(Predicate)}
57-
* @param predicate predicate applied to the value, if renderable
58-
* @return this condition if renderable and the value matches the predicate, otherwise a condition
59-
* that will not render.
60-
*/
61-
@Deprecated
62-
public IsEqualTo<T> when(Predicate<T> predicate) {
63-
return filter(predicate);
64-
}
65-
66-
/**
67-
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
68-
* condition that will not render (this).
69-
*
70-
* @deprecated replaced by {@link IsEqualTo#map(Function)}
71-
* @param mapper a mapping function to apply to the value, if renderable
72-
* @return a new condition with the result of applying the mapper to the value of this condition,
73-
* if renderable, otherwise a condition that will not render.
74-
*/
75-
@Deprecated
76-
public IsEqualTo<T> then(UnaryOperator<T> mapper) {
77-
return map(mapper);
78-
}
79-
8051
@Override
8152
public IsEqualTo<T> filter(Predicate<? super T> predicate) {
8253
return filterSupport(predicate, IsEqualTo::empty, this);

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717

1818
import java.util.function.Function;
1919
import java.util.function.Predicate;
20-
import java.util.function.UnaryOperator;
2120

2221
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2322

@@ -48,34 +47,6 @@ public static <T> IsGreaterThan<T> of(T value) {
4847
return new IsGreaterThan<>(value);
4948
}
5049

51-
/**
52-
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
53-
* that will not render.
54-
*
55-
* @deprecated replaced by {@link IsGreaterThan#filter(Predicate)}
56-
* @param predicate predicate applied to the value, if renderable
57-
* @return this condition if renderable and the value matches the predicate, otherwise a condition
58-
* that will not render.
59-
*/
60-
@Deprecated
61-
public IsGreaterThan<T> when(Predicate<T> predicate) {
62-
return filter(predicate);
63-
}
64-
65-
/**
66-
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
67-
* condition that will not render (this).
68-
*
69-
* @deprecated replaced by {@link IsGreaterThan#map(Function)}
70-
* @param mapper a mapping function to apply to the value, if renderable
71-
* @return a new condition with the result of applying the mapper to the value of this condition,
72-
* if renderable, otherwise a condition that will not render.
73-
*/
74-
@Deprecated
75-
public IsGreaterThan<T> then(UnaryOperator<T> mapper) {
76-
return map(mapper);
77-
}
78-
7950
@Override
8051
public IsGreaterThan<T> filter(Predicate<? super T> predicate) {
8152
return filterSupport(predicate, IsGreaterThan::empty, this);

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717

1818
import java.util.function.Function;
1919
import java.util.function.Predicate;
20-
import java.util.function.UnaryOperator;
2120

2221
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2322

@@ -48,34 +47,6 @@ public static <T> IsGreaterThanOrEqualTo<T> of(T value) {
4847
return new IsGreaterThanOrEqualTo<>(value);
4948
}
5049

51-
/**
52-
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
53-
* that will not render.
54-
*
55-
* @deprecated replaced by {@link IsGreaterThanOrEqualTo#filter(Predicate)}
56-
* @param predicate predicate applied to the value, if renderable
57-
* @return this condition if renderable and the value matches the predicate, otherwise a condition
58-
* that will not render.
59-
*/
60-
@Deprecated
61-
public IsGreaterThanOrEqualTo<T> when(Predicate<T> predicate) {
62-
return filter(predicate);
63-
}
64-
65-
/**
66-
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
67-
* condition that will not render (this).
68-
*
69-
* @deprecated replaced by {@link IsGreaterThanOrEqualTo#map(Function)}
70-
* @param mapper a mapping function to apply to the value, if renderable
71-
* @return a new condition with the result of applying the mapper to the value of this condition,
72-
* if renderable, otherwise a condition that will not render.
73-
*/
74-
@Deprecated
75-
public IsGreaterThanOrEqualTo<T> then(UnaryOperator<T> mapper) {
76-
return map(mapper);
77-
}
78-
7950
@Override
8051
public IsGreaterThanOrEqualTo<T> filter(Predicate<? super T> predicate) {
8152
return filterSupport(predicate, IsGreaterThanOrEqualTo::empty, this);

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,11 +20,9 @@
2020
import java.util.Arrays;
2121
import java.util.Collection;
2222
import java.util.Collections;
23-
import java.util.List;
2423
import java.util.function.BiFunction;
2524
import java.util.function.Function;
2625
import java.util.function.Predicate;
27-
import java.util.function.UnaryOperator;
2826
import java.util.stream.Collectors;
2927
import java.util.stream.Stream;
3028

@@ -40,6 +38,10 @@ public static <T> IsIn<T> empty() {
4038
return t;
4139
}
4240

41+
private <S> IsIn<S> emptyWithCallBack() {
42+
return new IsIn<>(Collections.emptyList(), emptyCallback);
43+
}
44+
4345
protected IsIn(Collection<T> values) {
4446
super(values);
4547
}
@@ -59,27 +61,9 @@ public IsIn<T> withListEmptyCallback(Callback callback) {
5961
return new IsIn<>(values, callback);
6062
}
6163

62-
/**
63-
* This method allows you to modify the condition's values before they are placed into the parameter map.
64-
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
65-
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
66-
* values out of the stream, then the condition will not render.
67-
*
68-
* @deprecated replaced by {@link IsIn#map(Function)} and {@link IsIn#filter(Predicate)}
69-
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
70-
* the values are placed in the parameter map
71-
* @return new condition with the specified transformer
72-
*/
73-
@Deprecated
74-
public IsIn<T> then(UnaryOperator<Stream<T>> valueStreamTransformer) {
75-
List<T> mapped = valueStreamTransformer.apply(values.stream())
76-
.collect(Collectors.toList());
77-
return new IsIn<>(mapped, emptyCallback);
78-
}
79-
8064
@Override
8165
public IsIn<T> filter(Predicate<? super T> predicate) {
82-
return filterSupport(predicate, IsIn::new, this, IsIn::empty);
66+
return filterSupport(predicate, IsIn::new, this, this::emptyWithCallBack);
8367
}
8468

8569
/**
@@ -93,7 +77,7 @@ public IsIn<T> filter(Predicate<? super T> predicate) {
9377
*/
9478
public <R> IsIn<R> map(Function<? super T, ? extends R> mapper) {
9579
BiFunction<Collection<R>, Callback, IsIn<R>> constructor = IsIn::new;
96-
return mapSupport(mapper, constructor, IsIn::empty);
80+
return mapSupport(mapper, constructor, this::emptyWithCallBack);
9781
}
9882

9983
@SafeVarargs

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,10 @@ public static IsInCaseInsensitive empty() {
3434
return EMPTY;
3535
}
3636

37+
private IsInCaseInsensitive emptyWithCallback() {
38+
return new IsInCaseInsensitive(Collections.emptyList(), emptyCallback);
39+
}
40+
3741
protected IsInCaseInsensitive(Collection<String> values) {
3842
super(values);
3943
}
@@ -56,7 +60,7 @@ public IsInCaseInsensitive withListEmptyCallback(Callback callback) {
5660

5761
@Override
5862
public IsInCaseInsensitive filter(Predicate<? super String> predicate) {
59-
return filterSupport(predicate, IsInCaseInsensitive::new, this, IsInCaseInsensitive::empty);
63+
return filterSupport(predicate, IsInCaseInsensitive::new, this, this::emptyWithCallback);
6064
}
6165

6266
/**
@@ -68,7 +72,7 @@ public IsInCaseInsensitive filter(Predicate<? super String> predicate) {
6872
* that will not render.
6973
*/
7074
public IsInCaseInsensitive map(UnaryOperator<String> mapper) {
71-
return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty);
75+
return mapSupport(mapper, IsInCaseInsensitive::new, this::emptyWithCallback);
7276
}
7377

7478
public static IsInCaseInsensitive of(String... values) {

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717

1818
import java.util.function.Function;
1919
import java.util.function.Predicate;
20-
import java.util.function.UnaryOperator;
2120

2221
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2322

@@ -48,34 +47,6 @@ public static <T> IsLessThan<T> of(T value) {
4847
return new IsLessThan<>(value);
4948
}
5049

51-
/**
52-
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
53-
* that will not render.
54-
*
55-
* @deprecated replaced by {@link IsLessThan#filter(Predicate)}
56-
* @param predicate predicate applied to the value, if renderable
57-
* @return this condition if renderable and the value matches the predicate, otherwise a condition
58-
* that will not render.
59-
*/
60-
@Deprecated
61-
public IsLessThan<T> when(Predicate<T> predicate) {
62-
return filter(predicate);
63-
}
64-
65-
/**
66-
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
67-
* condition that will not render (this).
68-
*
69-
* @deprecated replaced by {@link IsLessThan#map(Function)}
70-
* @param mapper a mapping function to apply to the value, if renderable
71-
* @return a new condition with the result of applying the mapper to the value of this condition,
72-
* if renderable, otherwise a condition that will not render.
73-
*/
74-
@Deprecated
75-
public IsLessThan<T> then(UnaryOperator<T> mapper) {
76-
return map(mapper);
77-
}
78-
7950
@Override
8051
public IsLessThan<T> filter(Predicate<? super T> predicate) {
8152
return filterSupport(predicate, IsLessThan::empty, this);

0 commit comments

Comments
 (0)