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} ${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 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 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 mapper) { - return (a, locale, constraintContext) -> ${class}.this - .validate(mapper.apply(a), locale, constraintContext); + default Arguments1Validator compose(Function 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 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 v${j};";echo;done) + +$(for j in `seq 1 ${i}`;do echo " protected final ValueValidator v${j};";done) public ${class}($(echo $(for j in `seq 1 ${i}`;do echo -n "ValueValidator 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 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 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 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 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 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 v1, ValueVal public Arguments1Validator apply( Function10 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 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 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 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> mapper) { - return (a, locale, constraintContext) -> { - final Arguments10 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 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 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 v1, ValueVal public Arguments1Validator apply( Function11 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 { + /** + * Convert an Arguments1Validator that validates Arguments11 to an + * Arguments11Validator + * @param validator validator for Arguments11 + * @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 type of argument at position 11 + * @param target result type + * @return arguments11 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments11Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments11Validator() { + @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, @Nullable A11 a11, Locale locale, ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11), locale, + constraintContext); + } + + @Override + public Arguments11Validator> lazy() { + return Arguments11Validator.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, @Nullable A11 a11, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments11 as a single object. + * @return a validator that takes an Arguments11 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments11 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments11 nonNullArgs = Objects + .requireNonNull(args); + return Arguments11Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), nonNullArgs.arg9(), nonNullArgs.arg10(), nonNullArgs.arg11(), locale, + constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments11Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments11Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, locale, constraintContext) -> Arguments11Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, locale, constraintContext) - .map(mapper); + return new Arguments11Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, Locale locale, ConstraintContext constraintContext) { + return Arguments11Validator.this + .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, locale, constraintContext) + .map(mapper); + } + + @Override + public Arguments11Validator> lazy() { + return Arguments11Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -53,9 +128,23 @@ default Arguments11Validator Arguments11Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, locale, constraintContext) -> Arguments11Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments11Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, Locale locale, ConstraintContext constraintContext) { + return Arguments11Validator.this + .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments11Validator> lazy() { + return Arguments11Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -63,12 +152,20 @@ default Arguments11Validator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments11 args = mapper - .apply(a); - return Arguments11Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), locale, - constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments11 args = mapper + .apply(a); + return Arguments11Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), + locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments11Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments12.java b/src/main/java/am/ik/yavi/arguments/Arguments12.java index 2dd2acd2..a1f172f5 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments12.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments12.java @@ -15,34 +15,475 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function12; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 12 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 + * @param the type of argument at position 12 * @since 0.3.0 */ -public class Arguments12 - extends Arguments11 { +public final class Arguments12 { + + 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; + + private final A11 arg11; - protected final A12 arg12; + private final A12 arg12; + /** + * Creates a new Arguments12 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, arg12 the argument at position 12 + */ Arguments12(@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, @Nullable A12 arg12) { - super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + 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; this.arg12 = arg12; } + /** + * Returns the argument at position 1. + * @return the argument at position 1 + */ @Nullable - public final A12 arg12() { + 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; + } + + /** + * Returns the argument at position 11. + * @return the argument at position 11 + */ + @Nullable + public A11 arg11() { + return this.arg11; + } + + /** + * Returns the argument at position 12. + * @return the argument at position 12 + */ + @Nullable + public A12 arg12() { return this.arg12; } - 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( Function12 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); } + /** + * 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 Arguments11 instance containing only the first 11 arguments. + * @return an Arguments11 instance with arguments from arg1 to arg11 + * @since 0.16.0 + */ + public Arguments11 first11() { + return new Arguments11<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } + + /** + * Returns a new Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg12 to arg12 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg12); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg11 to arg12 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg11, arg12); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg10 to arg12 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg10, arg11, arg12); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg9 to arg12 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg8 to arg12 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg7 to arg12 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments7 instance containing only the last 7 arguments. + * @return an Arguments7 instance with arguments from arg6 to arg12 + * @since 0.16.0 + */ + public Arguments7 last7() { + return new Arguments7<>(arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments8 instance containing only the last 8 arguments. + * @return an Arguments8 instance with arguments from arg5 to arg12 + * @since 0.16.0 + */ + public Arguments8 last8() { + return new Arguments8<>(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments9 instance containing only the last 9 arguments. + * @return an Arguments9 instance with arguments from arg4 to arg12 + * @since 0.16.0 + */ + public Arguments9 last9() { + return new Arguments9<>(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments10 instance containing only the last 10 arguments. + * @return an Arguments10 instance with arguments from arg3 to arg12 + * @since 0.16.0 + */ + public Arguments10 last10() { + return new Arguments10<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments11 instance containing only the last 11 arguments. + * @return an Arguments11 instance with arguments from arg2 to arg12 + * @since 0.16.0 + */ + public Arguments11 last11() { + return new Arguments11<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * 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 Arguments13 instance with the additional argument + * @since 0.16.0 + */ + public Arguments13 append(@Nullable B arg) { + return new Arguments13<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8, + this.arg9, this.arg10, this.arg11, this.arg12, 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 Arguments13 instance with the additional argument + * @since 0.16.0 + */ + public Arguments13 prepend(@Nullable B arg) { + return new Arguments13<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, + this.arg8, this.arg9, this.arg10, this.arg11, this.arg12); + } + + /** + * Returns a new Arguments12 instance with the arguments in reverse order. + * @return an Arguments12 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments12 reverse() { + return new Arguments12<>(arg12, 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; + } + Arguments12 that = (Arguments12) 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) && Objects.equals(this.arg12, that.arg12); + } + + /** + * 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, this.arg12); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments12{" + "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 + ", " + "arg12=" + this.arg12 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments12Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments12Combining.java index 7b46a6fc..ca81e1b0 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments12Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments12Combining.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.Function12; 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 @@ -72,13 +76,42 @@ public Arguments12Combining(ValueValidator v1, ValueVal public Arguments1Validator apply( Function12 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), this.v12.validate(a, locale, constraintContext)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments12Combining.this.v1.validate(a, locale, constraintContext), + Arguments12Combining.this.v2.validate(a, locale, constraintContext), + Arguments12Combining.this.v3.validate(a, locale, constraintContext), + Arguments12Combining.this.v4.validate(a, locale, constraintContext), + Arguments12Combining.this.v5.validate(a, locale, constraintContext), + Arguments12Combining.this.v6.validate(a, locale, constraintContext), + Arguments12Combining.this.v7.validate(a, locale, constraintContext), + Arguments12Combining.this.v8.validate(a, locale, constraintContext), + Arguments12Combining.this.v9.validate(a, locale, constraintContext), + Arguments12Combining.this.v10.validate(a, locale, constraintContext), + Arguments12Combining.this.v11.validate(a, locale, constraintContext), + Arguments12Combining.this.v12.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, + r12) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12), + Arguments12Combining.this.v1.validate(a, locale, constraintContext), + Arguments12Combining.this.v2.validate(a, locale, constraintContext), + Arguments12Combining.this.v3.validate(a, locale, constraintContext), + Arguments12Combining.this.v4.validate(a, locale, constraintContext), + Arguments12Combining.this.v5.validate(a, locale, constraintContext), + Arguments12Combining.this.v6.validate(a, locale, constraintContext), + Arguments12Combining.this.v7.validate(a, locale, constraintContext), + Arguments12Combining.this.v8.validate(a, locale, constraintContext), + Arguments12Combining.this.v9.validate(a, locale, constraintContext), + Arguments12Combining.this.v10.validate(a, locale, constraintContext), + Arguments12Combining.this.v11.validate(a, locale, constraintContext), + Arguments12Combining.this.v12.validate(a, locale, constraintContext)); + } + }; } public Arguments13Combining combine( diff --git a/src/main/java/am/ik/yavi/arguments/Arguments12Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments12Validator.java index ef58d54d..06593c13 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments12Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments12Validator.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,19 +35,94 @@ @FunctionalInterface public interface Arguments12Validator { + /** + * Convert an Arguments1Validator that validates Arguments12 to an + * Arguments12Validator + * @param validator validator for Arguments12 + * @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 type of argument at position 11 + * @param type of argument at position 12 + * @param target result type + * @return arguments12 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments12Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments12Validator() { + @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, @Nullable A11 a11, @Nullable A12 a12, Locale locale, + ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12), locale, + constraintContext); + } + + @Override + public Arguments12Validator> lazy() { + return Arguments12Validator.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, @Nullable A11 a11, @Nullable A12 a12, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments12 as a single object. + * @return a validator that takes an Arguments12 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments12 args, + Locale locale, ConstraintContext constraintContext) { + final Arguments12 nonNullArgs = Objects + .requireNonNull(args); + return Arguments12Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), nonNullArgs.arg9(), nonNullArgs.arg10(), nonNullArgs.arg11(), + nonNullArgs.arg12(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments12Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments12Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, locale, - constraintContext) -> Arguments12Validator.this + return new Arguments12Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, Locale locale, ConstraintContext constraintContext) { + return Arguments12Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, locale, constraintContext) .map(mapper); + } + + @Override + public Arguments12Validator> lazy() { + return Arguments12Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -54,10 +130,23 @@ default Arguments12Validator Arguments12Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, locale, - constraintContext) -> Arguments12Validator.this + return new Arguments12Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, Locale locale, ConstraintContext constraintContext) { + return Arguments12Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, locale, constraintContext) .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments12Validator> lazy() { + return Arguments12Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -65,12 +154,20 @@ default Arguments12Validator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments12 args = mapper - .apply(a); - return Arguments12Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), args.arg12(), - locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments12 args = mapper + .apply(a); + return Arguments12Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), + args.arg12(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments12Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments13.java b/src/main/java/am/ik/yavi/arguments/Arguments13.java index 16ad079c..b84355fe 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments13.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments13.java @@ -15,34 +15,508 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function13; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 13 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 + * @param the type of argument at position 12 + * @param the type of argument at position 13 * @since 0.3.0 */ -public class Arguments13 - extends Arguments12 { +public final class Arguments13 { + + 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; + + private final A11 arg11; + + private final A12 arg12; - protected final A13 arg13; + private final A13 arg13; + /** + * Creates a new Arguments13 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, arg12 the argument at position 12, + * arg13 the argument at position 13 + */ Arguments13(@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, @Nullable A12 arg12, @Nullable A13 arg13) { - super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + 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; + this.arg12 = arg12; this.arg13 = arg13; } + /** + * Returns the argument at position 1. + * @return the argument at position 1 + */ @Nullable - public final A13 arg13() { + 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; + } + + /** + * Returns the argument at position 11. + * @return the argument at position 11 + */ + @Nullable + public A11 arg11() { + return this.arg11; + } + + /** + * Returns the argument at position 12. + * @return the argument at position 12 + */ + @Nullable + public A12 arg12() { + return this.arg12; + } + + /** + * Returns the argument at position 13. + * @return the argument at position 13 + */ + @Nullable + public A13 arg13() { return this.arg13; } - 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( Function13 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); } + /** + * 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 Arguments11 instance containing only the first 11 arguments. + * @return an Arguments11 instance with arguments from arg1 to arg11 + * @since 0.16.0 + */ + public Arguments11 first11() { + return new Arguments11<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } + + /** + * Returns a new Arguments12 instance containing only the first 12 arguments. + * @return an Arguments12 instance with arguments from arg1 to arg12 + * @since 0.16.0 + */ + public Arguments12 first12() { + return new Arguments12<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg13 to arg13 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg13); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg12 to arg13 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg12, arg13); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg11 to arg13 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg11, arg12, arg13); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg10 to arg13 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg9 to arg13 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg8 to arg13 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments7 instance containing only the last 7 arguments. + * @return an Arguments7 instance with arguments from arg7 to arg13 + * @since 0.16.0 + */ + public Arguments7 last7() { + return new Arguments7<>(arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments8 instance containing only the last 8 arguments. + * @return an Arguments8 instance with arguments from arg6 to arg13 + * @since 0.16.0 + */ + public Arguments8 last8() { + return new Arguments8<>(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments9 instance containing only the last 9 arguments. + * @return an Arguments9 instance with arguments from arg5 to arg13 + * @since 0.16.0 + */ + public Arguments9 last9() { + return new Arguments9<>(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments10 instance containing only the last 10 arguments. + * @return an Arguments10 instance with arguments from arg4 to arg13 + * @since 0.16.0 + */ + public Arguments10 last10() { + return new Arguments10<>(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments11 instance containing only the last 11 arguments. + * @return an Arguments11 instance with arguments from arg3 to arg13 + * @since 0.16.0 + */ + public Arguments11 last11() { + return new Arguments11<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments12 instance containing only the last 12 arguments. + * @return an Arguments12 instance with arguments from arg2 to arg13 + * @since 0.16.0 + */ + public Arguments12 last12() { + return new Arguments12<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * 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 Arguments14 instance with the additional argument + * @since 0.16.0 + */ + public Arguments14 append(@Nullable B arg) { + return new Arguments14<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8, + this.arg9, this.arg10, this.arg11, this.arg12, this.arg13, 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 Arguments14 instance with the additional argument + * @since 0.16.0 + */ + public Arguments14 prepend(@Nullable B arg) { + return new Arguments14<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, + this.arg8, this.arg9, this.arg10, this.arg11, this.arg12, this.arg13); + } + + /** + * Returns a new Arguments13 instance with the arguments in reverse order. + * @return an Arguments13 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments13 reverse() { + return new Arguments13<>(arg13, arg12, 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; + } + Arguments13 that = (Arguments13) 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) && Objects.equals(this.arg12, that.arg12) + && Objects.equals(this.arg13, that.arg13); + } + + /** + * 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, this.arg12, this.arg13); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments13{" + "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 + ", " + "arg12=" + this.arg12 + ", " + "arg13=" + this.arg13 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments13Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments13Combining.java index a5ca2d06..ee2e6480 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments13Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments13Combining.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.Function13; 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 @@ -76,14 +80,44 @@ public Arguments13Combining(ValueValidator v1, ValueVal public Arguments1Validator apply( Function13 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), this.v12.validate(a, locale, constraintContext), - this.v13.validate(a, locale, constraintContext)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments13Combining.this.v1.validate(a, locale, constraintContext), + Arguments13Combining.this.v2.validate(a, locale, constraintContext), + Arguments13Combining.this.v3.validate(a, locale, constraintContext), + Arguments13Combining.this.v4.validate(a, locale, constraintContext), + Arguments13Combining.this.v5.validate(a, locale, constraintContext), + Arguments13Combining.this.v6.validate(a, locale, constraintContext), + Arguments13Combining.this.v7.validate(a, locale, constraintContext), + Arguments13Combining.this.v8.validate(a, locale, constraintContext), + Arguments13Combining.this.v9.validate(a, locale, constraintContext), + Arguments13Combining.this.v10.validate(a, locale, constraintContext), + Arguments13Combining.this.v11.validate(a, locale, constraintContext), + Arguments13Combining.this.v12.validate(a, locale, constraintContext), + Arguments13Combining.this.v13.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, r12, + r13) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13), + Arguments13Combining.this.v1.validate(a, locale, constraintContext), + Arguments13Combining.this.v2.validate(a, locale, constraintContext), + Arguments13Combining.this.v3.validate(a, locale, constraintContext), + Arguments13Combining.this.v4.validate(a, locale, constraintContext), + Arguments13Combining.this.v5.validate(a, locale, constraintContext), + Arguments13Combining.this.v6.validate(a, locale, constraintContext), + Arguments13Combining.this.v7.validate(a, locale, constraintContext), + Arguments13Combining.this.v8.validate(a, locale, constraintContext), + Arguments13Combining.this.v9.validate(a, locale, constraintContext), + Arguments13Combining.this.v10.validate(a, locale, constraintContext), + Arguments13Combining.this.v11.validate(a, locale, constraintContext), + Arguments13Combining.this.v12.validate(a, locale, constraintContext), + Arguments13Combining.this.v13.validate(a, locale, constraintContext)); + } + }; } public Arguments14Combining combine( diff --git a/src/main/java/am/ik/yavi/arguments/Arguments13Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments13Validator.java index 917f09c8..bf107d4c 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments13Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments13Validator.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,19 +35,95 @@ @FunctionalInterface public interface Arguments13Validator { + /** + * Convert an Arguments1Validator that validates Arguments13 to an + * Arguments13Validator + * @param validator validator for Arguments13 + * @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 type of argument at position 11 + * @param type of argument at position 12 + * @param type of argument at position 13 + * @param target result type + * @return arguments13 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments13Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments13Validator() { + @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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, Locale locale, + ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13), locale, + constraintContext); + } + + @Override + public Arguments13Validator> lazy() { + return Arguments13Validator.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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments13 as a single object. + * @return a validator that takes an Arguments13 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments13 args, + Locale locale, ConstraintContext constraintContext) { + final Arguments13 nonNullArgs = Objects + .requireNonNull(args); + return Arguments13Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), nonNullArgs.arg9(), nonNullArgs.arg10(), nonNullArgs.arg11(), + nonNullArgs.arg12(), nonNullArgs.arg13(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments13Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments13Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, locale, - constraintContext) -> Arguments13Validator.this + return new Arguments13Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, Locale locale, ConstraintContext constraintContext) { + return Arguments13Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, locale, constraintContext) .map(mapper); + } + + @Override + public Arguments13Validator> lazy() { + return Arguments13Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -54,10 +131,23 @@ default Arguments13Validator Arguments13Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, locale, - constraintContext) -> Arguments13Validator.this + return new Arguments13Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, Locale locale, ConstraintContext constraintContext) { + return Arguments13Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, locale, constraintContext) .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments13Validator> lazy() { + return Arguments13Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -65,12 +155,20 @@ default Arguments13Validator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments13 args = mapper - .apply(a); - return Arguments13Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), args.arg12(), - args.arg13(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments13 args = mapper + .apply(a); + return Arguments13Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), + args.arg12(), args.arg13(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments13Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments14.java b/src/main/java/am/ik/yavi/arguments/Arguments14.java index 95feff9a..70082b9d 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments14.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments14.java @@ -15,34 +15,541 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function14; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 14 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 + * @param the type of argument at position 12 + * @param the type of argument at position 13 + * @param the type of argument at position 14 * @since 0.3.0 */ -public class Arguments14 - extends Arguments13 { +public final class Arguments14 { + + 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; + + private final A11 arg11; + + private final A12 arg12; + + private final A13 arg13; - protected final A14 arg14; + private final A14 arg14; + /** + * Creates a new Arguments14 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, arg12 the argument at position 12, + * arg13 the argument at position 13, arg14 the argument at position 14 + */ Arguments14(@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, @Nullable A12 arg12, @Nullable A13 arg13, @Nullable A14 arg14) { - super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + 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; + this.arg12 = arg12; + this.arg13 = arg13; this.arg14 = arg14; } + /** + * 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 A5 arg5() { + return this.arg5; + } + + /** + * Returns the argument at position 6. + * @return the argument at position 6 + */ @Nullable - public final A14 arg14() { + 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; + } + + /** + * Returns the argument at position 12. + * @return the argument at position 12 + */ + @Nullable + public A12 arg12() { + return this.arg12; + } + + /** + * Returns the argument at position 13. + * @return the argument at position 13 + */ + @Nullable + public A13 arg13() { + return this.arg13; + } + + /** + * Returns the argument at position 14. + * @return the argument at position 14 + */ + @Nullable + public A14 arg14() { return this.arg14; } - 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( Function14 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); } + /** + * 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 Arguments11 instance containing only the first 11 arguments. + * @return an Arguments11 instance with arguments from arg1 to arg11 + * @since 0.16.0 + */ + public Arguments11 first11() { + return new Arguments11<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } + + /** + * Returns a new Arguments12 instance containing only the first 12 arguments. + * @return an Arguments12 instance with arguments from arg1 to arg12 + * @since 0.16.0 + */ + public Arguments12 first12() { + return new Arguments12<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments13 instance containing only the first 13 arguments. + * @return an Arguments13 instance with arguments from arg1 to arg13 + * @since 0.16.0 + */ + public Arguments13 first13() { + return new Arguments13<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg14 to arg14 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg14); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg13 to arg14 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg13, arg14); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg12 to arg14 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg12, arg13, arg14); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg11 to arg14 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg10 to arg14 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg9 to arg14 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments7 instance containing only the last 7 arguments. + * @return an Arguments7 instance with arguments from arg8 to arg14 + * @since 0.16.0 + */ + public Arguments7 last7() { + return new Arguments7<>(arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments8 instance containing only the last 8 arguments. + * @return an Arguments8 instance with arguments from arg7 to arg14 + * @since 0.16.0 + */ + public Arguments8 last8() { + return new Arguments8<>(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments9 instance containing only the last 9 arguments. + * @return an Arguments9 instance with arguments from arg6 to arg14 + * @since 0.16.0 + */ + public Arguments9 last9() { + return new Arguments9<>(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments10 instance containing only the last 10 arguments. + * @return an Arguments10 instance with arguments from arg5 to arg14 + * @since 0.16.0 + */ + public Arguments10 last10() { + return new Arguments10<>(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments11 instance containing only the last 11 arguments. + * @return an Arguments11 instance with arguments from arg4 to arg14 + * @since 0.16.0 + */ + public Arguments11 last11() { + return new Arguments11<>(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments12 instance containing only the last 12 arguments. + * @return an Arguments12 instance with arguments from arg3 to arg14 + * @since 0.16.0 + */ + public Arguments12 last12() { + return new Arguments12<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * Returns a new Arguments13 instance containing only the last 13 arguments. + * @return an Arguments13 instance with arguments from arg2 to arg14 + * @since 0.16.0 + */ + public Arguments13 last13() { + return new Arguments13<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } + + /** + * 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 Arguments15 instance with the additional argument + * @since 0.16.0 + */ + public Arguments15 append(@Nullable B arg) { + return new Arguments15<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8, + this.arg9, this.arg10, this.arg11, this.arg12, this.arg13, this.arg14, 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 Arguments15 instance with the additional argument + * @since 0.16.0 + */ + public Arguments15 prepend(@Nullable B arg) { + return new Arguments15<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, + this.arg8, this.arg9, this.arg10, this.arg11, this.arg12, this.arg13, this.arg14); + } + + /** + * Returns a new Arguments14 instance with the arguments in reverse order. + * @return an Arguments14 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments14 reverse() { + return new Arguments14<>(arg14, arg13, arg12, 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; + } + Arguments14 that = (Arguments14) 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) && Objects.equals(this.arg12, that.arg12) + && Objects.equals(this.arg13, that.arg13) && Objects.equals(this.arg14, that.arg14); + } + + /** + * 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, this.arg12, this.arg13, this.arg14); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments14{" + "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 + ", " + "arg12=" + this.arg12 + ", " + "arg13=" + this.arg13 + ", " + + "arg14=" + this.arg14 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments14Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments14Combining.java index b215880d..7c4f7729 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments14Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments14Combining.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.Function14; 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 @@ -79,14 +83,48 @@ public Arguments14Combining(ValueValidator v1, ValueVal public Arguments1Validator apply( Function14 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), this.v12.validate(a, locale, constraintContext), - this.v13.validate(a, locale, constraintContext), this.v14.validate(a, locale, constraintContext)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments14Combining.this.v1.validate(a, locale, constraintContext), + Arguments14Combining.this.v2.validate(a, locale, constraintContext), + Arguments14Combining.this.v3.validate(a, locale, constraintContext), + Arguments14Combining.this.v4.validate(a, locale, constraintContext), + Arguments14Combining.this.v5.validate(a, locale, constraintContext), + Arguments14Combining.this.v6.validate(a, locale, constraintContext), + Arguments14Combining.this.v7.validate(a, locale, constraintContext), + Arguments14Combining.this.v8.validate(a, locale, constraintContext), + Arguments14Combining.this.v9.validate(a, locale, constraintContext), + Arguments14Combining.this.v10.validate(a, locale, constraintContext), + Arguments14Combining.this.v11.validate(a, locale, constraintContext), + Arguments14Combining.this.v12.validate(a, locale, constraintContext), + Arguments14Combining.this.v13.validate(a, locale, constraintContext), + Arguments14Combining.this.v14.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, r12, r13, + r14) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, + r14), + Arguments14Combining.this.v1.validate(a, locale, constraintContext), + Arguments14Combining.this.v2.validate(a, locale, constraintContext), + Arguments14Combining.this.v3.validate(a, locale, constraintContext), + Arguments14Combining.this.v4.validate(a, locale, constraintContext), + Arguments14Combining.this.v5.validate(a, locale, constraintContext), + Arguments14Combining.this.v6.validate(a, locale, constraintContext), + Arguments14Combining.this.v7.validate(a, locale, constraintContext), + Arguments14Combining.this.v8.validate(a, locale, constraintContext), + Arguments14Combining.this.v9.validate(a, locale, constraintContext), + Arguments14Combining.this.v10.validate(a, locale, constraintContext), + Arguments14Combining.this.v11.validate(a, locale, constraintContext), + Arguments14Combining.this.v12.validate(a, locale, constraintContext), + Arguments14Combining.this.v13.validate(a, locale, constraintContext), + Arguments14Combining.this.v14.validate(a, locale, constraintContext)); + } + }; } public Arguments15Combining combine( diff --git a/src/main/java/am/ik/yavi/arguments/Arguments14Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments14Validator.java index a4ca8181..3ca0ae12 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments14Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments14Validator.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,20 +35,97 @@ @FunctionalInterface public interface Arguments14Validator { + /** + * Convert an Arguments1Validator that validates Arguments14 to an + * Arguments14Validator + * @param validator validator for Arguments14 + * @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 type of argument at position 11 + * @param type of argument at position 12 + * @param type of argument at position 13 + * @param type of argument at position 14 + * @param target result type + * @return arguments14 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments14Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments14Validator() { + @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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, @Nullable A14 a14, + Locale locale, ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14), + locale, constraintContext); + } + + @Override + public Arguments14Validator> lazy() { + return Arguments14Validator.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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, @Nullable A14 a14, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments14 as a single object. + * @return a validator that takes an Arguments14 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments14 args, + Locale locale, ConstraintContext constraintContext) { + final Arguments14 nonNullArgs = Objects + .requireNonNull(args); + return Arguments14Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), nonNullArgs.arg9(), nonNullArgs.arg10(), nonNullArgs.arg11(), + nonNullArgs.arg12(), nonNullArgs.arg13(), nonNullArgs.arg14(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments14Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments14Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, locale, - constraintContext) -> Arguments14Validator.this + return new Arguments14Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, A14 a14, Locale locale, ConstraintContext constraintContext) { + return Arguments14Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, locale, constraintContext) .map(mapper); + } + + @Override + public Arguments14Validator> lazy() { + return Arguments14Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -55,10 +133,23 @@ default Arguments14Validator Arguments14Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, locale, - constraintContext) -> Arguments14Validator.this + return new Arguments14Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, A14 a14, Locale locale, ConstraintContext constraintContext) { + return Arguments14Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, locale, constraintContext) .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments14Validator> lazy() { + return Arguments14Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -66,12 +157,20 @@ default Arguments14Validator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments14 args = mapper - .apply(a); - return Arguments14Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), args.arg12(), - args.arg13(), args.arg14(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments14 args = mapper + .apply(a); + return Arguments14Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), + args.arg12(), args.arg13(), args.arg14(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments14Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments15.java b/src/main/java/am/ik/yavi/arguments/Arguments15.java index ce57fd16..a2211268 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments15.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments15.java @@ -15,35 +15,579 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function15; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 15 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 + * @param the type of argument at position 12 + * @param the type of argument at position 13 + * @param the type of argument at position 14 + * @param the type of argument at position 15 * @since 0.3.0 */ -public class Arguments15 - extends Arguments14 { +public final class Arguments15 { + + 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; + + private final A11 arg11; + + private final A12 arg12; + + private final A13 arg13; + + private final A14 arg14; - protected final A15 arg15; + private final A15 arg15; + /** + * Creates a new Arguments15 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, arg12 the argument at position 12, + * arg13 the argument at position 13, arg14 the argument at position 14, arg15 the + * argument at position 15 + */ Arguments15(@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, @Nullable A12 arg12, @Nullable A13 arg13, @Nullable A14 arg14, @Nullable A15 arg15) { - super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + 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; + this.arg12 = arg12; + this.arg13 = arg13; + this.arg14 = arg14; this.arg15 = arg15; } + /** + * 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 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; + } + + /** + * Returns the argument at position 12. + * @return the argument at position 12 + */ + @Nullable + public A12 arg12() { + return this.arg12; + } + + /** + * Returns the argument at position 13. + * @return the argument at position 13 + */ + @Nullable + public A13 arg13() { + return this.arg13; + } + + /** + * Returns the argument at position 14. + * @return the argument at position 14 + */ + @Nullable + public A14 arg14() { + return this.arg14; + } + + /** + * Returns the argument at position 15. + * @return the argument at position 15 + */ @Nullable - public final A15 arg15() { + public A15 arg15() { return this.arg15; } - 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( Function15 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); } + /** + * 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 Arguments11 instance containing only the first 11 arguments. + * @return an Arguments11 instance with arguments from arg1 to arg11 + * @since 0.16.0 + */ + public Arguments11 first11() { + return new Arguments11<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } + + /** + * Returns a new Arguments12 instance containing only the first 12 arguments. + * @return an Arguments12 instance with arguments from arg1 to arg12 + * @since 0.16.0 + */ + public Arguments12 first12() { + return new Arguments12<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments13 instance containing only the first 13 arguments. + * @return an Arguments13 instance with arguments from arg1 to arg13 + * @since 0.16.0 + */ + public Arguments13 first13() { + return new Arguments13<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments14 instance containing only the first 14 arguments. + * @return an Arguments14 instance with arguments from arg1 to arg14 + * @since 0.16.0 + */ + public Arguments14 first14() { + return new Arguments14<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, + arg14); + } + + /** + * Returns a new Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg15 to arg15 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg15); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg14 to arg15 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg14, arg15); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg13 to arg15 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg13, arg14, arg15); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg12 to arg15 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg11 to arg15 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg10 to arg15 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments7 instance containing only the last 7 arguments. + * @return an Arguments7 instance with arguments from arg9 to arg15 + * @since 0.16.0 + */ + public Arguments7 last7() { + return new Arguments7<>(arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments8 instance containing only the last 8 arguments. + * @return an Arguments8 instance with arguments from arg8 to arg15 + * @since 0.16.0 + */ + public Arguments8 last8() { + return new Arguments8<>(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments9 instance containing only the last 9 arguments. + * @return an Arguments9 instance with arguments from arg7 to arg15 + * @since 0.16.0 + */ + public Arguments9 last9() { + return new Arguments9<>(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments10 instance containing only the last 10 arguments. + * @return an Arguments10 instance with arguments from arg6 to arg15 + * @since 0.16.0 + */ + public Arguments10 last10() { + return new Arguments10<>(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments11 instance containing only the last 11 arguments. + * @return an Arguments11 instance with arguments from arg5 to arg15 + * @since 0.16.0 + */ + public Arguments11 last11() { + return new Arguments11<>(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments12 instance containing only the last 12 arguments. + * @return an Arguments12 instance with arguments from arg4 to arg15 + * @since 0.16.0 + */ + public Arguments12 last12() { + return new Arguments12<>(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments13 instance containing only the last 13 arguments. + * @return an Arguments13 instance with arguments from arg3 to arg15 + * @since 0.16.0 + */ + public Arguments13 last13() { + return new Arguments13<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } + + /** + * Returns a new Arguments14 instance containing only the last 14 arguments. + * @return an Arguments14 instance with arguments from arg2 to arg15 + * @since 0.16.0 + */ + public Arguments14 last14() { + return new Arguments14<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, + arg15); + } + + /** + * 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 Arguments16 instance with the additional argument + * @since 0.16.0 + */ + public Arguments16 append( + @Nullable B arg) { + return new Arguments16<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8, + this.arg9, this.arg10, this.arg11, this.arg12, this.arg13, this.arg14, this.arg15, 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 Arguments16 instance with the additional argument + * @since 0.16.0 + */ + public Arguments16 prepend( + @Nullable B arg) { + return new Arguments16<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, + this.arg8, this.arg9, this.arg10, this.arg11, this.arg12, this.arg13, this.arg14, this.arg15); + } + + /** + * Returns a new Arguments15 instance with the arguments in reverse order. + * @return an Arguments15 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments15 reverse() { + return new Arguments15<>(arg15, arg14, arg13, arg12, 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; + } + Arguments15 that = (Arguments15) 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) && Objects.equals(this.arg12, that.arg12) + && Objects.equals(this.arg13, that.arg13) && Objects.equals(this.arg14, that.arg14) + && Objects.equals(this.arg15, that.arg15); + } + + /** + * 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, this.arg12, this.arg13, this.arg14, this.arg15); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments15{" + "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 + ", " + "arg12=" + this.arg12 + ", " + "arg13=" + this.arg13 + ", " + + "arg14=" + this.arg14 + ", " + "arg15=" + this.arg15 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments15Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments15Combining.java index f5484ec9..b1286c63 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments15Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments15Combining.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.Function15; 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 @@ -83,15 +87,50 @@ public Arguments15Combining(ValueValidator v1, ValueVal public Arguments1Validator apply( Function15 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), this.v12.validate(a, locale, constraintContext), - this.v13.validate(a, locale, constraintContext), this.v14.validate(a, locale, constraintContext), - this.v15.validate(a, locale, constraintContext)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments15Combining.this.v1.validate(a, locale, constraintContext), + Arguments15Combining.this.v2.validate(a, locale, constraintContext), + Arguments15Combining.this.v3.validate(a, locale, constraintContext), + Arguments15Combining.this.v4.validate(a, locale, constraintContext), + Arguments15Combining.this.v5.validate(a, locale, constraintContext), + Arguments15Combining.this.v6.validate(a, locale, constraintContext), + Arguments15Combining.this.v7.validate(a, locale, constraintContext), + Arguments15Combining.this.v8.validate(a, locale, constraintContext), + Arguments15Combining.this.v9.validate(a, locale, constraintContext), + Arguments15Combining.this.v10.validate(a, locale, constraintContext), + Arguments15Combining.this.v11.validate(a, locale, constraintContext), + Arguments15Combining.this.v12.validate(a, locale, constraintContext), + Arguments15Combining.this.v13.validate(a, locale, constraintContext), + Arguments15Combining.this.v14.validate(a, locale, constraintContext), + Arguments15Combining.this.v15.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, r12, r13, r14, + r15) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, + r14, r15), + Arguments15Combining.this.v1.validate(a, locale, constraintContext), + Arguments15Combining.this.v2.validate(a, locale, constraintContext), + Arguments15Combining.this.v3.validate(a, locale, constraintContext), + Arguments15Combining.this.v4.validate(a, locale, constraintContext), + Arguments15Combining.this.v5.validate(a, locale, constraintContext), + Arguments15Combining.this.v6.validate(a, locale, constraintContext), + Arguments15Combining.this.v7.validate(a, locale, constraintContext), + Arguments15Combining.this.v8.validate(a, locale, constraintContext), + Arguments15Combining.this.v9.validate(a, locale, constraintContext), + Arguments15Combining.this.v10.validate(a, locale, constraintContext), + Arguments15Combining.this.v11.validate(a, locale, constraintContext), + Arguments15Combining.this.v12.validate(a, locale, constraintContext), + Arguments15Combining.this.v13.validate(a, locale, constraintContext), + Arguments15Combining.this.v14.validate(a, locale, constraintContext), + Arguments15Combining.this.v15.validate(a, locale, constraintContext)); + } + }; } public Arguments16Combining combine( diff --git a/src/main/java/am/ik/yavi/arguments/Arguments15Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments15Validator.java index 0897ca30..de62fa89 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments15Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments15Validator.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,21 +35,102 @@ @FunctionalInterface public interface Arguments15Validator { + /** + * Convert an Arguments1Validator that validates Arguments15 to an + * Arguments15Validator + * @param validator validator for Arguments15 + * @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 type of argument at position 11 + * @param type of argument at position 12 + * @param type of argument at position 13 + * @param type of argument at position 14 + * @param type of argument at position 15 + * @param target result type + * @return arguments15 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments15Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments15Validator() { + @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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, @Nullable A14 a14, + @Nullable A15 a15, Locale locale, ConstraintContext constraintContext) { + return validator.validate( + Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15), locale, + constraintContext); + } + + @Override + public Arguments15Validator> lazy() { + return Arguments15Validator.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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, @Nullable A14 a14, @Nullable A15 a15, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments15 as a single object. + * @return a validator that takes an Arguments15 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate( + Arguments15 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments15 nonNullArgs = Objects + .requireNonNull(args); + return Arguments15Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), nonNullArgs.arg9(), nonNullArgs.arg10(), nonNullArgs.arg11(), + nonNullArgs.arg12(), nonNullArgs.arg13(), nonNullArgs.arg14(), nonNullArgs.arg15(), locale, + constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments15Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments15Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, locale, - constraintContext) -> Arguments15Validator.this + return new Arguments15Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, A14 a14, A15 a15, Locale locale, ConstraintContext constraintContext) { + return Arguments15Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, locale, constraintContext) .map(mapper); + } + + @Override + public Arguments15Validator> lazy() { + return Arguments15Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -56,11 +138,24 @@ default Arguments15Validator Arguments15Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, locale, - constraintContext) -> Arguments15Validator.this + return new Arguments15Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, A14 a14, A15 a15, Locale locale, ConstraintContext constraintContext) { + return Arguments15Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, locale, constraintContext) .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments15Validator> lazy() { + return Arguments15Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -68,12 +163,20 @@ default Arguments15Validator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments15 args = mapper - .apply(a); - return Arguments15Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), args.arg12(), - args.arg13(), args.arg14(), args.arg15(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments15 args = mapper + .apply(a); + return Arguments15Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), + args.arg12(), args.arg13(), args.arg14(), args.arg15(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments15Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments16.java b/src/main/java/am/ik/yavi/arguments/Arguments16.java index 13cbc670..2a55fc7c 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments16.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments16.java @@ -15,36 +15,587 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function16; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 16 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 + * @param the type of argument at position 12 + * @param the type of argument at position 13 + * @param the type of argument at position 14 + * @param the type of argument at position 15 + * @param the type of argument at position 16 * @since 0.3.0 */ -public class Arguments16 - extends Arguments15 { +public final class Arguments16 { + + 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; + + private final A11 arg11; + + private final A12 arg12; + + private final A13 arg13; + + private final A14 arg14; + + private final A15 arg15; - protected final A16 arg16; + private final A16 arg16; + /** + * Creates a new Arguments16 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, arg12 the argument at position 12, + * arg13 the argument at position 13, arg14 the argument at position 14, arg15 the + * argument at position 15, arg16 the argument at position 16 + */ Arguments16(@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, @Nullable A12 arg12, @Nullable A13 arg13, @Nullable A14 arg14, @Nullable A15 arg15, @Nullable A16 arg16) { - super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + 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; + this.arg12 = arg12; + this.arg13 = arg13; + this.arg14 = arg14; + this.arg15 = arg15; this.arg16 = arg16; } + /** + * 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 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; + } + + /** + * Returns the argument at position 12. + * @return the argument at position 12 + */ @Nullable - public final A16 arg16() { + public A12 arg12() { + return this.arg12; + } + + /** + * Returns the argument at position 13. + * @return the argument at position 13 + */ + @Nullable + public A13 arg13() { + return this.arg13; + } + + /** + * Returns the argument at position 14. + * @return the argument at position 14 + */ + @Nullable + public A14 arg14() { + return this.arg14; + } + + /** + * Returns the argument at position 15. + * @return the argument at position 15 + */ + @Nullable + public A15 arg15() { + return this.arg15; + } + + /** + * Returns the argument at position 16. + * @return the argument at position 16 + */ + @Nullable + public A16 arg16() { return this.arg16; } - 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( Function16 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); } + /** + * 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 Arguments11 instance containing only the first 11 arguments. + * @return an Arguments11 instance with arguments from arg1 to arg11 + * @since 0.16.0 + */ + public Arguments11 first11() { + return new Arguments11<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } + + /** + * Returns a new Arguments12 instance containing only the first 12 arguments. + * @return an Arguments12 instance with arguments from arg1 to arg12 + * @since 0.16.0 + */ + public Arguments12 first12() { + return new Arguments12<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } + + /** + * Returns a new Arguments13 instance containing only the first 13 arguments. + * @return an Arguments13 instance with arguments from arg1 to arg13 + * @since 0.16.0 + */ + public Arguments13 first13() { + return new Arguments13<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } + + /** + * Returns a new Arguments14 instance containing only the first 14 arguments. + * @return an Arguments14 instance with arguments from arg1 to arg14 + * @since 0.16.0 + */ + public Arguments14 first14() { + return new Arguments14<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, + arg14); + } + + /** + * Returns a new Arguments15 instance containing only the first 15 arguments. + * @return an Arguments15 instance with arguments from arg1 to arg15 + * @since 0.16.0 + */ + public Arguments15 first15() { + return new Arguments15<>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, + arg14, arg15); + } + + /** + * Returns a new Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg16 to arg16 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg16); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg15 to arg16 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg15, arg16); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg14 to arg16 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg14, arg15, arg16); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg13 to arg16 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg12 to arg16 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg11 to arg16 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments7 instance containing only the last 7 arguments. + * @return an Arguments7 instance with arguments from arg10 to arg16 + * @since 0.16.0 + */ + public Arguments7 last7() { + return new Arguments7<>(arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments8 instance containing only the last 8 arguments. + * @return an Arguments8 instance with arguments from arg9 to arg16 + * @since 0.16.0 + */ + public Arguments8 last8() { + return new Arguments8<>(arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments9 instance containing only the last 9 arguments. + * @return an Arguments9 instance with arguments from arg8 to arg16 + * @since 0.16.0 + */ + public Arguments9 last9() { + return new Arguments9<>(arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments10 instance containing only the last 10 arguments. + * @return an Arguments10 instance with arguments from arg7 to arg16 + * @since 0.16.0 + */ + public Arguments10 last10() { + return new Arguments10<>(arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments11 instance containing only the last 11 arguments. + * @return an Arguments11 instance with arguments from arg6 to arg16 + * @since 0.16.0 + */ + public Arguments11 last11() { + return new Arguments11<>(arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments12 instance containing only the last 12 arguments. + * @return an Arguments12 instance with arguments from arg5 to arg16 + * @since 0.16.0 + */ + public Arguments12 last12() { + return new Arguments12<>(arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments13 instance containing only the last 13 arguments. + * @return an Arguments13 instance with arguments from arg4 to arg16 + * @since 0.16.0 + */ + public Arguments13 last13() { + return new Arguments13<>(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } + + /** + * Returns a new Arguments14 instance containing only the last 14 arguments. + * @return an Arguments14 instance with arguments from arg3 to arg16 + * @since 0.16.0 + */ + public Arguments14 last14() { + return new Arguments14<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, + arg16); + } + + /** + * Returns a new Arguments15 instance containing only the last 15 arguments. + * @return an Arguments15 instance with arguments from arg2 to arg16 + * @since 0.16.0 + */ + public Arguments15 last15() { + return new Arguments15<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, + arg15, arg16); + } + + /** + * Returns a new Arguments16 instance with the arguments in reverse order. + * @return an Arguments16 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments16 reverse() { + return new Arguments16<>(arg16, arg15, arg14, arg13, arg12, 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; + } + Arguments16 that = (Arguments16) 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) && Objects.equals(this.arg12, that.arg12) + && Objects.equals(this.arg13, that.arg13) && Objects.equals(this.arg14, that.arg14) + && Objects.equals(this.arg15, that.arg15) && Objects.equals(this.arg16, that.arg16); + } + + /** + * 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, this.arg12, this.arg13, this.arg14, this.arg15, this.arg16); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments16{" + "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 + ", " + "arg12=" + this.arg12 + ", " + "arg13=" + this.arg13 + ", " + + "arg14=" + this.arg14 + ", " + "arg15=" + this.arg15 + ", " + "arg16=" + this.arg16 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments16Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments16Combining.java index 505a1b50..72d3e676 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments16Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments16Combining.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.Function16; 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 @@ -86,15 +90,51 @@ public Arguments16Combining(ValueValidator v1, ValueVal public Arguments1Validator apply( Function16 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), this.v12.validate(a, locale, constraintContext), - this.v13.validate(a, locale, constraintContext), this.v14.validate(a, locale, constraintContext), - this.v15.validate(a, locale, constraintContext), this.v16.validate(a, locale, constraintContext)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments16Combining.this.v1.validate(a, locale, constraintContext), + Arguments16Combining.this.v2.validate(a, locale, constraintContext), + Arguments16Combining.this.v3.validate(a, locale, constraintContext), + Arguments16Combining.this.v4.validate(a, locale, constraintContext), + Arguments16Combining.this.v5.validate(a, locale, constraintContext), + Arguments16Combining.this.v6.validate(a, locale, constraintContext), + Arguments16Combining.this.v7.validate(a, locale, constraintContext), + Arguments16Combining.this.v8.validate(a, locale, constraintContext), + Arguments16Combining.this.v9.validate(a, locale, constraintContext), + Arguments16Combining.this.v10.validate(a, locale, constraintContext), + Arguments16Combining.this.v11.validate(a, locale, constraintContext), + Arguments16Combining.this.v12.validate(a, locale, constraintContext), + Arguments16Combining.this.v13.validate(a, locale, constraintContext), + Arguments16Combining.this.v14.validate(a, locale, constraintContext), + Arguments16Combining.this.v15.validate(a, locale, constraintContext), + Arguments16Combining.this.v16.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, r12, r13, r14, r15, + r16) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, + r16), + Arguments16Combining.this.v1.validate(a, locale, constraintContext), + Arguments16Combining.this.v2.validate(a, locale, constraintContext), + Arguments16Combining.this.v3.validate(a, locale, constraintContext), + Arguments16Combining.this.v4.validate(a, locale, constraintContext), + Arguments16Combining.this.v5.validate(a, locale, constraintContext), + Arguments16Combining.this.v6.validate(a, locale, constraintContext), + Arguments16Combining.this.v7.validate(a, locale, constraintContext), + Arguments16Combining.this.v8.validate(a, locale, constraintContext), + Arguments16Combining.this.v9.validate(a, locale, constraintContext), + Arguments16Combining.this.v10.validate(a, locale, constraintContext), + Arguments16Combining.this.v11.validate(a, locale, constraintContext), + Arguments16Combining.this.v12.validate(a, locale, constraintContext), + Arguments16Combining.this.v13.validate(a, locale, constraintContext), + Arguments16Combining.this.v14.validate(a, locale, constraintContext), + Arguments16Combining.this.v15.validate(a, locale, constraintContext), + Arguments16Combining.this.v16.validate(a, locale, constraintContext)); + } + }; } } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments16Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments16Validator.java index e2348707..3582f161 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments16Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments16Validator.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,21 +35,104 @@ @FunctionalInterface public interface Arguments16Validator { + /** + * Convert an Arguments1Validator that validates Arguments16 to an + * Arguments16Validator + * @param validator validator for Arguments16 + * @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 type of argument at position 11 + * @param type of argument at position 12 + * @param type of argument at position 13 + * @param type of argument at position 14 + * @param type of argument at position 15 + * @param type of argument at position 16 + * @param target result type + * @return arguments16 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments16Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments16Validator() { + @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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, @Nullable A14 a14, + @Nullable A15 a15, @Nullable A16 a16, Locale locale, ConstraintContext constraintContext) { + return validator.validate( + Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16), locale, + constraintContext); + } + + @Override + public Arguments16Validator> lazy() { + return Arguments16Validator.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, @Nullable A11 a11, @Nullable A12 a12, @Nullable A13 a13, @Nullable A14 a14, @Nullable A15 a15, @Nullable A16 a16, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments16 as a single object. + * @return a validator that takes an Arguments16 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate( + Arguments16 args, + Locale locale, ConstraintContext constraintContext) { + final Arguments16 nonNullArgs = Objects + .requireNonNull(args); + return Arguments16Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), nonNullArgs.arg9(), nonNullArgs.arg10(), nonNullArgs.arg11(), + nonNullArgs.arg12(), nonNullArgs.arg13(), nonNullArgs.arg14(), nonNullArgs.arg15(), + nonNullArgs.arg16(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments16Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments16Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, locale, - constraintContext) -> Arguments16Validator.this + return new Arguments16Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, A14 a14, A15 a15, A16 a16, Locale locale, + ConstraintContext constraintContext) { + return Arguments16Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, locale, constraintContext) .map(mapper); + } + + @Override + public Arguments16Validator> lazy() { + return Arguments16Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -56,11 +140,25 @@ default Arguments16Validator Arguments16Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, locale, - constraintContext) -> Arguments16Validator.this + return new Arguments16Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, + A11 a11, A12 a12, A13 a13, A14 a14, A15 a15, A16 a16, Locale locale, + ConstraintContext constraintContext) { + return Arguments16Validator.this .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, locale, constraintContext) .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments16Validator> lazy() { + return Arguments16Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -68,12 +166,21 @@ default Arguments16Validator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments16 args = mapper - .apply(a); - return Arguments16Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), args.arg12(), - args.arg13(), args.arg14(), args.arg15(), args.arg16(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments16 args = mapper + .apply(a); + return Arguments16Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), args.arg10(), args.arg11(), + args.arg12(), args.arg13(), args.arg14(), args.arg15(), args.arg16(), locale, + constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments16Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments1Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments1Validator.java index 1deb36ba..8ed2de6e 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments1Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments1Validator.java @@ -18,6 +18,7 @@ import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Function; @@ -62,16 +63,69 @@ static Arguments1Validator from(ValueValidator valueValida 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()); + } + }; + } + @Override Validated validate(@Nullable A1 a1, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments1 as a single object. + * @return a validator that takes an Arguments1 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments1 args, Locale locale, ConstraintContext constraintContext) { + final Arguments1 nonNullArgs = Objects.requireNonNull(args); + return Arguments1Validator.this.validate(nonNullArgs.arg1(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments1Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ @Override default Arguments1Validator andThen(Function mapper) { - return (a1, locale, constraintContext) -> Arguments1Validator.this.validate(a1, locale, constraintContext) - .map(mapper); + return new Arguments1Validator() { + @Override + public Validated validate(A1 a1, Locale locale, ConstraintContext constraintContext) { + return Arguments1Validator.this.validate(a1, locale, constraintContext).map(mapper); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments1Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -79,8 +133,21 @@ default Arguments1Validator andThen(Function Arguments1Validator andThen(ValueValidator validator) { - return (a1, locale, constraintContext) -> Arguments1Validator.this.validate(a1, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments1Validator() { + @Override + public Validated validate(A1 a1, Locale locale, ConstraintContext constraintContext) { + return Arguments1Validator.this.validate(a1, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments1Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -88,8 +155,17 @@ default Arguments1Validator andThen(ValueValidator v */ @Override default Arguments1Validator compose(Function mapper) { - return (a, locale, constraintContext) -> Arguments1Validator.this.validate(mapper.apply(a), locale, - constraintContext); + 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); + } + }; } /** diff --git a/src/main/java/am/ik/yavi/arguments/Arguments2.java b/src/main/java/am/ik/yavi/arguments/Arguments2.java index e6b3c810..d2a7fb38 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments2.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments2.java @@ -15,30 +15,147 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function2; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 2 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 * @since 0.3.0 */ -public class Arguments2 extends Arguments1 { +public final class Arguments2 { + + private final A1 arg1; - protected final A2 arg2; + private final A2 arg2; + /** + * Creates a new Arguments2 instance with the provided arguments. + * @param arg1 the argument at position 1, arg2 the argument at position 2 + */ Arguments2(@Nullable A1 arg1, @Nullable A2 arg2) { - super(arg1); + this.arg1 = arg1; this.arg2 = arg2; } + /** + * 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 final A2 arg2() { + public A2 arg2() { return this.arg2; } - public final X map(Function2 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(Function2 mapper) { return mapper.apply(arg1, arg2); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg2 to arg2 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg2); + } + + /** + * 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 Arguments3 instance with the additional argument + * @since 0.16.0 + */ + public Arguments3 append(@Nullable B arg) { + return new Arguments3<>(this.arg1, this.arg2, 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 Arguments3 instance with the additional argument + * @since 0.16.0 + */ + public Arguments3 prepend(@Nullable B arg) { + return new Arguments3<>(arg, this.arg1, this.arg2); + } + + /** + * Returns a new Arguments2 instance with the arguments in reverse order. + * @return an Arguments2 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments2 reverse() { + return new Arguments2<>(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; + } + Arguments2 that = (Arguments2) obj; + return Objects.equals(this.arg1, that.arg1) && Objects.equals(this.arg2, that.arg2); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments2{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments2Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments2Combining.java index 1c63b7c8..8919348b 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments2Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments2Combining.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.Function2; 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 @@ -36,8 +40,20 @@ public Arguments2Combining(ValueValidator v1, ValueVali } public Arguments1Validator apply(Function2 f) { - return (a, locale, constraintContext) -> Validations.apply(f::apply, - this.v1.validate(a, locale, constraintContext), this.v2.validate(a, locale, constraintContext)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments2Combining.this.v1.validate(a, locale, constraintContext), + Arguments2Combining.this.v2.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply((r1, r2) -> () -> f.apply(r1, r2), + Arguments2Combining.this.v1.validate(a, locale, constraintContext), + Arguments2Combining.this.v2.validate(a, locale, constraintContext)); + } + }; } public Arguments3Combining combine(ValueValidator v3) { diff --git a/src/main/java/am/ik/yavi/arguments/Arguments2Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments2Validator.java index a4b26f41..cd70fe15 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments2Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments2Validator.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,23 +35,90 @@ @FunctionalInterface public interface Arguments2Validator { + /** + * Convert an Arguments1Validator that validates Arguments2 to an Arguments2Validator + * @param validator validator for Arguments2 + * @param type of first argument + * @param type of argument at position 2 + * @param target result type + * @return arguments2 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments2Validator unwrap(Arguments1Validator, X> validator) { + return new Arguments2Validator() { + @Override + public Validated validate(@Nullable A1 a1, @Nullable A2 a2, Locale locale, + ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2), locale, constraintContext); + } + + @Override + public Arguments2Validator> lazy() { + return Arguments2Validator.unwrap(validator.lazy()); + } + }; + } + Validated validate(@Nullable A1 a1, @Nullable A2 a2, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments2 as a single object. + * @return a validator that takes an Arguments2 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments2 args, Locale locale, ConstraintContext constraintContext) { + final Arguments2 nonNullArgs = Objects.requireNonNull(args); + return Arguments2Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), locale, + constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments2Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments2Validator andThen(Function mapper) { - return (a1, a2, locale, - constraintContext) -> Arguments2Validator.this.validate(a1, a2, locale, constraintContext).map(mapper); + return new Arguments2Validator() { + @Override + public Validated validate(A1 a1, A2 a2, Locale locale, ConstraintContext constraintContext) { + return Arguments2Validator.this.validate(a1, a2, locale, constraintContext).map(mapper); + } + + @Override + public Arguments2Validator> lazy() { + return Arguments2Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** * @since 0.11.0 */ default Arguments2Validator andThen(ValueValidator validator) { - return (a1, a2, locale, constraintContext) -> Arguments2Validator.this - .validate(a1, a2, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments2Validator() { + @Override + public Validated validate(A1 a1, A2 a2, Locale locale, ConstraintContext constraintContext) { + return Arguments2Validator.this.validate(a1, a2, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments2Validator> lazy() { + return Arguments2Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -58,9 +126,17 @@ default Arguments2Validator andThen(ValueValidator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments2 args = mapper.apply(a); - return Arguments2Validator.this.validate(args.arg1(), args.arg2(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments2 args = mapper.apply(a); + return Arguments2Validator.this.validate(args.arg1(), args.arg2(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments2Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments3.java b/src/main/java/am/ik/yavi/arguments/Arguments3.java index 1b53fff9..2b2d105d 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments3.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments3.java @@ -15,30 +15,180 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function3; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 3 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 * @since 0.3.0 */ -public class Arguments3 extends Arguments2 { +public final class Arguments3 { + + private final A1 arg1; + + private final A2 arg2; - protected final A3 arg3; + private final A3 arg3; + /** + * Creates a new Arguments3 instance with the provided arguments. + * @param arg1 the argument at position 1, arg2 the argument at position 2, arg3 the + * argument at position 3 + */ Arguments3(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3) { - super(arg1, arg2); + this.arg1 = arg1; + this.arg2 = arg2; this.arg3 = arg3; } + /** + * Returns the argument at position 1. + * @return the argument at position 1 + */ @Nullable - public final A3 arg3() { + 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; } - public final X map(Function3 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(Function3 mapper) { return mapper.apply(arg1, arg2, arg3); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg3 to arg3 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg3); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg2 to arg3 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg2, arg3); + } + + /** + * 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 Arguments4 instance with the additional argument + * @since 0.16.0 + */ + public Arguments4 append(@Nullable B arg) { + return new Arguments4<>(this.arg1, this.arg2, this.arg3, 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 Arguments4 instance with the additional argument + * @since 0.16.0 + */ + public Arguments4 prepend(@Nullable B arg) { + return new Arguments4<>(arg, this.arg1, this.arg2, this.arg3); + } + + /** + * Returns a new Arguments3 instance with the arguments in reverse order. + * @return an Arguments3 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments3 reverse() { + return new Arguments3<>(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; + } + Arguments3 that = (Arguments3) obj; + return Objects.equals(this.arg1, that.arg1) && Objects.equals(this.arg2, that.arg2) + && Objects.equals(this.arg3, that.arg3); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments3{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments3Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments3Combining.java index 976aad27..408dca53 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments3Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments3Combining.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.Function3; 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 @@ -40,9 +44,22 @@ public Arguments3Combining(ValueValidator v1, ValueVali } public Arguments1Validator apply(Function3 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)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments3Combining.this.v1.validate(a, locale, constraintContext), + Arguments3Combining.this.v2.validate(a, locale, constraintContext), + Arguments3Combining.this.v3.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply((r1, r2, r3) -> () -> f.apply(r1, r2, r3), + Arguments3Combining.this.v1.validate(a, locale, constraintContext), + Arguments3Combining.this.v2.validate(a, locale, constraintContext), + Arguments3Combining.this.v3.validate(a, locale, constraintContext)); + } + }; } public Arguments4Combining combine(ValueValidator v4) { diff --git a/src/main/java/am/ik/yavi/arguments/Arguments3Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments3Validator.java index 3e865855..61936614 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments3Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments3Validator.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,25 +35,94 @@ @FunctionalInterface public interface Arguments3Validator { + /** + * Convert an Arguments1Validator that validates Arguments3 to an Arguments3Validator + * @param validator validator for Arguments3 + * @param type of first argument + * @param type of argument at position 2 + * @param type of argument at position 3 + * @param target result type + * @return arguments3 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments3Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments3Validator() { + @Override + public Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, Locale locale, + ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3), locale, constraintContext); + } + + @Override + public Arguments3Validator> lazy() { + return Arguments3Validator.unwrap(validator.lazy()); + } + }; + } + Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments3 as a single object. + * @return a validator that takes an Arguments3 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments3 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments3 nonNullArgs = Objects.requireNonNull(args); + return Arguments3Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments3Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments3Validator andThen(Function mapper) { - return (a1, a2, a3, locale, constraintContext) -> Arguments3Validator.this - .validate(a1, a2, a3, locale, constraintContext) - .map(mapper); + return new Arguments3Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, Locale locale, ConstraintContext constraintContext) { + return Arguments3Validator.this.validate(a1, a2, a3, locale, constraintContext).map(mapper); + } + + @Override + public Arguments3Validator> lazy() { + return Arguments3Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** * @since 0.11.0 */ default Arguments3Validator andThen(ValueValidator validator) { - return (a1, a2, a3, locale, constraintContext) -> Arguments3Validator.this - .validate(a1, a2, a3, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments3Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, Locale locale, ConstraintContext constraintContext) { + return Arguments3Validator.this.validate(a1, a2, a3, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments3Validator> lazy() { + return Arguments3Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -60,9 +130,18 @@ default Arguments3Validator andThen(ValueValidator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments3 args = mapper.apply(a); - return Arguments3Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments3 args = mapper.apply(a); + return Arguments3Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), locale, + constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments3Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments4.java b/src/main/java/am/ik/yavi/arguments/Arguments4.java index 7dd343dd..9b3f803e 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments4.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments4.java @@ -15,30 +15,212 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function4; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 4 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 * @since 0.3.0 */ -public class Arguments4 extends Arguments3 { +public final class Arguments4 { + + private final A1 arg1; + + private final A2 arg2; + + private final A3 arg3; - protected final A4 arg4; + private final A4 arg4; + /** + * Creates a new Arguments4 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 + */ Arguments4(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3, @Nullable A4 arg4) { - super(arg1, arg2, arg3); + this.arg1 = arg1; + this.arg2 = arg2; + this.arg3 = arg3; this.arg4 = arg4; } + /** + * Returns the argument at position 1. + * @return the argument at position 1 + */ @Nullable - public final A4 arg4() { + 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; } - public final X map(Function4 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(Function4 mapper) { return mapper.apply(arg1, arg2, arg3, arg4); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg4 to arg4 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg4); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg3 to arg4 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg3, arg4); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg2 to arg4 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg2, arg3, arg4); + } + + /** + * 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 Arguments5 instance with the additional argument + * @since 0.16.0 + */ + public Arguments5 append(@Nullable B arg) { + return new Arguments5<>(this.arg1, this.arg2, this.arg3, this.arg4, 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 Arguments5 instance with the additional argument + * @since 0.16.0 + */ + public Arguments5 prepend(@Nullable B arg) { + return new Arguments5<>(arg, this.arg1, this.arg2, this.arg3, this.arg4); + } + + /** + * Returns a new Arguments4 instance with the arguments in reverse order. + * @return an Arguments4 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments4 reverse() { + return new Arguments4<>(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; + } + Arguments4 that = (Arguments4) 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); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments4{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + ", " + + "arg4=" + this.arg4 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments4Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments4Combining.java index 95cd0380..bd8f9f28 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments4Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments4Combining.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.Function4; 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 @@ -44,9 +48,25 @@ public Arguments4Combining(ValueValidator v1, ValueVali public Arguments1Validator apply( Function4 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)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments4Combining.this.v1.validate(a, locale, constraintContext), + Arguments4Combining.this.v2.validate(a, locale, constraintContext), + Arguments4Combining.this.v3.validate(a, locale, constraintContext), + Arguments4Combining.this.v4.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply( + (r1, r2, r3, r4) -> () -> f.apply(r1, r2, r3, r4), + Arguments4Combining.this.v1.validate(a, locale, constraintContext), + Arguments4Combining.this.v2.validate(a, locale, constraintContext), + Arguments4Combining.this.v3.validate(a, locale, constraintContext), + Arguments4Combining.this.v4.validate(a, locale, constraintContext)); + } + }; } public Arguments5Combining combine(ValueValidator v5) { diff --git a/src/main/java/am/ik/yavi/arguments/Arguments4Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments4Validator.java index 035b4a72..78d7d08a 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments4Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments4Validator.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,25 +35,98 @@ @FunctionalInterface public interface Arguments4Validator { + /** + * Convert an Arguments1Validator that validates Arguments4 to an Arguments4Validator + * @param validator validator for Arguments4 + * @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 target result type + * @return arguments4 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments4Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments4Validator() { + @Override + public Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4, + Locale locale, ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4), locale, constraintContext); + } + + @Override + public Arguments4Validator> lazy() { + return Arguments4Validator.unwrap(validator.lazy()); + } + }; + } + Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments4 as a single object. + * @return a validator that takes an Arguments4 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments4 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments4 nonNullArgs = Objects + .requireNonNull(args); + return Arguments4Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments4Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments4Validator andThen(Function mapper) { - return (a1, a2, a3, a4, locale, constraintContext) -> Arguments4Validator.this - .validate(a1, a2, a3, a4, locale, constraintContext) - .map(mapper); + return new Arguments4Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, Locale locale, + ConstraintContext constraintContext) { + return Arguments4Validator.this.validate(a1, a2, a3, a4, locale, constraintContext).map(mapper); + } + + @Override + public Arguments4Validator> lazy() { + return Arguments4Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** * @since 0.11.0 */ default Arguments4Validator andThen(ValueValidator validator) { - return (a1, a2, a3, a4, locale, constraintContext) -> Arguments4Validator.this - .validate(a1, a2, a3, a4, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments4Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, Locale locale, + ConstraintContext constraintContext) { + return Arguments4Validator.this.validate(a1, a2, a3, a4, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments4Validator> lazy() { + return Arguments4Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -60,10 +134,18 @@ default Arguments4Validator andThen(ValueValidator Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments4 args = mapper.apply(a); - return Arguments4Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), locale, - constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments4 args = mapper.apply(a); + return Arguments4Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), locale, + constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments4Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments5.java b/src/main/java/am/ik/yavi/arguments/Arguments5.java index 71f20ccd..ff3ead15 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments5.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments5.java @@ -15,30 +15,245 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function5; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 5 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 * @since 0.3.0 */ -public class Arguments5 extends Arguments4 { +public final class Arguments5 { + + private final A1 arg1; + + private final A2 arg2; + + private final A3 arg3; + + private final A4 arg4; - protected final A5 arg5; + private final A5 arg5; + /** + * Creates a new Arguments5 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 + */ Arguments5(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3, @Nullable A4 arg4, @Nullable A5 arg5) { - super(arg1, arg2, arg3, arg4); + this.arg1 = arg1; + this.arg2 = arg2; + this.arg3 = arg3; + this.arg4 = arg4; this.arg5 = arg5; } + /** + * 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 final A5 arg5() { + 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; } - public final X map(Function5 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(Function5 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg5 to arg5 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg5); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg4 to arg5 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg4, arg5); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg3 to arg5 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg3, arg4, arg5); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg2 to arg5 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg2, arg3, arg4, arg5); + } + + /** + * 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 Arguments6 instance with the additional argument + * @since 0.16.0 + */ + public Arguments6 append(@Nullable B arg) { + return new Arguments6<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, 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 Arguments6 instance with the additional argument + * @since 0.16.0 + */ + public Arguments6 prepend(@Nullable B arg) { + return new Arguments6<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5); + } + + /** + * Returns a new Arguments5 instance with the arguments in reverse order. + * @return an Arguments5 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments5 reverse() { + return new Arguments5<>(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; + } + Arguments5 that = (Arguments5) 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); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments5{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + ", " + + "arg4=" + this.arg4 + ", " + "arg5=" + this.arg5 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments5Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments5Combining.java index f2b1c63a..de0605fd 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments5Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments5Combining.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.Function5; 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 @@ -48,10 +52,27 @@ public Arguments5Combining(ValueValidator v1, ValueVali public Arguments1Validator apply( Function5 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)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments5Combining.this.v1.validate(a, locale, constraintContext), + Arguments5Combining.this.v2.validate(a, locale, constraintContext), + Arguments5Combining.this.v3.validate(a, locale, constraintContext), + Arguments5Combining.this.v4.validate(a, locale, constraintContext), + Arguments5Combining.this.v5.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply( + (r1, r2, r3, r4, r5) -> () -> f.apply(r1, r2, r3, r4, r5), + Arguments5Combining.this.v1.validate(a, locale, constraintContext), + Arguments5Combining.this.v2.validate(a, locale, constraintContext), + Arguments5Combining.this.v3.validate(a, locale, constraintContext), + Arguments5Combining.this.v4.validate(a, locale, constraintContext), + Arguments5Combining.this.v5.validate(a, locale, constraintContext)); + } + }; } public Arguments6Combining combine(ValueValidator v6) { diff --git a/src/main/java/am/ik/yavi/arguments/Arguments5Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments5Validator.java index b98e15d5..33e95e89 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments5Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments5Validator.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,25 +35,99 @@ @FunctionalInterface public interface Arguments5Validator { + /** + * Convert an Arguments1Validator that validates Arguments5 to an Arguments5Validator + * @param validator validator for Arguments5 + * @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 target result type + * @return arguments5 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments5Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments5Validator() { + @Override + public Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4, + @Nullable A5 a5, Locale locale, ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5), locale, constraintContext); + } + + @Override + public Arguments5Validator> lazy() { + return Arguments5Validator.unwrap(validator.lazy()); + } + }; + } + Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4, @Nullable A5 a5, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments5 as a single object. + * @return a validator that takes an Arguments5 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments5 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments5 nonNullArgs = Objects + .requireNonNull(args); + return Arguments5Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments5Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments5Validator andThen(Function mapper) { - return (a1, a2, a3, a4, a5, locale, constraintContext) -> Arguments5Validator.this - .validate(a1, a2, a3, a4, a5, locale, constraintContext) - .map(mapper); + return new Arguments5Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, Locale locale, + ConstraintContext constraintContext) { + return Arguments5Validator.this.validate(a1, a2, a3, a4, a5, locale, constraintContext).map(mapper); + } + + @Override + public Arguments5Validator> lazy() { + return Arguments5Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** * @since 0.11.0 */ default Arguments5Validator andThen(ValueValidator validator) { - return (a1, a2, a3, a4, a5, locale, constraintContext) -> Arguments5Validator.this - .validate(a1, a2, a3, a4, a5, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments5Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, Locale locale, + ConstraintContext constraintContext) { + return Arguments5Validator.this.validate(a1, a2, a3, a4, a5, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments5Validator> lazy() { + return Arguments5Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -60,11 +135,19 @@ default Arguments5Validator andThen(ValueValidator< */ default Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments5 args = mapper - .apply(a); - return Arguments5Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments5 args = mapper + .apply(a); + return Arguments5Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments5Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments6.java b/src/main/java/am/ik/yavi/arguments/Arguments6.java index 7ee1fab5..21aaedf0 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments6.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments6.java @@ -15,32 +15,278 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function6; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 6 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 * @since 0.3.0 */ -public class Arguments6 extends Arguments5 { +public final class Arguments6 { + + private final A1 arg1; + + private final A2 arg2; + + private final A3 arg3; + + private final A4 arg4; + + private final A5 arg5; - protected final A6 arg6; + private final A6 arg6; + /** + * Creates a new Arguments6 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 + */ Arguments6(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3, @Nullable A4 arg4, @Nullable A5 arg5, @Nullable A6 arg6) { - super(arg1, arg2, arg3, arg4, arg5); + this.arg1 = arg1; + this.arg2 = arg2; + this.arg3 = arg3; + this.arg4 = arg4; + this.arg5 = arg5; this.arg6 = arg6; } + /** + * Returns the argument at position 1. + * @return the argument at position 1 + */ @Nullable - public final A6 arg6() { + 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; } - 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( Function6 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg6 to arg6 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg6); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg5 to arg6 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg5, arg6); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg4 to arg6 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg4, arg5, arg6); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg3 to arg6 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg3, arg4, arg5, arg6); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg2 to arg6 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg2, arg3, arg4, arg5, arg6); + } + + /** + * 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 Arguments7 instance with the additional argument + * @since 0.16.0 + */ + public Arguments7 append(@Nullable B arg) { + return new Arguments7<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, 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 Arguments7 instance with the additional argument + * @since 0.16.0 + */ + public Arguments7 prepend(@Nullable B arg) { + return new Arguments7<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6); + } + + /** + * Returns a new Arguments6 instance with the arguments in reverse order. + * @return an Arguments6 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments6 reverse() { + return new Arguments6<>(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; + } + Arguments6 that = (Arguments6) 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); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments6{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + ", " + + "arg4=" + this.arg4 + ", " + "arg5=" + this.arg5 + ", " + "arg6=" + this.arg6 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments6Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments6Combining.java index 209a032b..4ec44c19 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments6Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments6Combining.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.Function6; 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 @@ -51,10 +55,29 @@ public Arguments6Combining(ValueValidator v1, ValueVali public Arguments1Validator apply( Function6 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)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments6Combining.this.v1.validate(a, locale, constraintContext), + Arguments6Combining.this.v2.validate(a, locale, constraintContext), + Arguments6Combining.this.v3.validate(a, locale, constraintContext), + Arguments6Combining.this.v4.validate(a, locale, constraintContext), + Arguments6Combining.this.v5.validate(a, locale, constraintContext), + Arguments6Combining.this.v6.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply( + (r1, r2, r3, r4, r5, r6) -> () -> f.apply(r1, r2, r3, r4, r5, r6), + Arguments6Combining.this.v1.validate(a, locale, constraintContext), + Arguments6Combining.this.v2.validate(a, locale, constraintContext), + Arguments6Combining.this.v3.validate(a, locale, constraintContext), + Arguments6Combining.this.v4.validate(a, locale, constraintContext), + Arguments6Combining.this.v5.validate(a, locale, constraintContext), + Arguments6Combining.this.v6.validate(a, locale, constraintContext)); + } + }; } public Arguments7Combining combine(ValueValidator v7) { diff --git a/src/main/java/am/ik/yavi/arguments/Arguments6Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments6Validator.java index f3c0a529..df295e85 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments6Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments6Validator.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,25 +35,100 @@ @FunctionalInterface public interface Arguments6Validator { + /** + * Convert an Arguments1Validator that validates Arguments6 to an Arguments6Validator + * @param validator validator for Arguments6 + * @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 target result type + * @return arguments6 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments6Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments6Validator() { + @Override + public Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4, + @Nullable A5 a5, @Nullable A6 a6, Locale locale, ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6), locale, constraintContext); + } + + @Override + public Arguments6Validator> lazy() { + return Arguments6Validator.unwrap(validator.lazy()); + } + }; + } + Validated validate(@Nullable A1 a1, @Nullable A2 a2, @Nullable A3 a3, @Nullable A4 a4, @Nullable A5 a5, @Nullable A6 a6, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments6 as a single object. + * @return a validator that takes an Arguments6 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments6 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments6 nonNullArgs = Objects + .requireNonNull(args); + return Arguments6Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments6Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments6Validator andThen(Function mapper) { - return (a1, a2, a3, a4, a5, a6, locale, constraintContext) -> Arguments6Validator.this - .validate(a1, a2, a3, a4, a5, a6, locale, constraintContext) - .map(mapper); + return new Arguments6Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, Locale locale, + ConstraintContext constraintContext) { + return Arguments6Validator.this.validate(a1, a2, a3, a4, a5, a6, locale, constraintContext).map(mapper); + } + + @Override + public Arguments6Validator> lazy() { + return Arguments6Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** * @since 0.11.0 */ default Arguments6Validator andThen(ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, locale, constraintContext) -> Arguments6Validator.this - .validate(a1, a2, a3, a4, a5, a6, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments6Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, Locale locale, + ConstraintContext constraintContext) { + return Arguments6Validator.this.validate(a1, a2, a3, a4, a5, a6, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments6Validator> lazy() { + return Arguments6Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -60,11 +136,19 @@ default Arguments6Validator andThen(ValueValida */ default Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments6 args = mapper - .apply(a); - return Arguments6Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments6 args = mapper + .apply(a); + return Arguments6Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments6Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments7.java b/src/main/java/am/ik/yavi/arguments/Arguments7.java index 27336ab6..f5f57b78 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments7.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments7.java @@ -15,32 +15,311 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function7; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 7 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 * @since 0.3.0 */ -public class Arguments7 extends Arguments6 { +public final class Arguments7 { + + private final A1 arg1; + + private final A2 arg2; + + private final A3 arg3; + + private final A4 arg4; + + private final A5 arg5; + + private final A6 arg6; - protected final A7 arg7; + private final A7 arg7; + /** + * Creates a new Arguments7 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 + */ Arguments7(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3, @Nullable A4 arg4, @Nullable A5 arg5, @Nullable A6 arg6, @Nullable A7 arg7) { - super(arg1, arg2, arg3, arg4, arg5, arg6); + this.arg1 = arg1; + this.arg2 = arg2; + this.arg3 = arg3; + this.arg4 = arg4; + this.arg5 = arg5; + this.arg6 = arg6; this.arg7 = arg7; } + /** + * Returns the argument at position 1. + * @return the argument at position 1 + */ @Nullable - public final A7 arg7() { + 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; } - 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( Function7 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg7 to arg7 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg7); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg6 to arg7 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg6, arg7); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg5 to arg7 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg5, arg6, arg7); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg4 to arg7 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg4, arg5, arg6, arg7); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg3 to arg7 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg3, arg4, arg5, arg6, arg7); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg2 to arg7 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg2, arg3, arg4, arg5, arg6, arg7); + } + + /** + * 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 Arguments8 instance with the additional argument + * @since 0.16.0 + */ + public Arguments8 append(@Nullable B arg) { + return new Arguments8<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, 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 Arguments8 instance with the additional argument + * @since 0.16.0 + */ + public Arguments8 prepend(@Nullable B arg) { + return new Arguments8<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7); + } + + /** + * Returns a new Arguments7 instance with the arguments in reverse order. + * @return an Arguments7 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments7 reverse() { + return new Arguments7<>(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; + } + Arguments7 that = (Arguments7) 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); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments7{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + ", " + + "arg4=" + this.arg4 + ", " + "arg5=" + this.arg5 + ", " + "arg6=" + this.arg6 + ", " + "arg7=" + + this.arg7 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments7Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments7Combining.java index c9386bf5..0c870b5c 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments7Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments7Combining.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.Function7; 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 @@ -55,11 +59,31 @@ public Arguments7Combining(ValueValidator v1, ValueVali public Arguments1Validator apply( Function7 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)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments7Combining.this.v1.validate(a, locale, constraintContext), + Arguments7Combining.this.v2.validate(a, locale, constraintContext), + Arguments7Combining.this.v3.validate(a, locale, constraintContext), + Arguments7Combining.this.v4.validate(a, locale, constraintContext), + Arguments7Combining.this.v5.validate(a, locale, constraintContext), + Arguments7Combining.this.v6.validate(a, locale, constraintContext), + Arguments7Combining.this.v7.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply( + (r1, r2, r3, r4, r5, r6, r7) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7), + Arguments7Combining.this.v1.validate(a, locale, constraintContext), + Arguments7Combining.this.v2.validate(a, locale, constraintContext), + Arguments7Combining.this.v3.validate(a, locale, constraintContext), + Arguments7Combining.this.v4.validate(a, locale, constraintContext), + Arguments7Combining.this.v5.validate(a, locale, constraintContext), + Arguments7Combining.this.v6.validate(a, locale, constraintContext), + Arguments7Combining.this.v7.validate(a, locale, constraintContext)); + } + }; } public Arguments8Combining combine( diff --git a/src/main/java/am/ik/yavi/arguments/Arguments7Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments7Validator.java index 8d652f9f..c08d43d7 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments7Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments7Validator.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,25 +35,104 @@ @FunctionalInterface public interface Arguments7Validator { + /** + * Convert an Arguments1Validator that validates Arguments7 to an Arguments7Validator + * @param validator validator for Arguments7 + * @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 target result type + * @return arguments7 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments7Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments7Validator() { + @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, Locale locale, + ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7), locale, constraintContext); + } + + @Override + public Arguments7Validator> lazy() { + return Arguments7Validator.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, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments7 as a single object. + * @return a validator that takes an Arguments7 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments7 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments7 nonNullArgs = Objects + .requireNonNull(args); + return Arguments7Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), locale, + constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments7Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments7Validator andThen(Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, locale, constraintContext) -> Arguments7Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, locale, constraintContext) - .map(mapper); + return new Arguments7Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, Locale locale, + ConstraintContext constraintContext) { + return Arguments7Validator.this.validate(a1, a2, a3, a4, a5, a6, a7, locale, constraintContext) + .map(mapper); + } + + @Override + public Arguments7Validator> lazy() { + return Arguments7Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** * @since 0.11.0 */ default Arguments7Validator andThen(ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, locale, constraintContext) -> Arguments7Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments7Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, Locale locale, + ConstraintContext constraintContext) { + return Arguments7Validator.this.validate(a1, a2, a3, a4, a5, a6, a7, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments7Validator> lazy() { + return Arguments7Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -60,11 +140,19 @@ default Arguments7Validator andThen(ValueVa */ default Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments7 args = mapper - .apply(a); - return Arguments7Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments7 args = mapper + .apply(a); + return Arguments7Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments7Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments8.java b/src/main/java/am/ik/yavi/arguments/Arguments8.java index a3844fb0..d41924fe 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments8.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments8.java @@ -15,32 +15,345 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function8; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 8 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 * @since 0.3.0 */ -public class Arguments8 extends Arguments7 { +public final class Arguments8 { + + 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; - protected final A8 arg8; + private final A8 arg8; + /** + * Creates a new Arguments8 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 + */ Arguments8(@Nullable A1 arg1, @Nullable A2 arg2, @Nullable A3 arg3, @Nullable A4 arg4, @Nullable A5 arg5, @Nullable A6 arg6, @Nullable A7 arg7, @Nullable A8 arg8) { - super(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + this.arg1 = arg1; + this.arg2 = arg2; + this.arg3 = arg3; + this.arg4 = arg4; + this.arg5 = arg5; + this.arg6 = arg6; + this.arg7 = arg7; this.arg8 = arg8; } + /** + * 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 final A8 arg8() { + 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; } - 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( Function8 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg8 to arg8 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg8); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg7 to arg8 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg7, arg8); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg6 to arg8 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg6, arg7, arg8); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg5 to arg8 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg5, arg6, arg7, arg8); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg4 to arg8 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg4, arg5, arg6, arg7, arg8); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg3 to arg8 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg3, arg4, arg5, arg6, arg7, arg8); + } + + /** + * Returns a new Arguments7 instance containing only the last 7 arguments. + * @return an Arguments7 instance with arguments from arg2 to arg8 + * @since 0.16.0 + */ + public Arguments7 last7() { + return new Arguments7<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } + + /** + * 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 Arguments9 instance with the additional argument + * @since 0.16.0 + */ + public Arguments9 append(@Nullable B arg) { + return new Arguments9<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8, + 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 Arguments9 instance with the additional argument + * @since 0.16.0 + */ + public Arguments9 prepend(@Nullable B arg) { + return new Arguments9<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, + this.arg8); + } + + /** + * Returns a new Arguments8 instance with the arguments in reverse order. + * @return an Arguments8 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments8 reverse() { + return new Arguments8<>(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; + } + Arguments8 that = (Arguments8) 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); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments8{" + "arg1=" + this.arg1 + ", " + "arg2=" + this.arg2 + ", " + "arg3=" + this.arg3 + ", " + + "arg4=" + this.arg4 + ", " + "arg5=" + this.arg5 + ", " + "arg6=" + this.arg6 + ", " + "arg7=" + + this.arg7 + ", " + "arg8=" + this.arg8 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments8Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments8Combining.java index 191ed34c..84742189 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments8Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments8Combining.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.Function8; 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 @@ -58,11 +62,33 @@ public Arguments8Combining(ValueValidator v1, ValueVali public Arguments1Validator apply( Function8 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)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments8Combining.this.v1.validate(a, locale, constraintContext), + Arguments8Combining.this.v2.validate(a, locale, constraintContext), + Arguments8Combining.this.v3.validate(a, locale, constraintContext), + Arguments8Combining.this.v4.validate(a, locale, constraintContext), + Arguments8Combining.this.v5.validate(a, locale, constraintContext), + Arguments8Combining.this.v6.validate(a, locale, constraintContext), + Arguments8Combining.this.v7.validate(a, locale, constraintContext), + Arguments8Combining.this.v8.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply( + (r1, r2, r3, r4, r5, r6, r7, r8) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8), + Arguments8Combining.this.v1.validate(a, locale, constraintContext), + Arguments8Combining.this.v2.validate(a, locale, constraintContext), + Arguments8Combining.this.v3.validate(a, locale, constraintContext), + Arguments8Combining.this.v4.validate(a, locale, constraintContext), + Arguments8Combining.this.v5.validate(a, locale, constraintContext), + Arguments8Combining.this.v6.validate(a, locale, constraintContext), + Arguments8Combining.this.v7.validate(a, locale, constraintContext), + Arguments8Combining.this.v8.validate(a, locale, constraintContext)); + } + }; } public Arguments9Combining combine( diff --git a/src/main/java/am/ik/yavi/arguments/Arguments8Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments8Validator.java index 573999c0..ca8e8535 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments8Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments8Validator.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,17 +35,84 @@ @FunctionalInterface public interface Arguments8Validator { + /** + * Convert an Arguments1Validator that validates Arguments8 to an Arguments8Validator + * @param validator validator for Arguments8 + * @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 target result type + * @return arguments8 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments8Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments8Validator() { + @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, Locale locale, + ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8), locale, constraintContext); + } + + @Override + public Arguments8Validator> lazy() { + return Arguments8Validator.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, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments8 as a single object. + * @return a validator that takes an Arguments8 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments8 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments8 nonNullArgs = Objects + .requireNonNull(args); + return Arguments8Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments8Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments8Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, locale, constraintContext) -> Arguments8Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, a8, locale, constraintContext) - .map(mapper); + return new Arguments8Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, Locale locale, + ConstraintContext constraintContext) { + return Arguments8Validator.this.validate(a1, a2, a3, a4, a5, a6, a7, a8, locale, constraintContext) + .map(mapper); + } + + @Override + public Arguments8Validator> lazy() { + return Arguments8Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -52,9 +120,22 @@ default Arguments8Validator andThen( */ default Arguments8Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, locale, constraintContext) -> Arguments8Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, a8, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments8Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, Locale locale, + ConstraintContext constraintContext) { + return Arguments8Validator.this.validate(a1, a2, a3, a4, a5, a6, a7, a8, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments8Validator> lazy() { + return Arguments8Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -62,11 +143,19 @@ default Arguments8Validator andThen( */ default Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments8 args = mapper - .apply(a); - return Arguments8Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments8 args = mapper + .apply(a); + return Arguments8Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments8Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments9.java b/src/main/java/am/ik/yavi/arguments/Arguments9.java index 5432d662..df593679 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments9.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments9.java @@ -15,32 +15,378 @@ */ package am.ik.yavi.arguments; +import java.util.Objects; + import am.ik.yavi.fn.Function9; import am.ik.yavi.jsr305.Nullable; /** + * A container class that holds 9 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 * @since 0.3.0 */ -public class Arguments9 extends Arguments8 { +public final class Arguments9 { + + 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; - protected final A9 arg9; + private final A9 arg9; + /** + * Creates a new Arguments9 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 + */ Arguments9(@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) { - super(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + 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; } + /** + * Returns the argument at position 1. + * @return the argument at position 1 + */ @Nullable - public final A9 arg9() { + 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; } - 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( Function9 mapper) { return mapper.apply(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); } + /** + * 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 Arguments1 instance containing only the last 1 arguments. + * @return an Arguments1 instance with arguments from arg9 to arg9 + * @since 0.16.0 + */ + public Arguments1 last1() { + return new Arguments1<>(arg9); + } + + /** + * Returns a new Arguments2 instance containing only the last 2 arguments. + * @return an Arguments2 instance with arguments from arg8 to arg9 + * @since 0.16.0 + */ + public Arguments2 last2() { + return new Arguments2<>(arg8, arg9); + } + + /** + * Returns a new Arguments3 instance containing only the last 3 arguments. + * @return an Arguments3 instance with arguments from arg7 to arg9 + * @since 0.16.0 + */ + public Arguments3 last3() { + return new Arguments3<>(arg7, arg8, arg9); + } + + /** + * Returns a new Arguments4 instance containing only the last 4 arguments. + * @return an Arguments4 instance with arguments from arg6 to arg9 + * @since 0.16.0 + */ + public Arguments4 last4() { + return new Arguments4<>(arg6, arg7, arg8, arg9); + } + + /** + * Returns a new Arguments5 instance containing only the last 5 arguments. + * @return an Arguments5 instance with arguments from arg5 to arg9 + * @since 0.16.0 + */ + public Arguments5 last5() { + return new Arguments5<>(arg5, arg6, arg7, arg8, arg9); + } + + /** + * Returns a new Arguments6 instance containing only the last 6 arguments. + * @return an Arguments6 instance with arguments from arg4 to arg9 + * @since 0.16.0 + */ + public Arguments6 last6() { + return new Arguments6<>(arg4, arg5, arg6, arg7, arg8, arg9); + } + + /** + * Returns a new Arguments7 instance containing only the last 7 arguments. + * @return an Arguments7 instance with arguments from arg3 to arg9 + * @since 0.16.0 + */ + public Arguments7 last7() { + return new Arguments7<>(arg3, arg4, arg5, arg6, arg7, arg8, arg9); + } + + /** + * Returns a new Arguments8 instance containing only the last 8 arguments. + * @return an Arguments8 instance with arguments from arg2 to arg9 + * @since 0.16.0 + */ + public Arguments8 last8() { + return new Arguments8<>(arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + } + + /** + * 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 Arguments10 instance with the additional argument + * @since 0.16.0 + */ + public Arguments10 append(@Nullable B arg) { + return new Arguments10<>(this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, this.arg8, + this.arg9, 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 Arguments10 instance with the additional argument + * @since 0.16.0 + */ + public Arguments10 prepend(@Nullable B arg) { + return new Arguments10<>(arg, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6, this.arg7, + this.arg8, this.arg9); + } + + /** + * Returns a new Arguments9 instance with the arguments in reverse order. + * @return an Arguments9 instance with arguments in reverse order + * @since 0.16.0 + */ + public Arguments9 reverse() { + return new Arguments9<>(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; + } + Arguments9 that = (Arguments9) 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); + } + + /** + * 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); + } + + /** + * Returns a string representation of the object. + * @return a string representation of the object + */ + @Override + public String toString() { + return "Arguments9{" + "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 + "}"; + } + } diff --git a/src/main/java/am/ik/yavi/arguments/Arguments9Combining.java b/src/main/java/am/ik/yavi/arguments/Arguments9Combining.java index d23174f4..5f5a498c 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments9Combining.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments9Combining.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.Function9; 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 @@ -62,12 +66,35 @@ public Arguments9Combining(ValueValidator v1, ValueVali public Arguments1Validator apply( Function9 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)); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + return Validations.apply(f::apply, Arguments9Combining.this.v1.validate(a, locale, constraintContext), + Arguments9Combining.this.v2.validate(a, locale, constraintContext), + Arguments9Combining.this.v3.validate(a, locale, constraintContext), + Arguments9Combining.this.v4.validate(a, locale, constraintContext), + Arguments9Combining.this.v5.validate(a, locale, constraintContext), + Arguments9Combining.this.v6.validate(a, locale, constraintContext), + Arguments9Combining.this.v7.validate(a, locale, constraintContext), + Arguments9Combining.this.v8.validate(a, locale, constraintContext), + Arguments9Combining.this.v9.validate(a, locale, constraintContext)); + } + + @Override + public Arguments1Validator> lazy() { + return (a, locale, constraintContext) -> Validations.apply( + (r1, r2, r3, r4, r5, r6, r7, r8, r9) -> () -> f.apply(r1, r2, r3, r4, r5, r6, r7, r8, r9), + Arguments9Combining.this.v1.validate(a, locale, constraintContext), + Arguments9Combining.this.v2.validate(a, locale, constraintContext), + Arguments9Combining.this.v3.validate(a, locale, constraintContext), + Arguments9Combining.this.v4.validate(a, locale, constraintContext), + Arguments9Combining.this.v5.validate(a, locale, constraintContext), + Arguments9Combining.this.v6.validate(a, locale, constraintContext), + Arguments9Combining.this.v7.validate(a, locale, constraintContext), + Arguments9Combining.this.v8.validate(a, locale, constraintContext), + Arguments9Combining.this.v9.validate(a, locale, constraintContext)); + } + }; } public Arguments10Combining combine( diff --git a/src/main/java/am/ik/yavi/arguments/Arguments9Validator.java b/src/main/java/am/ik/yavi/arguments/Arguments9Validator.java index 758b5b5b..1d5fe028 100644 --- a/src/main/java/am/ik/yavi/arguments/Arguments9Validator.java +++ b/src/main/java/am/ik/yavi/arguments/Arguments9Validator.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,86 @@ @FunctionalInterface public interface Arguments9Validator { + /** + * Convert an Arguments1Validator that validates Arguments9 to an Arguments9Validator + * @param validator validator for Arguments9 + * @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 target result type + * @return arguments9 validator that takes arguments directly + * @since 0.16.0 + */ + static Arguments9Validator unwrap( + Arguments1Validator, X> validator) { + return new Arguments9Validator() { + @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, Locale locale, + ConstraintContext constraintContext) { + return validator.validate(Arguments.of(a1, a2, a3, a4, a5, a6, a7, a8, a9), locale, constraintContext); + } + + @Override + public Arguments9Validator> lazy() { + return Arguments9Validator.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, Locale locale, ConstraintContext constraintContext); + /** + * Convert this validator to one that validates Arguments9 as a single object. + * @return a validator that takes an Arguments9 + * @since 0.16.0 + */ + default Arguments1Validator, X> wrap() { + return new Arguments1Validator, X>() { + @Override + public Validated validate(Arguments9 args, Locale locale, + ConstraintContext constraintContext) { + final Arguments9 nonNullArgs = Objects + .requireNonNull(args); + return Arguments9Validator.this.validate(nonNullArgs.arg1(), nonNullArgs.arg2(), nonNullArgs.arg3(), + nonNullArgs.arg4(), nonNullArgs.arg5(), nonNullArgs.arg6(), nonNullArgs.arg7(), + nonNullArgs.arg8(), nonNullArgs.arg9(), locale, constraintContext); + } + + @Override + public Arguments1Validator, Supplier> lazy() { + return Arguments9Validator.this.lazy().wrap(); + } + }; + } + /** * @since 0.7.0 */ default Arguments9Validator andThen( Function mapper) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, locale, constraintContext) -> Arguments9Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, locale, constraintContext) - .map(mapper); + return new Arguments9Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, Locale locale, + ConstraintContext constraintContext) { + return Arguments9Validator.this.validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, locale, constraintContext) + .map(mapper); + } + + @Override + public Arguments9Validator> lazy() { + return Arguments9Validator.this.lazy() + .andThen((Function, Supplier>) xSupplier -> () -> mapper.apply(xSupplier.get())); + } + }; } /** @@ -53,9 +122,22 @@ default Arguments9Validator andThen */ default Arguments9Validator andThen( ValueValidator validator) { - return (a1, a2, a3, a4, a5, a6, a7, a8, a9, locale, constraintContext) -> Arguments9Validator.this - .validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, locale, constraintContext) - .flatMap(v -> validator.validate(v, locale, constraintContext)); + return new Arguments9Validator() { + @Override + public Validated validate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, Locale locale, + ConstraintContext constraintContext) { + return Arguments9Validator.this.validate(a1, a2, a3, a4, a5, a6, a7, a8, a9, locale, constraintContext) + .flatMap(v -> validator.validate(v, locale, constraintContext)); + } + + @Override + public Arguments9Validator> lazy() { + return Arguments9Validator.this.lazy() + .andThen((xSupplier, locale, constraintContext) -> validator + .validate(Objects.requireNonNull(xSupplier).get(), locale, constraintContext) + .map(x2 -> () -> x2)); + } + }; } /** @@ -63,11 +145,19 @@ default Arguments9Validator andThen */ default Arguments1Validator compose( Function> mapper) { - return (a, locale, constraintContext) -> { - final Arguments9 args = mapper - .apply(a); - return Arguments9Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), args.arg5(), - args.arg6(), args.arg7(), args.arg8(), args.arg9(), locale, constraintContext); + return new Arguments1Validator() { + @Override + public Validated validate(A a, Locale locale, ConstraintContext constraintContext) { + final Arguments9 args = mapper + .apply(a); + return Arguments9Validator.this.validate(args.arg1(), args.arg2(), args.arg3(), args.arg4(), + args.arg5(), args.arg6(), args.arg7(), args.arg8(), args.arg9(), locale, constraintContext); + } + + @Override + public Arguments1Validator> lazy() { + return Arguments9Validator.this.lazy().compose(mapper); + } }; } diff --git a/src/main/java/am/ik/yavi/builder/Arguments10ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments10ValidatorBuilder.java index f6659d61..57f656ad 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments10ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments10ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -260,6 +262,23 @@ public Arguments11ValidatorBuilder Arguments11ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments11ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + this.v9, this.v10, validator); + } + + public Arguments11ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments11ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments11ValidatorBuilder _long( ValueValidator validator) { return new Arguments11ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/Arguments11ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments11ValidatorBuilder.java index a118bb92..0e55666c 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments11ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments11ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -264,6 +266,23 @@ public Arguments12ValidatorBuilder Arguments12ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments12ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + this.v9, this.v10, this.v11, validator); + } + + public Arguments12ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments12ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments12ValidatorBuilder _long( ValueValidator validator) { return new Arguments12ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/Arguments12ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments12ValidatorBuilder.java index 805cdf09..ecb3ca03 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments12ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments12ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -267,6 +269,23 @@ public Arguments13ValidatorBuilder Arguments13ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments13ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + this.v9, this.v10, this.v11, this.v12, validator); + } + + public Arguments13ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments13ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments13ValidatorBuilder _long( ValueValidator validator) { return new Arguments13ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/Arguments13ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments13ValidatorBuilder.java index 09e025c2..201b6a51 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments13ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments13ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -270,6 +272,23 @@ public Arguments14ValidatorBuilder Arguments14ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments14ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + this.v9, this.v10, this.v11, this.v12, this.v13, validator); + } + + public Arguments14ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments14ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments14ValidatorBuilder _long( ValueValidator validator) { return new Arguments14ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/Arguments14ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments14ValidatorBuilder.java index da45f684..0f675a8e 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments14ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments14ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -274,6 +276,23 @@ public Arguments15ValidatorBuilder Arguments15ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments15ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + this.v9, this.v10, this.v11, this.v12, this.v13, this.v14, validator); + } + + public Arguments15ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments15ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments15ValidatorBuilder _long( ValueValidator validator) { return new Arguments15ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/Arguments15ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments15ValidatorBuilder.java index 3ddef089..a64b42a1 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments15ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments15ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -277,6 +279,23 @@ public Arguments16ValidatorBuilder Arguments16ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments16ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + this.v9, this.v10, this.v11, this.v12, this.v13, this.v14, this.v15, validator); + } + + public Arguments16ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments16ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments16ValidatorBuilder _long( ValueValidator validator) { return new Arguments16ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/Arguments16ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments16ValidatorBuilder.java index 33a1ce15..0c8d5cb4 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments16ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments16ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; diff --git a/src/main/java/am/ik/yavi/builder/Arguments1ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments1ValidatorBuilder.java index 63c37fee..b0f68fc5 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments1ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments1ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -194,6 +196,19 @@ public Arguments2ValidatorBuilder _localTime(Strin return this._localTime(name, Function.identity()); } + public Arguments2ValidatorBuilder _localDate(ValueValidator validator) { + return new Arguments2ValidatorBuilder<>(this.v1, validator); + } + + public Arguments2ValidatorBuilder _localDate(String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments2ValidatorBuilder _localDate(String name) { + return this._localDate(name, Function.identity()); + } + public Arguments2ValidatorBuilder _long(ValueValidator validator) { return new Arguments2ValidatorBuilder<>(this.v1, validator); } diff --git a/src/main/java/am/ik/yavi/builder/Arguments2ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments2ValidatorBuilder.java index e67e4cf3..5c24d07c 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments2ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments2ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -201,6 +203,20 @@ public Arguments3ValidatorBuilder _localTi return this._localTime(name, Function.identity()); } + public Arguments3ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments3ValidatorBuilder<>(this.v1, this.v2, validator); + } + + public Arguments3ValidatorBuilder _localDate(String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments3ValidatorBuilder _localDate(String name) { + return this._localDate(name, Function.identity()); + } + public Arguments3ValidatorBuilder _long(ValueValidator validator) { return new Arguments3ValidatorBuilder<>(this.v1, this.v2, validator); } diff --git a/src/main/java/am/ik/yavi/builder/Arguments3ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments3ValidatorBuilder.java index 6443eeac..39ca7fd4 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments3ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments3ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -209,6 +211,20 @@ public Arguments4ValidatorBuilder return this._localTime(name, Function.identity()); } + public Arguments4ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments4ValidatorBuilder<>(this.v1, this.v2, this.v3, validator); + } + + public Arguments4ValidatorBuilder _localDate(String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments4ValidatorBuilder _localDate(String name) { + return this._localDate(name, Function.identity()); + } + public Arguments4ValidatorBuilder _long(ValueValidator validator) { return new Arguments4ValidatorBuilder<>(this.v1, this.v2, this.v3, validator); } diff --git a/src/main/java/am/ik/yavi/builder/Arguments4ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments4ValidatorBuilder.java index 9869dea9..9f1b55df 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments4ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments4ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -215,6 +217,20 @@ public Arguments5ValidatorBuilder Arguments5ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments5ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, validator); + } + + public Arguments5ValidatorBuilder _localDate(String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments5ValidatorBuilder _localDate(String name) { + return this._localDate(name, Function.identity()); + } + public Arguments5ValidatorBuilder _long( ValueValidator validator) { return new Arguments5ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, validator); diff --git a/src/main/java/am/ik/yavi/builder/Arguments5ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments5ValidatorBuilder.java index bc221eaf..2dc974fe 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments5ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments5ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -225,6 +227,22 @@ public Arguments6ValidatorBuilder Arguments6ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments6ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, validator); + } + + public Arguments6ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments6ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments6ValidatorBuilder _long( ValueValidator validator) { return new Arguments6ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, validator); diff --git a/src/main/java/am/ik/yavi/builder/Arguments6ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments6ValidatorBuilder.java index ffc01f15..edb00504 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments6ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments6ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -237,6 +239,22 @@ public Arguments7ValidatorBuilder Arguments7ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments7ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, validator); + } + + public Arguments7ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments7ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments7ValidatorBuilder _long( ValueValidator validator) { return new Arguments7ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, validator); diff --git a/src/main/java/am/ik/yavi/builder/Arguments7ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments7ValidatorBuilder.java index c91d6379..640fe235 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments7ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments7ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -251,6 +253,23 @@ public Arguments8ValidatorBuilder Arguments8ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments8ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, + validator); + } + + public Arguments8ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments8ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments8ValidatorBuilder _long( ValueValidator validator) { return new Arguments8ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, diff --git a/src/main/java/am/ik/yavi/builder/Arguments8ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments8ValidatorBuilder.java index 368aca6b..2892da15 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments8ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments8ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -254,6 +256,23 @@ public Arguments9ValidatorBuilder Arguments9ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments9ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + validator); + } + + public Arguments9ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments9ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments9ValidatorBuilder _long( ValueValidator validator) { return new Arguments9ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/Arguments9ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/Arguments9ValidatorBuilder.java index d05cd901..2a78467e 100644 --- a/src/main/java/am/ik/yavi/builder/Arguments9ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/Arguments9ValidatorBuilder.java @@ -19,6 +19,7 @@ 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; @@ -39,6 +40,7 @@ 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; @@ -257,6 +259,23 @@ public Arguments10ValidatorBuilder Arguments10ValidatorBuilder _localDate( + ValueValidator validator) { + return new Arguments10ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, + this.v9, validator); + } + + public Arguments10ValidatorBuilder _localDate( + String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments10ValidatorBuilder _localDate( + String name) { + return this._localDate(name, Function.identity()); + } + public Arguments10ValidatorBuilder _long( ValueValidator validator) { return new Arguments10ValidatorBuilder<>(this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, this.v8, diff --git a/src/main/java/am/ik/yavi/builder/ValidatorBuilder.java b/src/main/java/am/ik/yavi/builder/ValidatorBuilder.java index ecfb67a3..56e2876f 100644 --- a/src/main/java/am/ik/yavi/builder/ValidatorBuilder.java +++ b/src/main/java/am/ik/yavi/builder/ValidatorBuilder.java @@ -47,7 +47,6 @@ import am.ik.yavi.constraint.array.LongArrayConstraint; import am.ik.yavi.constraint.array.ObjectArrayConstraint; import am.ik.yavi.constraint.array.ShortArrayConstraint; -import am.ik.yavi.core.BiValidator; import am.ik.yavi.core.CollectionValidator; import am.ik.yavi.core.Constraint; import am.ik.yavi.core.ConstraintCondition; @@ -154,7 +153,7 @@ * @param the type of the target object to validate * @author Toshiaki Maki */ -public class ValidatorBuilder implements Cloneable { +public class ValidatorBuilder { private static final String DEFAULT_SEPARATOR = "."; @@ -226,16 +225,6 @@ public ValidatorBuilder cast() { return (ValidatorBuilder) this; } - /** - * @return the cloned builder - * @deprecated please use the copy constructor - * {@link #ValidatorBuilder(ValidatorBuilder)} - */ - @Deprecated - public ValidatorBuilder clone() { - return new ValidatorBuilder<>(this); - } - /** * Factory method for a {@code ValidatorBuilder} to build {@code Validator} instance. *

@@ -290,25 +279,6 @@ public Validator build() { this.failFast); } - /** - * Create a BiValidator instance using the given constraints. In case of - * Spring Framework's Validator integration - * - *

-	 * BiValidator<CartItem, Errors> validator = ValidatorBuilder
-	 *   .<CartItem>of()
-	 *   .constraint(...)
-	 *   .build(Errors::rejectValue);
-	 * 
- * @param errorHandler handler that handle if the validation fails - * @param the type of the error object - * @return BiValidator instance - */ - public BiValidator build(BiValidator.ErrorHandler errorHandler) { - final Validator validator = this.build(); - return new BiValidator<>(validator, errorHandler); - } - public ValidatorBuilder constraint(ToCharSequence f, String name, Function, CharSequenceConstraint> c) { return this.constraint(f, name, c, CharSequenceConstraint::new); diff --git a/src/main/java/am/ik/yavi/builder/YaviArguments.java b/src/main/java/am/ik/yavi/builder/YaviArguments.java index 02c1da7c..46688966 100644 --- a/src/main/java/am/ik/yavi/builder/YaviArguments.java +++ b/src/main/java/am/ik/yavi/builder/YaviArguments.java @@ -19,6 +19,7 @@ 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; @@ -38,6 +39,7 @@ 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; @@ -185,6 +187,19 @@ public Arguments1ValidatorBuilder _localTime(String name) return this._localTime(name, Function.identity()); } + public Arguments1ValidatorBuilder _localDate(ValueValidator validator) { + return new Arguments1ValidatorBuilder<>(validator); + } + + public Arguments1ValidatorBuilder _localDate(String name, + Function>, LocalDateConstraint>> constraints) { + return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build()); + } + + public Arguments1ValidatorBuilder _localDate(String name) { + return this._localDate(name, Function.identity()); + } + public Arguments1ValidatorBuilder _long(ValueValidator validator) { return new Arguments1ValidatorBuilder<>(validator); } diff --git a/src/main/java/am/ik/yavi/constraint/CharSequenceConstraint.java b/src/main/java/am/ik/yavi/constraint/CharSequenceConstraint.java index 6686119d..faeacc54 100644 --- a/src/main/java/am/ik/yavi/constraint/CharSequenceConstraint.java +++ b/src/main/java/am/ik/yavi/constraint/CharSequenceConstraint.java @@ -15,6 +15,19 @@ */ package am.ik.yavi.constraint; +import am.ik.yavi.constraint.base.ContainerConstraintBase; +import am.ik.yavi.constraint.charsequence.ByteSizeConstraint; +import am.ik.yavi.constraint.charsequence.CodePoints; +import am.ik.yavi.constraint.charsequence.CodePoints.CodePointsRanges; +import am.ik.yavi.constraint.charsequence.CodePoints.CodePointsSet; +import am.ik.yavi.constraint.charsequence.CodePoints.Range; +import am.ik.yavi.constraint.charsequence.CodePointsConstraint; +import am.ik.yavi.constraint.charsequence.EmojiConstraint; +import am.ik.yavi.constraint.charsequence.variant.VariantOptions; +import am.ik.yavi.constraint.inetaddress.InetAddressUtils; +import am.ik.yavi.constraint.password.CharSequencePasswordPoliciesBuilder; +import am.ik.yavi.core.ConstraintPredicate; +import am.ik.yavi.core.ViolationMessage; import java.math.BigDecimal; import java.math.BigInteger; import java.net.MalformedURLException; @@ -28,30 +41,34 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Locale; import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; import java.util.function.ToIntFunction; import java.util.regex.Pattern; -import am.ik.yavi.constraint.base.ContainerConstraintBase; -import am.ik.yavi.constraint.charsequence.ByteSizeConstraint; -import am.ik.yavi.constraint.charsequence.CodePoints; -import am.ik.yavi.constraint.charsequence.CodePoints.CodePointsRanges; -import am.ik.yavi.constraint.charsequence.CodePoints.CodePointsSet; -import am.ik.yavi.constraint.charsequence.CodePoints.Range; -import am.ik.yavi.constraint.charsequence.CodePointsConstraint; -import am.ik.yavi.constraint.charsequence.EmojiConstraint; -import am.ik.yavi.constraint.charsequence.variant.VariantOptions; -import am.ik.yavi.constraint.inetaddress.InetAddressUtils; -import am.ik.yavi.constraint.password.CharSequencePasswordPoliciesBuilder; -import am.ik.yavi.core.ConstraintPredicate; -import am.ik.yavi.core.ViolationMessage; - import static am.ik.yavi.core.NullAs.INVALID; import static am.ik.yavi.core.NullAs.VALID; -import static am.ik.yavi.core.ViolationMessage.Default.*; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_BIGDECIMAL; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_BIGINTEGER; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_BYTE; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_CONTAINS; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_DOUBLE; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_EMAIL; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_ENDSWITH; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_FLOAT; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_INTEGER; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_IPV4; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_IPV6; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_LOCAL_DATE; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_LONG; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_LUHN; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_NOT_BLANK; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_PATTERN; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_SHORT; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_STARTSWITH; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_URL; +import static am.ik.yavi.core.ViolationMessage.Default.CHAR_SEQUENCE_UUID; public class CharSequenceConstraint extends ContainerConstraintBase> { @@ -259,16 +276,6 @@ public CharSequenceConstraint isoLocalDate() { return this.isLocalDatePattern("uuuu-MM-dd"); } - /** - * Use {@link #isoLocalDate()} instead - * - * @since 0.12.0 - */ - @Deprecated - public CharSequenceConstraint isIsoLocalDate() { - return this.isoLocalDate(); - } - /** * @since 0.12.1 */ @@ -276,16 +283,6 @@ public CharSequenceConstraint localDate(String pattern) { return this.isLocalDatePattern(pattern); } - /** - * Use {@link #localDate(String)} instead - * - * @since 0.12.0 - */ - @Deprecated - public CharSequenceConstraint isLocalDate(String pattern) { - return this.localDate(pattern); - } - public EmojiConstraint emoji() { return new EmojiConstraint<>(this, this.normalizerForm, this.variantOptions); } diff --git a/src/main/java/am/ik/yavi/constraint/base/NumericConstraintBase.java b/src/main/java/am/ik/yavi/constraint/base/NumericConstraintBase.java index c5c1730f..12c7dc2b 100644 --- a/src/main/java/am/ik/yavi/constraint/base/NumericConstraintBase.java +++ b/src/main/java/am/ik/yavi/constraint/base/NumericConstraintBase.java @@ -81,18 +81,6 @@ public C negative() { return cast(); } - /** - * @deprecated in favour of {@link NumericConstraintBase#negativeOrZero} - * @since 0.10.0 - */ - @Deprecated - public C negaitveOrZero() { - this.predicates() - .add(ConstraintPredicate.of(this.isLessThanOrEqual(zeroValue()), NUMERIC_NEGATIVE_OR_ZERO, - () -> new Object[] {}, VALID)); - return cast(); - } - /** * @since 0.10.0 */ diff --git a/src/main/java/am/ik/yavi/core/BiValidator.java b/src/main/java/am/ik/yavi/core/BiValidator.java deleted file mode 100644 index 9cd0e700..00000000 --- a/src/main/java/am/ik/yavi/core/BiValidator.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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. - * 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.core; - -import java.util.function.BiConsumer; - -/** - * Deprecated in favor of {@link Validatable#toBiConsumer(am.ik.yavi.core.ErrorHandler)} - * and {@link ValueValidator#toBiConsumer(am.ik.yavi.core.ErrorHandler)} - * - * BiValidator is a wrapper class of Validator that takes target - * object to validate and arbitrary errors object.
- * The result of validation is contained in the errors object instead of returning it. - * This class is useful for a library to adapt both YAVI and other validation library such - * as Spring Framework's org.springframework.validation.Validator. Validator - * can be wrapped as follows: - * - *
- * Validator<CartItem> validator = ValidatorBuilder.<CartItem> of()
- *                        .constraint(CartItem::getQuantity, "quantity", c -> c.greaterThan(0))
- *                        .constraint(...)
- *                        .build();
- * BiValidator<CartItem, Errors> validator = new BiValidator<>(validator, Errors::rejectValue);
- * 
- * - * @param the type of the instance to validate - * @param the type of the errors object - * @author Toshiaki Maki - * @since 0.5.0 - */ -@Deprecated -public class BiValidator implements BiConsumer { - - private final ValueValidator validator; - - private final ErrorHandler errorHandler; - - /** - * Create a {@link BiValidator} from a {@link ValueValidator} - * @param validator value validator - * @param errorHandler error handler - * @since 0.13.0 - */ - public BiValidator(ValueValidator validator, ErrorHandler errorHandler) { - this.validator = validator; - this.errorHandler = errorHandler; - } - - public BiValidator(Validator validator, ErrorHandler errorHandler) { - this.validator = validator.applicative(); - this.errorHandler = errorHandler; - } - - public void accept(T target, E errors) { - final Validated validated = this.validator.validate(target); - if (!validated.isValid()) { - final ConstraintViolations violations = validated.errors(); - violations.apply((name, messageKey, args, defaultMessage) -> this.errorHandler.handleError(errors, name, - messageKey, args, defaultMessage)); - } - } - - @FunctionalInterface - @Deprecated - /** - * Deprecated in favor of {@link am.ik.yavi.core.ErrorHandler} - */ - public interface ErrorHandler { - - void handleError(E errors, String name, String messageKey, Object[] args, String defaultMessage); - - } - -} diff --git a/src/main/java/am/ik/yavi/core/ConstraintViolation.java b/src/main/java/am/ik/yavi/core/ConstraintViolation.java index 6412ebe5..05048e9a 100644 --- a/src/main/java/am/ik/yavi/core/ConstraintViolation.java +++ b/src/main/java/am/ik/yavi/core/ConstraintViolation.java @@ -22,18 +22,64 @@ import java.util.Locale; import java.util.function.Function; +/** + * Represents a single constraint violation that occurs during validation. + * + *

+ * This class encapsulates details about a validation failure, including: + *

    + *
  • The field or property name that failed validation
  • + *
  • The message key used for internationalization
  • + *
  • The default message format to use when no localized message is found
  • + *
  • Any arguments needed for message formatting
  • + *
  • The message formatter and locale to use for message formatting
  • + *
+ * + *

+ * ConstraintViolation objects are immutable after creation. The class provides a builder + * API for creating instances in a type-safe manner with required and optional properties + * clearly distinguished. + * + * @since 0.1.0 + */ public class ConstraintViolation { + /** + * Arguments to be used when formatting the constraint violation message. The last + * element in this array typically contains the value that violated the constraint. + */ private final Object[] args; + /** + * The default message format to use when no localized message is found for the + * message key. This format string may contain placeholders that will be replaced with + * values from the args array. + */ private final String defaultMessageFormat; + /** + * The locale to be used for message localization. If not explicitly specified, the + * system default locale is used. + */ private final Locale locale; + /** + * The message formatter responsible for formatting the constraint violation message. + * This formatter handles the localization and argument substitution in the message + * template. + */ private final MessageFormatter messageFormatter; + /** + * The key used to look up localized messages in resource bundles. This is the primary + * identifier for retrieving the proper message format. + */ private final String messageKey; + /** + * The field or property name that this constraint violation applies to. This + * identifies which part of the validated object failed validation. + */ private final String name; /** @@ -58,40 +104,135 @@ public ConstraintViolation(String name, String messageKey, String defaultMessage this.locale = locale == null ? Locale.getDefault() : locale; } + /** + * Returns the arguments used for message formatting. + * @return an array of objects that were provided as formatting arguments + */ public Object[] args() { return this.args; } + /** + * Returns the default message format string. + * @return the default message format string used when no localized message is found + */ public String defaultMessageFormat() { return this.defaultMessageFormat; } + /** + * Creates and returns a ViolationDetail object that contains structured information + * about this constraint violation. + * + *

+ * The detail object contains the message key, arguments, and formatted message, + * providing a more structured representation of the violation. + * @return a new ViolationDetail instance representing this constraint violation + */ public ViolationDetail detail() { return new ViolationDetail(this.messageKey, this.args, this.message()); } + /** + * Creates and returns a ViolationDetail object that contains structured information + * about this constraint violation, using the provided message formatter. + * + *

+ * This method allows changing the message formatter at runtime, affecting how the + * message in the violation detail is formatted. All other properties (message key, + * arguments) remain the same as in the original constraint violation. + * @param messageFormatter the message formatter to use for formatting the message + * @return a new ViolationDetail instance representing this constraint violation + * @since 0.16.0 + */ + public ViolationDetail detail(MessageFormatter messageFormatter) { + return new ViolationDetail(this.messageKey, this.args, this.message(messageFormatter)); + } + + /** + * Returns the locale used for message localization. + * @return the locale used for message formatting and localization + */ public Locale locale() { return this.locale; } + /** + * Returns the formatted, localized message for this constraint violation. + * + *

+ * The message is formatted using the configured message formatter, applying the + * message key, default message format, arguments, and locale. + * @return the formatted message describing the constraint violation + */ public String message() { return this.messageFormatter.format(this.messageKey, this.defaultMessageFormat, this.args, this.locale); } + /** + * Returns the formatted, localized message for this constraint violation using the + * provided message formatter instead of the one configured at creation time. + * + *

+ * This method allows changing the message formatter at runtime, which is useful when + * different formatting strategies need to be applied to the same constraint + * violation. All other properties (message key, default message format, arguments, + * and locale) remain the same as in the original constraint violation. + * + *

+ * Example usage:

{@code
+	 * // Using a custom message formatter for specific formatting needs
+	 * ConstraintViolation violation = // ... obtain violation
+	 * CustomMessageFormatter formatter = new CustomMessageFormatter();
+	 * String formattedMessage = violation.message(formatter);
+	 * }
+ * @param messageFormatter the message formatter to use for formatting the message + * @return the formatted message using the provided formatter + * @since 0.16.0 + */ + public String message(MessageFormatter messageFormatter) { + return messageFormatter.format(this.messageKey, this.defaultMessageFormat, this.args, this.locale); + } + + /** + * Returns the message key used for looking up localized messages. + * @return the message key for internationalization + */ public String messageKey() { return this.messageKey; } + /** + * Returns the field or property name that this constraint violation applies to. + * @return the name of the field or property that failed validation + */ public String name() { return this.name; } + /** + * Returns a string representation of this constraint violation. + * + *

+ * The string representation includes the name, message key, default message format, + * and arguments. + * @return a string representation of this constraint violation + */ @Override public String toString() { return "ConstraintViolation{" + "name='" + name + '\'' + ", messageKey='" + messageKey + '\'' + ", defaultMessageFormat='" + defaultMessageFormat + '\'' + ", args=" + Arrays.toString(args) + '}'; } + /** + * Returns the value that violated the constraint. + * + *

+ * By convention, the last element in the args array is the actual value that violated + * the constraint. This method provides convenient access to that value. + * @return the value that violated the constraint + * @throws ArrayIndexOutOfBoundsException if the args array is empty + */ public Object violatedValue() { return this.args[this.args.length - 1]; } @@ -215,7 +356,7 @@ public Builder args(Object... args) { /** * Sets the arguments to be used when formatting the message, automatically * including the name as the first argument. - * + * * This method is more convenient than {@link #args(Object...)} when the name * needs to be the first argument in the message, which is a common pattern for * constraint violations. @@ -234,7 +375,7 @@ public Builder argsWithPrependedName(Object... args) { * Sets the arguments to be used when formatting the message, automatically * prepending the name as the first argument and appending the violatedValue as * the last argument. - * + * * This method provides a complete solution for the most common constraint * violation formatting pattern by automatically handling both the name and * violated value positioning. @@ -287,16 +428,41 @@ public ConstraintViolation build() { } /** - * Container interface for the staged builder interfaces. This interface hierarchy - * enables a type-safe builder pattern that enforces required properties to be set in - * a specific order before optional properties. + * Container interface for the staged builder interfaces used in the + * ConstraintViolation's builder pattern. + * + *

+ * This interface hierarchy enables a type-safe builder pattern that enforces required + * properties to be set in a specific order before optional properties. The pattern + * ensures that a ConstraintViolation cannot be built without first setting all + * required properties. + * + *

+ * The staged building process follows this sequence: + *

    + *
  1. First, set the name property ({@link Name})
  2. + *
  3. Then, set the message key property ({@link MessageKey})
  4. + *
  5. Next, set the default message format property + * ({@link DefaultMessageFormat})
  6. + *
  7. Finally, optionally set any additional properties and build + * ({@link Optionals})
  8. + *
+ * + *

+ * This design prevents common errors by making it impossible to build an invalid + * ConstraintViolation instance. * * @since 0.15.0 + * @see Builder */ public interface StagedBuilders { /** * First stage of the builder which requires setting the name property. + * + *

+ * This is the entry point for the staged builder pattern. The name property + * specifies which field or property the constraint violation applies to. */ interface Name { @@ -313,13 +479,25 @@ interface Name { /** * Second stage of the builder which requires setting the message key property. + * + *

+ * This interface represents the second stage in the staged builder pattern after + * the name has been set. The message key is used for internationalization lookup + * to find the appropriate localized message template. */ interface MessageKey { + /** + * The default message key to use when no specific key is needed. This + * constant is used as a fallback when internationalization is not required. + */ String DEFAULT_MESSAGE_KEY = "_"; /** * Sets the message key for internationalization lookup. + * + *

+ * The message key is used to look up localized messages in resource bundles. * @param messageKey the key used to look up localized messages * @return the next stage of the builder which requires setting the default * message format @@ -336,7 +514,7 @@ interface MessageKey { *

  • Prepends the field name as the first argument in the argument list
  • *
  • Builds and returns the final ConstraintViolation object
  • * - * + * *

    * This method is particularly useful for simple constraint violations where * complex message formatting or internationalization is not required. @@ -357,11 +535,21 @@ default ConstraintViolation message(String message) { /** * Third stage of the builder which requires setting the default message format * property. + * + *

    + * This interface represents the third stage in the staged builder pattern after + * the message key has been set. The default message format is the fallback + * message template to use when no localized message is found for the message key. */ interface DefaultMessageFormat { /** * Sets the default message format to use when no localized message is found. + * + *

    + * This format string serves as a fallback when no localized message can be + * found for the specified message key. It may contain placeholders that will + * be replaced with values from the args array during message formatting. * @param defaultMessageFormat the default message format string * @return the final stage of the builder where all remaining properties are * optional @@ -373,11 +561,22 @@ interface DefaultMessageFormat { /** * Final stage of the builder where all remaining properties are optional. The * build() method can be called at any point from this stage. + * + *

    + * This interface represents the final stage in the staged builder pattern after + * all required properties have been set. At this point, the builder can be used + * to set optional properties like arguments, message formatter, and locale, or it + * can directly build the ConstraintViolation instance. */ interface Optionals { /** * Sets the arguments to be used when formatting the message. + * + *

    + * These arguments will be used to replace placeholders in the message format + * string. The exact replacement behavior depends on the message formatter + * being used. * @param args the arguments to be used in message formatting * @return this builder for method chaining */ @@ -386,10 +585,17 @@ interface Optionals { /** * Sets the arguments to be used when formatting the message, automatically * including the name as the first argument. - * + * + *

    * This method is more convenient than {@link #args(Object...)} when the name * needs to be the first argument in the message, which is a common pattern - * for constraint violations. + * for constraint violations. It automatically prepends the field or property + * name to the beginning of the arguments array. + * + *

    + * For example, if the name is "username" and the args are ["must be", 5, + * "characters"], the resulting arguments will be ["username", "must be", 5, + * "characters"]. * @param args the arguments to be used in message formatting (excluding the * name) * @return this builder for method chaining @@ -400,10 +606,20 @@ interface Optionals { * Sets the arguments to be used when formatting the message, automatically * prepending the name as the first argument and appending the violatedValue * as the last argument. - * + * + *

    * This method provides a complete solution for the most common constraint * violation formatting pattern by automatically handling both the name and - * violated value positioning. + * violated value positioning in the arguments array. + * + *

    + * For example, if the name is "username", the args are ["must be between", 3, + * "and", 20], and the violated value is "a", the resulting arguments will be + * ["username", "must be between", 3, "and", 20, "a"]. + * + *

    + * This is particularly useful for formatting validation messages that need to + * reference both the field name and the invalid value that was provided. * @param args optional arguments to be used in message formatting (excluding * both name and violated value) * @param violatedValue the value object that violated the constraint, actual @@ -413,20 +629,30 @@ interface Optionals { Optionals argsWithPrependedNameAndAppendedViolatedValue(Object[] args, ViolatedValue violatedValue); /** - * Sets the message formatter to be used for message formatting. If not - * prepending the name as the first argument and appending the violatedValue - * as the last argument. - * - * This method provides a complete solution for the most common constraint - * violation formatting pattern by automatically handling both the name and - * violated value positioning. + * Sets the message formatter to be used for message formatting. + * + *

    + * The message formatter is responsible for formatting the constraint + * violation message by using the message key to look up localized messages + * and applying the arguments to the message template. + * + *

    + * If not specified, a default {@link SimpleMessageFormatter} will be used. + * @param messageFormatter the message formatter to use for formatting the + * message * @return this builder for method chaining */ Optionals messageFormatter(MessageFormatter messageFormatter); /** - * Sets the locale to be used for message localization. If not specified, the - * system default locale will be used. + * Sets the locale to be used for message localization. + * + *

    + * The locale affects how messages are looked up and formatted, especially for + * internationalized applications that support multiple languages. + * + *

    + * If not specified, the system default locale will be used. * @param locale the locale to use for message localization * @return this builder for method chaining */ @@ -435,7 +661,13 @@ interface Optionals { /** * Builds a new {@link ConstraintViolation} instance with the configured * properties. - * @return a new {@link ConstraintViolation} instance + * + *

    + * This method finalizes the building process and creates a new immutable + * ConstraintViolation instance with all the properties that have been set on + * the builder. Any properties that weren't explicitly set will use + * appropriate default values. + * @return a new immutable {@link ConstraintViolation} instance */ ConstraintViolation build(); diff --git a/src/main/java/am/ik/yavi/core/ConstraintViolations.java b/src/main/java/am/ik/yavi/core/ConstraintViolations.java index 3ba112ed..9ed476d4 100644 --- a/src/main/java/am/ik/yavi/core/ConstraintViolations.java +++ b/src/main/java/am/ik/yavi/core/ConstraintViolations.java @@ -5,7 +5,7 @@ * 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 + * hcodep://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, @@ -68,8 +68,8 @@ public ConstraintViolations(List delegate) { * classes should clearly specify in their documentation any restrictions on what * elements may be added. * @param constraintViolation element to be appended to this list - * @return true (as specified by {@link Collection#add}) - * @throws UnsupportedOperationException if the add operation is not + * @return true (as specified by {@link Collection#add}) + * @throws UnsupportedOperationException if the add operation is not * supported by this list * @throws ClassCastException if the class of the specified element prevents it from * being added to this list @@ -89,7 +89,7 @@ public final boolean add(ConstraintViolation constraintViolation) { * subsequent elements to the right (adds one to their indices). * @param index index at which the specified element is to be inserted * @param element element to be inserted - * @throws UnsupportedOperationException if the add operation is not + * @throws UnsupportedOperationException if the add operation is not * supported by this list * @throws ClassCastException if the class of the specified element prevents it from * being added to this list @@ -98,7 +98,7 @@ public final boolean add(ConstraintViolation constraintViolation) { * @throws IllegalArgumentException if some property of the specified element prevents * it from being added to this list * @throws IndexOutOfBoundsException if the index is out of range - * (index < 0 || index > size()) + * (index < 0 || index > size()) */ @Override public final void add(int index, ConstraintViolation element) { @@ -112,8 +112,8 @@ public final void add(int index, ConstraintViolation element) { * is modified while the operation is in progress. (Note that this will occur if the * specified collection is this list, and it's nonempty.) * @param c collection containing elements to be added to this list - * @return true if this list changed as a result of the call - * @throws UnsupportedOperationException if the addAll operation is not + * @return true if this list changed as a result of the call + * @throws UnsupportedOperationException if the addAll operation is not * supported by this list * @throws ClassCastException if the class of an element of the specified collection * prevents it from being added to this list @@ -141,8 +141,8 @@ public final boolean addAll(Collection c) { * @param index index at which to insert the first element from the specified * collection * @param c collection containing elements to be added to this list - * @return true if this list changed as a result of the call - * @throws UnsupportedOperationException if the addAll operation is not + * @return true if this list changed as a result of the call + * @throws UnsupportedOperationException if the addAll operation is not * supported by this list * @throws ClassCastException if the class of an element of the specified collection * prevents it from being added to this list @@ -152,7 +152,7 @@ public final boolean addAll(Collection c) { * @throws IllegalArgumentException if some property of an element of the specified * collection prevents it from being added to this list * @throws IndexOutOfBoundsException if the index is out of range - * (index < 0 || index > size()) + * (index < 0 || index > size()) */ @Override public final boolean addAll(int index, Collection c) { @@ -162,7 +162,7 @@ public final boolean addAll(int index, Collection /** * This method is intended to be used with Spring MVC * - *

    sample

    + * sample * *
    * - * Similar idioms may be constructed for indexOf and lastIndexOf, - * and all of the algorithms in the Collections class can be applied to a - * subList. + * Similar idioms may be constructed for indexOf and + * lastIndexOf, and all of the algorithms in the Collections + * class can be applied to a subList. *

    *

    * The semantics of the list returned by this method become undefined if the backing @@ -486,8 +487,8 @@ public final int size() { * @param toIndex high endpoint (exclusive) of the subList * @return a view of the specified range within this list * @throws IndexOutOfBoundsException for an illegal endpoint index value - * (fromIndex < 0 || toIndex > size || - * fromIndex > toIndex) + * (fromIndex < 0 || toIndex > size || + * fromIndex > toIndex) */ @Override public final List subList(int fromIndex, int toIndex) { @@ -530,9 +531,9 @@ public final Object[] toArray() { *

    * If the list fits in the specified array with room to spare (i.e., the array has * more elements than the list), the element in the array immediately following the - * end of the list is set to null. (This is useful in determining the length - * of the list only if the caller knows that the list does not contain any null - * elements.) + * end of the list is set to null. (This is useful in determining the + * length of the list only if the caller knows that the list does not contain + * any null elements.) * *

    * Like the {@link #toArray()} method, this method acts as bridge between array-based @@ -541,8 +542,8 @@ public final Object[] toArray() { * save allocation costs. * *

    - * Suppose x is a list known to contain only strings. The following code can - * be used to dump the list into a newly allocated array of String: + * Suppose x is a list known to contain only strings. The following code + * can be used to dump the list into a newly allocated array of String: * *

     	 * {
    @@ -551,8 +552,8 @@ public final Object[] toArray() {
     	 * }
     	 * 
    *

    - * Note that toArray(new Object[0]) is identical in function to - * toArray(). + * Note that toArray(new Object[0]) is identical in function to + * toArray(). * @param a the array into which the elements of this list are to be stored, if it is * big enough; otherwise, a new array of the same runtime type is allocated for this * purpose. diff --git a/src/main/java/am/ik/yavi/factory/BiValidatorFactory.java b/src/main/java/am/ik/yavi/factory/BiValidatorFactory.java deleted file mode 100644 index 67efa79d..00000000 --- a/src/main/java/am/ik/yavi/factory/BiValidatorFactory.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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. - * 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.factory; - -import java.util.function.Function; - -import am.ik.yavi.builder.ValidatorBuilder; -import am.ik.yavi.core.BiValidator; -import am.ik.yavi.core.BiValidator.ErrorHandler; -import am.ik.yavi.jsr305.Nullable; -import am.ik.yavi.message.MessageFormatter; - -/** - * Deprecated in favor of {@link BiConsumerFactory} - * - * A factory class of BiValidator. It can be used to manage the common - * configurations of BiValidator in IoC container etc.
    - * - * In case of Spring Framework, you can define BiValidatorFactory as follows: - * - *

    - *{@literal @Bean}
    - * public BiValidatorFactory<Errors> biValidatorFactory(MessageSource messageSource) {
    - *   MessageFormatter messageFormatter = new MessageSourceMessageFormatter(messageSource::getMessage);
    - *   return new BiValidatorFactory<>(null, messageFormatter, Errors::rejectValues);
    - * }
    - * 
    - * - * A component can create a validator like following: - * - *
    - *{@literal @RestController}
    - * public class OrderController {
    - *     private final BiValidator<CartItem, Errors> validator;
    - *
    - *     public OrderController(BiValidatorFactory<Errors> factory) {
    - *         this.validator = factory.validator(builder -> builder.constraint(...));
    - *     }
    - * }
    - * 
    - * - * @param the type of the errors object - * @author Toshiaki Maki - * @since 0.5.0 - */ -@Deprecated -public class BiValidatorFactory extends ValidatorFactorySupport { - - private final BiValidator.ErrorHandler errorHandler; - - public BiValidatorFactory(@Nullable String messageKeySeparator, @Nullable MessageFormatter messageFormatter, - @Nullable ErrorHandler errorHandler) { - super(messageKeySeparator, messageFormatter); - this.errorHandler = errorHandler; - } - - public BiValidatorFactory(@Nullable ErrorHandler errorHandler) { - this(null, null, errorHandler); - } - - public BiValidator validator(Function, ValidatorBuilder> constraints) { - if (this.errorHandler == null) { - throw new IllegalArgumentException("'errorHandler' must not be null."); - } - final ValidatorBuilder builder = super.initBuilder(); - return constraints.apply(builder).build(this.errorHandler); - } - -} diff --git a/src/main/java/am/ik/yavi/processor/ConstraintMetaTemplate.java b/src/main/java/am/ik/yavi/processor/ConstraintMetaTemplate.java index 7f67c419..7ca7146c 100644 --- a/src/main/java/am/ik/yavi/processor/ConstraintMetaTemplate.java +++ b/src/main/java/am/ik/yavi/processor/ConstraintMetaTemplate.java @@ -88,7 +88,7 @@ static String templateArgument(String className, String type, String target, int + "\t\t\treturn %s;\n" + // "\t\t}\n" + // "\t}", simpleType, metaType, target.toUpperCase(), simpleType, metaType, target, className, type, - "am.ik.yavi.arguments.Arguments" + position + "::arg" + position); + className.replaceAll("<(.+)>", "") + "::arg" + position); } private static String simpleType(String type) { diff --git a/src/test/java/am/ik/yavi/arguments/ArgumentsTest.java b/src/test/java/am/ik/yavi/arguments/ArgumentsTest.java new file mode 100644 index 00000000..bb86d5d0 --- /dev/null +++ b/src/test/java/am/ik/yavi/arguments/ArgumentsTest.java @@ -0,0 +1,41 @@ +package am.ik.yavi.arguments; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class ArgumentsTest { + + @Test + void arguments3() { + Arguments3 args = Arguments.of(1, "two", 3.0); + assertThat(args.arg1()).isEqualTo(1); + assertThat(args.arg2()).isEqualTo("two"); + assertThat(args.arg3()).isEqualTo(3.0); + assertThat(args.first1()).isEqualTo(Arguments.of(1)); + assertThat(args.first2()).isEqualTo(Arguments.of(1, "two")); + assertThat(args.last1()).isEqualTo(Arguments.of(3.0)); + assertThat(args.last2()).isEqualTo(Arguments.of("two", 3.0)); + assertThat(args.append(4.0f)).isEqualTo(Arguments.of(1, "two", 3.0, 4.0f)); + assertThat(args.prepend(0)).isEqualTo(Arguments.of(0, 1, "two", 3.0)); + assertThat(args.reverse()).isEqualTo(Arguments.of(3.0, "two", 1)); + } + + @Test + void arguments4() { + Arguments4 args = Arguments.of(1, "two", 3.0, 4.0f); + assertThat(args.arg1()).isEqualTo(1); + assertThat(args.arg2()).isEqualTo("two"); + assertThat(args.arg3()).isEqualTo(3.0); + assertThat(args.arg4()).isEqualTo(4.0f); + assertThat(args.first1()).isEqualTo(Arguments.of(1)); + assertThat(args.first2()).isEqualTo(Arguments.of(1, "two")); + assertThat(args.first3()).isEqualTo(Arguments.of(1, "two", 3.0)); + assertThat(args.last1()).isEqualTo(Arguments.of(4.0f)); + assertThat(args.last2()).isEqualTo(Arguments.of(3.0, 4.0f)); + assertThat(args.last3()).isEqualTo(Arguments.of("two", 3.0, 4.0f)); + assertThat(args.append(5)).isEqualTo(Arguments.of(1, "two", 3.0, 4.0f, 5)); + assertThat(args.prepend(0)).isEqualTo(Arguments.of(0, 1, "two", 3.0, 4.0f)); + } + +} \ No newline at end of file diff --git a/src/test/java/am/ik/yavi/arguments/ArgumentsValidatorTest.java b/src/test/java/am/ik/yavi/arguments/ArgumentsValidatorTest.java index 7de5b604..42d970c6 100644 --- a/src/test/java/am/ik/yavi/arguments/ArgumentsValidatorTest.java +++ b/src/test/java/am/ik/yavi/arguments/ArgumentsValidatorTest.java @@ -15,26 +15,33 @@ */ package am.ik.yavi.arguments; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - import am.ik.yavi.Country; import am.ik.yavi.PhoneNumber; import am.ik.yavi.Range; import am.ik.yavi.User; import am.ik.yavi.builder.ArgumentsValidatorBuilder; +import am.ik.yavi.builder.LocalDateValidatorBuilder; +import am.ik.yavi.builder.LocalTimeValidatorBuilder; import am.ik.yavi.builder.StringValidatorBuilder; import am.ik.yavi.core.ConstraintViolations; import am.ik.yavi.core.ConstraintViolationsException; import am.ik.yavi.core.Validated; import am.ik.yavi.core.ViolationMessage; +import am.ik.yavi.fn.Pair; +import java.time.LocalDate; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; import org.junit.jupiter.api.Test; +import static am.ik.yavi.core.ValueValidator.passThrough; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -48,7 +55,7 @@ class ArgumentsValidatorTest { .build(); final Arguments2Validator arguments2Validator = ArgumentsValidatorBuilder.of(Range::new) - .builder(b -> b._integer(Arguments1::arg1, "from", c -> c.greaterThanOrEqual(0).lessThanOrEqual(9)) + .builder(b -> b._integer(Arguments2::arg1, "from", c -> c.greaterThanOrEqual(0).lessThanOrEqual(9)) ._integer(Arguments2::arg2, "to", c -> c.greaterThanOrEqual(0).lessThanOrEqual(9)) .constraintOnTarget(a -> a.arg1() < a.arg2(), "range", ViolationMessage.of("to.isGreaterThanFrom", "\"to\" must be greater than \"from\"."))) @@ -56,8 +63,8 @@ class ArgumentsValidatorTest { final Arguments3Validator arguments3Validator = ArgumentsValidatorBuilder .of(User::new) - .builder(b -> b._string(Arguments1::arg1, "name", c -> c.notNull().greaterThanOrEqual(1).lessThanOrEqual(20)) - ._string(Arguments2::arg2, "email", c -> c.notNull().greaterThanOrEqual(5).lessThanOrEqual(50).email()) + .builder(b -> b._string(Arguments3::arg1, "name", c -> c.notNull().greaterThanOrEqual(1).lessThanOrEqual(20)) + ._string(Arguments3::arg2, "email", c -> c.notNull().greaterThanOrEqual(5).lessThanOrEqual(50).email()) ._integer(Arguments3::arg3, "age", c -> c.notNull().greaterThanOrEqual(0).lessThanOrEqual(200))) .build(); @@ -385,4 +392,170 @@ void lazyValidationInConstructor_fail() { assertThat(violations.get(2).args()[0]).isEqualTo("seatCount"); } + @Test + void wrap() { + Arguments1Validator, User> wrapValidator = arguments3Validator.wrap(); + Validated validate = wrapValidator.validate(Arguments.of("foo", "foo@example", 18)); + assertThat(validate.isValid()).isTrue(); + User user = validate.value(); + assertThat(user.getName()).isEqualTo("foo"); + assertThat(user.getEmail()).isEqualTo("foo@example"); + assertThat(user.getAge()).isEqualTo(18); + } + + @Test + void unwrap() { + Arguments1Validator, User> wrapValidator = arguments3Validator + .compose(Function.identity()); + Arguments3Validator unwrapValidator = Arguments3Validator.unwrap(wrapValidator); + Validated validate = unwrapValidator.validate("foo", "foo@example", 18); + assertThat(validate.isValid()).isTrue(); + User user = validate.value(); + assertThat(user.getName()).isEqualTo("foo"); + assertThat(user.getEmail()).isEqualTo("foo@example"); + assertThat(user.getAge()).isEqualTo(18); + } + + static class TimeSlot { + + private final LocalTime startTime; + + private final LocalTime endTime; + + private static final Function> localTimeValidator = name -> LocalTimeValidatorBuilder + .of(name, c -> c.notNull()) + .build(); + + private static final LocalTimeValidator startTimeValidator = localTimeValidator.apply("startTime"); + + private static final LocalTimeValidator endTimeValidator = localTimeValidator.apply("endTime"); + + public static Arguments2Validator validator = startTimeValidator + .split(endTimeValidator) + .apply(TimeSlot::new); + + public TimeSlot(LocalTime startTime, LocalTime endTime) { + validator.lazy().validate(startTime, endTime); + this.startTime = startTime; + this.endTime = endTime; + } + + } + + static class Reservation { + + private final LocalDate date; + + private final LocalTime startTime; + + private final LocalTime endTime; + + private static final LocalDateValidator localDateValidator = LocalDateValidatorBuilder + .of("date", c -> c.notNull()) + .build(); + + public static Arguments1Validator, Reservation> v1 = localDateValidator + .wrap() + .>compose(Arguments3::first1) + .combine(TimeSlot.validator.wrap().compose(Arguments3::last2)) + .apply((localDate, timeSlot) -> new Reservation(Objects.requireNonNull(localDate), + Objects.requireNonNull(timeSlot).startTime, timeSlot.endTime)); + + public static final Arguments3Validator validator = Arguments3Validator + .unwrap(v1); + + public Reservation(LocalDate date, LocalTime startTime, LocalTime endTime) { + validator.lazy().validated(date, startTime, endTime); + this.date = date; + this.startTime = startTime; + this.endTime = endTime; + } + + } + + @Test + void wrapLazy() { + arguments1Validator.wrap().lazy().validated(Arguments.of("JP")); + arguments2Validator.wrap().lazy().validated(Arguments.of(1, 2)); + arguments3Validator.wrap().lazy().validated(Arguments.of("aa", "bb@cc.dd", 18)); + } + + @Test + void unwrapLazy() { + Arguments1Validator.unwrap(arguments1Validator.wrap()).lazy().validated("JP"); + Arguments2Validator.unwrap(arguments2Validator.wrap()).lazy().validated(1, 2); + Arguments3Validator.unwrap(arguments3Validator.wrap()).lazy().validated("aa", "bb@cc.dd", 18); + } + + @Test + void combine() { + Arguments1Validator, Range> rangeValidator = arguments2Validator.wrap(); + Arguments1Validator, User> userValidator = arguments3Validator.wrap(); + + Arguments1Validator, Range> composedRangeValidator = rangeValidator + .compose(Arguments5::first2); + Arguments1Validator, User> composedUserValidator = userValidator + .compose(Arguments5::last3); + + Arguments1Validator, Pair> combinedValidator = composedRangeValidator + .combine(composedUserValidator) + .apply((range, user) -> new Pair<>(Objects.requireNonNull(range), Objects.requireNonNull(user))); + + Arguments5Validator> unwrapValidator = Arguments5Validator + .unwrap(combinedValidator); + + { + Validated> pairValidated = unwrapValidator.validate(1, 2, "foo", "foo@example.com", 18); + assertThat(pairValidated.isValid()).isTrue(); + Pair pair = pairValidated.value(); + assertThat(pair.first().getFrom()).isEqualTo(1); + assertThat(pair.first().getTo()).isEqualTo(2); + assertThat(pair.second().getName()).isEqualTo("foo"); + assertThat(pair.second().getEmail()).isEqualTo("foo@example.com"); + assertThat(pair.second().getAge()).isEqualTo(18); + } + { + Validated> pairValidated = unwrapValidator.validate(20, 10, "foo", "barbar", -1); + assertThat(pairValidated.isValid()).isFalse(); + ConstraintViolations violations = pairValidated.errors(); + assertThat(violations).hasSize(5); + assertThat(violations.get(0).message()).isEqualTo("\"from\" must be less than or equal to 9"); + assertThat(violations.get(1).message()).isEqualTo("\"to\" must be less than or equal to 9"); + assertThat(violations.get(2).message()).isEqualTo("\"to\" must be greater than \"from\"."); + assertThat(violations.get(3).message()).isEqualTo("\"email\" must be a valid email address"); + assertThat(violations.get(4).message()).isEqualTo("\"age\" must be greater than or equal to 0"); + } + } + + @Test + void andThenLazy() { + arguments1Validator.andThen(Country::name).lazy().validated("JP"); + arguments2Validator.andThen(range -> range.getFrom() + "-" + range.getTo()).lazy().validated(1, 2); + arguments3Validator.andThen(User::getName).lazy().validated("aa", "bb@cc.dd", 18); + } + + @Test + void andThenValidatorLazy() { + arguments1Validator.andThen(passThrough()).lazy().validated("JP"); + arguments2Validator.andThen(passThrough()).lazy().validated(1, 2); + arguments3Validator.andThen(passThrough()).lazy().validated("aa", "bb@cc.dd", 18); + } + + @Test + void composeLazy() { + arguments1Validator.compose(objects -> (String) objects[0]).lazy().validated(new Object[] { "JP" }); + arguments2Validator.compose(objects -> Arguments.of((Integer) objects[0], (Integer) objects[1])) + .lazy() + .validated(new Object[] { 1, 2 }); + arguments3Validator + .compose(objects -> Arguments.of((String) objects[0], (String) objects[1], (Integer) objects[2])) + .lazy() + .validated(new Object[] { "aa", "bb@cc.dd", 18 }); + } + + @Test + void combineUnwrapLazy() { + new Reservation(LocalDate.of(2025, 10, 1), LocalTime.of(10, 0), LocalTime.of(11, 0)); + } + } diff --git a/src/test/java/am/ik/yavi/arguments/MethodInvocationTest.java b/src/test/java/am/ik/yavi/arguments/MethodInvocationTest.java index 3f94209a..a48b82b2 100644 --- a/src/test/java/am/ik/yavi/arguments/MethodInvocationTest.java +++ b/src/test/java/am/ik/yavi/arguments/MethodInvocationTest.java @@ -28,9 +28,9 @@ public class MethodInvocationTest { static final Arguments4Validator validator = ArgumentsValidatorBuilder .of(UserService::createUser) // .builder(b -> b // - ._object(Arguments1::arg1, "userService", c -> c.notNull()) - ._string(Arguments2::arg2, "email", c -> c.email()) - ._string(Arguments3::arg3, "name", c -> c.notNull()) + ._object(Arguments4::arg1, "userService", c -> c.notNull()) + ._string(Arguments4::arg2, "email", c -> c.email()) + ._string(Arguments4::arg3, "name", c -> c.notNull()) ._enum(Arguments4::arg4, "role", c -> c.notNull().oneOf(Role.USER, Role.ADMIN))) // .build(); diff --git a/src/test/java/am/ik/yavi/arguments/Product.java b/src/test/java/am/ik/yavi/arguments/Product.java index 8a11e800..4c9ea3a5 100644 --- a/src/test/java/am/ik/yavi/arguments/Product.java +++ b/src/test/java/am/ik/yavi/arguments/Product.java @@ -26,7 +26,7 @@ public class Product { static final Arguments2Validator validator = ArgumentsValidatorBuilder.of(Product::new) // .builder(b -> b // - ._string(Arguments1::arg1, "name", c -> c.notEmpty()) + ._string(Arguments2::arg1, "name", c -> c.notEmpty()) ._integer(Arguments2::arg2, "price", c -> c.greaterThan(0))) .build(); diff --git a/src/test/java/am/ik/yavi/constraint/BigDecimalConstraintTest.java b/src/test/java/am/ik/yavi/constraint/BigDecimalConstraintTest.java index 78223ebd..5993b9cf 100644 --- a/src/test/java/am/ik/yavi/constraint/BigDecimalConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/BigDecimalConstraintTest.java @@ -125,20 +125,6 @@ void invalidPositiveOrZero(BigDecimal value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(strings = { "99", "100" }) - void invalidNegaitveOrZero(BigDecimal value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(strings = { "-101", "-150", "0" }) - void validNegaitveOrZero(BigDecimal value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(strings = { "99", "100" }) void invalidNegativeOrZero(BigDecimal value) { diff --git a/src/test/java/am/ik/yavi/constraint/BigIntegerConstraintTest.java b/src/test/java/am/ik/yavi/constraint/BigIntegerConstraintTest.java index ad76d7e9..1ec7dd2e 100644 --- a/src/test/java/am/ik/yavi/constraint/BigIntegerConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/BigIntegerConstraintTest.java @@ -126,20 +126,6 @@ void invalidPositiveOrZero(BigInteger value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(strings = { "99", "100" }) - void invalidNegaitveOrZero(BigInteger value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(strings = { "-101", "-150", "0" }) - void validNegaitveOrZero(BigInteger value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(strings = { "99", "100" }) void invalidNegativeOrZero(BigInteger value) { diff --git a/src/test/java/am/ik/yavi/constraint/ByteConstraintTest.java b/src/test/java/am/ik/yavi/constraint/ByteConstraintTest.java index 6550a682..64c25491 100644 --- a/src/test/java/am/ik/yavi/constraint/ByteConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/ByteConstraintTest.java @@ -125,20 +125,6 @@ void invalidPositiveOrZero(byte value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(strings = { "99", "100" }) - void invalidNegaitveOrZero(byte value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(strings = { "-101", "-120", "0" }) - void validNegaitveOrZero(byte value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(strings = { "99", "100" }) void invalidNegativeOrZero(byte value) { diff --git a/src/test/java/am/ik/yavi/constraint/DoubleConstraintTest.java b/src/test/java/am/ik/yavi/constraint/DoubleConstraintTest.java index 82831626..ab8be927 100644 --- a/src/test/java/am/ik/yavi/constraint/DoubleConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/DoubleConstraintTest.java @@ -124,20 +124,6 @@ void invalidPositiveOrZero(double value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(doubles = { 99.0, 100 }) - void invalidNegaitveOrZero(double value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(doubles = { -101, -120, 0 }) - void validNegaitveOrZero(double value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(doubles = { 99.0, 100 }) void invalidNegativeOrZero(double value) { diff --git a/src/test/java/am/ik/yavi/constraint/FloatConstraintTest.java b/src/test/java/am/ik/yavi/constraint/FloatConstraintTest.java index 988faf29..12d58e62 100644 --- a/src/test/java/am/ik/yavi/constraint/FloatConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/FloatConstraintTest.java @@ -124,20 +124,6 @@ void invalidPositiveOrZero(float value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(floats = { 99.0f, 100f }) - void invalidNegaitveOrZero(float value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(floats = { -101f, -120f, 0f }) - void validNegaitveOrZero(float value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(floats = { 99.0f, 100f }) void invalidNegativeOrZero(float value) { diff --git a/src/test/java/am/ik/yavi/constraint/IntegerConstraintTest.java b/src/test/java/am/ik/yavi/constraint/IntegerConstraintTest.java index a6584035..067d02d3 100644 --- a/src/test/java/am/ik/yavi/constraint/IntegerConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/IntegerConstraintTest.java @@ -124,20 +124,6 @@ void invalidPositiveOrZero(int value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(ints = { 99, 100 }) - void invalidNegaitveOrZero(int value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(ints = { -101, -120, 0 }) - void validNegaitveOrZero(int value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(ints = { 99, 100 }) void invalidNegativeOrZero(int value) { diff --git a/src/test/java/am/ik/yavi/constraint/LongConstraintTest.java b/src/test/java/am/ik/yavi/constraint/LongConstraintTest.java index 06aa44f2..8f13ab8c 100644 --- a/src/test/java/am/ik/yavi/constraint/LongConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/LongConstraintTest.java @@ -124,20 +124,6 @@ void invalidPositiveOrZero(long value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(longs = { 99, 100 }) - void invalidNegaitveOrZero(long value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(longs = { -101, -120, 0 }) - void validNegaitveOrZero(long value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(longs = { 99, 100 }) void invalidNegativeOrZero(long value) { diff --git a/src/test/java/am/ik/yavi/constraint/ShortConstraintTest.java b/src/test/java/am/ik/yavi/constraint/ShortConstraintTest.java index aae9fa25..b0937300 100644 --- a/src/test/java/am/ik/yavi/constraint/ShortConstraintTest.java +++ b/src/test/java/am/ik/yavi/constraint/ShortConstraintTest.java @@ -124,20 +124,6 @@ void invalidPositiveOrZero(short value) { assertThat(predicate.test(value)).isFalse(); } - @ParameterizedTest - @ValueSource(shorts = { 99, 100 }) - void invalidNegaitveOrZero(short value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isFalse(); - } - - @ParameterizedTest - @ValueSource(shorts = { -101, -120, 0 }) - void validNegaitveOrZero(short value) { - Predicate predicate = retrievePredicate(NumericConstraintBase::negaitveOrZero); - assertThat(predicate.test(value)).isTrue(); - } - @ParameterizedTest @ValueSource(shorts = { 99, 100 }) void invalidNegativeOrZero(short value) { diff --git a/src/test/java/am/ik/yavi/core/BiValidatorTest.java b/src/test/java/am/ik/yavi/core/BiValidatorTest.java deleted file mode 100644 index a8084d5a..00000000 --- a/src/test/java/am/ik/yavi/core/BiValidatorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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. - * 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.core; - -import am.ik.yavi.User; -import am.ik.yavi.builder.ValidatorBuilder; -import am.ik.yavi.core.BiValidator.ErrorHandler; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import static org.assertj.core.api.Assertions.assertThat; - -class BiValidatorTest { - - static final ErrorHandler> errorHandler = (errors, name, messageKey, args, - defaultMessage) -> errors.add(ConstraintViolation.builder() - .name(name) - .messageKey(messageKey) - .defaultMessageFormat(defaultMessage) - .args(args) - .build()); - - static final Validator userValidator = ValidatorBuilder.of(User.class) - .constraint(User::getName, "name", c -> c.notNull().greaterThanOrEqual(1).lessThanOrEqual(20)) - .constraint(User::getEmail, "email", c -> c.notNull().greaterThanOrEqual(5).lessThanOrEqual(50).email()) - .constraint(User::getAge, "age", c -> c.notNull().greaterThanOrEqual(0).lessThanOrEqual(200)) - .constraint(User::isEnabled, "enabled", c -> c.isTrue()) - .build(); - - static Stream>> validators() { - return Stream.of(new BiValidator<>(userValidator, errorHandler), - new BiValidator<>(userValidator.applicative(), errorHandler)); - } - - @ParameterizedTest - @MethodSource("validators") - void allValid(BiValidator> validator) throws Exception { - User user = new User("Demo", "demo@example.com", 100); - user.setEnabled(true); - final List violations = new ArrayList<>(); - - validator.accept(user, violations); - assertThat(violations.size()).isEqualTo(0); - } - - @ParameterizedTest - @MethodSource("validators") - void allInvalid(BiValidator> validator) throws Exception { - User user = new User("", "example.com", 300); - user.setEnabled(false); - final List violations = new ArrayList<>(); - - validator.accept(user, violations); - assertThat(violations.size()).isEqualTo(4); - assertThat(violations.get(0).message()) - .isEqualTo("The size of \"name\" must be greater than or equal to 1. The given size is 0"); - assertThat(violations.get(0).messageKey()).isEqualTo("container.greaterThanOrEqual"); - assertThat(violations.get(1).message()).isEqualTo("\"email\" must be a valid email address"); - assertThat(violations.get(1).messageKey()).isEqualTo("charSequence.email"); - assertThat(violations.get(2).message()).isEqualTo("\"age\" must be less than or equal to 200"); - assertThat(violations.get(2).messageKey()).isEqualTo("numeric.lessThanOrEqual"); - assertThat(violations.get(3).message()).isEqualTo("\"enabled\" must be true"); - assertThat(violations.get(3).messageKey()).isEqualTo("boolean.isTrue"); - } - -} diff --git a/src/test/java/am/ik/yavi/core/CastTest.java b/src/test/java/am/ik/yavi/core/CastTest.java index 24a17fbf..04d042fa 100644 --- a/src/test/java/am/ik/yavi/core/CastTest.java +++ b/src/test/java/am/ik/yavi/core/CastTest.java @@ -15,12 +15,11 @@ */ package am.ik.yavi.core; +import am.ik.yavi.builder.ValidatorBuilder; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import am.ik.yavi.builder.ValidatorBuilder; - class CastTest { @Test @@ -54,7 +53,7 @@ void originalValidatorShouldAlsoWork_GH23() { static class Employee extends Person { - static final Validator validator = Person.validatorBuilder.clone() + static final Validator validator = new ValidatorBuilder<>(Person.validatorBuilder) .cast(Employee.class) .constraint(Employee::getServiceId, "service", Constraint::notNull) .build(); @@ -92,8 +91,7 @@ void setName(String name) { static class Student extends Person { - static final Validator validator = Person.validatorBuilder.clone() - .cast(Student.class) + static final Validator validator = new ValidatorBuilder<>(Person.validatorBuilder).cast(Student.class) .constraint(Student::getId, "id", Constraint::notNull) .build(); diff --git a/src/test/java/am/ik/yavi/factory/BiValidatorFactoryTest.java b/src/test/java/am/ik/yavi/factory/BiValidatorFactoryTest.java deleted file mode 100644 index 6ec06baf..00000000 --- a/src/test/java/am/ik/yavi/factory/BiValidatorFactoryTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - * 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.factory; - -import am.ik.yavi.User; -import am.ik.yavi.core.BiValidator; -import am.ik.yavi.core.BiValidator.ErrorHandler; -import am.ik.yavi.core.ConstraintViolation; -import java.util.ArrayList; -import java.util.List; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class BiValidatorFactoryTest { - - private final ErrorHandler> errorHandler = (errors, name, messageKey, args, - defaultMessage) -> errors.add(ConstraintViolation.builder() - .name(name) - .messageKey(messageKey) - .defaultMessageFormat(defaultMessage) - .args(args) - .build()); - - private final BiValidatorFactory> validatorFactory = new BiValidatorFactory<>( - this.errorHandler); - - @Test - void validator() { - final BiValidator> validator = this.validatorFactory - .validator(builder -> builder - .constraint(User::getName, "name", c -> c.notNull().greaterThanOrEqual(1).lessThanOrEqual(20)) - .constraint(User::getEmail, "email", c -> c.notNull().greaterThanOrEqual(5).lessThanOrEqual(50).email()) - .constraint(User::getAge, "age", c -> c.notNull().greaterThanOrEqual(0).lessThanOrEqual(200)) - .constraint(User::isEnabled, "enabled", c -> c.isTrue())); - - final User user = new User("", "example.com", 300); - user.setEnabled(false); - final List violations = new ArrayList<>(); - - validator.accept(user, violations); - assertThat(violations.size()).isEqualTo(4); - assertThat(violations.get(0).message()) - .isEqualTo("The size of \"name\" must be greater than or equal to 1. The given size is 0"); - assertThat(violations.get(0).messageKey()).isEqualTo("container.greaterThanOrEqual"); - assertThat(violations.get(1).message()).isEqualTo("\"email\" must be a valid email address"); - assertThat(violations.get(1).messageKey()).isEqualTo("charSequence.email"); - assertThat(violations.get(2).message()).isEqualTo("\"age\" must be less than or equal to 200"); - assertThat(violations.get(2).messageKey()).isEqualTo("numeric.lessThanOrEqual"); - assertThat(violations.get(3).message()).isEqualTo("\"enabled\" must be true"); - assertThat(violations.get(3).messageKey()).isEqualTo("boolean.isTrue"); - } - -} \ No newline at end of file diff --git a/src/test/java/am/ik/yavi/meta/_PersonArgumentsMeta.java b/src/test/java/am/ik/yavi/meta/_PersonArgumentsMeta.java index eb40bf24..2c0303d4 100644 --- a/src/test/java/am/ik/yavi/meta/_PersonArgumentsMeta.java +++ b/src/test/java/am/ik/yavi/meta/_PersonArgumentsMeta.java @@ -27,7 +27,7 @@ public String name() { @Override public java.util.function.Function, java.lang.String> toValue() { - return am.ik.yavi.arguments.Arguments1::arg1; + return am.ik.yavi.arguments.Arguments3::arg1; } }; @@ -40,7 +40,7 @@ public String name() { @Override public java.util.function.Function, java.lang.String> toValue() { - return am.ik.yavi.arguments.Arguments2::arg2; + return am.ik.yavi.arguments.Arguments3::arg2; } }; diff --git a/src/test/java/am/ik/yavi/meta/_UserServiceCreateUserArgumentsMeta.java b/src/test/java/am/ik/yavi/meta/_UserServiceCreateUserArgumentsMeta.java index f13fa99c..d5e02e59 100644 --- a/src/test/java/am/ik/yavi/meta/_UserServiceCreateUserArgumentsMeta.java +++ b/src/test/java/am/ik/yavi/meta/_UserServiceCreateUserArgumentsMeta.java @@ -26,7 +26,7 @@ public String name() { @Override public java.util.function.Function, am.ik.yavi.meta.UserService> toValue() { - return am.ik.yavi.arguments.Arguments1::arg1; + return am.ik.yavi.arguments.Arguments3::arg1; } }; @@ -39,7 +39,7 @@ public String name() { @Override public java.util.function.Function, String> toValue() { - return am.ik.yavi.arguments.Arguments2::arg2; + return am.ik.yavi.arguments.Arguments3::arg2; } }; diff --git a/src/test/resources/test/_Car2ArgumentsMeta.java b/src/test/resources/test/_Car2ArgumentsMeta.java index 71dbe972..2eb24898 100644 --- a/src/test/resources/test/_Car2ArgumentsMeta.java +++ b/src/test/resources/test/_Car2ArgumentsMeta.java @@ -26,7 +26,7 @@ public String name() { @Override public java.util.function.Function, java.lang.String> toValue() { - return am.ik.yavi.arguments.Arguments1::arg1; + return am.ik.yavi.arguments.Arguments2::arg1; } }; diff --git a/src/test/resources/test/_UserServiceCreateUserArgumentsMeta.java b/src/test/resources/test/_UserServiceCreateUserArgumentsMeta.java index 94a3d053..81a046d3 100644 --- a/src/test/resources/test/_UserServiceCreateUserArgumentsMeta.java +++ b/src/test/resources/test/_UserServiceCreateUserArgumentsMeta.java @@ -26,7 +26,7 @@ public String name() { @Override public java.util.function.Function, test.UserService> toValue() { - return am.ik.yavi.arguments.Arguments1::arg1; + return am.ik.yavi.arguments.Arguments3::arg1; } }; @@ -39,7 +39,7 @@ public String name() { @Override public java.util.function.Function, java.lang.String> toValue() { - return am.ik.yavi.arguments.Arguments2::arg2; + return am.ik.yavi.arguments.Arguments3::arg2; } };
     	 * @PostMapping("users")
    @@ -186,7 +186,7 @@ public ConstraintViolations apply(Callback callback) {
     	/**
     	 * Removes all of the elements from this list (optional operation). The list will be
     	 * empty after this call returns.
    -	 * @throws UnsupportedOperationException if the clear operation is not
    +	 * @throws UnsupportedOperationException if the clear operation is not
     	 * supported by this list
     	 */
     	@Override
    @@ -195,12 +195,12 @@ public final void clear() {
     	}
     
     	/**
    -	 * Returns true if this list contains the specified element. More formally,
    -	 * returns true if and only if this list contains at least one element
    -	 * e such that
    -	 * (o==null ? e==null : o.equals(e)).
    +	 * Returns true if this list contains the specified element. More
    +	 * formally, returns true if and only if this list contains at least one
    +	 * element e such that
    +	 * (o==null ? e==null : o.equals(e)).
     	 * @param o element whose presence in this list is to be tested
    -	 * @return true if this list contains the specified element
    +	 * @return true if this list contains the specified element
     	 * @throws ClassCastException if the type of the specified element is incompatible
     	 * with this list (optional)
     	 * @throws NullPointerException if the specified element is null and this list does
    @@ -213,11 +213,11 @@ public final boolean contains(Object o) {
     	}
     
     	/**
    -	 * Returns true if this list contains all of the elements of the specified
    -	 * collection.
    +	 * Returns true if this list contains all of the elements of the
    +	 * specified collection.
     	 * @param c collection to be checked for containment in this list
    -	 * @return true if this list contains all of the elements of the specified
    -	 * collection
    +	 * @return true if this list contains all of the elements of the
    +	 * specified collection
     	 * @throws ClassCastException if the types of one or more elements in the specified
     	 * collection are incompatible with this list
     	 * (optional)
    @@ -241,7 +241,7 @@ public List details() {
     	 * @param index index of the element to return
     	 * @return the element at the specified position in this list
     	 * @throws IndexOutOfBoundsException if the index is out of range
    -	 * (index < 0 || index >= size())
    +	 * (index < 0 || index >= size())
     	 */
     	@Override
     	public final ConstraintViolation get(int index) {
    @@ -251,9 +251,9 @@ public final ConstraintViolation get(int index) {
     	/**
     	 * Returns the index of the first occurrence of the specified element in this list, or
     	 * -1 if this list does not contain the element. More formally, returns the lowest
    -	 * index i such that
    -	 * (o==null ? get(i)==null : o.equals(get(i))), or -1 if
    -	 * there is no such index.
    +	 * index i such that
    +	 * (o==null ? get(i)==null : o.equals(get(i))), or -1
    +	 * if there is no such index.
     	 * @param o element to search for
     	 * @return the index of the first occurrence of the specified element in this list, or
     	 * -1 if this list does not contain the element
    @@ -269,8 +269,8 @@ public final int indexOf(Object o) {
     	}
     
     	/**
    -	 * Returns true if this list contains no elements.
    -	 * @return true if this list contains no elements
    +	 * Returns true if this list contains no elements.
    +	 * @return true if this list contains no elements
     	 */
     	@Override
     	public final boolean isEmpty() {
    @@ -293,9 +293,9 @@ public final Iterator iterator() {
     	/**
     	 * Returns the index of the last occurrence of the specified element in this list, or
     	 * -1 if this list does not contain the element. More formally, returns the highest
    -	 * index i such that
    -	 * (o==null ? get(i)==null : o.equals(get(i))), or -1 if
    -	 * there is no such index.
    +	 * index i such that
    +	 * (o==null ? get(i)==null : o.equals(get(i))), or -1
    +	 * if there is no such index.
     	 * @param o element to search for
     	 * @return the index of the last occurrence of the specified element in this list, or
     	 * -1 if this list does not contain the element
    @@ -340,18 +340,19 @@ public final ListIterator listIterator(int index) {
     	/**
     	 * Removes the first occurrence of the specified element from this list, if it is
     	 * present (optional operation). If this list does not contain the element, it is
    -	 * unchanged. More formally, removes the element with the lowest index i such
    -	 * that (o==null ? get(i)==null : o.equals(get(i))) (if
    -	 * such an element exists). Returns true if this list contained the specified
    -	 * element (or equivalently, if this list changed as a result of the call).
    +	 * unchanged. More formally, removes the element with the lowest index i
    +	 * such that
    +	 * (o==null ? get(i)==null : o.equals(get(i))) (if
    +	 * such an element exists). Returns true if this list contained the
    +	 * specified element (or equivalently, if this list changed as a result of the call).
     	 * @param o element to be removed from this list, if present
    -	 * @return true if this list contained the specified element
    +	 * @return true if this list contained the specified element
     	 * @throws ClassCastException if the type of the specified element is incompatible
     	 * with this list (optional)
     	 * @throws NullPointerException if the specified element is null and this list does
     	 * not permit null elements
     	 * (optional)
    -	 * @throws UnsupportedOperationException if the remove operation is not
    +	 * @throws UnsupportedOperationException if the remove operation is not
     	 * supported by this list
     	 */
     	@Override
    @@ -365,10 +366,10 @@ public final boolean remove(Object o) {
     	 * Returns the element that was removed from the list.
     	 * @param index the index of the element to be removed
     	 * @return the element previously at the specified position
    -	 * @throws UnsupportedOperationException if the remove operation is not
    +	 * @throws UnsupportedOperationException if the remove operation is not
     	 * supported by this list
     	 * @throws IndexOutOfBoundsException if the index is out of range
    -	 * (index < 0 || index >= size())
    +	 * (index < 0 || index >= size())
     	 */
     	@Override
     	public final ConstraintViolation remove(int index) {
    @@ -379,9 +380,9 @@ public final ConstraintViolation remove(int index) {
     	 * Removes from this list all of its elements that are contained in the specified
     	 * collection (optional operation).
     	 * @param c collection containing elements to be removed from this list
    -	 * @return true if this list changed as a result of the call
    -	 * @throws UnsupportedOperationException if the removeAll operation is not
    -	 * supported by this list
    +	 * @return true if this list changed as a result of the call
    +	 * @throws UnsupportedOperationException if the removeAll operation is
    +	 * not supported by this list
     	 * @throws ClassCastException if the class of an element of this list is incompatible
     	 * with the specified collection
     	 * (optional)
    @@ -402,9 +403,9 @@ public final boolean removeAll(Collection c) {
     	 * collection (optional operation). In other words, removes from this list all of its
     	 * elements that are not contained in the specified collection.
     	 * @param c collection containing elements to be retained in this list
    -	 * @return true if this list changed as a result of the call
    -	 * @throws UnsupportedOperationException if the retainAll operation is not
    -	 * supported by this list
    +	 * @return true if this list changed as a result of the call
    +	 * @throws UnsupportedOperationException if the retainAll operation is
    +	 * not supported by this list
     	 * @throws ClassCastException if the class of an element of this list is incompatible
     	 * with the specified collection
     	 * (optional)
    @@ -426,7 +427,7 @@ public final boolean retainAll(Collection c) {
     	 * @param index index of the element to replace
     	 * @param element element to be stored at the specified position
     	 * @return the element previously at the specified position
    -	 * @throws UnsupportedOperationException if the set operation is not
    +	 * @throws UnsupportedOperationException if the set operation is not
     	 * supported by this list
     	 * @throws ClassCastException if the class of the specified element prevents it from
     	 * being added to this list
    @@ -435,7 +436,7 @@ public final boolean retainAll(Collection c) {
     	 * @throws IllegalArgumentException if some property of the specified element prevents
     	 * it from being added to this list
     	 * @throws IndexOutOfBoundsException if the index is out of range
    -	 * (index < 0 || index >= size())
    +	 * (index < 0 || index >= size())
     	 */
     	@Override
     	public final ConstraintViolation set(int index, ConstraintViolation element) {
    @@ -444,7 +445,7 @@ public final ConstraintViolation set(int index, ConstraintViolation element) {
     
     	/**
     	 * Returns the number of elements in this list. If this list contains more than
    -	 * Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
    +	 * Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
     	 * @return the number of elements in this list
     	 */
     	@Override
    @@ -454,11 +455,11 @@ public final int size() {
     
     	/**
     	 * Returns a view of the portion of this list between the specified
    -	 * fromIndex, inclusive, and toIndex, exclusive. (If
    -	 * fromIndex and toIndex are equal, the returned list is empty.) The
    -	 * returned list is backed by this list, so non-structural changes in the returned
    -	 * list are reflected in this list, and vice-versa. The returned list supports all of
    -	 * the optional list operations supported by this list.
    +	 * fromIndex, inclusive, and toIndex, exclusive. (If
    +	 * fromIndex and toIndex are equal, the returned list is
    +	 * empty.) The returned list is backed by this list, so non-structural changes in the
    +	 * returned list are reflected in this list, and vice-versa. The returned list
    +	 * supports all of the optional list operations supported by this list.
     	 * 

    *

    * This method eliminates the need for explicit range operations (of the sort that @@ -472,9 +473,9 @@ public final int size() { * } *