diff --git a/README.md b/README.md
index d7e39561..d587e43e 100644
--- a/README.md
+++ b/README.md
@@ -63,7 +63,7 @@ your `pom.xml`:
am.ik.yavi
yavi
- 0.14.4
+ 0.15.0
```
@@ -73,13 +73,13 @@ This tutorial uses JUnit 5 and AssertJ. Add the following dependencies as needed
org.junit.jupiter
junit-jupiter-api
- 5.9.3
+ 5.11.4
test
org.assertj
assertj-core
- 3.24.2
+ 3.26.3
test
```
@@ -271,7 +271,7 @@ class CarTest {
@Test
void licensePlateTooShort() {
Validated validated = Car.of("Morris", "D", 4);
- assertThat(violations.isValid()).isFalse();
+ assertThat(validated.isValid()).isFalse();
ConstraintViolations violations = validated.errors();
assertThat(violations).hasSize(1);
assertThat(violations.get(0).message())
@@ -281,7 +281,7 @@ class CarTest {
@Test
void seatCountTooLow() {
Validated validated = Car.of("Morris", "DD-AB-123", 1);
- assertThat(violations.isValid()).isFalse();
+ assertThat(validated.isValid()).isFalse();
ConstraintViolations violations = validated.errors();
assertThat(violations).hasSize(1);
assertThat(violations.get(0).message()).isEqualTo("\"seatCount\" must be greater than or equal to 2");
@@ -389,6 +389,65 @@ class CarTest {
}
```
+#### Reusable and composable validators
+
+Let's take a look at a more advanced usage.
+
+The following constraints are domain rules that can potentially be used not only for the `Car` class:
+
+> * `manufacturer` must never be null
+> * `licensePlate` must never be null and must be between 2 and 14 characters long
+> * `seatCount` must be at least 2
+
+In YAVI, you can define small validators for each value and then combine them to compose validators for objects.
+
+Please take a look at the following definition:
+
+```java
+package com.example;
+
+import am.ik.yavi.builder.IntegerValidatorBuilder;
+import am.ik.yavi.builder.StringValidatorBuilder;
+import am.ik.yavi.core.Validated;
+
+public final class Car {
+
+ public static StringValidator manufacturerValidator = StringValidatorBuilder
+ .of("manufacturer", c -> c.notNull())
+ .build();
+
+ public static StringValidator licensePlateValidator = StringValidatorBuilder
+ .of("licensePlate", c -> c.notNull().greaterThanOrEqual(2).lessThanOrEqual(14))
+ .build();
+
+ public static IntegerValidator seatCountValidator = IntegerValidatorBuilder
+ .of("seatCount", c -> c.greaterThanOrEqual(2))
+ .build();
+
+ private static Arguments3Validator validator = manufacturerValidator
+ .split(licensePlateValidator)
+ .split(seatCountValidator)
+ .apply(Car::new);
+
+ private final String manufacturer;
+
+ private final String licensePlate;
+
+ private final Integer seatCount;
+
+ public static Validated of(String manufacturer, String licensePlate, Integer seatCount) {
+ return validator.validate(manufacturer, licensePlate, seatCount);
+ }
+
+ // omitted
+
+}
+```
+
+After defining validators for `manufacturer`, `licensePlate`, and `seatCount`, it combines these three validators (`StringValidator` is a validator that validates a `String` and returns an object of type `T`, and `IntegerValidator` is a validator that validates an `Integer` and returns an object of type `T`) to create an `Arguments3Validator`.
+
+These small validators can also be used for generating other objects, which prevents domain rules from being scattered throughout the code.
+
#### Where to go next?
That concludes the 5 minutes tour through the world of YAVI. If you want a more complete
diff --git a/pom.xml b/pom.xml
index 0c201590..dbdaff91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
am.ik.yavi
yavi
- 0.15.0
+ 0.16.0
yavi
Yet Another Validation (lambda based type safe validation)
diff --git a/scripts/generate-args.sh b/scripts/generate-args.sh
index 15f5bf07..94adc521 100755
--- a/scripts/generate-args.sh
+++ b/scripts/generate-args.sh
@@ -6,9 +6,308 @@ for i in `seq 1 ${n}`;do
class="Arguments${i}"
file="$(dirname $0)/../src/main/java/am/ik/yavi/arguments/${class}.java"
echo $file
+
+ # Create all arg method declarations
+ arg_methods=""
+ for j in `seq 1 ${i}`; do
+ arg_methods+="
+ /**
+ * Returns the argument at position ${j}.
+ *
+ * @return the argument at position ${j}
+ */
+ @Nullable
+ public A${j} arg${j}() {
+ return this.arg${j};
+ }
+"
+ done
+
+ # Create all firstM methods (for N > 1)
+ first_methods=""
+ if [ ${i} -gt 1 ]; then
+ for j in `seq 1 $((${i} - 1))`; do
+ # Create type parameters for first method
+ first_type_params=""
+ for k in `seq 1 ${j}`; do
+ first_type_params="${first_type_params}A${k}"
+ if [ ${k} -lt ${j} ]; then
+ first_type_params="${first_type_params}, "
+ fi
+ done
+
+ # Create arguments for first method
+ first_args=""
+ for k in `seq 1 ${j}`; do
+ first_args="${first_args}arg${k}"
+ if [ ${k} -lt ${j} ]; then
+ first_args="${first_args}, "
+ fi
+ done
+
+ # Add first method
+ first_methods+="
+ /**
+ * Returns a new Arguments${j} instance containing only the first ${j} arguments.
+ *
+ * @return an Arguments${j} instance with arguments from arg1 to arg${j}
+ * @since 0.16.0
+ */
+ public Arguments${j}<${first_type_params}> first${j}() {
+ return new Arguments${j}<>(${first_args});
+ }
+"
+ done
+ fi
+
+ # Create all lastM methods (for N > 1)
+ last_methods=""
+ if [ ${i} -gt 1 ]; then
+ for j in `seq 1 $((${i} - 1))`; do
+ # Calculate starting position for last method
+ start_pos=$((${i} - ${j} + 1))
+
+ # Create type parameters for last method
+ last_type_params=""
+ for k in `seq ${start_pos} ${i}`; do
+ last_type_params="${last_type_params}A${k}"
+ if [ ${k} -lt ${i} ]; then
+ last_type_params="${last_type_params}, "
+ fi
+ done
+
+ # Create arguments for last method
+ last_args=""
+ for k in `seq ${start_pos} ${i}`; do
+ last_args="${last_args}arg${k}"
+ if [ ${k} -lt ${i} ]; then
+ last_args="${last_args}, "
+ fi
+ done
+
+ # Add last method
+ last_methods+="
+ /**
+ * Returns a new Arguments${j} instance containing only the last ${j} arguments.
+ *
+ * @return an Arguments${j} instance with arguments from arg${start_pos} to arg${i}
+ * @since 0.16.0
+ */
+ public Arguments${j}<${last_type_params}> last${j}() {
+ return new Arguments${j}<>(${last_args});
+ }
+"
+ done
+ fi
+
+ # Create append method (only for classes less than max size)
+ append_method=""
+ if [ ${i} -lt ${n} ]; then
+ new_size=$((${i} + 1))
+ append_method="
+ /**
+ * Appends an additional argument to create a new, larger Arguments instance.
+ *
+ * @param the type of the argument to append
+ * @param arg the argument to append
+ * @return a new Arguments${new_size} instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments${new_size}<"
+
+ # Add type parameters for result
+ for j in `seq 1 ${i}`; do
+ append_method+="A${j}"
+ if [ ${j} -lt ${i} ] || [ ${i} -lt ${new_size} ]; then
+ append_method+=", "
+ fi
+ done
+ append_method+="B> append(@Nullable B arg) {
+ return new Arguments${new_size}<>("
+
+ # Add arguments for result constructor
+ for j in `seq 1 ${i}`; do
+ append_method+="this.arg${j}"
+ if [ ${j} -lt ${i} ] || [ ${i} -lt ${new_size} ]; then
+ append_method+=", "
+ fi
+ done
+ append_method+="arg);
+ }
+"
+ fi
+
+ # Create prepend method (only for classes less than max size)
+ prepend_method=""
+ if [ ${i} -lt ${n} ]; then
+ new_size=$((${i} + 1))
+ prepend_method="
+ /**
+ * Prepends an additional argument to create a new, larger Arguments instance.
+ *
+ * @param the type of the argument to prepend
+ * @param arg the argument to prepend
+ * @return a new Arguments${new_size} instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments${new_size} prepend(@Nullable B arg) {
+ return new Arguments${new_size}<>(arg, "
+
+ # Add arguments for result constructor (arg prepended)
+ for j in `seq 1 ${i}`; do
+ prepend_method+="this.arg${j}"
+ if [ ${j} -lt ${i} ]; then
+ prepend_method+=", "
+ fi
+ done
+ prepend_method+=");
+ }
+"
+ fi
+
+ # Create reverse method
+ reverse_method=""
+ if [ ${i} -gt 1 ]; then
+ # Create type parameters for reverse method (in reverse order)
+ reverse_type_params=""
+ for j in `seq ${i} -1 1`; do
+ reverse_type_params="${reverse_type_params}A${j}"
+ if [ ${j} -gt 1 ]; then
+ reverse_type_params="${reverse_type_params}, "
+ fi
+ done
+
+ # Create arguments for reverse method (in reverse order)
+ reverse_args=""
+ for j in `seq ${i} -1 1`; do
+ reverse_args="${reverse_args}arg${j}"
+ if [ ${j} -gt 1 ]; then
+ reverse_args="${reverse_args}, "
+ fi
+ done
+
+ # Add reverse method
+ reverse_method="
+ /**
+ * Returns a new Arguments${i} instance with the arguments in reverse order.
+ *
+ * @return an Arguments${i} instance with arguments in reverse order
+ * @since 0.16.0
+ */
+ public Arguments${i}<${reverse_type_params}> reverse() {
+ return new Arguments${i}<>(${reverse_args});
+ }
+"
+ fi
+
+ # Create class type parameters
+ class_type_params=""
+ for j in `seq 1 ${i}`; do
+ class_type_params="${class_type_params}A${j}"
+ if [ ${j} -lt ${i} ]; then
+ class_type_params="${class_type_params}, "
+ fi
+ done
+
+ # Create JavaDoc param tags for each type parameter
+ type_param_docs=""
+ for j in `seq 1 ${i}`; do
+ type_param_docs="${type_param_docs}
+ * @param the type of argument at position ${j}"
+ done
+
+ # Create field declarations for all arguments
+ field_declarations=""
+ for j in `seq 1 ${i}`; do
+ field_declarations+="
+ private final A${j} arg${j};"
+ done
+
+ # Create constructor parameters
+ constructor_params=""
+ for j in `seq 1 ${i}`; do
+ constructor_params="${constructor_params}@Nullable A${j} arg${j}"
+ if [ ${j} -lt ${i} ]; then
+ constructor_params="${constructor_params}, "
+ fi
+ done
+
+ # Create constructor parameter assignments
+ constructor_assignments=""
+ for j in `seq 1 ${i}`; do
+ constructor_assignments+="
+ this.arg${j} = arg${j};"
+ done
+
+ # Create function parameters
+ function_params=""
+ for j in `seq 1 ${i}`; do
+ function_params="${function_params}? super A${j}"
+ if [ ${j} -lt ${i} ]; then
+ function_params="${function_params}, "
+ fi
+ done
+
+ # Create map function arguments
+ map_args=""
+ for j in `seq 1 ${i}`; do
+ map_args="${map_args}arg${j}"
+ if [ ${j} -lt ${i} ]; then
+ map_args="${map_args}, "
+ fi
+ done
+
+ # Create constructor param documentation
+ param_docs=""
+ for j in `seq 1 ${i}`; do
+ param_docs="${param_docs}arg${j} the argument at position ${j}"
+ if [ ${j} -lt ${i} ]; then
+ param_docs="${param_docs}, "
+ fi
+ done
+
+ # Create equals method parameters
+ equals_params=""
+ for j in `seq 1 ${i}`; do
+ equals_params="${equals_params}Objects.equals(this.arg${j}, that.arg${j})"
+ if [ ${j} -lt ${i} ]; then
+ equals_params="${equals_params} && "
+ fi
+ done
+
+ # Create hashCode method parameters
+ hashcode_params=""
+ for j in `seq 1 ${i}`; do
+ hashcode_params="${hashcode_params}this.arg${j}"
+ if [ ${j} -lt ${i} ]; then
+ hashcode_params="${hashcode_params}, "
+ fi
+ done
+
+ # Create toString method parameters
+ tostring_params=""
+ for j in `seq 1 ${i}`; do
+ tostring_params="${tostring_params}\"arg${j}=\" + this.arg${j}"
+ if [ ${j} -lt ${i} ]; then
+ tostring_params="${tostring_params} + \", \" + "
+ fi
+ done
+
+ # Build the class definition (no inheritance now)
+ class_definition="${class}<${class_type_params}>"
+
cat < ${file}
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,74 +323,85 @@ for i in `seq 1 ${n}`;do
*/
package am.ik.yavi.arguments;
+import java.util.Objects;
+
import am.ik.yavi.fn.Function${i};
import am.ik.yavi.jsr305.Nullable;
/**
- * Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
+ * A container class that holds ${i} arguments, providing type-safe access
+ * to each argument and mapping functionality to transform these arguments.
*
+ * Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh${type_param_docs}
* @since 0.3.0
*/
-public class ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//')> $(if [ ${i} -gt 1 ];then echo -n "extends Arguments$((${i} - 1))<$(echo $(for j in `seq 1 $((${i} - 1))`;do echo -n "A${j}, ";done) | sed 's/,$//')>"; else echo -n "";fi) {
+public final class ${class_definition} {
+${field_declarations}
- protected final A${i} arg${i};
-
- ${class}($(echo $(for j in `seq 1 ${i}`;do echo -n "@Nullable A${j} arg${j}, ";done) | sed 's/,$//')) {$(if [ ${i} -gt 1 ];then echo;echo " super($(echo $(for j in `seq 1 $((${i} - 1))`;do echo -n "arg${j}, ";done) | sed 's/,$//'));";fi)
- this.arg${i} = arg${i};
+ /**
+ * Creates a new Arguments${i} instance with the provided arguments.
+ *
+ * @param ${param_docs}
+ */
+ ${class}(${constructor_params}) {${constructor_assignments}
}
+${arg_methods}
+ /**
+ * Applies the provided mapping function to all arguments contained in this instance.
+ *
+ * @param the type of the result
+ * @param mapper the function to apply to the arguments
+ * @return the result of applying the mapper function to the arguments
+ */
+ public X map(Function${i}<${function_params}, ? extends X> mapper) {
+ return mapper.apply(${map_args});
+ }${first_methods}${last_methods}${append_method}${prepend_method}${reverse_method}
- @Nullable
- public final A${i} arg${i}() {
- return this.arg${i};
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ *
+ * @param obj the reference object with which to compare
+ * @return true if this object is the same as the obj argument; false otherwise
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean equals(@Nullable Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ ${class}<${class_type_params}> that = (${class}<${class_type_params}>) obj;
+ return ${equals_params};
}
- public final X map(Function${i}<$(echo $(for j in `seq 1 ${i}`;do echo -n "? super A${j}, ";done) | sed 's/,$//'), ? extends X> mapper) {
- return mapper.apply($(echo $(for j in `seq 1 ${i}`;do echo -n "arg${j}, ";done) | sed 's/,$//'));
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return a hash code value for this object
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(${hashcode_params});
}
-}
-EOF
-done
-
-cat << EOF > $(dirname $0)/../src/main/java/am/ik/yavi/arguments/Arguments.java
-/*
- * Copyright (C) 2018-2024 Toshiaki Maki
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package am.ik.yavi.arguments;
-import am.ik.yavi.jsr305.Nullable;
-
-/**
- * Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
- *
- * @since 0.3.0
- */
-public final class Arguments {
-$(for i in `seq 1 ${n}`;do
- cat < Arguments${i}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//')> of($(echo $(for j in `seq 1 ${i}`;do echo -n "@Nullable A${j} arg${j}, ";done) | sed 's/,$//')) {
- return new Arguments${i}<>($(echo $(for j in `seq 1 ${i}`;do echo -n "arg${j}, ";done) | sed 's/,$//'));
+ /**
+ * Returns a string representation of the object.
+ *
+ * @return a string representation of the object
+ */
+ @Override
+ public String toString() {
+ return "${class}{" + ${tostring_params} + "}";
}
-
-EOJ
-done)
}
EOF
+done
cat << EOF > $(dirname $0)/../src/main/java/am/ik/yavi/builder/ArgumentsValidatorBuilder.java
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -170,12 +480,13 @@ for i in `seq 1 ${n}`;do
class="Arguments${i}Validator"
file="$(dirname $0)/../src/main/java/am/ik/yavi/arguments/${class}.java"
arguments="Arguments${i}<$(echo $(for j in `seq 1 ${i}`;do echo -n "? extends A${j}, ";done) | sed 's/,$//')>"
+ wrapArguments="Arguments${i}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//')>"
args="$(echo $(for j in `seq 1 ${i}`;do echo -n "@Nullable A${j} a${j}, ";done) | sed 's/,$//')"
as="$(echo $(for j in `seq 1 ${i}`;do echo -n "a${j}, ";done) | sed 's/,$//')"
echo $file
cat < ${file}
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -194,6 +505,7 @@ package am.ik.yavi.arguments;
$(if [ "${i}" != "1" ];then
cat < Arguments1Validator from(ValueValidator valueValidator) {
return valueValidator::validate;
}
+
+ /**
+ * Convert an Arguments1Validator that validates Arguments1<A1> to an Arguments1Validator<A1, X>
+ *
+ * @param validator validator for Arguments1<A1>
+ * @param class of argument1
+ * @param target class
+ * @return arguments1 validator that takes an A1 directly
+ * @since 0.16.0
+ */
+ static Arguments1Validator unwrap(Arguments1Validator, X> validator) {
+ return new Arguments1Validator() {
+ @Override
+ public Validated validate(A1 a1, Locale locale, ConstraintContext constraintContext) {
+ return validator.validate(Arguments.of(a1), locale, constraintContext);
+ }
+
+ @Override
+ public Arguments1Validator> lazy() {
+ return Arguments1Validator.unwrap(validator.lazy());
+ }
+ };
+ }
EOD
else
cat < {
+
+ /**
+ * Convert an Arguments1Validator that validates Arguments${i} to an ${class}
+ *
+ * @param validator validator for Arguments${i}
+ * @param type of first argument
+$(if [ ${i} -gt 1 ]; then for j in $(seq 2 ${i}); do echo " * @param type of argument at position ${j}"; done; fi)
+ * @param target result type
+ * @return arguments${i} validator that takes arguments directly
+ * @since 0.16.0
+ */
+ static <$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X> ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X> unwrap(
+ Arguments1Validator<${wrapArguments}, X> validator) {
+ return new ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X>() {
+ @Override
+ public Validated validate(${args}, Locale locale, ConstraintContext constraintContext) {
+ return validator.validate(Arguments.of(${as}), locale, constraintContext);
+ }
+
+ @Override
+ public ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), Supplier> lazy() {
+ return ${class}.unwrap(validator.lazy());
+ }
+ };
+ }
EOD
fi)
@@ -280,21 +641,65 @@ cat < wrap() {
+ return new Arguments1Validator<${wrapArguments}, X>() {
+ @Override
+ public Validated validate(${wrapArguments} args, Locale locale,
+ ConstraintContext constraintContext) {
+ final ${arguments} nonNullArgs = Objects.requireNonNull(args);
+ return ${class}.this.validate($(echo $(for j in `seq 1 ${i}`;do echo -n "nonNullArgs.arg${j}(), ";done) | sed 's/,$//'),
+ locale, constraintContext);
+ }
+
+ @Override
+ public Arguments1Validator<${wrapArguments}, Supplier> lazy() {
+ return ${class}.this.lazy().wrap();
+ }
+ };
+ }
+
/**
* @since 0.7.0
*/$(if [ "${i}" == "1" ];then echo;echo " @Override"; fi)
default ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X2> andThen(Function super X, ? extends X2> mapper) {
- return (${as}, locale, constraintContext) -> ${class}.this
- .validate(${as}, locale, constraintContext).map(mapper);
+ return new ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X2>() {
+ @Override
+ public Validated validate($(echo $(for j in `seq 1 ${i}`;do echo -n "A${j} a${j}, ";done) | sed 's/,$//'), Locale locale, ConstraintContext constraintContext) {
+ return ${class}.this.validate(${as}, locale, constraintContext).map(mapper);
+ }
+
+ @Override
+ public ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), Supplier> lazy() {
+ return ${class}.this.lazy()
+ .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get()));
+ }
+ };
}
/**
* @since 0.11.0
*/$(if [ "${i}" == "1" ];then echo;echo " @Override"; fi)
default ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X2> andThen(ValueValidator super X, X2> validator) {
- return (${as}, locale, constraintContext) -> ${class}.this
- .validate(${as}, locale, constraintContext)
- .flatMap(v -> validator.validate(v, locale, constraintContext));
+ return new ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), X2>() {
+ @Override
+ public Validated validate($(echo $(for j in `seq 1 ${i}`;do echo -n "A${j} a${j}, ";done) | sed 's/,$//'), Locale locale, ConstraintContext constraintContext) {
+ return ${class}.this.validate(${as}, locale, constraintContext)
+ .flatMap(v -> validator.validate(v, locale, constraintContext));
+ }
+
+ @Override
+ public ${class}<$(echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done) | sed 's/,$//'), Supplier> lazy() {
+ return ${class}.this.lazy().andThen((xSupplier, locale, constraintContext) -> validator
+ .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext)
+ .map(x2 -> () -> x2));
+ }
+ };
}
/**
@@ -303,19 +708,35 @@ fi)
$(if [ "${i}" == "1" ];then
cat < ${class} compose(
- Function super A, ? extends A1> mapper) {
- return (a, locale, constraintContext) -> ${class}.this
- .validate(mapper.apply(a), locale, constraintContext);
+ default Arguments1Validator compose(Function super A, ? extends A1> mapper) {
+ return new Arguments1Validator() {
+ @Override
+ public Validated validate(A a, Locale locale, ConstraintContext constraintContext) {
+ return Arguments1Validator.this.validate(mapper.apply(a), locale, constraintContext);
+ }
+
+ @Override
+ public Arguments1Validator> lazy() {
+ return Arguments1Validator.this.lazy().compose(mapper);
+ }
+ };
}
EOD
else
cat < Arguments1Validator compose(
Function super A, ? extends ${arguments}> mapper) {
- return (a, locale, constraintContext) -> {
- final ${arguments} args = mapper.apply(a);
- return ${class}.this.validate($(echo $(for j in `seq 1 ${i}`;do echo -n "args.arg${j}(), ";done) | sed 's/,$//'), locale, constraintContext);
+ return new Arguments1Validator() {
+ @Override
+ public Validated validate(A a, Locale locale, ConstraintContext constraintContext) {
+ final ${arguments} args = mapper.apply(a);
+ return ${class}.this.validate($(echo $(for j in `seq 1 ${i}`;do echo -n "args.arg${j}(), ";done) | sed 's/,$//'), locale, constraintContext);
+ }
+
+ @Override
+ public Arguments1Validator> lazy() {
+ return ${class}.this.lazy().compose(mapper);
+ }
};
}
EOD
@@ -429,7 +850,7 @@ for i in `seq 1 ${n}`;do
echo $file
cat < ${file}
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -494,7 +915,7 @@ for i in `seq 2 ${nn}`;do
echo $file
cat < ${file}
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -563,7 +984,7 @@ for i in `seq 2 ${nn}`;do
echo $file
cat < ${file}
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -579,27 +1000,43 @@ for i in `seq 2 ${nn}`;do
*/
package am.ik.yavi.arguments;
+import am.ik.yavi.core.ConstraintContext;
+import am.ik.yavi.core.Validated;
import am.ik.yavi.core.ValueValidator;
import am.ik.yavi.fn.Function${i};
import am.ik.yavi.fn.Validations;
+import java.util.Locale;
+import java.util.function.Supplier;
/**
- * Generated by
- * https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
+ * Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
*
* @since 0.7.0
*/
public class ${class} {
-$(for j in `seq 1 ${i}`;do echo " protected final ValueValidator super A, ? extends R${j}> v${j};";echo;done)
+
+$(for j in `seq 1 ${i}`;do echo " protected final ValueValidator super A, ? extends R${j}> v${j};";done)
public ${class}($(echo $(for j in `seq 1 ${i}`;do echo -n "ValueValidator super A, ? extends R${j}> v${j}, ";done) | sed 's/,$//')) {
$(for j in `seq 1 ${i}`;do echo " this.v${j} = v${j};";done)
}
public Arguments1Validator apply(Function${i}<$(echo $(for j in `seq 1 ${i}`;do echo -n "? super R${j}, ";done) | sed 's/,$//'), ? extends X> f) {
- return (a, locale, constraintContext) -> Validations.apply(f::apply, $(echo $(for j in `seq 1 ${i}`;do echo -n "this.v${j}.validate(a, locale, constraintContext), ";done) | sed 's/,$//'));
+ return new Arguments1Validator() {
+ @Override
+ public Validated validate(A a, Locale locale, ConstraintContext constraintContext) {
+ return Validations.apply(f::apply, $(echo $(for j in `seq 1 ${i}`;do echo -n "${class}.this.v${j}.validate(a, locale, constraintContext), ";done) | sed 's/,$//'));
+ }
+
+ @Override
+ public Arguments1Validator> lazy() {
+ return (a, locale, constraintContext) -> Validations.apply(($(echo $(for j in `seq 1 ${i}`;do echo -n "r${j}, ";done) | sed 's/,$//')) -> () -> f.apply($(echo $(for j in `seq 1 ${i}`;do echo -n "r${j}, ";done) | sed 's/,$//')),
+ $(echo $(for j in `seq 1 ${i}`;do echo -n "${class}.this.v${j}.validate(a, locale, constraintContext), ";done) | sed 's/,$//'));
+ }
+ };
}
-$(if [ ${i} -lt ${nn} ];then echo;echo " public Arguments$((${i} + 1))Combining combine(ValueValidator super A, ? extends R$((${i} + 1))> v$((${i} + 1))) {"; echo " return new Arguments$((${i} + 1))Combining<>($(echo $(for j in `seq 1 $((${i} + 1))`;do echo -n "v${j}, ";done) | sed 's/,$//'));"; echo " }"; else echo -n "";fi)
+$(if [ ${i} -lt ${nn} ];then echo; echo " public Arguments$((${i} + 1))Combining combine(ValueValidator super A, ? extends R$((${i} + 1))> v$((${i} + 1))) {"; echo " return new Arguments$((${i} + 1))Combining<>($(echo $(for j in `seq 1 $((${i} + 1))`;do echo -n "v${j}, ";done) | sed 's/,$//'));"; echo " }"; else echo -n "";fi)
+
}
EOF
done
@@ -609,7 +1046,7 @@ file="$(dirname $0)/../src/main/java/am/ik/yavi/arguments/${class}.java"
echo $file
cat < ${file}
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -721,7 +1158,7 @@ fi
echo $file
cat < ${file}
/*
- * Copyright (C) 2018-2024 Toshiaki Maki
+ * Copyright (C) 2018-2025 Toshiaki Maki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -741,6 +1178,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDateTime;
+import java.time.LocalDate;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.Year;
@@ -769,6 +1207,7 @@ import am.ik.yavi.constraint.FloatConstraint;
import am.ik.yavi.constraint.InstantConstraint;
import am.ik.yavi.constraint.IntegerConstraint;
import am.ik.yavi.constraint.LocalDateTimeConstraint;
+import am.ik.yavi.constraint.LocalDateConstraint;
import am.ik.yavi.constraint.LocalTimeConstraint;
import am.ik.yavi.constraint.LongConstraint;
import am.ik.yavi.constraint.ObjectConstraint;
@@ -939,6 +1378,19 @@ cat < ${next_class}<$(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done);fi) LocalDate, $(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "R${j}, ";done);fi) T> _localDate(ValueValidator validator) {
+ return new ${next_class}<>($(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "this.v${j}, ";done); fi) validator);
+ }
+
+ public ${next_class}<$(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done);fi) LocalDate, $(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "R${j}, ";done);fi) LocalDate> _localDate(String name,
+ Function>, LocalDateConstraint>> constraints) {
+ return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build());
+ }
+
+ public ${next_class}<$(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done);fi) LocalDate, $(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "R${j}, ";done);fi) LocalDate> _localDate(String name) {
+ return this._localDate(name, Function.identity());
+ }
+
public ${next_class}<$(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "A${j}, ";done);fi) Long, $(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "R${j}, ";done);fi) T> _long(ValueValidator validator) {
return new ${next_class}<>($(if [ "${i}" -gt 0 ];then echo $(for j in `seq 1 ${i}`;do echo -n "this.v${j}, ";done); fi) validator);
}
diff --git a/src/main/java/am/ik/yavi/arguments/Arguments1.java b/src/main/java/am/ik/yavi/arguments/Arguments1.java
index 52cf7985..c6b88bff 100644
--- a/src/main/java/am/ik/yavi/arguments/Arguments1.java
+++ b/src/main/java/am/ik/yavi/arguments/Arguments1.java
@@ -15,29 +15,107 @@
*/
package am.ik.yavi.arguments;
+import java.util.Objects;
+
import am.ik.yavi.fn.Function1;
import am.ik.yavi.jsr305.Nullable;
/**
+ * A container class that holds 1 arguments, providing type-safe access to each argument
+ * and mapping functionality to transform these arguments.
+ *
* Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
*
+ * @param the type of argument at position 1
* @since 0.3.0
*/
-public class Arguments1 {
+public final class Arguments1 {
- protected final A1 arg1;
+ private final A1 arg1;
+ /**
+ * Creates a new Arguments1 instance with the provided arguments.
+ * @param arg1 the argument at position 1
+ */
Arguments1(@Nullable A1 arg1) {
this.arg1 = arg1;
}
+ /**
+ * Returns the argument at position 1.
+ * @return the argument at position 1
+ */
@Nullable
- public final A1 arg1() {
+ public A1 arg1() {
return this.arg1;
}
- public final X map(Function1 super A1, ? extends X> mapper) {
+ /**
+ * Applies the provided mapping function to all arguments contained in this instance.
+ * @param the type of the result
+ * @param mapper the function to apply to the arguments
+ * @return the result of applying the mapper function to the arguments
+ */
+ public X map(Function1 super A1, ? extends X> mapper) {
return mapper.apply(arg1);
}
+ /**
+ * Appends an additional argument to create a new, larger Arguments instance.
+ * @param the type of the argument to append
+ * @param arg the argument to append
+ * @return a new Arguments2 instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments2 append(@Nullable B arg) {
+ return new Arguments2<>(this.arg1, arg);
+ }
+
+ /**
+ * Prepends an additional argument to create a new, larger Arguments instance.
+ * @param the type of the argument to prepend
+ * @param arg the argument to prepend
+ * @return a new Arguments2 instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments2 prepend(@Nullable B arg) {
+ return new Arguments2<>(arg, this.arg1);
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ * @param obj the reference object with which to compare
+ * @return true if this object is the same as the obj argument; false otherwise
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean equals(@Nullable Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ Arguments1 that = (Arguments1) obj;
+ return Objects.equals(this.arg1, that.arg1);
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ * @return a hash code value for this object
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.arg1);
+ }
+
+ /**
+ * Returns a string representation of the object.
+ * @return a string representation of the object
+ */
+ @Override
+ public String toString() {
+ return "Arguments1{" + "arg1=" + this.arg1 + "}";
+ }
+
}
diff --git a/src/main/java/am/ik/yavi/arguments/Arguments10.java b/src/main/java/am/ik/yavi/arguments/Arguments10.java
index 6f712e55..1b000757 100644
--- a/src/main/java/am/ik/yavi/arguments/Arguments10.java
+++ b/src/main/java/am/ik/yavi/arguments/Arguments10.java
@@ -15,33 +15,411 @@
*/
package am.ik.yavi.arguments;
+import java.util.Objects;
+
import am.ik.yavi.fn.Function10;
import am.ik.yavi.jsr305.Nullable;
/**
+ * A container class that holds 10 arguments, providing type-safe access to each argument
+ * and mapping functionality to transform these arguments.
+ *
* Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
*
+ * @param the type of argument at position 1
+ * @param the type of argument at position 2
+ * @param the type of argument at position 3
+ * @param the type of argument at position 4
+ * @param the type of argument at position 5
+ * @param the type of argument at position 6
+ * @param the type of argument at position 7
+ * @param the type of argument at position 8
+ * @param the type of argument at position 9
+ * @param the type of argument at position 10
* @since 0.3.0
*/
-public class Arguments10
- extends Arguments9 {
+public final class Arguments10 {
+
+ private final A1 arg1;
+
+ private final A2 arg2;
+
+ private final A3 arg3;
+
+ private final A4 arg4;
+
+ private final A5 arg5;
+
+ private final A6 arg6;
+
+ private final A7 arg7;
+
+ private final A8 arg8;
+
+ private final A9 arg9;
- protected final A10 arg10;
+ private final A10 arg10;
+ /**
+ * Creates a new Arguments10 instance with the provided arguments.
+ * @param arg1 the argument at position 1, arg2 the argument at position 2, arg3 the
+ * argument at position 3, arg4 the argument at position 4, arg5 the argument at
+ * position 5, arg6 the argument at position 6, arg7 the argument at position 7, arg8
+ * the argument at position 8, arg9 the argument at position 9, arg10 the argument at
+ * position 10
+ */
Arguments10(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3, @Nullable A4 arg4, @Nullable A5 arg5,
@Nullable A6 arg6, @Nullable A7 arg7, @Nullable A8 arg8, @Nullable A9 arg9, @Nullable A10 arg10) {
- super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+ this.arg1 = arg1;
+ this.arg2 = arg2;
+ this.arg3 = arg3;
+ this.arg4 = arg4;
+ this.arg5 = arg5;
+ this.arg6 = arg6;
+ this.arg7 = arg7;
+ this.arg8 = arg8;
+ this.arg9 = arg9;
this.arg10 = arg10;
}
+ /**
+ * Returns the argument at position 1.
+ * @return the argument at position 1
+ */
@Nullable
- public final A10 arg10() {
+ public A1 arg1() {
+ return this.arg1;
+ }
+
+ /**
+ * Returns the argument at position 2.
+ * @return the argument at position 2
+ */
+ @Nullable
+ public A2 arg2() {
+ return this.arg2;
+ }
+
+ /**
+ * Returns the argument at position 3.
+ * @return the argument at position 3
+ */
+ @Nullable
+ public A3 arg3() {
+ return this.arg3;
+ }
+
+ /**
+ * Returns the argument at position 4.
+ * @return the argument at position 4
+ */
+ @Nullable
+ public A4 arg4() {
+ return this.arg4;
+ }
+
+ /**
+ * Returns the argument at position 5.
+ * @return the argument at position 5
+ */
+ @Nullable
+ public A5 arg5() {
+ return this.arg5;
+ }
+
+ /**
+ * Returns the argument at position 6.
+ * @return the argument at position 6
+ */
+ @Nullable
+ public A6 arg6() {
+ return this.arg6;
+ }
+
+ /**
+ * Returns the argument at position 7.
+ * @return the argument at position 7
+ */
+ @Nullable
+ public A7 arg7() {
+ return this.arg7;
+ }
+
+ /**
+ * Returns the argument at position 8.
+ * @return the argument at position 8
+ */
+ @Nullable
+ public A8 arg8() {
+ return this.arg8;
+ }
+
+ /**
+ * Returns the argument at position 9.
+ * @return the argument at position 9
+ */
+ @Nullable
+ public A9 arg9() {
+ return this.arg9;
+ }
+
+ /**
+ * Returns the argument at position 10.
+ * @return the argument at position 10
+ */
+ @Nullable
+ public A10 arg10() {
return this.arg10;
}
- public final X map(
+ /**
+ * Applies the provided mapping function to all arguments contained in this instance.
+ * @param the type of the result
+ * @param mapper the function to apply to the arguments
+ * @return the result of applying the mapper function to the arguments
+ */
+ public X map(
Function10 super A1, ? super A2, ? super A3, ? super A4, ? super A5, ? super A6, ? super A7, ? super A8, ? super A9, ? super A10, ? extends X> mapper) {
return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
}
+ /**
+ * Returns a new Arguments1 instance containing only the first 1 arguments.
+ * @return an Arguments1 instance with arguments from arg1 to arg1
+ * @since 0.16.0
+ */
+ public Arguments1 first1() {
+ return new Arguments1<>(arg1);
+ }
+
+ /**
+ * Returns a new Arguments2 instance containing only the first 2 arguments.
+ * @return an Arguments2 instance with arguments from arg1 to arg2
+ * @since 0.16.0
+ */
+ public Arguments2 first2() {
+ return new Arguments2<>(arg1, arg2);
+ }
+
+ /**
+ * Returns a new Arguments3 instance containing only the first 3 arguments.
+ * @return an Arguments3 instance with arguments from arg1 to arg3
+ * @since 0.16.0
+ */
+ public Arguments3 first3() {
+ return new Arguments3<>(arg1, arg2, arg3);
+ }
+
+ /**
+ * Returns a new Arguments4 instance containing only the first 4 arguments.
+ * @return an Arguments4 instance with arguments from arg1 to arg4
+ * @since 0.16.0
+ */
+ public Arguments4 first4() {
+ return new Arguments4<>(arg1, arg2, arg3, arg4);
+ }
+
+ /**
+ * Returns a new Arguments5 instance containing only the first 5 arguments.
+ * @return an Arguments5 instance with arguments from arg1 to arg5
+ * @since 0.16.0
+ */
+ public Arguments5 first5() {
+ return new Arguments5<>(arg1, arg2, arg3, arg4, arg5);
+ }
+
+ /**
+ * Returns a new Arguments6 instance containing only the first 6 arguments.
+ * @return an Arguments6 instance with arguments from arg1 to arg6
+ * @since 0.16.0
+ */
+ public Arguments6 first6() {
+ return new Arguments6<>(arg1, arg2, arg3, arg4, arg5, arg6);
+ }
+
+ /**
+ * Returns a new Arguments7 instance containing only the first 7 arguments.
+ * @return an Arguments7 instance with arguments from arg1 to arg7
+ * @since 0.16.0
+ */
+ public Arguments7 first7() {
+ return new Arguments7<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+ }
+
+ /**
+ * Returns a new Arguments8 instance containing only the first 8 arguments.
+ * @return an Arguments8 instance with arguments from arg1 to arg8
+ * @since 0.16.0
+ */
+ public Arguments8 first8() {
+ return new Arguments8<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+ }
+
+ /**
+ * Returns a new Arguments9 instance containing only the first 9 arguments.
+ * @return an Arguments9 instance with arguments from arg1 to arg9
+ * @since 0.16.0
+ */
+ public Arguments9 first9() {
+ return new Arguments9<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+ }
+
+ /**
+ * Returns a new Arguments1 instance containing only the last 1 arguments.
+ * @return an Arguments1 instance with arguments from arg10 to arg10
+ * @since 0.16.0
+ */
+ public Arguments1 last1() {
+ return new Arguments1<>(arg10);
+ }
+
+ /**
+ * Returns a new Arguments2 instance containing only the last 2 arguments.
+ * @return an Arguments2 instance with arguments from arg9 to arg10
+ * @since 0.16.0
+ */
+ public Arguments2 last2() {
+ return new Arguments2<>(arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments3 instance containing only the last 3 arguments.
+ * @return an Arguments3 instance with arguments from arg8 to arg10
+ * @since 0.16.0
+ */
+ public Arguments3 last3() {
+ return new Arguments3<>(arg8, arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments4 instance containing only the last 4 arguments.
+ * @return an Arguments4 instance with arguments from arg7 to arg10
+ * @since 0.16.0
+ */
+ public Arguments4 last4() {
+ return new Arguments4<>(arg7, arg8, arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments5 instance containing only the last 5 arguments.
+ * @return an Arguments5 instance with arguments from arg6 to arg10
+ * @since 0.16.0
+ */
+ public Arguments5 last5() {
+ return new Arguments5<>(arg6, arg7, arg8, arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments6 instance containing only the last 6 arguments.
+ * @return an Arguments6 instance with arguments from arg5 to arg10
+ * @since 0.16.0
+ */
+ public Arguments6 last6() {
+ return new Arguments6<>(arg5, arg6, arg7, arg8, arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments7 instance containing only the last 7 arguments.
+ * @return an Arguments7 instance with arguments from arg4 to arg10
+ * @since 0.16.0
+ */
+ public Arguments7 last7() {
+ return new Arguments7<>(arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments8 instance containing only the last 8 arguments.
+ * @return an Arguments8 instance with arguments from arg3 to arg10
+ * @since 0.16.0
+ */
+ public Arguments8 last8() {
+ return new Arguments8<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments9 instance containing only the last 9 arguments.
+ * @return an Arguments9 instance with arguments from arg2 to arg10
+ * @since 0.16.0
+ */
+ public Arguments9 last9() {
+ return new Arguments9<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+ }
+
+ /**
+ * Appends an additional argument to create a new, larger Arguments instance.
+ * @param the type of the argument to append
+ * @param arg the argument to append
+ * @return a new Arguments11 instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments11 append(@Nullable B arg) {
+ return new Arguments11<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8,
+ this.arg9, this.arg10, arg);
+ }
+
+ /**
+ * Prepends an additional argument to create a new, larger Arguments instance.
+ * @param the type of the argument to prepend
+ * @param arg the argument to prepend
+ * @return a new Arguments11 instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments11 prepend(@Nullable B arg) {
+ return new Arguments11<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7,
+ this.arg8, this.arg9, this.arg10);
+ }
+
+ /**
+ * Returns a new Arguments10 instance with the arguments in reverse order.
+ * @return an Arguments10 instance with arguments in reverse order
+ * @since 0.16.0
+ */
+ public Arguments10 reverse() {
+ return new Arguments10<>(arg10, arg9, arg8, arg7, arg6, arg5, arg4, arg3, arg2, arg1);
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ * @param obj the reference object with which to compare
+ * @return true if this object is the same as the obj argument; false otherwise
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean equals(@Nullable Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ Arguments10 that = (Arguments10) obj;
+ return Objects.equals(this.arg1, that.arg1) && Objects.equals(this.arg2, that.arg2)
+ && Objects.equals(this.arg3, that.arg3) && Objects.equals(this.arg4, that.arg4)
+ && Objects.equals(this.arg5, that.arg5) && Objects.equals(this.arg6, that.arg6)
+ && Objects.equals(this.arg7, that.arg7) && Objects.equals(this.arg8, that.arg8)
+ && Objects.equals(this.arg9, that.arg9) && Objects.equals(this.arg10, that.arg10);
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ * @return a hash code value for this object
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8,
+ this.arg9, this.arg10);
+ }
+
+ /**
+ * Returns a string representation of the object.
+ * @return a string representation of the object
+ */
+ @Override
+ public String toString() {
+ return "Arguments10{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + ", "
+ + "arg4=" + this.arg4 + ", " + "arg5=" + this.arg5 + ", " + "arg6=" + this.arg6 + ", " + "arg7="
+ + this.arg7 + ", " + "arg8=" + this.arg8 + ", " + "arg9=" + this.arg9 + ", " + "arg10=" + this.arg10
+ + "}";
+ }
+
}
diff --git a/src/main/java/am/ik/yavi/arguments/Arguments10Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments10Combining.java
index 442aeaf0..8c43a3bc 100644
--- a/src/main/java/am/ik/yavi/arguments/Arguments10Combining.java
+++ b/src/main/java/am/ik/yavi/arguments/Arguments10Combining.java
@@ -15,9 +15,13 @@
*/
package am.ik.yavi.arguments;
+import am.ik.yavi.core.ConstraintContext;
+import am.ik.yavi.core.Validated;
import am.ik.yavi.core.ValueValidator;
import am.ik.yavi.fn.Function10;
import am.ik.yavi.fn.Validations;
+import java.util.Locale;
+import java.util.function.Supplier;
/**
* Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
@@ -65,12 +69,38 @@ public Arguments10Combining(ValueValidator super A, ? extends R1> v1, ValueVal
public Arguments1Validator apply(
Function10 super R1, ? super R2, ? super R3, ? super R4, ? super R5, ? super R6, ? super R7, ? super R8, ? super R9, ? super R10, ? extends X> f) {
- return (a, locale, constraintContext) -> Validations.apply(f::apply,
- this.v1.validate(a, locale, constraintContext), this.v2.validate(a, locale, constraintContext),
- this.v3.validate(a, locale, constraintContext), this.v4.validate(a, locale, constraintContext),
- this.v5.validate(a, locale, constraintContext), this.v6.validate(a, locale, constraintContext),
- this.v7.validate(a, locale, constraintContext), this.v8.validate(a, locale, constraintContext),
- this.v9.validate(a, locale, constraintContext), this.v10.validate(a, locale, constraintContext));
+ return new Arguments1Validator() {
+ @Override
+ public Validated validate(A a, Locale locale, ConstraintContext constraintContext) {
+ return Validations.apply(f::apply, Arguments10Combining.this.v1.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v2.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v3.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v4.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v5.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v6.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v7.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v8.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v9.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v10.validate(a, locale, constraintContext));
+ }
+
+ @Override
+ public Arguments1Validator> lazy() {
+ return (a, locale, constraintContext) -> Validations.apply(
+ (r1, r2, r3, r4, r5, r6, r7, r8, r9,
+ r10) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10),
+ Arguments10Combining.this.v1.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v2.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v3.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v4.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v5.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v6.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v7.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v8.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v9.validate(a, locale, constraintContext),
+ Arguments10Combining.this.v10.validate(a, locale, constraintContext));
+ }
+ };
}
public Arguments11Combining combine(
diff --git a/src/main/java/am/ik/yavi/arguments/Arguments10Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments10Validator.java
index e37e53b7..faa54150 100644
--- a/src/main/java/am/ik/yavi/arguments/Arguments10Validator.java
+++ b/src/main/java/am/ik/yavi/arguments/Arguments10Validator.java
@@ -16,6 +16,7 @@
package am.ik.yavi.arguments;
import java.util.Locale;
+import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -34,18 +35,90 @@
@FunctionalInterface
public interface Arguments10Validator {
+ /**
+ * Convert an Arguments1Validator that validates Arguments10 to an
+ * Arguments10Validator
+ * @param validator validator for Arguments10
+ * @param type of first argument
+ * @param type of argument at position 2
+ * @param type of argument at position 3
+ * @param type of argument at position 4
+ * @param type of argument at position 5
+ * @param type of argument at position 6
+ * @param type of argument at position 7
+ * @param type of argument at position 8
+ * @param type of argument at position 9
+ * @param type of argument at position 10
+ * @param target result type
+ * @return arguments10 validator that takes arguments directly
+ * @since 0.16.0
+ */
+ static Arguments10Validator unwrap(
+ Arguments1Validator, X> validator) {
+ return new Arguments10Validator() {
+ @Override
+ public Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4,
+ @Nullable A5 a5, @Nullable A6 a6, @Nullable A7 a7, @Nullable A8 a8, @Nullable A9 a9,
+ @Nullable A10 a10, Locale locale, ConstraintContext constraintContext) {
+ return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10), locale,
+ constraintContext);
+ }
+
+ @Override
+ public Arguments10Validator> lazy() {
+ return Arguments10Validator.unwrap(validator.lazy());
+ }
+ };
+ }
+
Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4, @Nullable A5 a5,
@Nullable A6 a6, @Nullable A7 a7, @Nullable A8 a8, @Nullable A9 a9, @Nullable A10 a10, Locale locale,
ConstraintContext constraintContext);
+ /**
+ * Convert this validator to one that validates Arguments10 as a single object.
+ * @return a validator that takes an Arguments10
+ * @since 0.16.0
+ */
+ default Arguments1Validator, X> wrap() {
+ return new Arguments1Validator, X>() {
+ @Override
+ public Validated validate(Arguments10 args, Locale locale,
+ ConstraintContext constraintContext) {
+ final Arguments10 extends A1, ? extends A2, ? extends A3, ? extends A4, ? extends A5, ? extends A6, ? extends A7, ? extends A8, ? extends A9, ? extends A10> nonNullArgs = Objects
+ .requireNonNull(args);
+ return Arguments10Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(),
+ nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(),
+ nonNullArgs.arg8(), nonNullArgs.arg9(), nonNullArgs.arg10(), locale, constraintContext);
+ }
+
+ @Override
+ public Arguments1Validator, Supplier> lazy() {
+ return Arguments10Validator.this.lazy().wrap();
+ }
+ };
+ }
+
/**
* @since 0.7.0
*/
default Arguments10Validator andThen(
Function super X, ? extends X2> mapper) {
- return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, locale, constraintContext) -> Arguments10Validator.this
- .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, locale, constraintContext)
- .map(mapper);
+ return new Arguments10Validator() {
+ @Override
+ public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
+ Locale locale, ConstraintContext constraintContext) {
+ return Arguments10Validator.this
+ .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, locale, constraintContext)
+ .map(mapper);
+ }
+
+ @Override
+ public Arguments10Validator> lazy() {
+ return Arguments10Validator.this.lazy()
+ .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get()));
+ }
+ };
}
/**
@@ -53,9 +126,23 @@ default Arguments10Validator a
*/
default Arguments10Validator andThen(
ValueValidator super X, X2> validator) {
- return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, locale, constraintContext) -> Arguments10Validator.this
- .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, locale, constraintContext)
- .flatMap(v -> validator.validate(v, locale, constraintContext));
+ return new Arguments10Validator() {
+ @Override
+ public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10,
+ Locale locale, ConstraintContext constraintContext) {
+ return Arguments10Validator.this
+ .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, locale, constraintContext)
+ .flatMap(v -> validator.validate(v, locale, constraintContext));
+ }
+
+ @Override
+ public Arguments10Validator> lazy() {
+ return Arguments10Validator.this.lazy()
+ .andThen((xSupplier, locale, constraintContext) -> validator
+ .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext)
+ .map(x2 -> () -> x2));
+ }
+ };
}
/**
@@ -63,11 +150,20 @@ default Arguments10Validator a
*/
default Arguments1Validator compose(
Function super A, ? extends Arguments10 extends A1, ? extends A2, ? extends A3, ? extends A4, ? extends A5, ? extends A6, ? extends A7, ? extends A8, ? extends A9, ? extends A10>> mapper) {
- return (a, locale, constraintContext) -> {
- final Arguments10 extends A1, ? extends A2, ? extends A3, ? extends A4, ? extends A5, ? extends A6, ? extends A7, ? extends A8, ? extends A9, ? extends A10> args = mapper
- .apply(a);
- return Arguments10Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(),
- args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), locale, constraintContext);
+ return new Arguments1Validator() {
+ @Override
+ public Validated validate(A a, Locale locale, ConstraintContext constraintContext) {
+ final Arguments10 extends A1, ? extends A2, ? extends A3, ? extends A4, ? extends A5, ? extends A6, ? extends A7, ? extends A8, ? extends A9, ? extends A10> args = mapper
+ .apply(a);
+ return Arguments10Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(),
+ args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), locale,
+ constraintContext);
+ }
+
+ @Override
+ public Arguments1Validator> lazy() {
+ return Arguments10Validator.this.lazy().compose(mapper);
+ }
};
}
diff --git a/src/main/java/am/ik/yavi/arguments/Arguments11.java b/src/main/java/am/ik/yavi/arguments/Arguments11.java
index 40bf0d95..dea7b083 100644
--- a/src/main/java/am/ik/yavi/arguments/Arguments11.java
+++ b/src/main/java/am/ik/yavi/arguments/Arguments11.java
@@ -15,34 +15,444 @@
*/
package am.ik.yavi.arguments;
+import java.util.Objects;
+
import am.ik.yavi.fn.Function11;
import am.ik.yavi.jsr305.Nullable;
/**
+ * A container class that holds 11 arguments, providing type-safe access to each argument
+ * and mapping functionality to transform these arguments.
+ *
* Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
*
+ * @param the type of argument at position 1
+ * @param the type of argument at position 2
+ * @param the type of argument at position 3
+ * @param the type of argument at position 4
+ * @param the type of argument at position 5
+ * @param the type of argument at position 6
+ * @param the type of argument at position 7
+ * @param the type of argument at position 8
+ * @param the type of argument at position 9
+ * @param the type of argument at position 10
+ * @param the type of argument at position 11
* @since 0.3.0
*/
-public class Arguments11
- extends Arguments10 {
+public final class Arguments11 {
+
+ private final A1 arg1;
+
+ private final A2 arg2;
+
+ private final A3 arg3;
+
+ private final A4 arg4;
+
+ private final A5 arg5;
+
+ private final A6 arg6;
+
+ private final A7 arg7;
+
+ private final A8 arg8;
+
+ private final A9 arg9;
+
+ private final A10 arg10;
- protected final A11 arg11;
+ private final A11 arg11;
+ /**
+ * Creates a new Arguments11 instance with the provided arguments.
+ * @param arg1 the argument at position 1, arg2 the argument at position 2, arg3 the
+ * argument at position 3, arg4 the argument at position 4, arg5 the argument at
+ * position 5, arg6 the argument at position 6, arg7 the argument at position 7, arg8
+ * the argument at position 8, arg9 the argument at position 9, arg10 the argument at
+ * position 10, arg11 the argument at position 11
+ */
Arguments11(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3, @Nullable A4 arg4, @Nullable A5 arg5,
@Nullable A6 arg6, @Nullable A7 arg7, @Nullable A8 arg8, @Nullable A9 arg9, @Nullable A10 arg10,
@Nullable A11 arg11) {
- super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+ this.arg1 = arg1;
+ this.arg2 = arg2;
+ this.arg3 = arg3;
+ this.arg4 = arg4;
+ this.arg5 = arg5;
+ this.arg6 = arg6;
+ this.arg7 = arg7;
+ this.arg8 = arg8;
+ this.arg9 = arg9;
+ this.arg10 = arg10;
this.arg11 = arg11;
}
+ /**
+ * Returns the argument at position 1.
+ * @return the argument at position 1
+ */
+ @Nullable
+ public A1 arg1() {
+ return this.arg1;
+ }
+
+ /**
+ * Returns the argument at position 2.
+ * @return the argument at position 2
+ */
+ @Nullable
+ public A2 arg2() {
+ return this.arg2;
+ }
+
+ /**
+ * Returns the argument at position 3.
+ * @return the argument at position 3
+ */
+ @Nullable
+ public A3 arg3() {
+ return this.arg3;
+ }
+
+ /**
+ * Returns the argument at position 4.
+ * @return the argument at position 4
+ */
+ @Nullable
+ public A4 arg4() {
+ return this.arg4;
+ }
+
+ /**
+ * Returns the argument at position 5.
+ * @return the argument at position 5
+ */
@Nullable
- public final A11 arg11() {
+ public A5 arg5() {
+ return this.arg5;
+ }
+
+ /**
+ * Returns the argument at position 6.
+ * @return the argument at position 6
+ */
+ @Nullable
+ public A6 arg6() {
+ return this.arg6;
+ }
+
+ /**
+ * Returns the argument at position 7.
+ * @return the argument at position 7
+ */
+ @Nullable
+ public A7 arg7() {
+ return this.arg7;
+ }
+
+ /**
+ * Returns the argument at position 8.
+ * @return the argument at position 8
+ */
+ @Nullable
+ public A8 arg8() {
+ return this.arg8;
+ }
+
+ /**
+ * Returns the argument at position 9.
+ * @return the argument at position 9
+ */
+ @Nullable
+ public A9 arg9() {
+ return this.arg9;
+ }
+
+ /**
+ * Returns the argument at position 10.
+ * @return the argument at position 10
+ */
+ @Nullable
+ public A10 arg10() {
+ return this.arg10;
+ }
+
+ /**
+ * Returns the argument at position 11.
+ * @return the argument at position 11
+ */
+ @Nullable
+ public A11 arg11() {
return this.arg11;
}
- public final X map(
+ /**
+ * Applies the provided mapping function to all arguments contained in this instance.
+ * @param the type of the result
+ * @param mapper the function to apply to the arguments
+ * @return the result of applying the mapper function to the arguments
+ */
+ public X map(
Function11 super A1, ? super A2, ? super A3, ? super A4, ? super A5, ? super A6, ? super A7, ? super A8, ? super A9, ? super A10, ? super A11, ? extends X> mapper) {
return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
}
+ /**
+ * Returns a new Arguments1 instance containing only the first 1 arguments.
+ * @return an Arguments1 instance with arguments from arg1 to arg1
+ * @since 0.16.0
+ */
+ public Arguments1 first1() {
+ return new Arguments1<>(arg1);
+ }
+
+ /**
+ * Returns a new Arguments2 instance containing only the first 2 arguments.
+ * @return an Arguments2 instance with arguments from arg1 to arg2
+ * @since 0.16.0
+ */
+ public Arguments2 first2() {
+ return new Arguments2<>(arg1, arg2);
+ }
+
+ /**
+ * Returns a new Arguments3 instance containing only the first 3 arguments.
+ * @return an Arguments3 instance with arguments from arg1 to arg3
+ * @since 0.16.0
+ */
+ public Arguments3 first3() {
+ return new Arguments3<>(arg1, arg2, arg3);
+ }
+
+ /**
+ * Returns a new Arguments4 instance containing only the first 4 arguments.
+ * @return an Arguments4 instance with arguments from arg1 to arg4
+ * @since 0.16.0
+ */
+ public Arguments4 first4() {
+ return new Arguments4<>(arg1, arg2, arg3, arg4);
+ }
+
+ /**
+ * Returns a new Arguments5 instance containing only the first 5 arguments.
+ * @return an Arguments5 instance with arguments from arg1 to arg5
+ * @since 0.16.0
+ */
+ public Arguments5 first5() {
+ return new Arguments5<>(arg1, arg2, arg3, arg4, arg5);
+ }
+
+ /**
+ * Returns a new Arguments6 instance containing only the first 6 arguments.
+ * @return an Arguments6 instance with arguments from arg1 to arg6
+ * @since 0.16.0
+ */
+ public Arguments6 first6() {
+ return new Arguments6<>(arg1, arg2, arg3, arg4, arg5, arg6);
+ }
+
+ /**
+ * Returns a new Arguments7 instance containing only the first 7 arguments.
+ * @return an Arguments7 instance with arguments from arg1 to arg7
+ * @since 0.16.0
+ */
+ public Arguments7 first7() {
+ return new Arguments7<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+ }
+
+ /**
+ * Returns a new Arguments8 instance containing only the first 8 arguments.
+ * @return an Arguments8 instance with arguments from arg1 to arg8
+ * @since 0.16.0
+ */
+ public Arguments8 first8() {
+ return new Arguments8<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+ }
+
+ /**
+ * Returns a new Arguments9 instance containing only the first 9 arguments.
+ * @return an Arguments9 instance with arguments from arg1 to arg9
+ * @since 0.16.0
+ */
+ public Arguments9 first9() {
+ return new Arguments9<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+ }
+
+ /**
+ * Returns a new Arguments10 instance containing only the first 10 arguments.
+ * @return an Arguments10 instance with arguments from arg1 to arg10
+ * @since 0.16.0
+ */
+ public Arguments10 first10() {
+ return new Arguments10<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
+ }
+
+ /**
+ * Returns a new Arguments1 instance containing only the last 1 arguments.
+ * @return an Arguments1 instance with arguments from arg11 to arg11
+ * @since 0.16.0
+ */
+ public Arguments1 last1() {
+ return new Arguments1<>(arg11);
+ }
+
+ /**
+ * Returns a new Arguments2 instance containing only the last 2 arguments.
+ * @return an Arguments2 instance with arguments from arg10 to arg11
+ * @since 0.16.0
+ */
+ public Arguments2 last2() {
+ return new Arguments2<>(arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments3 instance containing only the last 3 arguments.
+ * @return an Arguments3 instance with arguments from arg9 to arg11
+ * @since 0.16.0
+ */
+ public Arguments3 last3() {
+ return new Arguments3<>(arg9, arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments4 instance containing only the last 4 arguments.
+ * @return an Arguments4 instance with arguments from arg8 to arg11
+ * @since 0.16.0
+ */
+ public Arguments4 last4() {
+ return new Arguments4<>(arg8, arg9, arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments5 instance containing only the last 5 arguments.
+ * @return an Arguments5 instance with arguments from arg7 to arg11
+ * @since 0.16.0
+ */
+ public Arguments5 last5() {
+ return new Arguments5<>(arg7, arg8, arg9, arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments6 instance containing only the last 6 arguments.
+ * @return an Arguments6 instance with arguments from arg6 to arg11
+ * @since 0.16.0
+ */
+ public Arguments6 last6() {
+ return new Arguments6<>(arg6, arg7, arg8, arg9, arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments7 instance containing only the last 7 arguments.
+ * @return an Arguments7 instance with arguments from arg5 to arg11
+ * @since 0.16.0
+ */
+ public Arguments7 last7() {
+ return new Arguments7<>(arg5, arg6, arg7, arg8, arg9, arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments8 instance containing only the last 8 arguments.
+ * @return an Arguments8 instance with arguments from arg4 to arg11
+ * @since 0.16.0
+ */
+ public Arguments8 last8() {
+ return new Arguments8<>(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments9 instance containing only the last 9 arguments.
+ * @return an Arguments9 instance with arguments from arg3 to arg11
+ * @since 0.16.0
+ */
+ public Arguments9 last9() {
+ return new Arguments9<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
+ }
+
+ /**
+ * Returns a new Arguments10 instance containing only the last 10 arguments.
+ * @return an Arguments10 instance with arguments from arg2 to arg11
+ * @since 0.16.0
+ */
+ public Arguments10 last10() {
+ return new Arguments10<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
+ }
+
+ /**
+ * Appends an additional argument to create a new, larger Arguments instance.
+ * @param the type of the argument to append
+ * @param arg the argument to append
+ * @return a new Arguments12 instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments12 append(@Nullable B arg) {
+ return new Arguments12<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8,
+ this.arg9, this.arg10, this.arg11, arg);
+ }
+
+ /**
+ * Prepends an additional argument to create a new, larger Arguments instance.
+ * @param the type of the argument to prepend
+ * @param arg the argument to prepend
+ * @return a new Arguments12 instance with the additional argument
+ * @since 0.16.0
+ */
+ public Arguments12 prepend(@Nullable B arg) {
+ return new Arguments12<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7,
+ this.arg8, this.arg9, this.arg10, this.arg11);
+ }
+
+ /**
+ * Returns a new Arguments11 instance with the arguments in reverse order.
+ * @return an Arguments11 instance with arguments in reverse order
+ * @since 0.16.0
+ */
+ public Arguments11 reverse() {
+ return new Arguments11<>(arg11, arg10, arg9, arg8, arg7, arg6, arg5, arg4, arg3, arg2, arg1);
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ * @param obj the reference object with which to compare
+ * @return true if this object is the same as the obj argument; false otherwise
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean equals(@Nullable Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ Arguments11 that = (Arguments11) obj;
+ return Objects.equals(this.arg1, that.arg1) && Objects.equals(this.arg2, that.arg2)
+ && Objects.equals(this.arg3, that.arg3) && Objects.equals(this.arg4, that.arg4)
+ && Objects.equals(this.arg5, that.arg5) && Objects.equals(this.arg6, that.arg6)
+ && Objects.equals(this.arg7, that.arg7) && Objects.equals(this.arg8, that.arg8)
+ && Objects.equals(this.arg9, that.arg9) && Objects.equals(this.arg10, that.arg10)
+ && Objects.equals(this.arg11, that.arg11);
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ * @return a hash code value for this object
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8,
+ this.arg9, this.arg10, this.arg11);
+ }
+
+ /**
+ * Returns a string representation of the object.
+ * @return a string representation of the object
+ */
+ @Override
+ public String toString() {
+ return "Arguments11{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + ", "
+ + "arg4=" + this.arg4 + ", " + "arg5=" + this.arg5 + ", " + "arg6=" + this.arg6 + ", " + "arg7="
+ + this.arg7 + ", " + "arg8=" + this.arg8 + ", " + "arg9=" + this.arg9 + ", " + "arg10=" + this.arg10
+ + ", " + "arg11=" + this.arg11 + "}";
+ }
+
}
diff --git a/src/main/java/am/ik/yavi/arguments/Arguments11Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments11Combining.java
index 4c62b0e3..6e3b647c 100644
--- a/src/main/java/am/ik/yavi/arguments/Arguments11Combining.java
+++ b/src/main/java/am/ik/yavi/arguments/Arguments11Combining.java
@@ -15,9 +15,13 @@
*/
package am.ik.yavi.arguments;
+import am.ik.yavi.core.ConstraintContext;
+import am.ik.yavi.core.Validated;
import am.ik.yavi.core.ValueValidator;
import am.ik.yavi.fn.Function11;
import am.ik.yavi.fn.Validations;
+import java.util.Locale;
+import java.util.function.Supplier;
/**
* Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
@@ -69,13 +73,40 @@ public Arguments11Combining(ValueValidator super A, ? extends R1> v1, ValueVal
public Arguments1Validator apply(
Function11 super R1, ? super R2, ? super R3, ? super R4, ? super R5, ? super R6, ? super R7, ? super R8, ? super R9, ? super R10, ? super R11, ? extends X> f) {
- return (a, locale, constraintContext) -> Validations.apply(f::apply,
- this.v1.validate(a, locale, constraintContext), this.v2.validate(a, locale, constraintContext),
- this.v3.validate(a, locale, constraintContext), this.v4.validate(a, locale, constraintContext),
- this.v5.validate(a, locale, constraintContext), this.v6.validate(a, locale, constraintContext),
- this.v7.validate(a, locale, constraintContext), this.v8.validate(a, locale, constraintContext),
- this.v9.validate(a, locale, constraintContext), this.v10.validate(a, locale, constraintContext),
- this.v11.validate(a, locale, constraintContext));
+ return new Arguments1Validator() {
+ @Override
+ public Validated validate(A a, Locale locale, ConstraintContext constraintContext) {
+ return Validations.apply(f::apply, Arguments11Combining.this.v1.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v2.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v3.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v4.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v5.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v6.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v7.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v8.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v9.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v10.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v11.validate(a, locale, constraintContext));
+ }
+
+ @Override
+ public Arguments1Validator> lazy() {
+ return (a, locale, constraintContext) -> Validations.apply(
+ (r1, r2, r3, r4, r5, r6, r7, r8, r9, r10,
+ r11) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11),
+ Arguments11Combining.this.v1.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v2.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v3.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v4.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v5.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v6.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v7.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v8.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v9.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v10.validate(a, locale, constraintContext),
+ Arguments11Combining.this.v11.validate(a, locale, constraintContext));
+ }
+ };
}
public Arguments12Combining combine(
diff --git a/src/main/java/am/ik/yavi/arguments/Arguments11Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments11Validator.java
index 35f7b2e1..889870d9 100644
--- a/src/main/java/am/ik/yavi/arguments/Arguments11Validator.java
+++ b/src/main/java/am/ik/yavi/arguments/Arguments11Validator.java
@@ -16,6 +16,7 @@
package am.ik.yavi.arguments;
import java.util.Locale;
+import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -34,18 +35,92 @@
@FunctionalInterface
public interface Arguments11Validator