Skip to content

Commit 2143928

Browse files
committed
Add "then" value processing to all single and two value conditions
1 parent fd688e9 commit 2143928

25 files changed

+933
-27
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.BiPredicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2223

@@ -53,4 +54,9 @@ public static <T> Builder<T> isBetween(Supplier<T> valueSupplier1) {
5354
public IsBetween<T> when(BiPredicate<T, T> predicate) {
5455
return new IsBetween<>(valueSupplier1, valueSupplier2, predicate);
5556
}
57+
58+
public IsBetween<T> then(UnaryOperator<T> transformer1, UnaryOperator<T> transformer2) {
59+
return shouldRender() ? new IsBetween<>(() -> transformer1.apply(value1()),
60+
() -> transformer2.apply(value2())) : this;
61+
}
5662
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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.
@@ -16,6 +16,7 @@
1616
package org.mybatis.dynamic.sql.where.condition;
1717

1818
import java.util.function.Supplier;
19+
import java.util.function.UnaryOperator;
1920

2021
import org.mybatis.dynamic.sql.util.Predicates;
2122

@@ -39,4 +40,10 @@ protected IsBetweenWhenPresent<T> build() {
3940
public static <T> Builder<T> isBetweenWhenPresent(Supplier<T> valueSupplier) {
4041
return new Builder<>(valueSupplier);
4142
}
43+
44+
@Override
45+
public IsBetweenWhenPresent<T> then(UnaryOperator<T> transformer1, UnaryOperator<T> transformer2) {
46+
return shouldRender() ? new IsBetweenWhenPresent<>(() -> transformer1.apply(value1()),
47+
() -> transformer2.apply(value2())) : this;
48+
}
4249
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsEqualTo<T> of(Supplier<T> valueSupplier) {
4243
public IsEqualTo<T> when(Predicate<T> predicate) {
4344
return new IsEqualTo<>(valueSupplier, predicate);
4445
}
46+
47+
public IsEqualTo<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsEqualTo<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsEqualToWhenPresent<T> extends IsEqualTo<T> {
2223

@@ -27,4 +28,9 @@ protected IsEqualToWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsEqualToWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsEqualToWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsEqualToWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsEqualToWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsGreaterThan<T> of(Supplier<T> valueSupplier) {
4243
public IsGreaterThan<T> when(Predicate<T> predicate) {
4344
return new IsGreaterThan<>(valueSupplier, predicate);
4445
}
46+
47+
public IsGreaterThan<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsGreaterThan<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsGreaterThanOrEqualTo<T> of(Supplier<T> valueSupplier) {
4243
public IsGreaterThanOrEqualTo<T> when(Predicate<T> predicate) {
4344
return new IsGreaterThanOrEqualTo<>(valueSupplier, predicate);
4445
}
46+
47+
public IsGreaterThanOrEqualTo<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsGreaterThanOrEqualTo<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsGreaterThanOrEqualToWhenPresent<T> extends IsGreaterThanOrEqualTo<T> {
2223

@@ -27,4 +28,9 @@ protected IsGreaterThanOrEqualToWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsGreaterThanOrEqualToWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsGreaterThanOrEqualToWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsGreaterThanOrEqualToWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsGreaterThanOrEqualToWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsGreaterThanWhenPresent<T> extends IsGreaterThan<T> {
2223

@@ -27,4 +28,9 @@ protected IsGreaterThanWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsGreaterThanWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsGreaterThanWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsGreaterThanWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsGreaterThanWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsLessThan<T> of(Supplier<T> valueSupplier) {
4243
public IsLessThan<T> when(Predicate<T> predicate) {
4344
return new IsLessThan<>(valueSupplier, predicate);
4445
}
46+
47+
public IsLessThan<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsLessThan<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsLessThanOrEqualTo<T> of(Supplier<T> valueSupplier) {
4243
public IsLessThanOrEqualTo<T> when(Predicate<T> predicate) {
4344
return new IsLessThanOrEqualTo<>(valueSupplier, predicate);
4445
}
46+
47+
public IsLessThanOrEqualTo<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsLessThanOrEqualTo<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsLessThanOrEqualToWhenPresent<T> extends IsLessThanOrEqualTo<T> {
2223

@@ -27,4 +28,9 @@ protected IsLessThanOrEqualToWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsLessThanOrEqualToWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsLessThanOrEqualToWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsLessThanOrEqualToWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsLessThanOrEqualToWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsLessThanWhenPresent<T> extends IsLessThan<T> {
2223

@@ -27,4 +28,9 @@ protected IsLessThanWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsLessThanWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsLessThanWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsLessThanWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsLessThanWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223
import org.mybatis.dynamic.sql.util.StringUtilities;
@@ -47,4 +48,8 @@ public static IsLikeCaseInsensitive of(Supplier<String> valueSupplier) {
4748
public IsLikeCaseInsensitive when(Predicate<String> predicate) {
4849
return new IsLikeCaseInsensitive(valueSupplier, predicate);
4950
}
51+
52+
public IsLikeCaseInsensitive then(UnaryOperator<String> transformer) {
53+
return shouldRender() ? new IsLikeCaseInsensitive(() -> transformer.apply(value())) : this;
54+
}
5055
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsLikeCaseInsensitiveWhenPresent extends IsLikeCaseInsensitive {
2223

@@ -27,4 +28,9 @@ protected IsLikeCaseInsensitiveWhenPresent(Supplier<String> valueSupplier) {
2728
public static IsLikeCaseInsensitiveWhenPresent of(Supplier<String> valueSupplier) {
2829
return new IsLikeCaseInsensitiveWhenPresent(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsLikeCaseInsensitiveWhenPresent then(UnaryOperator<String> transformer) {
34+
return shouldRender() ? new IsLikeCaseInsensitiveWhenPresent(() -> transformer.apply(value())) : this;
35+
}
3036
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsLikeWhenPresent<T> extends IsLike<T> {
2223

@@ -27,4 +28,9 @@ protected IsLikeWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsLikeWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsLikeWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsLikeWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsLikeWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 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,6 +17,7 @@
1717

1818
import java.util.function.BiPredicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2223

@@ -54,4 +55,9 @@ public static <T> Builder<T> isNotBetween(Supplier<T> valueSupplier1) {
5455
public IsNotBetween<T> when(BiPredicate<T, T> predicate) {
5556
return new IsNotBetween<>(valueSupplier1, valueSupplier2, predicate);
5657
}
58+
59+
public IsNotBetween<T> then(UnaryOperator<T> transformer1, UnaryOperator<T> transformer2) {
60+
return shouldRender() ? new IsNotBetween<>(() -> transformer1.apply(value1()),
61+
() -> transformer2.apply(value2())) : this;
62+
}
5763
}

0 commit comments

Comments
 (0)