Skip to content

Commit 90ece3a

Browse files
committed
Rename ValueValidator#andThen to map for better semantic clarity
- Mark andThen(Function) as deprecated - Add new map(Function) method with same implementation - Add @SInCE 0.17.0 annotation - Improve class Javadoc to better explain ValueValidator's purpose - Keep original andThen(Function) for backward compatibility
1 parent 0e5315b commit 90ece3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+322
-55
lines changed

scripts/generate-args.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,23 @@ fi)
665665
}
666666
667667
/**
668+
* @deprecated Use {@link #map(Function)} instead.
668669
* @since 0.7.0
669670
*/$(if [ "${i}" == "1" ];then echo;echo " @Override"; fi)
671+
@Deprecated
670672
default <X2> ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X2> andThen(Function<? super X, ? extends X2> mapper) {
673+
return this.map(mapper);
674+
}
675+
676+
/**
677+
* Maps the validated value to a new type using the provided mapper function. This is
678+
* a transformation operation that applies the function only if validation succeeds.
679+
* @param mapper function to transform the validated value
680+
* @param <X2> the type after transformation
681+
* @return a value validator that applies the mapping function after validation
682+
* @since 0.17.0
683+
*/$(if [ "${i}" == "1" ];then echo;echo " @Override"; fi)
684+
default <X2> ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X2> map(Function<? super X, ? extends X2> mapper) {
671685
return new ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X2>() {
672686
@Override
673687
public Validated<X2> validate($(echo $(for j in `seq 1 ${i}`;do echo -n "A${j} a${j}, ";done) | sed 's/,$//'), Locale locale, ConstraintContext constraintContext) {
@@ -677,7 +691,7 @@ fi)
677691
@Override
678692
public ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), Supplier<X2>> lazy() {
679693
return ${class}.this.lazy()
680-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
694+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
681695
}
682696
};
683697
}

src/main/java/am/ik/yavi/arguments/Arguments10Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,25 @@ public Arguments1Validator<Arguments10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>,
100100
}
101101

102102
/**
103+
* @deprecated Use {@link #map(Function)} instead.
103104
* @since 0.7.0
104105
*/
106+
@Deprecated
105107
default <X2> Arguments10Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, X2> andThen(
106108
Function<? super X, ? extends X2> mapper) {
109+
return this.map(mapper);
110+
}
111+
112+
/**
113+
* Maps the validated value to a new type using the provided mapper function. This is
114+
* a transformation operation that applies the function only if validation succeeds.
115+
* @param mapper function to transform the validated value
116+
* @param <X2> the type after transformation
117+
* @return a value validator that applies the mapping function after validation
118+
* @since 0.17.0
119+
*/
120+
default <X2> Arguments10Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, X2> map(
121+
Function<? super X, ? extends X2> mapper) {
107122
return new Arguments10Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, X2>() {
108123
@Override
109124
public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
@@ -116,7 +131,7 @@ public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A
116131
@Override
117132
public Arguments10Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Supplier<X2>> lazy() {
118133
return Arguments10Validator.this.lazy()
119-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
134+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
120135
}
121136
};
122137
}

src/main/java/am/ik/yavi/arguments/Arguments11Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,25 @@ public Arguments1Validator<Arguments11<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
102102
}
103103

104104
/**
105+
* @deprecated Use {@link #map(Function)} instead.
105106
* @since 0.7.0
106107
*/
108+
@Deprecated
107109
default <X2> Arguments11Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, X2> andThen(
108110
Function<? super X, ? extends X2> mapper) {
111+
return this.map(mapper);
112+
}
113+
114+
/**
115+
* Maps the validated value to a new type using the provided mapper function. This is
116+
* a transformation operation that applies the function only if validation succeeds.
117+
* @param mapper function to transform the validated value
118+
* @param <X2> the type after transformation
119+
* @return a value validator that applies the mapping function after validation
120+
* @since 0.17.0
121+
*/
122+
default <X2> Arguments11Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, X2> map(
123+
Function<? super X, ? extends X2> mapper) {
109124
return new Arguments11Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, X2>() {
110125
@Override
111126
public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
@@ -118,7 +133,7 @@ public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A
118133
@Override
119134
public Arguments11Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, Supplier<X2>> lazy() {
120135
return Arguments11Validator.this.lazy()
121-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
136+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
122137
}
123138
};
124139
}

src/main/java/am/ik/yavi/arguments/Arguments12Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,25 @@ public Arguments1Validator<Arguments12<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
104104
}
105105

106106
/**
107+
* @deprecated Use {@link #map(Function)} instead.
107108
* @since 0.7.0
108109
*/
110+
@Deprecated
109111
default <X2> Arguments12Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, X2> andThen(
110112
Function<? super X, ? extends X2> mapper) {
113+
return this.map(mapper);
114+
}
115+
116+
/**
117+
* Maps the validated value to a new type using the provided mapper function. This is
118+
* a transformation operation that applies the function only if validation succeeds.
119+
* @param mapper function to transform the validated value
120+
* @param <X2> the type after transformation
121+
* @return a value validator that applies the mapping function after validation
122+
* @since 0.17.0
123+
*/
124+
default <X2> Arguments12Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, X2> map(
125+
Function<? super X, ? extends X2> mapper) {
111126
return new Arguments12Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, X2>() {
112127
@Override
113128
public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
@@ -120,7 +135,7 @@ public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A
120135
@Override
121136
public Arguments12Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, Supplier<X2>> lazy() {
122137
return Arguments12Validator.this.lazy()
123-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
138+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
124139
}
125140
};
126141
}

src/main/java/am/ik/yavi/arguments/Arguments13Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,25 @@ public Arguments1Validator<Arguments13<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
105105
}
106106

107107
/**
108+
* @deprecated Use {@link #map(Function)} instead.
108109
* @since 0.7.0
109110
*/
111+
@Deprecated
110112
default <X2> Arguments13Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, X2> andThen(
111113
Function<? super X, ? extends X2> mapper) {
114+
return this.map(mapper);
115+
}
116+
117+
/**
118+
* Maps the validated value to a new type using the provided mapper function. This is
119+
* a transformation operation that applies the function only if validation succeeds.
120+
* @param mapper function to transform the validated value
121+
* @param <X2> the type after transformation
122+
* @return a value validator that applies the mapping function after validation
123+
* @since 0.17.0
124+
*/
125+
default <X2> Arguments13Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, X2> map(
126+
Function<? super X, ? extends X2> mapper) {
112127
return new Arguments13Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, X2>() {
113128
@Override
114129
public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
@@ -121,7 +136,7 @@ public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A
121136
@Override
122137
public Arguments13Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, Supplier<X2>> lazy() {
123138
return Arguments13Validator.this.lazy()
124-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
139+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
125140
}
126141
};
127142
}

src/main/java/am/ik/yavi/arguments/Arguments14Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,25 @@ public Arguments1Validator<Arguments14<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
107107
}
108108

109109
/**
110+
* @deprecated Use {@link #map(Function)} instead.
110111
* @since 0.7.0
111112
*/
113+
@Deprecated
112114
default <X2> Arguments14Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, X2> andThen(
113115
Function<? super X, ? extends X2> mapper) {
116+
return this.map(mapper);
117+
}
118+
119+
/**
120+
* Maps the validated value to a new type using the provided mapper function. This is
121+
* a transformation operation that applies the function only if validation succeeds.
122+
* @param mapper function to transform the validated value
123+
* @param <X2> the type after transformation
124+
* @return a value validator that applies the mapping function after validation
125+
* @since 0.17.0
126+
*/
127+
default <X2> Arguments14Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, X2> map(
128+
Function<? super X, ? extends X2> mapper) {
114129
return new Arguments14Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, X2>() {
115130
@Override
116131
public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
@@ -123,7 +138,7 @@ public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A
123138
@Override
124139
public Arguments14Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, Supplier<X2>> lazy() {
125140
return Arguments14Validator.this.lazy()
126-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
141+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
127142
}
128143
};
129144
}

src/main/java/am/ik/yavi/arguments/Arguments15Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,25 @@ public Arguments1Validator<Arguments15<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
111111
}
112112

113113
/**
114+
* @deprecated Use {@link #map(Function)} instead.
114115
* @since 0.7.0
115116
*/
117+
@Deprecated
116118
default <X2> Arguments15Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, X2> andThen(
117119
Function<? super X, ? extends X2> mapper) {
120+
return this.map(mapper);
121+
}
122+
123+
/**
124+
* Maps the validated value to a new type using the provided mapper function. This is
125+
* a transformation operation that applies the function only if validation succeeds.
126+
* @param mapper function to transform the validated value
127+
* @param <X2> the type after transformation
128+
* @return a value validator that applies the mapping function after validation
129+
* @since 0.17.0
130+
*/
131+
default <X2> Arguments15Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, X2> map(
132+
Function<? super X, ? extends X2> mapper) {
118133
return new Arguments15Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, X2>() {
119134
@Override
120135
public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
@@ -128,7 +143,7 @@ public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A
128143
@Override
129144
public Arguments15Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, Supplier<X2>> lazy() {
130145
return Arguments15Validator.this.lazy()
131-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
146+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
132147
}
133148
};
134149
}

src/main/java/am/ik/yavi/arguments/Arguments16Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,25 @@ public Arguments1Validator<Arguments16<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10,
112112
}
113113

114114
/**
115+
* @deprecated Use {@link #map(Function)} instead.
115116
* @since 0.7.0
116117
*/
118+
@Deprecated
117119
default <X2> Arguments16Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, X2> andThen(
118120
Function<? super X, ? extends X2> mapper) {
121+
return this.map(mapper);
122+
}
123+
124+
/**
125+
* Maps the validated value to a new type using the provided mapper function. This is
126+
* a transformation operation that applies the function only if validation succeeds.
127+
* @param mapper function to transform the validated value
128+
* @param <X2> the type after transformation
129+
* @return a value validator that applies the mapping function after validation
130+
* @since 0.17.0
131+
*/
132+
default <X2> Arguments16Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, X2> map(
133+
Function<? super X, ? extends X2> mapper) {
119134
return new Arguments16Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, X2>() {
120135
@Override
121136
public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
@@ -130,7 +145,7 @@ public Validated<X2> validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A
130145
@Override
131146
public Arguments16Validator<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, Supplier<X2>> lazy() {
132147
return Arguments16Validator.this.lazy()
133-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
148+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
134149
}
135150
};
136151
}

src/main/java/am/ik/yavi/arguments/Arguments1Validator.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,25 @@ public Arguments1Validator<Arguments1<A1>, Supplier<X>> lazy() {
110110
}
111111

112112
/**
113+
* @deprecated Use {@link #map(Function)} instead.
113114
* @since 0.7.0
114115
*/
115116
@Override
117+
@Deprecated
116118
default <X2> Arguments1Validator<A1, X2> andThen(Function<? super X, ? extends X2> mapper) {
119+
return this.map(mapper);
120+
}
121+
122+
/**
123+
* Maps the validated value to a new type using the provided mapper function. This is
124+
* a transformation operation that applies the function only if validation succeeds.
125+
* @param mapper function to transform the validated value
126+
* @param <X2> the type after transformation
127+
* @return a value validator that applies the mapping function after validation
128+
* @since 0.17.0
129+
*/
130+
@Override
131+
default <X2> Arguments1Validator<A1, X2> map(Function<? super X, ? extends X2> mapper) {
117132
return new Arguments1Validator<A1, X2>() {
118133
@Override
119134
public Validated<X2> validate(A1 a1, Locale locale, ConstraintContext constraintContext) {
@@ -123,7 +138,7 @@ public Validated<X2> validate(A1 a1, Locale locale, ConstraintContext constraint
123138
@Override
124139
public Arguments1Validator<A1, Supplier<X2>> lazy() {
125140
return Arguments1Validator.this.lazy()
126-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
141+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
127142
}
128143
};
129144
}

src/main/java/am/ik/yavi/arguments/Arguments2Validator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,23 @@ public Arguments1Validator<Arguments2<A1, A2>, Supplier<X>> lazy() {
8383
}
8484

8585
/**
86+
* @deprecated Use {@link #map(Function)} instead.
8687
* @since 0.7.0
8788
*/
89+
@Deprecated
8890
default <X2> Arguments2Validator<A1, A2, X2> andThen(Function<? super X, ? extends X2> mapper) {
91+
return this.map(mapper);
92+
}
93+
94+
/**
95+
* Maps the validated value to a new type using the provided mapper function. This is
96+
* a transformation operation that applies the function only if validation succeeds.
97+
* @param mapper function to transform the validated value
98+
* @param <X2> the type after transformation
99+
* @return a value validator that applies the mapping function after validation
100+
* @since 0.17.0
101+
*/
102+
default <X2> Arguments2Validator<A1, A2, X2> map(Function<? super X, ? extends X2> mapper) {
89103
return new Arguments2Validator<A1, A2, X2>() {
90104
@Override
91105
public Validated<X2> validate(A1 a1, A2 a2, Locale locale, ConstraintContext constraintContext) {
@@ -95,7 +109,7 @@ public Validated<X2> validate(A1 a1, A2 a2, Locale locale, ConstraintContext con
95109
@Override
96110
public Arguments2Validator<A1, A2, Supplier<X2>> lazy() {
97111
return Arguments2Validator.this.lazy()
98-
.andThen((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
112+
.map((Function<Supplier<X>, Supplier<X2>>) xSupplier -> () -> mapper.apply(xSupplier.get()));
99113
}
100114
};
101115
}

0 commit comments

Comments
 (0)