index int64 | repo_id string | file_path string | content string |
|---|---|---|---|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/FloatValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.FloatValidator;
import am.ik.yavi.constraint.FloatConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.7.0
*/
public class FloatValidatorBuilder implements ValueValidatorBuilder<Float, Float> {
private final Function<ValidatorBuilder<Arguments1<Float>>, ValidatorBuilder<Arguments1<Float>>> builder;
public static FloatValidatorBuilder of(String name,
Function<FloatConstraint<Arguments1<Float>>, FloatConstraint<Arguments1<Float>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static FloatValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<Float>>, ValidatorBuilder<Arguments1<Float>>> builder) {
return new FloatValidatorBuilder(builder);
}
FloatValidatorBuilder(Function<ValidatorBuilder<Arguments1<Float>>, ValidatorBuilder<Arguments1<Float>>> builder) {
this.builder = builder;
}
@Override
public <T> FloatValidator<T> build(Function<? super Float, ? extends T> mapper) {
final Validator<Arguments1<Float>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new FloatValidator<>(validator, mapper::apply);
}
@Override
public FloatValidator<Float> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/InstantValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.Instant;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.InstantValidator;
import am.ik.yavi.constraint.InstantConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.10.0
*/
public class InstantValidatorBuilder implements ValueValidatorBuilder<Instant, Instant> {
private final Function<ValidatorBuilder<Arguments1<Instant>>, ValidatorBuilder<Arguments1<Instant>>> builder;
public static InstantValidatorBuilder of(String name,
Function<InstantConstraint<Arguments1<Instant>>, InstantConstraint<Arguments1<Instant>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static InstantValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<Instant>>, ValidatorBuilder<Arguments1<Instant>>> builder) {
return new InstantValidatorBuilder(builder);
}
InstantValidatorBuilder(
Function<ValidatorBuilder<Arguments1<Instant>>, ValidatorBuilder<Arguments1<Instant>>> builder) {
this.builder = builder;
}
@Override
public <T> InstantValidator<T> build(Function<? super Instant, ? extends T> mapper) {
final Validator<Arguments1<Instant>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new InstantValidator<>(validator, mapper::apply);
}
@Override
public InstantValidator<Instant> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/IntegerValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.IntegerValidator;
import am.ik.yavi.constraint.IntegerConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.7.0
*/
public class IntegerValidatorBuilder implements ValueValidatorBuilder<Integer, Integer> {
private final Function<ValidatorBuilder<Arguments1<Integer>>, ValidatorBuilder<Arguments1<Integer>>> builder;
public static IntegerValidatorBuilder of(String name,
Function<IntegerConstraint<Arguments1<Integer>>, IntegerConstraint<Arguments1<Integer>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static IntegerValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<Integer>>, ValidatorBuilder<Arguments1<Integer>>> builder) {
return new IntegerValidatorBuilder(builder);
}
IntegerValidatorBuilder(
Function<ValidatorBuilder<Arguments1<Integer>>, ValidatorBuilder<Arguments1<Integer>>> builder) {
this.builder = builder;
}
@Override
public <T> IntegerValidator<T> build(Function<? super Integer, ? extends T> mapper) {
final Validator<Arguments1<Integer>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new IntegerValidator<>(validator, mapper::apply);
}
@Override
public IntegerValidator<Integer> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/LocalDateTimeValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.LocalDateTime;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.LocalDateTimeValidator;
import am.ik.yavi.constraint.LocalDateTimeConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.10.0
*/
public class LocalDateTimeValidatorBuilder implements ValueValidatorBuilder<LocalDateTime, LocalDateTime> {
private final Function<ValidatorBuilder<Arguments1<LocalDateTime>>, ValidatorBuilder<Arguments1<LocalDateTime>>> builder;
public static LocalDateTimeValidatorBuilder of(String name,
Function<LocalDateTimeConstraint<Arguments1<LocalDateTime>>, LocalDateTimeConstraint<Arguments1<LocalDateTime>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static LocalDateTimeValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<LocalDateTime>>, ValidatorBuilder<Arguments1<LocalDateTime>>> builder) {
return new LocalDateTimeValidatorBuilder(builder);
}
LocalDateTimeValidatorBuilder(
Function<ValidatorBuilder<Arguments1<LocalDateTime>>, ValidatorBuilder<Arguments1<LocalDateTime>>> builder) {
this.builder = builder;
}
@Override
public <T> LocalDateTimeValidator<T> build(Function<? super LocalDateTime, ? extends T> mapper) {
final Validator<Arguments1<LocalDateTime>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new LocalDateTimeValidator<>(validator, mapper::apply);
}
@Override
public LocalDateTimeValidator<LocalDateTime> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/LocalDateValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.LocalDate;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.LocalDateValidator;
import am.ik.yavi.constraint.LocalDateConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.10.0
*/
public class LocalDateValidatorBuilder implements ValueValidatorBuilder<LocalDate, LocalDate> {
private final Function<ValidatorBuilder<Arguments1<LocalDate>>, ValidatorBuilder<Arguments1<LocalDate>>> builder;
public static LocalDateValidatorBuilder of(String name,
Function<LocalDateConstraint<Arguments1<LocalDate>>, LocalDateConstraint<Arguments1<LocalDate>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static LocalDateValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<LocalDate>>, ValidatorBuilder<Arguments1<LocalDate>>> builder) {
return new LocalDateValidatorBuilder(builder);
}
LocalDateValidatorBuilder(
Function<ValidatorBuilder<Arguments1<LocalDate>>, ValidatorBuilder<Arguments1<LocalDate>>> builder) {
this.builder = builder;
}
@Override
public <T> LocalDateValidator<T> build(Function<? super LocalDate, ? extends T> mapper) {
final Validator<Arguments1<LocalDate>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new LocalDateValidator<>(validator, mapper::apply);
}
@Override
public LocalDateValidator<LocalDate> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/LocalTimeValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.LocalTime;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.LocalTimeValidator;
import am.ik.yavi.constraint.LocalTimeConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.14.0
*/
public class LocalTimeValidatorBuilder implements ValueValidatorBuilder<LocalTime, LocalTime> {
private final Function<ValidatorBuilder<Arguments1<LocalTime>>, ValidatorBuilder<Arguments1<LocalTime>>> builder;
public static LocalTimeValidatorBuilder of(String name,
Function<LocalTimeConstraint<Arguments1<LocalTime>>, LocalTimeConstraint<Arguments1<LocalTime>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static LocalTimeValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<LocalTime>>, ValidatorBuilder<Arguments1<LocalTime>>> builder) {
return new LocalTimeValidatorBuilder(builder);
}
LocalTimeValidatorBuilder(
Function<ValidatorBuilder<Arguments1<LocalTime>>, ValidatorBuilder<Arguments1<LocalTime>>> builder) {
this.builder = builder;
}
@Override
public <T> LocalTimeValidator<T> build(Function<? super LocalTime, ? extends T> mapper) {
final Validator<Arguments1<LocalTime>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new LocalTimeValidator<>(validator, mapper::apply);
}
@Override
public LocalTimeValidator<LocalTime> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/LongValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.LongValidator;
import am.ik.yavi.constraint.LongConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.7.0
*/
public class LongValidatorBuilder implements ValueValidatorBuilder<Long, Long> {
private final Function<ValidatorBuilder<Arguments1<Long>>, ValidatorBuilder<Arguments1<Long>>> builder;
public static LongValidatorBuilder of(String name,
Function<LongConstraint<Arguments1<Long>>, LongConstraint<Arguments1<Long>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static LongValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<Long>>, ValidatorBuilder<Arguments1<Long>>> builder) {
return new LongValidatorBuilder(builder);
}
LongValidatorBuilder(Function<ValidatorBuilder<Arguments1<Long>>, ValidatorBuilder<Arguments1<Long>>> builder) {
this.builder = builder;
}
@Override
public <T> LongValidator<T> build(Function<? super Long, ? extends T> mapper) {
final Validator<Arguments1<Long>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new LongValidator<>(validator, mapper::apply);
}
@Override
public LongValidator<Long> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/ObjectValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.ObjectValidator;
import am.ik.yavi.constraint.ObjectConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.8.0
*/
public class ObjectValidatorBuilder<X> implements ValueValidatorBuilder<X, X> {
private final Function<ValidatorBuilder<Arguments1<X>>, ValidatorBuilder<Arguments1<X>>> builder;
public static <X> ObjectValidatorBuilder<X> of(String name,
Function<ObjectConstraint<Arguments1<X>, X>, ObjectConstraint<Arguments1<X>, X>> constraints) {
return wrap(b -> b.constraintOnObject(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static <X> ObjectValidatorBuilder<X> wrap(
Function<ValidatorBuilder<Arguments1<X>>, ValidatorBuilder<Arguments1<X>>> builder) {
return new ObjectValidatorBuilder<>(builder);
}
ObjectValidatorBuilder(Function<ValidatorBuilder<Arguments1<X>>, ValidatorBuilder<Arguments1<X>>> builder) {
this.builder = builder;
}
@Override
public <T> ObjectValidator<X, T> build(Function<? super X, ? extends T> mapper) {
final Validator<Arguments1<X>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new ObjectValidator<>(validator, mapper::apply);
}
@Override
public ObjectValidator<X, X> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/OffsetDateTimeValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.OffsetDateTime;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.OffsetDateTimeValidator;
import am.ik.yavi.constraint.OffsetDateTimeConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.10.0
*/
public class OffsetDateTimeValidatorBuilder implements ValueValidatorBuilder<OffsetDateTime, OffsetDateTime> {
private final Function<ValidatorBuilder<Arguments1<OffsetDateTime>>, ValidatorBuilder<Arguments1<OffsetDateTime>>> builder;
public static OffsetDateTimeValidatorBuilder of(String name,
Function<OffsetDateTimeConstraint<Arguments1<OffsetDateTime>>, OffsetDateTimeConstraint<Arguments1<OffsetDateTime>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static OffsetDateTimeValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<OffsetDateTime>>, ValidatorBuilder<Arguments1<OffsetDateTime>>> builder) {
return new OffsetDateTimeValidatorBuilder(builder);
}
OffsetDateTimeValidatorBuilder(
Function<ValidatorBuilder<Arguments1<OffsetDateTime>>, ValidatorBuilder<Arguments1<OffsetDateTime>>> builder) {
this.builder = builder;
}
@Override
public <T> OffsetDateTimeValidator<T> build(Function<? super OffsetDateTime, ? extends T> mapper) {
final Validator<Arguments1<OffsetDateTime>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new OffsetDateTimeValidator<>(validator, mapper::apply);
}
@Override
public OffsetDateTimeValidator<OffsetDateTime> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/ShortValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.ShortValidator;
import am.ik.yavi.constraint.ShortConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.7.0
*/
public class ShortValidatorBuilder implements ValueValidatorBuilder<Short, Short> {
private final Function<ValidatorBuilder<Arguments1<Short>>, ValidatorBuilder<Arguments1<Short>>> builder;
public static ShortValidatorBuilder of(String name,
Function<ShortConstraint<Arguments1<Short>>, ShortConstraint<Arguments1<Short>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static ShortValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<Short>>, ValidatorBuilder<Arguments1<Short>>> builder) {
return new ShortValidatorBuilder(builder);
}
ShortValidatorBuilder(Function<ValidatorBuilder<Arguments1<Short>>, ValidatorBuilder<Arguments1<Short>>> builder) {
this.builder = builder;
}
@Override
public <T> ShortValidator<T> build(Function<? super Short, ? extends T> mapper) {
final Validator<Arguments1<Short>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new ShortValidator<>(validator, mapper::apply);
}
@Override
public ShortValidator<Short> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/StringValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.StringValidator;
import am.ik.yavi.constraint.CharSequenceConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.7.0
*/
public class StringValidatorBuilder implements ValueValidatorBuilder<String, String> {
private final Function<ValidatorBuilder<Arguments1<String>>, ValidatorBuilder<Arguments1<String>>> builder;
public static StringValidatorBuilder of(String name,
Function<CharSequenceConstraint<Arguments1<String>, String>, CharSequenceConstraint<Arguments1<String>, String>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static StringValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<String>>, ValidatorBuilder<Arguments1<String>>> builder) {
return new StringValidatorBuilder(builder);
}
StringValidatorBuilder(
Function<ValidatorBuilder<Arguments1<String>>, ValidatorBuilder<Arguments1<String>>> builder) {
this.builder = builder;
}
@Override
public <T> StringValidator<T> build(Function<? super String, ? extends T> mapper) {
final Validator<Arguments1<String>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new StringValidator<>(validator, mapper::apply);
}
@Override
public StringValidator<String> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/ValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import am.ik.yavi.constraint.BigDecimalConstraint;
import am.ik.yavi.constraint.BigIntegerConstraint;
import am.ik.yavi.constraint.BooleanConstraint;
import am.ik.yavi.constraint.ByteConstraint;
import am.ik.yavi.constraint.CharSequenceConstraint;
import am.ik.yavi.constraint.CharacterConstraint;
import am.ik.yavi.constraint.CollectionConstraint;
import am.ik.yavi.constraint.DoubleConstraint;
import am.ik.yavi.constraint.EnumConstraint;
import am.ik.yavi.constraint.FloatConstraint;
import am.ik.yavi.constraint.InstantConstraint;
import am.ik.yavi.constraint.IntegerConstraint;
import am.ik.yavi.constraint.LocalDateConstraint;
import am.ik.yavi.constraint.LocalDateTimeConstraint;
import am.ik.yavi.constraint.LocalTimeConstraint;
import am.ik.yavi.constraint.LongConstraint;
import am.ik.yavi.constraint.MapConstraint;
import am.ik.yavi.constraint.ObjectConstraint;
import am.ik.yavi.constraint.OffsetDateTimeConstraint;
import am.ik.yavi.constraint.ShortConstraint;
import am.ik.yavi.constraint.YearConstraint;
import am.ik.yavi.constraint.YearMonthConstraint;
import am.ik.yavi.constraint.ZonedDateTimeConstraint;
import am.ik.yavi.constraint.array.BooleanArrayConstraint;
import am.ik.yavi.constraint.array.ByteArrayConstraint;
import am.ik.yavi.constraint.array.CharArrayConstraint;
import am.ik.yavi.constraint.array.DoubleArrayConstraint;
import am.ik.yavi.constraint.array.FloatArrayConstraint;
import am.ik.yavi.constraint.array.IntArrayConstraint;
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.CollectionValidator;
import am.ik.yavi.core.Constraint;
import am.ik.yavi.core.ConstraintCondition;
import am.ik.yavi.core.ConstraintGroup;
import am.ik.yavi.core.ConstraintPredicate;
import am.ik.yavi.core.ConstraintPredicates;
import am.ik.yavi.core.CustomConstraint;
import am.ik.yavi.core.NestedCollectionValidator;
import am.ik.yavi.core.NestedConstraintCondition;
import am.ik.yavi.core.NestedConstraintPredicates;
import am.ik.yavi.core.NestedValidator;
import am.ik.yavi.core.NullAs;
import am.ik.yavi.core.Validatable;
import am.ik.yavi.core.Validator;
import am.ik.yavi.core.ValueValidator;
import am.ik.yavi.core.ViolatedArguments;
import am.ik.yavi.core.ViolationMessage;
import am.ik.yavi.fn.Pair;
import am.ik.yavi.message.MessageFormatter;
import am.ik.yavi.message.SimpleMessageFormatter;
import am.ik.yavi.meta.BigDecimalConstraintMeta;
import am.ik.yavi.meta.BigIntegerConstraintMeta;
import am.ik.yavi.meta.BooleanConstraintMeta;
import am.ik.yavi.meta.ByteConstraintMeta;
import am.ik.yavi.meta.CharacterConstraintMeta;
import am.ik.yavi.meta.DoubleConstraintMeta;
import am.ik.yavi.meta.FloatConstraintMeta;
import am.ik.yavi.meta.InstantConstraintMeta;
import am.ik.yavi.meta.IntegerConstraintMeta;
import am.ik.yavi.meta.LocalDateConstraintMeta;
import am.ik.yavi.meta.LocalDateTimeConstraintMeta;
import am.ik.yavi.meta.LocalTimeConstraintMeta;
import am.ik.yavi.meta.LongConstraintMeta;
import am.ik.yavi.meta.ObjectConstraintMeta;
import am.ik.yavi.meta.OffsetDateTimeConstraintMeta;
import am.ik.yavi.meta.ShortConstraintMeta;
import am.ik.yavi.meta.StringConstraintMeta;
import am.ik.yavi.meta.YearConstraintMeta;
import am.ik.yavi.meta.YearMonthConstraintMeta;
import am.ik.yavi.meta.ZonedDateTimeConstraintMeta;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
/**
* A builder class for creating {@link Validator} instances with fluent API.
* <p>
* ValidatorBuilder allows construction of validators with various constraints for
* different types of properties. It supports validation for primitive types, collections,
* arrays, nested objects, and conditional validation. The builder follows a fluent
* pattern where constraints can be chained together to create complex validation rules.
* <p>
* The builder provides two types of methods:
* <ul>
* <li>Methods prefixed with "_" (like {@code _string}, {@code _integer}) - Concise
* shorthand methods that explicitly specify the type. These methods are provided for
* cases where type inference fails with the overloaded constraint methods.</li>
* <li>Methods prefixed with "constraint" - More descriptive constraint methods with the
* same functionality. These methods are recommended when type inference works
* correctly.</li>
* </ul>
* <p>
* Properties are referenced using method references or lambda expressions, along with a
* name for error messages, and a function to define constraints on that property.
* <p>
* Example usage: <pre>{@code
* Validator<Person> validator = ValidatorBuilder.<Person>of()
* // Using constraint method with successful type inference
* .constraint(Person::getName, "name", c -> c.notBlank().lessThan(20))
* // Using _integer method for explicit type declaration
* ._integer(Person::getAge, "age", c -> c.greaterThan(0).lessThan(120))
* .build();
* }</pre>
* <p>
* Advanced features:
* <ul>
* <li>Nested validation for complex object graphs</li>
* <li>Collection validation for elements in arrays, collections, and maps</li>
* <li>Conditional validation based on predicate conditions</li>
* <li>Group-based validation for differentiating validation contexts</li>
* <li>Custom message formatting</li>
* <li>Fail-fast capability to abort validation on first error</li>
* </ul>
*
* @param <T> the type of the target object to validate
* @author Toshiaki Maki
*/
public class ValidatorBuilder<T> {
private static final String DEFAULT_SEPARATOR = ".";
final List<CollectionValidator<T, ?, ?>> collectionValidators = new ArrayList<>();
final List<Pair<ConstraintCondition<T>, Validatable<T>>> conditionalValidators = new ArrayList<>();
final String messageKeySeparator;
final List<ConstraintPredicates<T, ?>> predicatesList = new ArrayList<>();
MessageFormatter messageFormatter;
boolean failFast = false;
ConflictStrategy conflictStrategy = ConflictStrategy.NOOP;
/**
* Constructs a new ValidatorBuilder with the default message key separator. The
* default separator is a dot (".").
*/
public ValidatorBuilder() {
this(DEFAULT_SEPARATOR);
}
/**
* Constructs a new ValidatorBuilder with the specified message key separator.
* @param messageKeySeparator the separator used for constructing message keys for
* nested properties (e.g., "address.street")
*/
public ValidatorBuilder(String messageKeySeparator) {
this.messageKeySeparator = messageKeySeparator;
}
/**
* The copy constructor
*
* @since 0.10.0
*/
public ValidatorBuilder(ValidatorBuilder<T> cloningSource) {
this(cloningSource.messageKeySeparator);
this.collectionValidators.addAll(cloningSource.collectionValidators);
this.conditionalValidators.addAll(cloningSource.conditionalValidators);
this.predicatesList.addAll(cloningSource.predicatesList);
this.messageFormatter = cloningSource.messageFormatter;
this.failFast = cloningSource.failFast;
}
/**
* Casts this ValidatorBuilder to a ValidatorBuilder for a subtype of T. This is
* useful when you want to reuse validators for a supertype when validating a subtype.
* @param <S> the subtype of T
* @param clazz the Class object of the subtype
* @return this ValidatorBuilder cast to ValidatorBuilder<S>
*/
@SuppressWarnings("unchecked")
public <S extends T> ValidatorBuilder<S> cast(Class<S> clazz) {
return (ValidatorBuilder<S>) this;
}
/**
* Casts this ValidatorBuilder to a ValidatorBuilder for a subtype of T. This method
* doesn't require the Class object parameter.
* @param <S> the subtype of T
* @return this ValidatorBuilder cast to ValidatorBuilder<S>
*/
@SuppressWarnings("unchecked")
public <S extends T> ValidatorBuilder<S> cast() {
return (ValidatorBuilder<S>) this;
}
/**
* Factory method for a {@code ValidatorBuilder} to build {@code Validator} instance.
* <p>
* This method accepts a Class parameter which can be useful for explicitly specifying
* the type to validate, although the type parameter can often be inferred from the
* context.
* <p>
* Example: <pre>{@code
* Validator<Person> validator = ValidatorBuilder.of(Person.class)
* ._string(Person::getName, "name", c -> c.notBlank())
* .build();
* }</pre>
* @param <X> the type of the instance to validate
* @param clazz the Class object of the type to validate
* @return a new ValidatorBuilder instance
*/
public static <X> ValidatorBuilder<X> of(Class<X> clazz) {
return new ValidatorBuilder<>();
}
/**
* Factory method for a {@code ValidatorBuilder} to build {@code Validator} instance.
* <p>
* This method uses type inference to determine the type parameter, which makes for a
* more concise syntax in most cases.
* <p>
* Example: <pre>{@code
* Validator<Person> validator = ValidatorBuilder.<Person>of()
* .constraint(Person::getName, "name", c -> c.notBlank())
* .build();
* }</pre>
* @param <X> the type of the instance to validate
* @return a new ValidatorBuilder instance
*/
public static <X> ValidatorBuilder<X> of() {
return new ValidatorBuilder<>();
}
/**
* Builds a Validator instance with all the constraints that have been added to this
* builder.
* <p>
* This is the final step in the builder chain, which creates the actual validator
* that can be used to validate objects of type T.
* @return a new Validator instance configured with all added constraints
*/
public Validator<T> build() {
return new Validator<>(messageKeySeparator,
new PredicatesList<>(this.conflictStrategy, this.predicatesList).toList(), this.collectionValidators,
this.conditionalValidators,
this.messageFormatter == null ? SimpleMessageFormatter.getInstance() : this.messageFormatter,
this.failFast);
}
public ValidatorBuilder<T> constraint(ToCharSequence<T, String> f, String name,
Function<CharSequenceConstraint<T, String>, CharSequenceConstraint<T, String>> c) {
return this.constraint(f, name, c, CharSequenceConstraint::new);
}
/**
* @since 0.14.0
*/
public <E extends Enum<E>> ValidatorBuilder<T> constraint(toEnum<T, E> f, String name,
Function<EnumConstraint<T, E>, EnumConstraint<T, E>> c) {
return this.constraint(f, name, c, EnumConstraint::new);
}
/**
* @since 0.14.0
*/
public <E extends Enum<E>> ValidatorBuilder<T> _enum(toEnum<T, E> f, String name,
Function<EnumConstraint<T, E>, EnumConstraint<T, E>> c) {
return this.constraint(f, name, c);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(StringConstraintMeta<T> meta,
Function<CharSequenceConstraint<T, String>, CharSequenceConstraint<T, String>> c) {
return this.constraint(meta.toValue(), meta.name(), c, CharSequenceConstraint::new);
}
public <E extends CharSequence> ValidatorBuilder<T> _charSequence(ToCharSequence<T, E> f, String name,
Function<CharSequenceConstraint<T, E>, CharSequenceConstraint<T, E>> c) {
return this.constraint(f, name, c, CharSequenceConstraint::new);
}
/**
* Adds a constraint for a String property of type T.
* <p>
* This is a shorthand method for validating String properties with a more concise
* method name. For example: <pre>{@code
* ValidatorBuilder<Person> builder = ValidatorBuilder.<Person>of()
* ._string(Person::getName, "name", c -> c.notBlank().lessThan(100))
* }</pre>
* @param f a function to extract the String property from type T
* @param name the property name used in error messages
* @param c a function to configure constraints on the String property
* @return this builder instance for method chaining
*/
public ValidatorBuilder<T> _string(ToCharSequence<T, String> f, String name,
Function<CharSequenceConstraint<T, String>, CharSequenceConstraint<T, String>> c) {
return this.constraint(f, name, c, CharSequenceConstraint::new);
}
public ValidatorBuilder<T> constraint(ToBoolean<T> f, String name,
Function<BooleanConstraint<T>, BooleanConstraint<T>> c) {
return this.constraint(f, name, c, BooleanConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(BooleanConstraintMeta<T> meta,
Function<BooleanConstraint<T>, BooleanConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, BooleanConstraint::new);
}
public ValidatorBuilder<T> _boolean(ToBoolean<T> f, String name,
Function<BooleanConstraint<T>, BooleanConstraint<T>> c) {
return this.constraint(f, name, c, BooleanConstraint::new);
}
public ValidatorBuilder<T> constraint(ToCharacter<T> f, String name,
Function<CharacterConstraint<T>, CharacterConstraint<T>> c) {
return this.constraint(f, name, c, CharacterConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(CharacterConstraintMeta<T> meta,
Function<CharacterConstraint<T>, CharacterConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, CharacterConstraint::new);
}
public ValidatorBuilder<T> _character(ToCharacter<T> f, String name,
Function<CharacterConstraint<T>, CharacterConstraint<T>> c) {
return this.constraint(f, name, c, CharacterConstraint::new);
}
public ValidatorBuilder<T> constraint(ToByte<T> f, String name, Function<ByteConstraint<T>, ByteConstraint<T>> c) {
return this.constraint(f, name, c, ByteConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(ByteConstraintMeta<T> meta,
Function<ByteConstraint<T>, ByteConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, ByteConstraint::new);
}
public ValidatorBuilder<T> _byte(ToByte<T> f, String name, Function<ByteConstraint<T>, ByteConstraint<T>> c) {
return this.constraint(f, name, c, ByteConstraint::new);
}
public ValidatorBuilder<T> constraint(ToShort<T> f, String name,
Function<ShortConstraint<T>, ShortConstraint<T>> c) {
return this.constraint(f, name, c, ShortConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(ShortConstraintMeta<T> meta,
Function<ShortConstraint<T>, ShortConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, ShortConstraint::new);
}
public ValidatorBuilder<T> _short(ToShort<T> f, String name, Function<ShortConstraint<T>, ShortConstraint<T>> c) {
return this.constraint(f, name, c, ShortConstraint::new);
}
public ValidatorBuilder<T> constraint(ToInteger<T> f, String name,
Function<IntegerConstraint<T>, IntegerConstraint<T>> c) {
return this.constraint(f, name, c, IntegerConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(IntegerConstraintMeta<T> meta,
Function<IntegerConstraint<T>, IntegerConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, IntegerConstraint::new);
}
public ValidatorBuilder<T> _integer(ToInteger<T> f, String name,
Function<IntegerConstraint<T>, IntegerConstraint<T>> c) {
return this.constraint(f, name, c, IntegerConstraint::new);
}
public ValidatorBuilder<T> constraint(ToLong<T> f, String name, Function<LongConstraint<T>, LongConstraint<T>> c) {
return this.constraint(f, name, c, LongConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(LongConstraintMeta<T> meta,
Function<LongConstraint<T>, LongConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, LongConstraint::new);
}
public ValidatorBuilder<T> _long(ToLong<T> f, String name, Function<LongConstraint<T>, LongConstraint<T>> c) {
return this.constraint(f, name, c, LongConstraint::new);
}
public ValidatorBuilder<T> constraint(ToFloat<T> f, String name,
Function<FloatConstraint<T>, FloatConstraint<T>> c) {
return this.constraint(f, name, c, FloatConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(FloatConstraintMeta<T> meta,
Function<FloatConstraint<T>, FloatConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, FloatConstraint::new);
}
public ValidatorBuilder<T> _float(ToFloat<T> f, String name, Function<FloatConstraint<T>, FloatConstraint<T>> c) {
return this.constraint(f, name, c, FloatConstraint::new);
}
public ValidatorBuilder<T> constraint(ToDouble<T> f, String name,
Function<DoubleConstraint<T>, DoubleConstraint<T>> c) {
return this.constraint(f, name, c, DoubleConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(DoubleConstraintMeta<T> meta,
Function<DoubleConstraint<T>, DoubleConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, DoubleConstraint::new);
}
public ValidatorBuilder<T> _double(ToDouble<T> f, String name,
Function<DoubleConstraint<T>, DoubleConstraint<T>> c) {
return this.constraint(f, name, c, DoubleConstraint::new);
}
public ValidatorBuilder<T> constraint(ToBigInteger<T> f, String name,
Function<BigIntegerConstraint<T>, BigIntegerConstraint<T>> c) {
return this.constraint(f, name, c, BigIntegerConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(BigIntegerConstraintMeta<T> meta,
Function<BigIntegerConstraint<T>, BigIntegerConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, BigIntegerConstraint::new);
}
public ValidatorBuilder<T> _bigInteger(ToBigInteger<T> f, String name,
Function<BigIntegerConstraint<T>, BigIntegerConstraint<T>> c) {
return this.constraint(f, name, c, BigIntegerConstraint::new);
}
public ValidatorBuilder<T> constraint(ToBigDecimal<T> f, String name,
Function<BigDecimalConstraint<T>, BigDecimalConstraint<T>> c) {
return this.constraint(f, name, c, BigDecimalConstraint::new);
}
/**
* @since 0.4.0
*/
public ValidatorBuilder<T> constraint(BigDecimalConstraintMeta<T> meta,
Function<BigDecimalConstraint<T>, BigDecimalConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, BigDecimalConstraint::new);
}
public ValidatorBuilder<T> _bigDecimal(ToBigDecimal<T> f, String name,
Function<BigDecimalConstraint<T>, BigDecimalConstraint<T>> c) {
return this.constraint(f, name, c, BigDecimalConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(ToLocalTimeConstraint<T> f, String name,
Function<LocalTimeConstraint<T>, LocalTimeConstraint<T>> c) {
return this.constraint(f, name, c, LocalTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(LocalTimeConstraintMeta<T> meta,
Function<LocalTimeConstraint<T>, LocalTimeConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, LocalTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> _localTime(ToLocalTimeConstraint<T> f, String name,
Function<LocalTimeConstraint<T>, LocalTimeConstraint<T>> c) {
return this.constraint(f, name, c, LocalTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(ToLocalDateConstraint<T> f, String name,
Function<LocalDateConstraint<T>, LocalDateConstraint<T>> c) {
return this.constraint(f, name, c, LocalDateConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(LocalDateConstraintMeta<T> meta,
Function<LocalDateConstraint<T>, LocalDateConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, LocalDateConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> _localDate(ToLocalDateConstraint<T> f, String name,
Function<LocalDateConstraint<T>, LocalDateConstraint<T>> c) {
return this.constraint(f, name, c, LocalDateConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(ToLocalDateTimeConstraint<T> f, String name,
Function<LocalDateTimeConstraint<T>, LocalDateTimeConstraint<T>> c) {
return this.constraint(f, name, c, LocalDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(LocalDateTimeConstraintMeta<T> meta,
Function<LocalDateTimeConstraint<T>, LocalDateTimeConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, LocalDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> _localDateTime(ToLocalDateTimeConstraint<T> f, String name,
Function<LocalDateTimeConstraint<T>, LocalDateTimeConstraint<T>> c) {
return this.constraint(f, name, c, LocalDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(ToZonedDateTimeConstraint<T> f, String name,
Function<ZonedDateTimeConstraint<T>, ZonedDateTimeConstraint<T>> c) {
return this.constraint(f, name, c, ZonedDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(ZonedDateTimeConstraintMeta<T> meta,
Function<ZonedDateTimeConstraint<T>, ZonedDateTimeConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, ZonedDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> _zonedDateTime(ToZonedDateTimeConstraint<T> f, String name,
Function<ZonedDateTimeConstraint<T>, ZonedDateTimeConstraint<T>> c) {
return this.constraint(f, name, c, ZonedDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(ToOffsetDateTimeConstraint<T> f, String name,
Function<OffsetDateTimeConstraint<T>, OffsetDateTimeConstraint<T>> c) {
return this.constraint(f, name, c, OffsetDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(OffsetDateTimeConstraintMeta<T> meta,
Function<OffsetDateTimeConstraint<T>, OffsetDateTimeConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, OffsetDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> _offsetDateTime(ToOffsetDateTimeConstraint<T> f, String name,
Function<OffsetDateTimeConstraint<T>, OffsetDateTimeConstraint<T>> c) {
return this.constraint(f, name, c, OffsetDateTimeConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(ToInstantConstraint<T> f, String name,
Function<InstantConstraint<T>, InstantConstraint<T>> c) {
return this.constraint(f, name, c, InstantConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> constraint(InstantConstraintMeta<T> meta,
Function<InstantConstraint<T>, InstantConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, InstantConstraint::new);
}
/**
* @since 0.10.0
*/
public ValidatorBuilder<T> _instant(ToInstantConstraint<T> f, String name,
Function<InstantConstraint<T>, InstantConstraint<T>> c) {
return this.constraint(f, name, c, InstantConstraint::new);
}
/**
* @since 0.11.0
*/
public ValidatorBuilder<T> constraint(ToYearMonthConstraint<T> f, String name,
Function<YearMonthConstraint<T>, YearMonthConstraint<T>> c) {
return this.constraint(f, name, c, YearMonthConstraint::new);
}
/**
* @since 0.11.0
*/
public ValidatorBuilder<T> constraint(YearMonthConstraintMeta<T> meta,
Function<YearMonthConstraint<T>, YearMonthConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, YearMonthConstraint::new);
}
/**
* @since 0.11.0
*/
public ValidatorBuilder<T> _yearMonth(ToYearMonthConstraint<T> f, String name,
Function<YearMonthConstraint<T>, YearMonthConstraint<T>> c) {
return this.constraint(f, name, c, YearMonthConstraint::new);
}
/**
* @since 0.11.0
*/
public ValidatorBuilder<T> constraint(ToYearConstraint<T> f, String name,
Function<YearConstraint<T>, YearConstraint<T>> c) {
return this.constraint(f, name, c, YearConstraint::new);
}
/**
* @since 0.11.0
*/
public ValidatorBuilder<T> constraint(YearConstraintMeta<T> meta,
Function<YearConstraint<T>, YearConstraint<T>> c) {
return this.constraint(meta.toValue(), meta.name(), c, YearConstraint::new);
}
/**
* @since 0.11.0
*/
public ValidatorBuilder<T> _year(ToYearConstraint<T> f, String name,
Function<YearConstraint<T>, YearConstraint<T>> c) {
return this.constraint(f, name, c, YearConstraint::new);
}
public <L extends Collection<E>, E> ValidatorBuilder<T> constraint(ToCollection<T, L, E> f, String name,
Function<CollectionConstraint<T, L, E>, CollectionConstraint<T, L, E>> c) {
return this.constraint(f, name, c, CollectionConstraint::new);
}
public <L extends Collection<E>, E> ValidatorBuilder<T> _collection(ToCollection<T, L, E> f, String name,
Function<CollectionConstraint<T, L, E>, CollectionConstraint<T, L, E>> c) {
return this.constraint(f, name, c, CollectionConstraint::new);
}
public <K, V> ValidatorBuilder<T> constraint(ToMap<T, K, V> f, String name,
Function<MapConstraint<T, K, V>, MapConstraint<T, K, V>> c) {
return this.constraint(f, name, c, MapConstraint::new);
}
public <K, V> ValidatorBuilder<T> _map(ToMap<T, K, V> f, String name,
Function<MapConstraint<T, K, V>, MapConstraint<T, K, V>> c) {
return this.constraint(f, name, c, MapConstraint::new);
}
public <E> ValidatorBuilder<T> constraint(ToObjectArray<T, E> f, String name,
Function<ObjectArrayConstraint<T, E>, ObjectArrayConstraint<T, E>> c) {
return this.constraint(f, name, c, ObjectArrayConstraint::new);
}
public <E> ValidatorBuilder<T> _objectArray(ToObjectArray<T, E> f, String name,
Function<ObjectArrayConstraint<T, E>, ObjectArrayConstraint<T, E>> c) {
return this.constraint(f, name, c, ObjectArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToBooleanArray<T> f, String name,
Function<BooleanArrayConstraint<T>, BooleanArrayConstraint<T>> c) {
return this.constraint(f, name, c, BooleanArrayConstraint::new);
}
public ValidatorBuilder<T> _booleanArray(ToBooleanArray<T> f, String name,
Function<BooleanArrayConstraint<T>, BooleanArrayConstraint<T>> c) {
return this.constraint(f, name, c, BooleanArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToCharArray<T> f, String name,
Function<CharArrayConstraint<T>, CharArrayConstraint<T>> c) {
return this.constraint(f, name, c, CharArrayConstraint::new);
}
public ValidatorBuilder<T> _charArray(ToCharArray<T> f, String name,
Function<CharArrayConstraint<T>, CharArrayConstraint<T>> c) {
return this.constraint(f, name, c, CharArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToByteArray<T> f, String name,
Function<ByteArrayConstraint<T>, ByteArrayConstraint<T>> c) {
return this.constraint(f, name, c, ByteArrayConstraint::new);
}
public ValidatorBuilder<T> _byteArray(ToByteArray<T> f, String name,
Function<ByteArrayConstraint<T>, ByteArrayConstraint<T>> c) {
return this.constraint(f, name, c, ByteArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToShortArray<T> f, String name,
Function<ShortArrayConstraint<T>, ShortArrayConstraint<T>> c) {
return this.constraint(f, name, c, ShortArrayConstraint::new);
}
public ValidatorBuilder<T> _shortArray(ToShortArray<T> f, String name,
Function<ShortArrayConstraint<T>, ShortArrayConstraint<T>> c) {
return this.constraint(f, name, c, ShortArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToIntArray<T> f, String name,
Function<IntArrayConstraint<T>, IntArrayConstraint<T>> c) {
return this.constraint(f, name, c, IntArrayConstraint::new);
}
public ValidatorBuilder<T> _intArray(ToIntArray<T> f, String name,
Function<IntArrayConstraint<T>, IntArrayConstraint<T>> c) {
return this.constraint(f, name, c, IntArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToLongArray<T> f, String name,
Function<LongArrayConstraint<T>, LongArrayConstraint<T>> c) {
return this.constraint(f, name, c, LongArrayConstraint::new);
}
public ValidatorBuilder<T> _longArray(ToLongArray<T> f, String name,
Function<LongArrayConstraint<T>, LongArrayConstraint<T>> c) {
return this.constraint(f, name, c, LongArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToFloatArray<T> f, String name,
Function<FloatArrayConstraint<T>, FloatArrayConstraint<T>> c) {
return this.constraint(f, name, c, FloatArrayConstraint::new);
}
public ValidatorBuilder<T> _floatArray(ToFloatArray<T> f, String name,
Function<FloatArrayConstraint<T>, FloatArrayConstraint<T>> c) {
return this.constraint(f, name, c, FloatArrayConstraint::new);
}
public ValidatorBuilder<T> constraint(ToDoubleArray<T> f, String name,
Function<DoubleArrayConstraint<T>, DoubleArrayConstraint<T>> c) {
return this.constraint(f, name, c, DoubleArrayConstraint::new);
}
public ValidatorBuilder<T> _doubleArray(ToDoubleArray<T> f, String name,
Function<DoubleArrayConstraint<T>, DoubleArrayConstraint<T>> c) {
return this.constraint(f, name, c, DoubleArrayConstraint::new);
}
/**
* Adds a conditional validator that is only applied when the specified condition is
* met.
* <p>
* This method allows you to apply validation rules conditionally based on the state
* of the object being validated. The validation will only be performed if the
* condition predicate returns true for the target object.
* @param <R> the return type of the validator
* @param condition the condition that determines whether validation should be applied
* @param applicative the validator to apply when the condition is met
* @return this builder instance for method chaining
* @since 0.11.0
*/
public <R> ValidatorBuilder<T> constraintOnCondition(ConstraintCondition<T> condition,
ValueValidator<T, R> applicative) {
this.conditionalValidators.add(new Pair<>(condition, Validatable.from(applicative)));
return this;
}
/**
* Adds a conditional validator that is only applied when the specified condition is
* met.
* <p>
* This method allows you to apply a complete validator conditionally based on the
* state of the object being validated. The validation will only be performed if the
* condition predicate returns true for the target object.
* <p>
* Example: <pre>{@code
* // Only validate credit card if payment method is "card"
* ValidatorBuilder<Payment> builder = ValidatorBuilder.<Payment>of()
* .constraint(Payment::getMethod, "method", c -> c.notBlank())
* .constraintOnCondition(
* payment -> "card".equals(payment.getMethod()),
* ValidatorBuilder.<Payment>of()
* .constraint(Payment::getCardNumber, "cardNumber", c -> c.notBlank().pattern("[0-9]{16}"))
* .constraint(Payment::getCardExpiry, "cardExpiry", c -> c.notBlank().pattern("[0-9]{2}/[0-9]{2}"))
* .build()
* );
* }</pre>
* @param condition the condition that determines whether validation should be applied
* @param validator the validator to apply when the condition is met
* @return this builder instance for method chaining
*/
public ValidatorBuilder<T> constraintOnCondition(ConstraintCondition<T> condition, Validator<T> validator) {
this.conditionalValidators.add(new Pair<>(condition, validator));
return this;
}
/**
* Adds a conditional validator using a builder converter that is only applied when
* the specified condition is met.
* <p>
* This method allows you to define conditional validation using a builder converter
* function. The validation will only be performed if the condition predicate returns
* true for the target object.
* <p>
* Example: <pre>{@code
* ValidatorBuilder<Order> builder = ValidatorBuilder.<Order>of()
* ._integer(Order::getAmount, "amount", c -> c.greaterThan(0))
* .constraintOnCondition(
* order -> order.getAmount() > 10000,
* b -> b._string(Order::getApprovalCode, "approvalCode", c -> c.notBlank())
* );
* }</pre>
* @param condition the condition that determines whether validation should be applied
* @param converter a function that accepts and returns a ValidatorBuilder to define
* additional constraints
* @return this builder instance for method chaining
*/
public ValidatorBuilder<T> constraintOnCondition(ConstraintCondition<T> condition,
ValidatorBuilderConverter<T> converter) {
ValidatorBuilder<T> builder = converter.apply(new ValidatorBuilder<>());
Validator<T> validator = builder.build();
return this.constraintOnCondition(condition, validator);
}
/**
* Adds a group-based validator that is applied only when the given constraint group
* is active.
* <p>
* This method provides a way to organize validation rules into logical groups that
* can be selectively applied during validation. For example, you might have different
* validation rules for creating vs. updating an entity.
* <p>
* The validation will only be performed if the constraint group is active during
* validation.
* @param <R> the return type of the validator
* @param group the constraint group that determines whether validation should be
* applied
* @param applicative the validator to apply when the group is active
* @return this builder instance for method chaining
*/
public <R> ValidatorBuilder<T> constraintOnGroup(ConstraintGroup group, ValueValidator<T, R> applicative) {
return this.constraintOnCondition(group.toCondition(), applicative);
}
/**
* Adds a group-based validator that is applied only when the given constraint group
* is active.
* <p>
* This method provides a way to organize validation rules into logical groups that
* can be selectively applied during validation. For example, you might have different
* validation rules for creating vs. updating an entity.
* <p>
* Example: <pre>{@code
* // Define validation groups
* ConstraintGroup CREATE = new ConstraintGroup("CREATE");
* ConstraintGroup UPDATE = new ConstraintGroup("UPDATE");
*
* // Create validator with group-specific constraints
* Validator<User> validator = ValidatorBuilder.<User>of()
* // Common validation for all scenarios
* .constraint(User::getUsername, "username", c -> c.notBlank())
*
* // Password validation only for user creation
* .constraintOnGroup(CREATE,
* ValidatorBuilder.<User>of()
* .constraint(User::getPassword, "password", c -> c.notBlank().greaterThanOrEqual(8))
* .build())
*
* // ID validation only for user updates
* .constraintOnGroup(UPDATE,
* ValidatorBuilder.<User>of()
* .constraint(User::getId, "id", c -> c.greaterThan(0))
* .build())
* .build();
*
* // Validate for creation
* ConstraintViolations violations = validator.validate(user, CREATE);
* }</pre>
* @param group the constraint group that determines whether validation should be
* applied
* @param validator the validator to apply when the group is active
* @return this builder instance for method chaining
*/
public ValidatorBuilder<T> constraintOnGroup(ConstraintGroup group, Validator<T> validator) {
return this.constraintOnCondition(group.toCondition(), validator);
}
/**
* Adds a group-based validator using a builder converter that is applied only when
* the given constraint group is active.
* <p>
* This method provides a way to organize validation rules into logical groups using a
* builder converter function. The validation will only be performed if the constraint
* group is active during validation.
* <p>
* Example: <pre>{@code
* // Define validation groups
* ConstraintGroup ADMIN = new ConstraintGroup("ADMIN");
* ConstraintGroup USER = new ConstraintGroup("USER");
*
* // Create validator with group-specific constraints
* Validator<Document> validator = ValidatorBuilder.<Document>of()
* // Common validation for all scenarios
* .constraint(Document::getTitle, "title", c -> c.notBlank())
*
* // Admin-only validation using converter function
* .constraintOnGroup(ADMIN, builder ->
* builder.constraint(Document::getSecurityLevel, "securityLevel", c -> c.notBlank())
* .constraint(Document::isClassified, "classified", c -> c.isTrue())
* )
* .build();
* }</pre>
* @param group the constraint group that determines whether validation should be
* applied
* @param converter a function that accepts and returns a ValidatorBuilder to define
* additional constraints
* @return this builder instance for method chaining
*/
public ValidatorBuilder<T> constraintOnGroup(ConstraintGroup group, ValidatorBuilderConverter<T> converter) {
return this.constraintOnCondition(group.toCondition(), converter);
}
public <E> ValidatorBuilder<T> constraintOnObject(Function<T, E> f, String name,
Function<ObjectConstraint<T, E>, ObjectConstraint<T, E>> c) {
return this.constraint(f, name, c, ObjectConstraint::new);
}
/**
* @since 0.4.0
*/
public <E> ValidatorBuilder<T> _object(Function<T, E> f, String name,
Function<ObjectConstraint<T, E>, ObjectConstraint<T, E>> c) {
return this.constraint(f, name, c, ObjectConstraint::new);
}
public <E> ValidatorBuilder<T> constraint(ObjectConstraintMeta<T, E> meta,
Function<ObjectConstraint<T, E>, ObjectConstraint<T, E>> c) {
return this.constraint(meta.toValue(), meta.name(), c, ObjectConstraint::new);
}
public ValidatorBuilder<T> constraintOnTarget(Predicate<T> predicate, String name,
ViolatedArguments<T> violatedArguments, ViolationMessage violationMessage) {
Deque<ConstraintPredicate<T>> predicates = new LinkedList<>();
predicates.add(ConstraintPredicate.of(predicate, violationMessage, violatedArguments, NullAs.INVALID));
this.predicatesList.add(new ConstraintPredicates<>(Function.identity(), name, predicates));
return this;
}
public ValidatorBuilder<T> constraintOnTarget(Predicate<T> predicate, String name,
ViolationMessage violationMessage) {
return this.constraintOnTarget(predicate, name, violatedValue -> CustomConstraint.EMPTY_ARRAY,
violationMessage);
}
public ValidatorBuilder<T> constraintOnTarget(Predicate<T> predicate, String name, String messageKey,
String defaultMessage) {
return this.constraintOnTarget(predicate, name, ViolationMessage.of(messageKey, defaultMessage));
}
public ValidatorBuilder<T> constraintOnTarget(CustomConstraint<T> customConstraint, String name) {
return this.constraintOnTarget(customConstraint, name, customConstraint, customConstraint);
}
/**
* @since 0.7.0
*/
public ValidatorBuilder<T> constraintOnTarget(String name,
Function<ObjectConstraint<T, T>, ObjectConstraint<T, T>> c) {
return this.constraint(Function.identity(), name, c, ObjectConstraint::new);
}
public <L extends Collection<E>, E> ValidatorBuilder<T> forEach(ToCollection<T, L, E> toCollection, String name,
Validator<E> validator) {
return this.forEach(toCollection, name, validator, NullAs.INVALID);
}
public <L extends Collection<E>, E> ValidatorBuilder<T> forEach(ToCollection<T, L, E> toCollection, String name,
ValidatorBuilderConverter<E> converter) {
return this.forEach(toCollection, name, converter, NullAs.INVALID);
}
public <K, V> ValidatorBuilder<T> forEach(ToMap<T, K, V> toMap, String name, Validator<V> validator) {
return this.forEach(this.toMapToCollection(toMap), name, validator);
}
public <K, V> ValidatorBuilder<T> forEach(ToMap<T, K, V> toMap, String name,
ValidatorBuilderConverter<V> converter) {
return this.forEach(this.toMapToCollection(toMap), name, converter);
}
public <E> ValidatorBuilder<T> forEach(ToObjectArray<T, E> toObjectArray, String name, Validator<E> validator) {
return this.forEach(this.toObjectArrayToCollection(toObjectArray), name, validator);
}
public <E> ValidatorBuilder<T> forEach(ToObjectArray<T, E> toObjectArray, String name,
ValidatorBuilderConverter<E> converter) {
return this.forEach(this.toObjectArrayToCollection(toObjectArray), name, converter);
}
public <L extends Collection<E>, E> ValidatorBuilder<T> forEachIfPresent(ToCollection<T, L, E> toCollection,
String name, Validator<E> validator) {
return this.forEach(toCollection, name, validator, NullAs.VALID);
}
public <L extends Collection<E>, E> ValidatorBuilder<T> forEachIfPresent(ToCollection<T, L, E> toCollection,
String name, ValidatorBuilderConverter<E> converter) {
return this.forEach(toCollection, name, converter, NullAs.VALID);
}
public <K, V> ValidatorBuilder<T> forEachIfPresent(ToMap<T, K, V> toMap, String name, Validator<V> validator) {
return this.forEachIfPresent(this.toMapToCollection(toMap), name, validator);
}
public <K, V> ValidatorBuilder<T> forEachIfPresent(ToMap<T, K, V> toMap, String name,
ValidatorBuilderConverter<V> converter) {
return this.forEachIfPresent(this.toMapToCollection(toMap), name, converter);
}
public <E> ValidatorBuilder<T> forEachIfPresent(ToObjectArray<T, E> toObjectArray, String name,
Validator<E> validator) {
return this.forEachIfPresent(this.toObjectArrayToCollection(toObjectArray), name, validator);
}
public <E> ValidatorBuilder<T> forEachIfPresent(ToObjectArray<T, E> toObjectArray, String name,
ValidatorBuilderConverter<E> converter) {
return this.forEachIfPresent(this.toObjectArrayToCollection(toObjectArray), name, converter);
}
/**
* Sets a custom message formatter for the validator.
* <p>
* Message formatters are responsible for creating error messages when validation
* fails. By default, {@link SimpleMessageFormatter} is used, but you can provide your
* own implementation for custom error message formatting.
* <p>
* Example: <pre>{@code
* // Create a validator with a custom message formatter
* Validator<User> validator = ValidatorBuilder.<User>of()
* .constraint(User::getName, "name", c -> c.notBlank())
* .messageFormatter(new CustomMessageFormatter())
* .build();
* }</pre>
* @param messageFormatter the custom message formatter to use
* @return this builder instance for method chaining
*/
public ValidatorBuilder<T> messageFormatter(MessageFormatter messageFormatter) {
this.messageFormatter = messageFormatter;
return this;
}
/**
* Set whether to enable fail fast mode. If enabled, Validator returns from the
* current validation as soon as the first constraint violation occurs.
* @param failFast whether to enable fail fast mode
* @since 0.8.0
*/
public ValidatorBuilder<T> failFast(boolean failFast) {
this.failFast = failFast;
return this;
}
/**
* Sets the {@link ConflictStrategy} that defines the behavior when a constraint name
* conflicts when adding a constraint. By default, {@link ConflictStrategy#NOOP} is
* used.
* @param conflictStrategy Conflict Strategy
* @return validator builder (self)
* @since 0.13.0
*/
public ValidatorBuilder<T> conflictStrategy(ConflictStrategy conflictStrategy) {
this.conflictStrategy = conflictStrategy;
return this;
}
/**
* Adds a nested validator for a property that requires complex validation.
* <p>
* This method allows validation of complex object graphs by applying a separate
* validator to a nested property of the target object. If the nested property is
* null, validation will fail with a "must not be null" violation unless nestIfPresent
* is used instead.
* <p>
* Example: <pre>{@code
* Validator<Address> addressValidator = ValidatorBuilder.<Address>of()
* .constraint(Address::getStreet, "street", c -> c.notBlank())
* .constraint(Address::getCity, "city", c -> c.notBlank())
* .build();
*
* Validator<Person> personValidator = ValidatorBuilder.<Person>of()
* .constraint(Person::getName, "name", c -> c.notBlank())
* .nest(Person::getAddress, "address", addressValidator)
* .build();
* }</pre>
* @param <N> the type of the nested property
* @param nested a function to extract the nested property from type T
* @param name the property name used in error messages
* @param validator the validator to apply to the nested property
* @return this builder instance for method chaining
*/
public <N> ValidatorBuilder<T> nest(Function<T, N> nested, String name, Validator<N> validator) {
return this.nest(nested, name, validator, NullAs.INVALID);
}
public <N> ValidatorBuilder<T> nest(ObjectConstraintMeta<T, N> meta, Validator<N> validator) {
return this.nest(meta.toValue(), meta.name(), validator, NullAs.INVALID);
}
public <N> ValidatorBuilder<T> nest(Function<T, N> nested, String name, ValidatorBuilderConverter<N> converter) {
return this.nest(nested, name, converter, NullAs.INVALID);
}
public <N> ValidatorBuilder<T> nest(ObjectConstraintMeta<T, N> meta, ValidatorBuilderConverter<N> converter) {
return this.nest(meta.toValue(), meta.name(), converter, NullAs.INVALID);
}
/**
* Adds a nested validator for a property that requires complex validation, but only
* applies it if the property is non-null.
* <p>
* This method works like {@link #nest(Function, String, Validator)}, but does not
* generate a "must not be null" error if the nested property is null. Instead,
* validation is skipped for null properties.
* <p>
* Example: <pre>{@code
* // Address is optional, but if present, must be valid
* Validator<Person> personValidator = ValidatorBuilder.<Person>of()
* .constraint(Person::getName, "name", c -> c.notBlank())
* .nestIfPresent(Person::getAddress, "address", addressValidator)
* .build();
* }</pre>
* @param <N> the type of the nested property
* @param nested a function to extract the nested property from type T
* @param name the property name used in error messages
* @param validator the validator to apply to the nested property if it is non-null
* @return this builder instance for method chaining
*/
public <N> ValidatorBuilder<T> nestIfPresent(Function<T, N> nested, String name, Validator<N> validator) {
return this.nest(nested, name, validator, NullAs.VALID);
}
public <N> ValidatorBuilder<T> nestIfPresent(ObjectConstraintMeta<T, N> meta, Validator<N> validator) {
return this.nest(meta.toValue(), meta.name(), validator, NullAs.VALID);
}
public <N> ValidatorBuilder<T> nestIfPresent(Function<T, N> nested, String name,
ValidatorBuilderConverter<N> converter) {
return this.nest(nested, name, converter, NullAs.VALID);
}
public <N> ValidatorBuilder<T> nestIfPresent(ObjectConstraintMeta<T, N> meta,
ValidatorBuilderConverter<N> converter) {
return this.nest(meta.toValue(), meta.name(), converter, NullAs.VALID);
}
protected final <V, C extends Constraint<T, V, C>> ValidatorBuilder<T> constraint(Function<T, V> f, String name,
Function<C, C> c, Supplier<C> supplier) {
C constraint = supplier.get();
Deque<ConstraintPredicate<V>> predicates = c.apply(constraint).predicates();
this.predicatesList.add(new ConstraintPredicates<>(f, name, predicates));
return this;
}
protected <L extends Collection<E>, E> ValidatorBuilder<T> forEach(ToCollection<T, L, E> toCollection, String name,
ValidatorBuilderConverter<E> converter, NullAs nullAs) {
ValidatorBuilder<E> builder = converter.apply(new ValidatorBuilder<>());
return this.forEach(toCollection, name, builder.build(), nullAs);
}
protected final <L extends Collection<E>, E> ValidatorBuilder<T> forEach(ToCollection<T, L, E> toCollection,
String name, Validator<E> validator, NullAs nullAs) {
if (!nullAs.skipNull()) {
this.constraintOnObject(toCollection, name, Constraint::notNull);
}
this.collectionValidators.add(new CollectionValidator<>(toCollection, name, validator));
return this;
}
protected final <N> ValidatorBuilder<T> nest(Function<T, N> nested, String name,
ValidatorBuilderConverter<N> converter, NullAs nullAs) {
if (!nullAs.skipNull()) {
this.constraintOnObject(nested, name, Constraint::notNull);
}
ValidatorBuilder<N> builder = converter.apply(new ValidatorBuilder<>());
builder.predicatesList.forEach(this.appendNestedPredicates(nested, name, false));
builder.conditionalValidators.forEach(this.appendNestedConditionalValidator(nested, name));
builder.collectionValidators.forEach(appendNestedCollectionValidator(nested, name));
return this;
}
protected final <N> ValidatorBuilder<T> nest(Function<T, N> nested, String name, Validator<N> validator,
NullAs nullAs) {
if (!nullAs.skipNull()) {
this.constraintOnObject(nested, name, Constraint::notNull);
}
validator.forEachPredicates(this.appendNestedPredicates(nested, name, validator.isFailFast()));
validator.forEachConditionalValidator(this.appendNestedConditionalValidator(nested, name));
validator.forEachCollectionValidator(appendNestedCollectionValidator(nested, name));
return this;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private <N> Consumer<ConstraintPredicates<N, ?>> appendNestedPredicates(Function<T, N> nested, String name,
boolean failFast) {
return predicates -> {
String nestedName = name + this.messageKeySeparator + predicates.name();
ConstraintPredicates<T, ?> constraintPredicates = new NestedConstraintPredicates(
this.toNestedValue(nested, predicates), nestedName, predicates.predicates(),
this.toNestedFunction(nested, predicates), failFast);
this.predicatesList.add(constraintPredicates);
};
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private <N> Function<T, ?> toNestedFunction(Function<T, N> nested, ConstraintPredicates<N, ?> predicates) {
if (predicates instanceof NestedConstraintPredicates) {
return target -> {
N nestedValue = nested.apply(target);
if (nestedValue == null) {
return null;
}
return (N) ((NestedConstraintPredicates) predicates).nestedValue(nestedValue);
};
}
return nested;
}
private <N> Consumer<Pair<ConstraintCondition<N>, Validatable<N>>> appendNestedConditionalValidator(
Function<T, N> nested, String name) {
return conditionalValidator -> {
final ConstraintCondition<T> condition = new NestedConstraintCondition<>(nested,
conditionalValidator.first());
final Validatable<N> validator = conditionalValidator.second();
final String nestedPrefix = toNestedPrefix(name, validator);
final Validatable<T> v = new NestedValidator<>(nested, validator, nestedPrefix);
this.conditionalValidators.add(new Pair<>(condition, v));
};
}
private <N> String toNestedPrefix(String name, Validatable<N> validator) {
if (validator instanceof NestedValidator) {
final NestedValidator<?, ?> nestedValidator = (NestedValidator<?, ?>) validator;
return name + this.messageKeySeparator + nestedValidator.getPrefix();
}
return name + this.messageKeySeparator;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private <N> Consumer<CollectionValidator<N, ?, ?>> appendNestedCollectionValidator(Function<T, N> nested,
String name) {
return collectionValidator -> {
String nestedName = name + this.messageKeySeparator + collectionValidator.name();
CollectionValidator<T, ?, ?> validator = new NestedCollectionValidator(
toNestedCollection(nested, collectionValidator), nestedName, collectionValidator.validator(),
nested);
this.collectionValidators.add(validator);
};
}
private <K, V> ToCollection<T, Collection<V>, V> toMapToCollection(ToMap<T, K, V> toMap) {
return t -> {
Map<K, V> map = toMap.apply(t);
if (map == null) {
return null;
}
return map.values();
};
}
private <N> Function<T, Object> toNestedValue(Function<T, N> nested, ConstraintPredicates<N, ?> predicates) {
return (T target) -> {
N nestedValue = nested.apply(target);
if (nestedValue == null) {
return null;
}
return predicates.toValue().apply(nestedValue);
};
}
private <N, C extends Collection<?>> Function<T, Object> toNestedCollection(Function<T, N> nested,
CollectionValidator<N, C, ?> validator) {
return (T target) -> {
N nestedCollection = nested.apply(target);
if (nestedCollection == null) {
return null;
}
return validator.toCollection().apply(nestedCollection);
};
}
private <E> ToCollection<T, Collection<E>, E> toObjectArrayToCollection(ToObjectArray<T, E> toObjectArray) {
return t -> {
E[] array = toObjectArray.apply(t);
if (array == null) {
return null;
}
return Arrays.asList(array);
};
}
public interface ToBigDecimal<T> extends Function<T, BigDecimal> {
}
public interface ToBigInteger<T> extends Function<T, BigInteger> {
}
public interface ToBoolean<T> extends Function<T, Boolean> {
}
public interface ToBooleanArray<T> extends Function<T, boolean[]> {
}
public interface ToByte<T> extends Function<T, Byte> {
}
public interface ToByteArray<T> extends Function<T, byte[]> {
}
public interface ToCharArray<T> extends Function<T, char[]> {
}
public interface ToCharSequence<T, E extends CharSequence> extends Function<T, E> {
}
public interface toEnum<T, E extends Enum> extends Function<T, E> {
}
public interface ToCharacter<T> extends Function<T, Character> {
}
public interface ToCollection<T, L extends Collection<E>, E> extends Function<T, L> {
}
public interface ToDouble<T> extends Function<T, Double> {
}
public interface ToDoubleArray<T> extends Function<T, double[]> {
}
public interface ToFloat<T> extends Function<T, Float> {
}
public interface ToFloatArray<T> extends Function<T, float[]> {
}
public interface ToIntArray<T> extends Function<T, int[]> {
}
public interface ToInteger<T> extends Function<T, Integer> {
}
public interface ToLong<T> extends Function<T, Long> {
}
public interface ToLongArray<T> extends Function<T, long[]> {
}
public interface ToMap<T, K, V> extends Function<T, Map<K, V>> {
}
public interface ToObjectArray<T, E> extends Function<T, E[]> {
}
public interface ToShort<T> extends Function<T, Short> {
}
public interface ToShortArray<T> extends Function<T, short[]> {
}
public interface ToLocalTimeConstraint<T> extends Function<T, LocalTime> {
}
public interface ToZonedDateTimeConstraint<T> extends Function<T, ZonedDateTime> {
}
public interface ToOffsetDateTimeConstraint<T> extends Function<T, OffsetDateTime> {
}
public interface ToLocalDateTimeConstraint<T> extends Function<T, LocalDateTime> {
}
public interface ToLocalDateConstraint<T> extends Function<T, LocalDate> {
}
public interface ToInstantConstraint<T> extends Function<T, Instant> {
}
public interface ToYearConstraint<T> extends Function<T, Year> {
}
public interface ToYearMonthConstraint<T> extends Function<T, YearMonth> {
}
public interface ValidatorBuilderConverter<T> extends Function<ValidatorBuilder<T>, ValidatorBuilder<T>> {
}
/**
* An internal class that manages predicate conflicts
*
* @param <T> target type
* @since 0.13.0
*/
static final class PredicatesList<T> {
private final ConflictStrategy conflictStrategy;
private final Map<String, List<ConstraintPredicates<T, ?>>> predicatesListMap = new LinkedHashMap<>();
public PredicatesList(ConflictStrategy conflictStrategy) {
this.conflictStrategy = conflictStrategy;
}
public PredicatesList(ConflictStrategy conflictStrategy, List<ConstraintPredicates<T, ?>> predicatesList) {
this(conflictStrategy);
predicatesList.forEach(this::add);
}
public void add(ConstraintPredicates<T, ?> predicates) {
final List<ConstraintPredicates<T, ?>> predicatesList = this.predicatesListMap
.computeIfAbsent(predicates.name(), s -> new ArrayList<>());
if (!predicatesList.isEmpty()) {
this.conflictStrategy.resolveConflict(predicatesList, predicates);
}
predicatesList.add(predicates);
}
public List<ConstraintPredicates<T, ?>> toList() {
final int length = predicatesListMap.values().stream().mapToInt(List::size).sum();
final List<ConstraintPredicates<T, ?>> list = new ArrayList<>(length);
for (List<ConstraintPredicates<T, ?>> predicates : predicatesListMap.values()) {
list.addAll(predicates);
}
return list;
}
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/ValueValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.util.function.Function;
import am.ik.yavi.core.ValueValidator;
/**
* Builder for ValueValidator
*
* @param <A> argument type
* @param <R> result type
* @since 0.14.0
*/
public interface ValueValidatorBuilder<A, R> {
ValueValidator<? super A, ? extends R> build();
<T> ValueValidator<? super A, ? extends T> build(Function<? super R, ? extends T> mapper);
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/YaviArguments.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
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;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.constraint.BigDecimalConstraint;
import am.ik.yavi.constraint.BigIntegerConstraint;
import am.ik.yavi.constraint.BooleanConstraint;
import am.ik.yavi.constraint.CharSequenceConstraint;
import am.ik.yavi.constraint.DoubleConstraint;
import am.ik.yavi.constraint.EnumConstraint;
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;
import am.ik.yavi.constraint.OffsetDateTimeConstraint;
import am.ik.yavi.constraint.ShortConstraint;
import am.ik.yavi.constraint.YearConstraint;
import am.ik.yavi.constraint.YearMonthConstraint;
import am.ik.yavi.constraint.ZonedDateTimeConstraint;
import am.ik.yavi.core.ValueValidator;
/**
* Generated by https://github.com/making/yavi/blob/develop/scripts/generate-args.sh
*
* @since 0.14.0
*/
public final class YaviArguments {
public <T> Arguments1ValidatorBuilder<BigDecimal, T> _bigDecimal(ValueValidator<BigDecimal, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<BigDecimal, BigDecimal> _bigDecimal(String name,
Function<BigDecimalConstraint<Arguments1<BigDecimal>>, BigDecimalConstraint<Arguments1<BigDecimal>>> constraints) {
return this._bigDecimal(BigDecimalValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<BigDecimal, BigDecimal> _bigDecimal(String name) {
return this._bigDecimal(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<BigInteger, T> _bigInteger(ValueValidator<BigInteger, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<BigInteger, BigInteger> _bigInteger(String name,
Function<BigIntegerConstraint<Arguments1<BigInteger>>, BigIntegerConstraint<Arguments1<BigInteger>>> constraints) {
return this._bigInteger(BigIntegerValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<BigInteger, BigInteger> _bigInteger(String name) {
return this._bigInteger(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Boolean, T> _boolean(ValueValidator<Boolean, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Boolean, Boolean> _boolean(String name,
Function<BooleanConstraint<Arguments1<Boolean>>, BooleanConstraint<Arguments1<Boolean>>> constraints) {
return this._boolean(BooleanValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Boolean, Boolean> _boolean(String name) {
return this._boolean(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Double, T> _double(ValueValidator<Double, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Double, Double> _double(String name,
Function<DoubleConstraint<Arguments1<Double>>, DoubleConstraint<Arguments1<Double>>> constraints) {
return this._double(DoubleValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Double, Double> _double(String name) {
return this._double(name, Function.identity());
}
public <E extends Enum<E>, T> Arguments1ValidatorBuilder<E, T> _enum(ValueValidator<E, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public <E extends Enum<E>> Arguments1ValidatorBuilder<E, E> _enum(String name,
Function<EnumConstraint<Arguments1<E>, E>, EnumConstraint<Arguments1<E>, E>> constraints) {
return this._enum(EnumValidatorBuilder.of(name, constraints).build());
}
public <E extends Enum<E>> Arguments1ValidatorBuilder<E, E> _enum(String name) {
return this._enum(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Float, T> _float(ValueValidator<Float, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Float, Float> _float(String name,
Function<FloatConstraint<Arguments1<Float>>, FloatConstraint<Arguments1<Float>>> constraints) {
return this._float(FloatValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Float, Float> _float(String name) {
return this._float(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Instant, T> _instant(ValueValidator<Instant, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Instant, Instant> _instant(String name,
Function<InstantConstraint<Arguments1<Instant>>, InstantConstraint<Arguments1<Instant>>> constraints) {
return this._instant(InstantValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Instant, Instant> _instant(String name) {
return this._instant(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Integer, T> _integer(ValueValidator<Integer, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Integer, Integer> _integer(String name,
Function<IntegerConstraint<Arguments1<Integer>>, IntegerConstraint<Arguments1<Integer>>> constraints) {
return this._integer(IntegerValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Integer, Integer> _integer(String name) {
return this._integer(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<LocalDateTime, T> _localDateTime(ValueValidator<LocalDateTime, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<LocalDateTime, LocalDateTime> _localDateTime(String name,
Function<LocalDateTimeConstraint<Arguments1<LocalDateTime>>, LocalDateTimeConstraint<Arguments1<LocalDateTime>>> constraints) {
return this._localDateTime(LocalDateTimeValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<LocalDateTime, LocalDateTime> _localDateTime(String name) {
return this._localDateTime(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<LocalTime, T> _localTime(ValueValidator<LocalTime, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<LocalTime, LocalTime> _localTime(String name,
Function<LocalTimeConstraint<Arguments1<LocalTime>>, LocalTimeConstraint<Arguments1<LocalTime>>> constraints) {
return this._localTime(LocalTimeValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<LocalTime, LocalTime> _localTime(String name) {
return this._localTime(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<LocalDate, T> _localDate(ValueValidator<LocalDate, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<LocalDate, LocalDate> _localDate(String name,
Function<LocalDateConstraint<Arguments1<LocalDate>>, LocalDateConstraint<Arguments1<LocalDate>>> constraints) {
return this._localDate(LocalDateValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<LocalDate, LocalDate> _localDate(String name) {
return this._localDate(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Long, T> _long(ValueValidator<Long, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Long, Long> _long(String name,
Function<LongConstraint<Arguments1<Long>>, LongConstraint<Arguments1<Long>>> constraints) {
return this._long(LongValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Long, Long> _long(String name) {
return this._long(name, Function.identity());
}
public <T1, T2> Arguments1ValidatorBuilder<T1, T2> _object(ValueValidator<T1, T2> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public <T> Arguments1ValidatorBuilder<T, T> _object(String name,
Function<ObjectConstraint<Arguments1<T>, T>, ObjectConstraint<Arguments1<T>, T>> constraints) {
return this._object(ObjectValidatorBuilder.of(name, constraints).build());
}
public <T> Arguments1ValidatorBuilder<T, T> _object(String name) {
return this._object(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<OffsetDateTime, T> _offsetDateTime(
ValueValidator<OffsetDateTime, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<OffsetDateTime, OffsetDateTime> _offsetDateTime(String name,
Function<OffsetDateTimeConstraint<Arguments1<OffsetDateTime>>, OffsetDateTimeConstraint<Arguments1<OffsetDateTime>>> constraints) {
return this._offsetDateTime(OffsetDateTimeValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<OffsetDateTime, OffsetDateTime> _offsetDateTime(String name) {
return this._offsetDateTime(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Short, T> _short(ValueValidator<Short, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Short, Short> _short(String name,
Function<ShortConstraint<Arguments1<Short>>, ShortConstraint<Arguments1<Short>>> constraints) {
return this._short(ShortValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Short, Short> _short(String name) {
return this._short(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<String, T> _string(ValueValidator<String, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<String, String> _string(String name,
Function<CharSequenceConstraint<Arguments1<String>, String>, CharSequenceConstraint<Arguments1<String>, String>> constraints) {
return this._string(StringValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<String, String> _string(String name) {
return this._string(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<YearMonth, T> _yearMonth(ValueValidator<YearMonth, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<YearMonth, YearMonth> _yearMonth(String name,
Function<YearMonthConstraint<Arguments1<YearMonth>>, YearMonthConstraint<Arguments1<YearMonth>>> constraints) {
return this._yearMonth(YearMonthValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<YearMonth, YearMonth> _yearMonth(String name) {
return this._yearMonth(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<Year, T> _year(ValueValidator<Year, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<Year, Year> _year(String name,
Function<YearConstraint<Arguments1<Year>>, YearConstraint<Arguments1<Year>>> constraints) {
return this._year(YearValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<Year, Year> _year(String name) {
return this._year(name, Function.identity());
}
public <T> Arguments1ValidatorBuilder<ZonedDateTime, T> _zonedDateTime(ValueValidator<ZonedDateTime, T> validator) {
return new Arguments1ValidatorBuilder<>(validator);
}
public Arguments1ValidatorBuilder<ZonedDateTime, ZonedDateTime> _zonedDateTime(String name,
Function<ZonedDateTimeConstraint<Arguments1<ZonedDateTime>>, ZonedDateTimeConstraint<Arguments1<ZonedDateTime>>> constraints) {
return this._zonedDateTime(ZonedDateTimeValidatorBuilder.of(name, constraints).build());
}
public Arguments1ValidatorBuilder<ZonedDateTime, ZonedDateTime> _zonedDateTime(String name) {
return this._zonedDateTime(name, Function.identity());
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/YearMonthValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.YearMonth;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.YearMonthValidator;
import am.ik.yavi.constraint.YearMonthConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.11.0
*/
public class YearMonthValidatorBuilder implements ValueValidatorBuilder<YearMonth, YearMonth> {
private final Function<ValidatorBuilder<Arguments1<YearMonth>>, ValidatorBuilder<Arguments1<YearMonth>>> builder;
public static YearMonthValidatorBuilder of(String name,
Function<YearMonthConstraint<Arguments1<YearMonth>>, YearMonthConstraint<Arguments1<YearMonth>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static YearMonthValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<YearMonth>>, ValidatorBuilder<Arguments1<YearMonth>>> builder) {
return new YearMonthValidatorBuilder(builder);
}
YearMonthValidatorBuilder(
Function<ValidatorBuilder<Arguments1<YearMonth>>, ValidatorBuilder<Arguments1<YearMonth>>> builder) {
this.builder = builder;
}
@Override
public <T> YearMonthValidator<T> build(Function<? super YearMonth, ? extends T> mapper) {
final Validator<Arguments1<YearMonth>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new YearMonthValidator<>(validator, mapper::apply);
}
@Override
public YearMonthValidator<YearMonth> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/YearValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.Year;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.YearValidator;
import am.ik.yavi.constraint.YearConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.11.0
*/
public class YearValidatorBuilder implements ValueValidatorBuilder<Year, Year> {
private final Function<ValidatorBuilder<Arguments1<Year>>, ValidatorBuilder<Arguments1<Year>>> builder;
public static YearValidatorBuilder of(String name,
Function<YearConstraint<Arguments1<Year>>, YearConstraint<Arguments1<Year>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static YearValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<Year>>, ValidatorBuilder<Arguments1<Year>>> builder) {
return new YearValidatorBuilder(builder);
}
YearValidatorBuilder(Function<ValidatorBuilder<Arguments1<Year>>, ValidatorBuilder<Arguments1<Year>>> builder) {
this.builder = builder;
}
@Override
public <T> YearValidator<T> build(Function<? super Year, ? extends T> mapper) {
final Validator<Arguments1<Year>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new YearValidator<>(validator, mapper::apply);
}
@Override
public YearValidator<Year> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/ZonedDateTimeValidatorBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.builder;
import java.time.ZonedDateTime;
import java.util.function.Function;
import am.ik.yavi.arguments.Arguments1;
import am.ik.yavi.arguments.ZonedDateTimeValidator;
import am.ik.yavi.constraint.ZonedDateTimeConstraint;
import am.ik.yavi.core.Validator;
/**
* @since 0.10.0
*/
public class ZonedDateTimeValidatorBuilder implements ValueValidatorBuilder<ZonedDateTime, ZonedDateTime> {
private final Function<ValidatorBuilder<Arguments1<ZonedDateTime>>, ValidatorBuilder<Arguments1<ZonedDateTime>>> builder;
public static ZonedDateTimeValidatorBuilder of(String name,
Function<ZonedDateTimeConstraint<Arguments1<ZonedDateTime>>, ZonedDateTimeConstraint<Arguments1<ZonedDateTime>>> constraints) {
return wrap(b -> b.constraint(Arguments1::arg1, name, constraints));
}
/**
* @since 0.11.3
*/
public static ZonedDateTimeValidatorBuilder wrap(
Function<ValidatorBuilder<Arguments1<ZonedDateTime>>, ValidatorBuilder<Arguments1<ZonedDateTime>>> builder) {
return new ZonedDateTimeValidatorBuilder(builder);
}
ZonedDateTimeValidatorBuilder(
Function<ValidatorBuilder<Arguments1<ZonedDateTime>>, ValidatorBuilder<Arguments1<ZonedDateTime>>> builder) {
this.builder = builder;
}
@Override
public <T> ZonedDateTimeValidator<T> build(Function<? super ZonedDateTime, ? extends T> mapper) {
final Validator<Arguments1<ZonedDateTime>> validator = this.builder.apply(ValidatorBuilder.of()).build();
return new ZonedDateTimeValidator<>(validator, mapper::apply);
}
@Override
public ZonedDateTimeValidator<ZonedDateTime> build() {
return build(x -> x);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/builder/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.builder;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/BigDecimalConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.math.BigDecimal;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class BigDecimalConstraint<T> extends NumericConstraintBase<T, BigDecimal, BigDecimalConstraint<T>> {
@Override
public BigDecimalConstraint<T> cast() {
return this;
}
@Override
protected Predicate<BigDecimal> isGreaterThan(BigDecimal min) {
return x -> x.compareTo(min) > 0;
}
@Override
protected Predicate<BigDecimal> isGreaterThanOrEqual(BigDecimal min) {
return x -> x.compareTo(min) >= 0;
}
@Override
protected Predicate<BigDecimal> isLessThan(BigDecimal max) {
return x -> x.compareTo(max) < 0;
}
@Override
protected Predicate<BigDecimal> isLessThanOrEqual(BigDecimal max) {
return x -> x.compareTo(max) <= 0;
}
@Override
protected BigDecimal zeroValue() {
return BigDecimal.ZERO;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/BigIntegerConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.math.BigInteger;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class BigIntegerConstraint<T> extends NumericConstraintBase<T, BigInteger, BigIntegerConstraint<T>> {
@Override
public BigIntegerConstraint<T> cast() {
return this;
}
@Override
protected Predicate<BigInteger> isGreaterThan(BigInteger min) {
return x -> x.compareTo(min) > 0;
}
@Override
protected Predicate<BigInteger> isGreaterThanOrEqual(BigInteger min) {
return x -> x.compareTo(min) >= 0;
}
@Override
protected Predicate<BigInteger> isLessThan(BigInteger max) {
return x -> x.compareTo(max) < 0;
}
@Override
protected Predicate<BigInteger> isLessThanOrEqual(BigInteger max) {
return x -> x.compareTo(max) <= 0;
}
@Override
protected BigInteger zeroValue() {
return BigInteger.ZERO;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/BooleanConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.BOOLEAN_IS_FALSE;
import static am.ik.yavi.core.ViolationMessage.Default.BOOLEAN_IS_TRUE;
import am.ik.yavi.constraint.base.ConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class BooleanConstraint<T> extends ConstraintBase<T, Boolean, BooleanConstraint<T>> {
@Override
public BooleanConstraint<T> cast() {
return this;
}
public BooleanConstraint<T> isFalse() {
this.predicates().add(ConstraintPredicate.of(x -> !x, BOOLEAN_IS_FALSE, () -> new Object[] {}, VALID));
return this;
}
public BooleanConstraint<T> isTrue() {
this.predicates().add(ConstraintPredicate.of(x -> x, BOOLEAN_IS_TRUE, () -> new Object[] {}, VALID));
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/ByteConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class ByteConstraint<T> extends NumericConstraintBase<T, Byte, ByteConstraint<T>> {
@Override
public ByteConstraint<T> cast() {
return this;
}
@Override
protected Predicate<Byte> isGreaterThan(Byte min) {
return x -> x > min;
}
@Override
protected Predicate<Byte> isGreaterThanOrEqual(Byte min) {
return x -> x >= min;
}
@Override
protected Predicate<Byte> isLessThan(Byte max) {
return x -> x < max;
}
@Override
protected Predicate<Byte> isLessThanOrEqual(Byte max) {
return x -> x <= max;
}
@Override
protected Byte zeroValue() {
return 0;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/CharSequenceConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.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;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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 static am.ik.yavi.core.NullAs.INVALID;
import static am.ik.yavi.core.NullAs.VALID;
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<T, E extends CharSequence>
extends ContainerConstraintBase<T, E, CharSequenceConstraint<T, E>> {
private static final String EMAIL_PART = "[^\\x00-\\x1F()<>@,;:\\\\\".\\[\\]\\s]";
private static final String DOMAIN_PATTERN = EMAIL_PART + "+(\\." + EMAIL_PART + "+)*";
private static final Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^" + EMAIL_PART + "+(\\." + EMAIL_PART
+ "+)*@(" + DOMAIN_PATTERN + "|" + InetAddressUtils.IPV4_REGEX + ")$", Pattern.CASE_INSENSITIVE);
private static final Pattern VALID_UUID_REGEX = Pattern.compile("\\p{XDigit}{8}(-\\p{XDigit}{4}){4}\\p{XDigit}{8}");
protected final Normalizer.Form normalizerForm;
protected final VariantOptions variantOptions;
public CharSequenceConstraint() {
this(Normalizer.Form.NFC, VariantOptions.builder().build());
}
public CharSequenceConstraint(Normalizer.Form normalizerForm, VariantOptions variantOptions) {
this.normalizerForm = normalizerForm;
this.variantOptions = variantOptions;
}
public ByteSizeConstraint<T, E> asByteArray(Charset charset) {
return new ByteSizeConstraint<>(this, charset);
}
public ByteSizeConstraint<T, E> asByteArray() {
return this.asByteArray(StandardCharsets.UTF_8);
}
@Override
public CharSequenceConstraint<T, E> cast() {
return this;
}
public CodePointsConstraint.Builder<T, E> codePoints(CodePoints<E> codePoints) {
return new CodePointsConstraint.Builder<>(this, codePoints);
}
public CodePointsConstraint.Builder<T, E> codePoints(Set<Integer> allowedCodePoints) {
return this.codePoints((CodePointsSet<E>) () -> allowedCodePoints);
}
public CodePointsConstraint.Builder<T, E> codePoints(int begin, int end) {
return this.codePoints(Range.of(begin, end));
}
public CodePointsConstraint.Builder<T, E> codePoints(Range range, Range... ranges) {
return this.codePoints((CodePointsRanges<E>) () -> {
List<Range> list = new ArrayList<>();
list.add(range);
list.addAll(Arrays.asList(ranges));
return list;
});
}
public CharSequenceConstraint<T, E> contains(CharSequence s) {
this.predicates()
.add(ConstraintPredicate.of(x -> x.toString().contains(s), CHAR_SEQUENCE_CONTAINS, () -> new Object[] { s },
VALID));
return this;
}
/**
* Does the given value start with the {@code prefix}
* @param prefix the prefix the value has to start with
* @since 0.10.0
*/
public CharSequenceConstraint<T, E> startsWith(CharSequence prefix) {
this.predicates()
.add(ConstraintPredicate.of(x -> x.toString().startsWith(prefix.toString()), CHAR_SEQUENCE_STARTSWITH,
() -> new Object[] { prefix }, VALID));
return this;
}
/**
* Does the given value end with the {@code suffix}
* @param suffix the suffix the value has to end with
* @since 0.10.0
*/
public CharSequenceConstraint<T, E> endsWith(CharSequence suffix) {
this.predicates()
.add(ConstraintPredicate.of(x -> x.toString().endsWith(suffix.toString()), CHAR_SEQUENCE_ENDSWITH,
() -> new Object[] { suffix }, VALID));
return this;
}
public CharSequenceConstraint<T, E> email() {
this.predicates().add(ConstraintPredicate.of(x -> {
if (size().applyAsInt(x) == 0) {
return true;
}
return VALID_EMAIL_ADDRESS_REGEX.matcher(x).matches();
}, CHAR_SEQUENCE_EMAIL, () -> new Object[] {}, VALID));
return this;
}
/**
* @since 0.7.0
*/
public CharSequenceConstraint<T, E> password(
Function<CharSequencePasswordPoliciesBuilder<T, E>, List<ConstraintPredicate<E>>> builder) {
final List<ConstraintPredicate<E>> predicates = builder.apply(new CharSequencePasswordPoliciesBuilder<>());
this.predicates().addAll(predicates);
return this;
}
private <U> CharSequenceConstraint<T, E> isValidRepresentationOf(Function<String, U> converter,
ViolationMessage message) {
this.predicates().add(ConstraintPredicate.of(x -> {
if (size().applyAsInt(x) == 0) {
return true;
}
try {
converter.apply(x.toString());
return true;
}
catch (NumberFormatException ignored) {
return false;
}
}, message, () -> new Object[] {}, VALID));
return this;
}
/**
* @since 0.12.0
*/
private CharSequenceConstraint<T, E> isLocalDatePattern(String pattern) {
this.predicates().add(ConstraintPredicate.of(x -> {
try {
DateTimeFormatter.ofPattern(pattern).withResolverStyle(ResolverStyle.STRICT).parse(x);
return true;
}
catch (DateTimeParseException ignored) {
return false;
}
}, CHAR_SEQUENCE_LOCAL_DATE, () -> new Object[] { pattern }, VALID));
return this;
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isByte() {
return this.isValidRepresentationOf(Byte::parseByte, CHAR_SEQUENCE_BYTE);
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isShort() {
return this.isValidRepresentationOf(Short::parseShort, CHAR_SEQUENCE_SHORT);
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isInteger() {
return this.isValidRepresentationOf(Integer::parseInt, CHAR_SEQUENCE_INTEGER);
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isLong() {
return this.isValidRepresentationOf(Long::parseLong, CHAR_SEQUENCE_LONG);
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isFloat() {
return this.isValidRepresentationOf(Float::parseFloat, CHAR_SEQUENCE_FLOAT);
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isDouble() {
return this.isValidRepresentationOf(Double::parseDouble, CHAR_SEQUENCE_DOUBLE);
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isBigInteger() {
return this.isValidRepresentationOf(BigInteger::new, CHAR_SEQUENCE_BIGINTEGER);
}
/**
* @since 0.6.0
*/
public CharSequenceConstraint<T, E> isBigDecimal() {
return this.isValidRepresentationOf(BigDecimal::new, CHAR_SEQUENCE_BIGDECIMAL);
}
/**
* @since 0.12.1
*/
public CharSequenceConstraint<T, E> isoLocalDate() {
return this.isLocalDatePattern("uuuu-MM-dd");
}
/**
* @since 0.12.1
*/
public CharSequenceConstraint<T, E> localDate(String pattern) {
return this.isLocalDatePattern(pattern);
}
public EmojiConstraint<T, E> emoji() {
return new EmojiConstraint<>(this, this.normalizerForm, this.variantOptions);
}
public CharSequenceConstraint<T, E> normalizer(Normalizer.Form normalizerForm) {
CharSequenceConstraint<T, E> constraint = new CharSequenceConstraint<>(normalizerForm, this.variantOptions);
constraint.predicates().addAll(this.predicates());
return constraint;
}
public CharSequenceConstraint<T, E> notBlank() {
this.predicates()
.add(ConstraintPredicate.of(x -> x != null && trim(x.toString()).length() != 0, CHAR_SEQUENCE_NOT_BLANK,
() -> new Object[] {}, INVALID));
return this;
}
public CharSequenceConstraint<T, E> pattern(String regex) {
this.predicates()
.add(ConstraintPredicate.of(x -> Pattern.matches(regex, x), CHAR_SEQUENCE_PATTERN,
() -> new Object[] { regex }, VALID));
return this;
}
/**
* @since 0.11.1
*/
public CharSequenceConstraint<T, E> pattern(Pattern regex) {
this.predicates()
.add(ConstraintPredicate.of(x -> regex.matcher(x).matches(), CHAR_SEQUENCE_PATTERN,
() -> new Object[] { regex.pattern() }, VALID));
return this;
}
/**
* @since 0.11.1
*/
public CharSequenceConstraint<T, E> pattern(Supplier<Pattern> regexSupplier) {
this.predicates()
.add(ConstraintPredicate.of(x -> regexSupplier.get().matcher(x).matches(), CHAR_SEQUENCE_PATTERN,
() -> new Object[] { regexSupplier.get().pattern() }, VALID));
return this;
}
/**
* @since 0.7.0
*/
public CharSequenceConstraint<T, E> ipv4() {
this.predicates()
.add(ConstraintPredicate.of(x -> InetAddressUtils.isIpv4(x.toString()), CHAR_SEQUENCE_IPV4,
() -> new Object[] {}, VALID));
return this;
}
/**
* @since 0.7.0
*/
public CharSequenceConstraint<T, E> ipv6() {
this.predicates()
.add(ConstraintPredicate.of(x -> InetAddressUtils.isIpv6(x.toString()), CHAR_SEQUENCE_IPV6,
() -> new Object[] {}, VALID));
return this;
}
public CharSequenceConstraint<T, E> url() {
this.predicates().add(ConstraintPredicate.of(x -> {
if (size().applyAsInt(x) == 0) {
return true;
}
try {
new URL(x.toString());
return true;
}
catch (MalformedURLException e) {
return false;
}
}, CHAR_SEQUENCE_URL, () -> new Object[] {}, VALID));
return this;
}
/**
* @since 0.10.0
*/
public CharSequenceConstraint<T, E> uuid() {
this.predicates().add(ConstraintPredicate.of(x -> {
if (size().applyAsInt(x) == 0) {
return true;
}
return VALID_UUID_REGEX.matcher(x).matches();
}, CHAR_SEQUENCE_UUID, () -> new Object[] {}, VALID));
return this;
}
/**
* @since 0.7.0
*/
public CharSequenceConstraint<T, E> luhn() {
this.predicates()
.add(ConstraintPredicate.of(CharSequenceConstraint::luhnCheck, CHAR_SEQUENCE_LUHN, () -> new Object[] {},
VALID));
return this;
}
// https://github.com/apache/commons-validator/blob/master/src/main/java/org/apache/commons/validator/CreditCardValidator.java
static boolean luhnCheck(CharSequence cardNumber) {
// number must be validated as 0..9 numeric first!!
final int digits = cardNumber.length();
final int oddOrEven = digits & 1;
long sum = 0;
for (int count = 0; count < digits; count++) {
int digit;
try {
digit = Integer.parseInt(cardNumber.charAt(count) + "");
}
catch (NumberFormatException e) {
return false;
}
if (((count & 1) ^ oddOrEven) == 0) { // not
digit *= 2;
if (digit > 9) {
digit -= 9;
}
}
sum += digit;
}
return sum != 0 && (sum % 10 == 0);
}
public CharSequenceConstraint<T, E> variant(Function<VariantOptions.Builder, VariantOptions.Builder> opts) {
VariantOptions.Builder builder = VariantOptions.builder();
CharSequenceConstraint<T, E> constraint = new CharSequenceConstraint<>(this.normalizerForm,
opts.apply(builder).build());
constraint.predicates().addAll(this.predicates());
return constraint;
}
protected String normalize(String s) {
String str = this.variantOptions.ignored(s);
return this.normalizerForm == null ? str : Normalizer.normalize(str, this.normalizerForm);
}
@Override
protected ToIntFunction<E> size() {
return cs -> {
String s = this.normalize(cs.toString());
return s.codePointCount(0, s.length());
};
}
private static String trim(String s) {
if (s.length() == 0) {
return s;
}
StringBuilder sb = new StringBuilder(s);
while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
sb.deleteCharAt(0);
}
while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/CharacterConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class CharacterConstraint<T> extends NumericConstraintBase<T, Character, CharacterConstraint<T>> {
@Override
public CharacterConstraint<T> cast() {
return this;
}
@Override
protected Predicate<Character> isGreaterThan(Character min) {
return x -> x > min;
}
@Override
protected Predicate<Character> isGreaterThanOrEqual(Character min) {
return x -> x >= min;
}
@Override
protected Predicate<Character> isLessThan(Character max) {
return x -> x < max;
}
@Override
protected Predicate<Character> isLessThanOrEqual(Character max) {
return x -> x <= max;
}
@Override
protected Character zeroValue() {
return Character.MIN_VALUE;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/CollectionConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
import am.ik.yavi.core.ViolatedValue;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.COLLECTION_CONTAINS;
import static am.ik.yavi.core.ViolationMessage.Default.COLLECTION_CONTAINS_ALL;
import static am.ik.yavi.core.ViolationMessage.Default.COLLECTION_UNIQUE;
public class CollectionConstraint<T, L extends Collection<E>, E>
extends ContainerConstraintBase<T, L, CollectionConstraint<T, L, E>> {
@Override
public CollectionConstraint<T, L, E> cast() {
return this;
}
public CollectionConstraint<T, L, E> contains(E s) {
this.predicates()
.add(ConstraintPredicate.of(x -> x.contains(s), COLLECTION_CONTAINS, () -> new Object[] { s }, VALID));
return this;
}
/**
* @since 0.8.3
*/
public CollectionConstraint<T, L, E> unique() {
this.predicates().add(ConstraintPredicate.withViolatedValue(collection -> {
final Set<E> duplicates = new LinkedHashSet<>();
final Set<E> uniqElements = new HashSet<>(collection.size());
for (E element : collection) {
if (uniqElements.contains(element)) {
duplicates.add(element);
}
else {
uniqElements.add(element);
}
}
if (duplicates.isEmpty()) {
return Optional.empty();
}
else {
return Optional.of(new ViolatedValue(duplicates));
}
}, COLLECTION_UNIQUE, () -> new Object[] {}, VALID));
return this;
}
/**
* @since 0.14.3
*/
public CollectionConstraint<T, L, E> containsAll(Collection<? extends E> values) {
this.predicates().add(ConstraintPredicate.withViolatedValue(collection -> {
final Set<E> missingValues = new HashSet<>(values);
if (collection instanceof Set) {
missingValues.removeAll(collection);
}
else {
missingValues.removeAll(new HashSet<>(collection));
}
return missingValues.isEmpty() ? Optional.empty() : Optional.of(new ViolatedValue(missingValues));
}, COLLECTION_CONTAINS_ALL, () -> new Object[] { values.toString() }, VALID));
return this;
}
@Override
protected ToIntFunction<L> size() {
return Collection::size;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/DoubleConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class DoubleConstraint<T> extends NumericConstraintBase<T, Double, DoubleConstraint<T>> {
@Override
public DoubleConstraint<T> cast() {
return this;
}
@Override
protected Predicate<Double> isGreaterThan(Double min) {
return x -> x > min;
}
@Override
protected Predicate<Double> isGreaterThanOrEqual(Double min) {
return x -> x >= min;
}
@Override
protected Predicate<Double> isLessThan(Double max) {
return x -> x < max;
}
@Override
protected Predicate<Double> isLessThanOrEqual(Double max) {
return x -> x <= max;
}
@Override
protected Double zeroValue() {
return 0.0;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/EnumConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import am.ik.yavi.constraint.base.ConstraintBase;
import java.util.Arrays;
import java.util.EnumSet;
/**
* class for enum constraints
*
* @since 0.14.0
*/
public class EnumConstraint<T, E extends Enum<E>> extends ConstraintBase<T, E, EnumConstraint<T, E>> {
@Override
public EnumConstraint<T, E> cast() {
return this;
}
@SafeVarargs
public final EnumConstraint<T, E> oneOf(E... values) throws IllegalArgumentException {
if (values.length == 0) {
throw new IllegalArgumentException("oneOf must accept at least one value");
}
EnumSet<E> enumSet = EnumSet.copyOf(Arrays.asList(values));
return super.oneOf(enumSet);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/FloatConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class FloatConstraint<T> extends NumericConstraintBase<T, Float, FloatConstraint<T>> {
@Override
public FloatConstraint<T> cast() {
return this;
}
@Override
protected Predicate<Float> isGreaterThan(Float min) {
return x -> x > min;
}
@Override
protected Predicate<Float> isGreaterThanOrEqual(Float min) {
return x -> x >= min;
}
@Override
protected Predicate<Float> isLessThan(Float max) {
return x -> x < max;
}
@Override
protected Predicate<Float> isLessThanOrEqual(Float max) {
return x -> x <= max;
}
@Override
protected Float zeroValue() {
return 0f;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/InstantConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.Instant;
import am.ik.yavi.constraint.base.TemporalConstraintBase;
/**
* This is the actual class for constraints on Instant.
*
* @since 0.10.0
*/
public class InstantConstraint<T> extends TemporalConstraintBase<T, Instant, InstantConstraint<T>> {
@Override
protected boolean isAfter(Instant a, Instant b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(Instant a, Instant b) {
return a.isBefore(b);
}
@Override
protected Instant getNow(Clock clock) {
return Instant.now(clock);
}
@Override
public InstantConstraint<T> cast() {
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/IntegerConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class IntegerConstraint<T> extends NumericConstraintBase<T, Integer, IntegerConstraint<T>> {
@Override
public IntegerConstraint<T> cast() {
return this;
}
@Override
protected Predicate<Integer> isGreaterThan(Integer min) {
return x -> x > min;
}
@Override
protected Predicate<Integer> isGreaterThanOrEqual(Integer min) {
return x -> x >= min;
}
@Override
protected Predicate<Integer> isLessThan(Integer max) {
return x -> x < max;
}
@Override
protected Predicate<Integer> isLessThanOrEqual(Integer max) {
return x -> x <= max;
}
@Override
protected Integer zeroValue() {
return 0;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/LocalDateConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.LocalDate;
import am.ik.yavi.constraint.base.ChronoLocalDateConstraintBase;
/**
* This is the actual class for constraints on LocalDate.
*
* @author Diego Krupitza
* @since 0.10.0
*/
public class LocalDateConstraint<T> extends ChronoLocalDateConstraintBase<T, LocalDate, LocalDateConstraint<T>> {
@Override
public LocalDateConstraint<T> cast() {
return this;
}
@Override
protected LocalDate getNow(Clock clock) {
return LocalDate.now(clock);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/LocalDateTimeConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.LocalDateTime;
import am.ik.yavi.constraint.base.ChronoLocalDateTimeConstraintBase;
/**
* This is the actual class for constraints on LocalDateTime.
*
* @author Diego Krupitza
* @since 0.10.0
*/
public class LocalDateTimeConstraint<T>
extends ChronoLocalDateTimeConstraintBase<T, LocalDateTime, LocalDateTimeConstraint<T>> {
@Override
public LocalDateTimeConstraint<T> cast() {
return this;
}
@Override
protected LocalDateTime getNow(Clock clock) {
return LocalDateTime.now(clock);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/LocalTimeConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.LocalTime;
import am.ik.yavi.constraint.base.TemporalConstraintBase;
/**
* This is the actual class for constraints on LocalTime.
*
* @author Diego Krupitza
* @since 0.10.0
*/
public class LocalTimeConstraint<T> extends TemporalConstraintBase<T, LocalTime, LocalTimeConstraint<T>> {
@Override
protected boolean isAfter(LocalTime a, LocalTime b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(LocalTime a, LocalTime b) {
return a.isBefore(b);
}
@Override
protected LocalTime getNow(Clock clock) {
return LocalTime.now(clock);
}
@Override
public LocalTimeConstraint<T> cast() {
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/LongConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class LongConstraint<T> extends NumericConstraintBase<T, Long, LongConstraint<T>> {
@Override
public LongConstraint<T> cast() {
return this;
}
@Override
protected Predicate<Long> isGreaterThan(Long min) {
return x -> x > min;
}
@Override
protected Predicate<Long> isGreaterThanOrEqual(Long min) {
return x -> x >= min;
}
@Override
protected Predicate<Long> isLessThan(Long max) {
return x -> x < max;
}
@Override
protected Predicate<Long> isLessThanOrEqual(Long max) {
return x -> x <= max;
}
@Override
protected Long zeroValue() {
return 0L;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/MapConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.Map;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.MAP_CONTAINS_KEY;
import static am.ik.yavi.core.ViolationMessage.Default.MAP_CONTAINS_VALUE;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class MapConstraint<T, K, V> extends ContainerConstraintBase<T, Map<K, V>, MapConstraint<T, K, V>> {
@Override
public MapConstraint<T, K, V> cast() {
return this;
}
public MapConstraint<T, K, V> containsKey(K k) {
this.predicates()
.add(ConstraintPredicate.of(x -> x.containsKey(k), MAP_CONTAINS_KEY, () -> new Object[] { k }, VALID));
return this;
}
public MapConstraint<T, K, V> containsValue(V v) {
this.predicates()
.add(ConstraintPredicate.of(x -> x.containsValue(v), MAP_CONTAINS_VALUE, () -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<Map<K, V>> size() {
return Map::size;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/ObjectConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.List;
import java.util.function.Function;
import am.ik.yavi.constraint.base.ConstraintBase;
import am.ik.yavi.constraint.password.ObjectPasswordPoliciesBuilder;
import am.ik.yavi.core.ConstraintPredicate;
public class ObjectConstraint<T, E> extends ConstraintBase<T, E, ObjectConstraint<T, E>> {
@Override
public ObjectConstraint<T, E> cast() {
return this;
}
/**
* @since 0.7.0
*/
public ObjectConstraint<T, E> password(
Function<ObjectPasswordPoliciesBuilder<T, E>, List<ConstraintPredicate<E>>> builder) {
final List<ConstraintPredicate<E>> predicates = builder.apply(new ObjectPasswordPoliciesBuilder<>());
this.predicates().addAll(predicates);
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/OffsetDateTimeConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.OffsetDateTime;
import am.ik.yavi.constraint.base.TemporalConstraintBase;
/**
* This is the actual class for constraints on OffsetDateTime.
*
* @since 0.10.0
*/
public class OffsetDateTimeConstraint<T>
extends TemporalConstraintBase<T, OffsetDateTime, OffsetDateTimeConstraint<T>> {
@Override
protected boolean isAfter(OffsetDateTime a, OffsetDateTime b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(OffsetDateTime a, OffsetDateTime b) {
return a.isBefore(b);
}
@Override
protected OffsetDateTime getNow(Clock clock) {
return OffsetDateTime.now(clock);
}
@Override
public OffsetDateTimeConstraint<T> cast() {
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/ShortConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.util.function.Predicate;
import am.ik.yavi.constraint.base.NumericConstraintBase;
public class ShortConstraint<T> extends NumericConstraintBase<T, Short, ShortConstraint<T>> {
@Override
public ShortConstraint<T> cast() {
return this;
}
@Override
protected Predicate<Short> isGreaterThan(Short min) {
return x -> x > min;
}
@Override
protected Predicate<Short> isGreaterThanOrEqual(Short min) {
return x -> x >= min;
}
@Override
protected Predicate<Short> isLessThan(Short max) {
return x -> x < max;
}
@Override
protected Predicate<Short> isLessThanOrEqual(Short max) {
return x -> x <= max;
}
@Override
protected Short zeroValue() {
return 0;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/YearConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.Year;
import am.ik.yavi.constraint.base.TemporalConstraintBase;
/**
* This is the actual class for constraints on Year.
*
* @since 0.11.0
*/
public class YearConstraint<T> extends TemporalConstraintBase<T, Year, YearConstraint<T>> {
@Override
protected boolean isAfter(Year a, Year b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(Year a, Year b) {
return a.isBefore(b);
}
@Override
protected Year getNow(Clock clock) {
return Year.now(clock);
}
@Override
public YearConstraint<T> cast() {
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/YearMonthConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.YearMonth;
import am.ik.yavi.constraint.base.TemporalConstraintBase;
/**
* This is the actual class for constraints on YearMonth.
*
* @since 0.11.0
*/
public class YearMonthConstraint<T> extends TemporalConstraintBase<T, YearMonth, YearMonthConstraint<T>> {
@Override
protected boolean isAfter(YearMonth a, YearMonth b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(YearMonth a, YearMonth b) {
return a.isBefore(b);
}
@Override
protected YearMonth getNow(Clock clock) {
return YearMonth.now(clock);
}
@Override
public YearMonthConstraint<T> cast() {
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/ZonedDateTimeConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint;
import java.time.Clock;
import java.time.ZonedDateTime;
import am.ik.yavi.constraint.base.ChronoZonedDateTimeConstraintBase;
/**
* This is the actual class for constraints on ZonedDateTime.
*
* @author Diego Krupitza
* @since 0.10.0
*/
public class ZonedDateTimeConstraint<T>
extends ChronoZonedDateTimeConstraintBase<T, ZonedDateTime, ZonedDateTimeConstraint<T>> {
@Override
protected ZonedDateTime getNow(Clock clock) {
return ZonedDateTime.now(clock);
}
@Override
public ZonedDateTimeConstraint<T> cast() {
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/BooleanArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class BooleanArrayConstraint<T> extends ContainerConstraintBase<T, boolean[], BooleanArrayConstraint<T>> {
@Override
public BooleanArrayConstraint<T> cast() {
return this;
}
public BooleanArrayConstraint<T> contains(boolean v) {
this.predicates().add(ConstraintPredicate.of(x -> {
for (boolean e : x) {
if (e == v) {
return true;
}
}
return false;
}, ARRAY_CONTAINS, () -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<boolean[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/ByteArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class ByteArrayConstraint<T> extends ContainerConstraintBase<T, byte[], ByteArrayConstraint<T>> {
@Override
public ByteArrayConstraint<T> cast() {
return this;
}
public ByteArrayConstraint<T> contains(byte v) {
this.predicates().add(ConstraintPredicate.of(x -> {
for (byte e : x) {
if (e == v) {
return true;
}
}
return false;
}, ARRAY_CONTAINS, () -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<byte[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/CharArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class CharArrayConstraint<T> extends ContainerConstraintBase<T, char[], CharArrayConstraint<T>> {
@Override
public CharArrayConstraint<T> cast() {
return this;
}
public CharArrayConstraint<T> contains(char v) {
this.predicates().add(ConstraintPredicate.of(x -> {
for (char e : x) {
if (e == v) {
return true;
}
}
return false;
}, ARRAY_CONTAINS, () -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<char[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/DoubleArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.Arrays;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class DoubleArrayConstraint<T> extends ContainerConstraintBase<T, double[], DoubleArrayConstraint<T>> {
@Override
public DoubleArrayConstraint<T> cast() {
return this;
}
public DoubleArrayConstraint<T> contains(double v) {
this.predicates()
.add(ConstraintPredicate.of(x -> Arrays.stream(x).anyMatch(e -> e == v), ARRAY_CONTAINS,
() -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<double[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/FloatArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class FloatArrayConstraint<T> extends ContainerConstraintBase<T, float[], FloatArrayConstraint<T>> {
@Override
public FloatArrayConstraint<T> cast() {
return this;
}
public FloatArrayConstraint<T> contains(float v) {
this.predicates().add(ConstraintPredicate.of(x -> {
for (float e : x) {
if (e == v) {
return true;
}
}
return false;
}, ARRAY_CONTAINS, () -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<float[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/IntArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.Arrays;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class IntArrayConstraint<T> extends ContainerConstraintBase<T, int[], IntArrayConstraint<T>> {
@Override
public IntArrayConstraint<T> cast() {
return this;
}
public IntArrayConstraint<T> contains(int v) {
this.predicates()
.add(ConstraintPredicate.of(x -> Arrays.stream(x).anyMatch(e -> e == v), ARRAY_CONTAINS,
() -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<int[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/LongArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.Arrays;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class LongArrayConstraint<T> extends ContainerConstraintBase<T, long[], LongArrayConstraint<T>> {
@Override
public LongArrayConstraint<T> cast() {
return this;
}
public LongArrayConstraint<T> contains(long v) {
this.predicates()
.add(ConstraintPredicate.of(x -> Arrays.stream(x).anyMatch(e -> e == v), ARRAY_CONTAINS,
() -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<long[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/ObjectArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.Arrays;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class ObjectArrayConstraint<T, E> extends ContainerConstraintBase<T, E[], ObjectArrayConstraint<T, E>> {
@Override
public ObjectArrayConstraint<T, E> cast() {
return this;
}
public ObjectArrayConstraint<T, E> contains(E s) {
this.predicates()
.add(ConstraintPredicate.of(x -> Arrays.asList(x).contains(s), ARRAY_CONTAINS, () -> new Object[] { s },
VALID));
return this;
}
@Override
protected ToIntFunction<E[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/ShortArrayConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.array;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.ARRAY_CONTAINS;
import am.ik.yavi.constraint.base.ContainerConstraintBase;
import am.ik.yavi.core.ConstraintPredicate;
public class ShortArrayConstraint<T> extends ContainerConstraintBase<T, short[], ShortArrayConstraint<T>> {
@Override
public ShortArrayConstraint<T> cast() {
return this;
}
public ShortArrayConstraint<T> contains(short v) {
this.predicates().add(ConstraintPredicate.of(x -> {
for (short e : x) {
if (e == v) {
return true;
}
}
return false;
}, ARRAY_CONTAINS, () -> new Object[] { v }, VALID));
return this;
}
@Override
protected ToIntFunction<short[]> size() {
return x -> x.length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/array/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint.array;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/ChronoLocalDateConstraintBase.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.base;
import java.time.chrono.ChronoLocalDate;
import am.ik.yavi.core.Constraint;
/**
* This is the base class for constraints on ChronoLocalDate.
*
* @author Diego Krupitza
* @since 0.10.0
*/
public abstract class ChronoLocalDateConstraintBase<T, V extends ChronoLocalDate, C extends Constraint<T, V, C>>
extends TemporalConstraintBase<T, V, C> {
@Override
protected boolean isAfter(V a, V b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(V a, V b) {
return a.isBefore(b);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/ChronoLocalDateTimeConstraintBase.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.base;
import java.time.chrono.ChronoLocalDateTime;
import am.ik.yavi.core.Constraint;
/**
* This is the base class for constraints on ChronoLocalDateTime.
*
* @author Diego Krupitza
* @since 0.10.0
*/
public abstract class ChronoLocalDateTimeConstraintBase<T, V extends ChronoLocalDateTime<?>, C extends Constraint<T, V, C>>
extends TemporalConstraintBase<T, V, C> {
@Override
protected boolean isAfter(V a, V b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(V a, V b) {
return a.isBefore(b);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/ChronoZonedDateTimeConstraintBase.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.base;
import java.time.chrono.ChronoZonedDateTime;
import am.ik.yavi.core.Constraint;
/**
* This is the base class for constraints on ChronoZonedDateTime.
*
* @author Diego Krupitza
* @since 0.10.0
*/
public abstract class ChronoZonedDateTimeConstraintBase<T, V extends ChronoZonedDateTime<?>, C extends Constraint<T, V, C>>
extends TemporalConstraintBase<T, V, C> {
@Override
protected boolean isAfter(V a, V b) {
return a.isAfter(b);
}
@Override
protected boolean isBefore(V a, V b) {
return a.isBefore(b);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/ConstraintBase.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.base;
import java.util.Deque;
import java.util.LinkedList;
import am.ik.yavi.core.Constraint;
import am.ik.yavi.core.ConstraintPredicate;
public abstract class ConstraintBase<T, V, C extends Constraint<T, V, C>> implements Constraint<T, V, C> {
private final Deque<ConstraintPredicate<V>> predicates = new LinkedList<>();
@Override
public Deque<ConstraintPredicate<V>> predicates() {
return this.predicates;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/ContainerConstraintBase.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.base;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.ToIntFunction;
import static am.ik.yavi.core.NullAs.INVALID;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_FIXED_SIZE;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_GREATER_THAN;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_GREATER_THAN_OR_EQUAL;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_LESS_THAN;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_LESS_THAN_OR_EQUAL;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_NOT_EMPTY;
import am.ik.yavi.core.Constraint;
import am.ik.yavi.core.ConstraintPredicate;
import am.ik.yavi.core.ViolatedValue;
public abstract class ContainerConstraintBase<T, V, C extends Constraint<T, V, C>> extends ConstraintBase<T, V, C> {
public C fixedSize(int size) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(
this.checkSizePredicate(x -> size().applyAsInt(x) == size, this.size()), CONTAINER_FIXED_SIZE,
() -> new Object[] { size }, VALID));
return cast();
}
public C greaterThan(int min) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(
this.checkSizePredicate(x -> size().applyAsInt(x) > min, this.size()), CONTAINER_GREATER_THAN,
() -> new Object[] { min }, VALID));
return cast();
}
public C greaterThanOrEqual(int min) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(
this.checkSizePredicate(x -> size().applyAsInt(x) >= min, this.size()),
CONTAINER_GREATER_THAN_OR_EQUAL, () -> new Object[] { min }, VALID));
return cast();
}
public C lessThan(int max) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(
this.checkSizePredicate(x -> size().applyAsInt(x) < max, this.size()), CONTAINER_LESS_THAN,
() -> new Object[] { max }, VALID));
return cast();
}
public C lessThanOrEqual(int max) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(
this.checkSizePredicate(x -> size().applyAsInt(x) <= max, this.size()),
CONTAINER_LESS_THAN_OR_EQUAL, () -> new Object[] { max }, VALID));
return cast();
}
public C notEmpty() {
this.predicates()
.add(ConstraintPredicate.of(x -> x != null && size().applyAsInt(x) != 0, CONTAINER_NOT_EMPTY,
() -> new Object[] {}, INVALID));
return cast();
}
protected Function<V, Optional<ViolatedValue>> checkSizePredicate(Predicate<V> predicate, ToIntFunction<V> size) {
return v -> {
if (predicate.test(v)) {
return Optional.empty();
}
int s = size.applyAsInt(v);
return Optional.of(new ViolatedValue(s));
};
}
protected abstract ToIntFunction<V> size();
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/NumericConstraintBase.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.base;
import java.util.function.Predicate;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.*;
import am.ik.yavi.core.Constraint;
import am.ik.yavi.core.ConstraintPredicate;
public abstract class NumericConstraintBase<T, V, C extends Constraint<T, V, C>> extends ConstraintBase<T, V, C> {
public C greaterThan(V min) {
this.predicates()
.add(ConstraintPredicate.of(this.isGreaterThan(min), NUMERIC_GREATER_THAN, () -> new Object[] { min },
VALID));
return cast();
}
public C greaterThanOrEqual(V min) {
this.predicates()
.add(ConstraintPredicate.of(this.isGreaterThanOrEqual(min), NUMERIC_GREATER_THAN_OR_EQUAL,
() -> new Object[] { min }, VALID));
return cast();
}
public C lessThan(V max) {
this.predicates()
.add(ConstraintPredicate.of(this.isLessThan(max), NUMERIC_LESS_THAN, () -> new Object[] { max }, VALID));
return cast();
}
public C lessThanOrEqual(V max) {
this.predicates()
.add(ConstraintPredicate.of(this.isLessThanOrEqual(max), NUMERIC_LESS_THAN_OR_EQUAL,
() -> new Object[] { max }, VALID));
return cast();
}
/**
* @since 0.10.0
*/
public C positive() {
this.predicates()
.add(ConstraintPredicate.of(this.isGreaterThan(zeroValue()), NUMERIC_POSITIVE, () -> new Object[] {},
VALID));
return cast();
}
/**
* @since 0.10.0
*/
public C positiveOrZero() {
this.predicates()
.add(ConstraintPredicate.of(this.isGreaterThanOrEqual(zeroValue()), NUMERIC_POSITIVE_OR_ZERO,
() -> new Object[] {}, VALID));
return cast();
}
/**
* @since 0.10.0
*/
public C negative() {
this.predicates()
.add(ConstraintPredicate.of(this.isLessThan(zeroValue()), NUMERIC_NEGATIVE, () -> new Object[] {}, VALID));
return cast();
}
/**
* @since 0.10.0
*/
public C negativeOrZero() {
this.predicates()
.add(ConstraintPredicate.of(this.isLessThanOrEqual(zeroValue()), NUMERIC_NEGATIVE_OR_ZERO,
() -> new Object[] {}, VALID));
return cast();
}
protected abstract Predicate<V> isGreaterThan(V min);
protected abstract Predicate<V> isGreaterThanOrEqual(V min);
protected abstract Predicate<V> isLessThan(V max);
protected abstract Predicate<V> isLessThanOrEqual(V max);
protected abstract V zeroValue();
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/TemporalConstraintBase.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.base;
import java.time.Clock;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.LongPredicate;
import java.util.function.Supplier;
import am.ik.yavi.core.Constraint;
import am.ik.yavi.core.ConstraintPredicate;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_AFTER;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_AFTER_OR_EQUAL;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_BEFORE;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_BEFORE_OR_EQUAL;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_BETWEEN;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_FIELD;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_FUTURE;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_FUTURE_OR_PRESENT;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_PAST;
import static am.ik.yavi.core.ViolationMessage.Default.TEMPORAL_PAST_OR_PRESENT;
/**
* This is the base class for constraints on Temporal classes. Methods in the class
* require the {@link V} to extend Temporal.
*
* @author Diego Krupitza
* @author Toshiaki Maki
* @since 0.10.0
*/
public abstract class TemporalConstraintBase<T, V extends TemporalAccessor, C extends Constraint<T, V, C>>
extends ConstraintBase<T, V, C> {
abstract protected boolean isAfter(V a, V b);
abstract protected boolean isBefore(V a, V b);
abstract protected V getNow(Clock clock);
public C past() {
return this.past(Clock.systemDefaultZone());
}
public C past(Clock clock) {
return this.before(() -> this.getNow(clock), false).message(TEMPORAL_PAST);
}
public C pastOrPresent() {
return this.pastOrPresent(Clock.systemDefaultZone());
}
public C pastOrPresent(Clock clock) {
return this.beforeOrEqual(() -> this.getNow(clock), false).message(TEMPORAL_PAST_OR_PRESENT);
}
public C future() {
return this.future(Clock.systemDefaultZone());
}
public C future(Clock clock) {
return this.after(() -> this.getNow(clock), false).message(TEMPORAL_FUTURE);
}
public C futureOrPresent() {
return this.futureOrPresent(Clock.systemDefaultZone());
}
public C futureOrPresent(Clock clock) {
return this.afterOrEqual(() -> this.getNow(clock), false).message(TEMPORAL_FUTURE_OR_PRESENT);
}
/**
* Check if the given temporal is before the supplied {@code other} <br>
* You can specify whether to memoize the result of the supplier by using the argument
* <code>memoize</code>. If you set <code>memoize</code> to <code>false</code> and the
* supplier return value changes each time, be aware that the value used to compare
* the input values and the value contained in the error message can be different.
* @param other the supplier providing the other temporal that is before
* @param memoize whether to memoize the result of supplier
* @since 0.11.1
*/
public C before(Supplier<V> other, boolean memoize) {
final Supplier<V> supplier = memoize ? memoize(other) : other;
this.predicates()
.add(ConstraintPredicate.of(x -> this.isBefore(x, supplier.get()), TEMPORAL_BEFORE,
() -> new Object[] { supplier.get() }, VALID));
return cast();
}
/**
* Check if the given temporal if before the supplied {@code other}. <br>
* <strong>The result of the supplier is memoized</strong>. That means the supplier is
* cached to always return the same value and is not available if you want to
* dynamically return different values.<br>
* If you don't want to memoize, use {@link #before(Supplier, boolean)} instead.
* @param other the supplier providing the other temporal that is before
*/
public C before(Supplier<V> other) {
return this.before(other, true);
}
/**
* Check if the given temporal is before or equals to the supplied {@code other}<br>
* You can specify whether to memoize the result of the supplier by using the argument
* <code>memoize</code>. If you set <code>memoize</code> to <code>false</code> and the
* supplier return value changes each time, be aware that the value used to compare
* the input values and the value contained in the error message can be different.
* @param other the supplier providing the other temporal that is before or equals to
* @param memoize whether to memoize the result of supplier
* @since 0.11.1
*/
public C beforeOrEqual(Supplier<V> other, boolean memoize) {
final Supplier<V> supplier = memoize ? memoize(other) : other;
this.predicates()
.add(ConstraintPredicate.of(x -> !this.isAfter(x, supplier.get()), TEMPORAL_BEFORE_OR_EQUAL,
() -> new Object[] { supplier.get() }, VALID));
return cast();
}
/**
* Check if the given temporal if before or equals to the supplied {@code other}. <br>
* <strong>The result of the supplier is memoized</strong>. That means the supplier is
* cached to always return the same value and is not available if you want to
* dynamically return different values.<br>
* If you don't want to memoize, use {@link #beforeOrEqual(Supplier, boolean)}
* instead.
* @param other the supplier providing the other temporal that is before or equals to
*/
public C beforeOrEqual(Supplier<V> other) {
return beforeOrEqual(other, true);
}
/**
* Check if the given temporal is after the supplied {@code other}<br>
* You can specify whether to memoize the result of the supplier by using the argument
* <code>memoize</code>. If you set <code>memoize</code> to <code>false</code> and the
* supplier return value changes each time, be aware that the value used to compare
* the input values and the value contained in the error message can be different.
* @param other the supplier providing the other temporal that is after
* @param memoize whether to memoize the result of supplier
* @since 0.11.1
*/
public C after(Supplier<V> other, boolean memoize) {
final Supplier<V> supplier = memoize ? memoize(other) : other;
this.predicates()
.add(ConstraintPredicate.of(x -> this.isAfter(x, supplier.get()), TEMPORAL_AFTER,
() -> new Object[] { supplier.get() }, VALID));
return cast();
}
/**
* Check if the given temporal if after the supplied {@code other}. <br>
* <strong>The result of the supplier is memoized</strong>. That means the supplier is
* cached to always return the same value and is not available if you want to
* dynamically return different values.<br>
* If you don't want to memoize, use {@link #after(Supplier, boolean)} instead.
* @param other the supplier providing the other temporal that is after
*/
public C after(Supplier<V> other) {
return this.after(other, true);
}
/**
* Check if the given temporal is after or equals to the supplied {@code other}<br>
* You can specify whether to memoize the result of the supplier by using the argument
* <code>memoize</code>. If you set <code>memoize</code> to <code>false</code> and the
* supplier return value changes each time, be aware that the value used to compare
* the input values and the value contained in the error message can be different.
* @param other the supplier providing the other temporal that is after or equals to
* @param memoize whether to memoize the result of supplier
* @since 0.11.1
*/
public C afterOrEqual(Supplier<V> other, boolean memoize) {
final Supplier<V> supplier = memoize ? memoize(other) : other;
this.predicates()
.add(ConstraintPredicate.of(x -> !this.isBefore(x, supplier.get()), TEMPORAL_AFTER_OR_EQUAL,
() -> new Object[] { supplier.get() }, VALID));
return cast();
}
/**
* Check if the given temporal if after or equals to the supplied {@code other}. <br>
* <strong>The result of the supplier is memoized</strong>. That means the supplier is
* cached to always return the same value and is not available if you want to
* dynamically return different values.<br>
* If you don't want to memoize, use {@link #afterOrEqual(Supplier, boolean)} instead.
* @param other the supplier providing the other temporal that is after or equals to
*/
public C afterOrEqual(Supplier<V> other) {
return afterOrEqual(other, true);
}
/**
* Is the given temporal between the supplied {@code rangeFrom} and {@code rangeTo}.
* The range is not inclusive. This means if the dates are equal (rangeFrom = x =
* rangeTo) it is invalid<br>
* You can specify whether to memoize the result of the supplier by using the argument
* <code>memoize</code>. If you set <code>memoize</code> to <code>false</code> and the
* supplier return value changes each time, be aware that the value used to compare
* the input values and the value contained in the error message can be different.
* @param rangeFrom the supplier provide the start of the range the temporal has to be
* in
* @param rangeTo the supplier provide the end of the range the temporal has to be in
* @param memoize whether to memoize the result of supplier
* @since 0.11.1
*/
public C between(Supplier<V> rangeFrom, Supplier<V> rangeTo, boolean memoize) {
final Supplier<V> supplierFrom = memoize ? memoize(rangeFrom) : rangeFrom;
final Supplier<V> supplierTo = memoize ? memoize(rangeTo) : rangeTo;
this.predicates().add(ConstraintPredicate.of(x -> {
final V from = supplierFrom.get();
final V to = supplierTo.get();
if (this.isAfter(from, to)) {
throw new IllegalArgumentException("Parameter 'rangeFrom' has to be before 'rangeTo'");
}
return this.isBefore(from, x) && this.isAfter(to, x);
}, TEMPORAL_BETWEEN, () -> new Object[] { supplierFrom.get(), supplierTo.get() }, VALID));
return cast();
}
/**
* Is the given temporal between the supplied {@code rangeFrom} and {@code rangeTo}.
* The range is not inclusive. This means if the dates are equal (rangeFrom = x =
* rangeTo) it is invalid <strong>The result of the supplier is memoized</strong>.
* That means the supplier is cached to always return the same value and is not
* available if you want to dynamically return different values.<br>
* If you don't want to memoize, use {@link #between(Supplier, Supplier, boolean)}
* instead.
* @param rangeFrom the supplier provide the start of the range the temporal has to be
* in
* @param rangeTo the supplier provide the end of the range the temporal has to be in
*/
public C between(Supplier<V> rangeFrom, Supplier<V> rangeTo) {
return this.between(rangeFrom, rangeTo, true);
}
public C fieldPredicate(TemporalField field, LongPredicate predicate) {
this.predicates()
.add(ConstraintPredicate.of(x -> predicate.test(x.getLong(field)), TEMPORAL_FIELD,
() -> new Object[] { field }, VALID));
return cast();
}
static <T> Supplier<T> memoize(Supplier<T> delegate) {
final AtomicReference<T> supplier = new AtomicReference<>();
return () -> {
final T value = supplier.get();
if (value == null) {
return supplier.updateAndGet(prev -> prev == null ? delegate.get() : prev);
}
return value;
};
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/base/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint.base;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/ByteSizeConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence;
import java.nio.charset.Charset;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.BYTE_SIZE_FIXED_SIZE;
import static am.ik.yavi.core.ViolationMessage.Default.BYTE_SIZE_GREATER_THAN;
import static am.ik.yavi.core.ViolationMessage.Default.BYTE_SIZE_GREATER_THAN_OR_EQUAL;
import static am.ik.yavi.core.ViolationMessage.Default.BYTE_SIZE_LESS_THAN;
import static am.ik.yavi.core.ViolationMessage.Default.BYTE_SIZE_LESS_THAN_OR_EQUAL;
import am.ik.yavi.constraint.CharSequenceConstraint;
import am.ik.yavi.core.ConstraintPredicate;
public class ByteSizeConstraint<T, E extends CharSequence> extends CharSequenceConstraint<T, E> {
private final Charset charset;
public ByteSizeConstraint(CharSequenceConstraint<T, E> delegate, Charset charset) {
super();
this.charset = charset;
this.predicates().addAll(delegate.predicates());
}
@Override
public ByteSizeConstraint<T, E> cast() {
return this;
}
@Override
public ByteSizeConstraint<T, E> fixedSize(int size) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) == size, this::size),
BYTE_SIZE_FIXED_SIZE, () -> new Object[] { size }, VALID));
return this;
}
@Override
public ByteSizeConstraint<T, E> greaterThan(int min) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) > min, this::size),
BYTE_SIZE_GREATER_THAN, () -> new Object[] { min }, VALID));
return this;
}
@Override
public ByteSizeConstraint<T, E> greaterThanOrEqual(int min) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) >= min, this::size),
BYTE_SIZE_GREATER_THAN_OR_EQUAL, () -> new Object[] { min }, VALID));
return this;
}
@Override
public ByteSizeConstraint<T, E> lessThan(int max) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) < max, this::size),
BYTE_SIZE_LESS_THAN, () -> new Object[] { max }, VALID));
return this;
}
@Override
public ByteSizeConstraint<T, E> lessThanOrEqual(int max) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) <= max, this::size),
BYTE_SIZE_LESS_THAN_OR_EQUAL, () -> new Object[] { max }, VALID));
return this;
}
private int size(E x) {
return x.toString().getBytes(charset).length;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/CodePoints.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import am.ik.yavi.jsr305.Nullable;
@FunctionalInterface
public interface CodePoints<E extends CharSequence> {
Set<Integer> allExcludedCodePoints(E s);
@FunctionalInterface
interface CodePointsRanges<E extends CharSequence> extends CodePoints<E> {
@Override
default Set<Integer> allExcludedCodePoints(@Nullable E s) {
if (s == null || s.length() == 0) {
return Collections.emptySet();
}
String str = s.toString();
Set<Integer> excludedCodePoints = new LinkedHashSet<>();
int len = str.length();
Integer codePoint;
List<Range> ranges = this.asRanges();
for (int i = 0; i < len; i += Character.charCount(codePoint)) {
codePoint = str.codePointAt(i);
boolean included = false;
for (Range range : ranges) {
if (range.begin() <= codePoint && codePoint <= range.end()) {
included = true;
break;
}
}
if (!included) {
excludedCodePoints.add(codePoint);
}
}
return excludedCodePoints;
}
List<Range> asRanges();
}
@FunctionalInterface
interface CodePointsSet<E extends CharSequence> extends CodePoints<E> {
@Override
default Set<Integer> allExcludedCodePoints(@Nullable E s) {
if (s == null || s.length() == 0) {
return Collections.emptySet();
}
String str = s.toString();
Set<Integer> excludedCodePoints = new LinkedHashSet<>();
int len = str.length();
Integer codePoint;
Set<Integer> set = this.asSet();
for (int i = 0; i < len; i += Character.charCount(codePoint)) {
codePoint = str.codePointAt(i);
if (!set.contains(codePoint)) {
excludedCodePoints.add(codePoint);
}
}
return excludedCodePoints;
}
Set<Integer> asSet();
}
interface Range {
static Range of(String begin, String end) {
return Range.of(begin.codePoints().sorted().findFirst().orElse(0),
end.codePoints().sorted().findFirst().orElse(0));
}
static Range of(int begin, int end) {
if (begin > end) {
throw new IllegalArgumentException("begin must not be greater than end [" + begin + ", " + end + "]");
}
return new Range() {
@Override
public int begin() {
return begin;
}
@Override
public int end() {
return end;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Range)) {
return false;
}
Range range = (Range) obj;
return Objects.equals(begin, range.begin()) && Objects.equals(end, range.end());
}
@Override
public int hashCode() {
return Objects.hash(begin, end);
}
};
}
static Range single(int value) {
return of(value, value);
}
int begin();
int end();
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/CodePointsConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.CODE_POINTS_ALL_INCLUDED;
import static am.ik.yavi.core.ViolationMessage.Default.CODE_POINTS_NOT_INCLUDED;
import am.ik.yavi.constraint.CharSequenceConstraint;
import am.ik.yavi.core.ConstraintPredicate;
import am.ik.yavi.core.ViolatedValue;
public class CodePointsConstraint<T, E extends CharSequence> extends CharSequenceConstraint<T, E> {
private final CodePoints<E> codePoints;
public CodePointsConstraint(CharSequenceConstraint<T, E> delegate, CodePoints<E> codePoints) {
super();
this.codePoints = codePoints;
this.predicates().addAll(delegate.predicates());
}
public CodePointsConstraint<T, E> asBlackList() {
this.predicates().add(ConstraintPredicate.withViolatedValue(x -> {
Set<Integer> excludedFromBlackList = this.codePoints.allExcludedCodePoints(x);
Integer codePoint;
String str = x.toString();
int len = str.length();
Set<Integer> included = new LinkedHashSet<>();
for (int i = 0; i < len; i += Character.charCount(codePoint)) {
codePoint = str.codePointAt(i);
if (!excludedFromBlackList.contains(codePoint)) {
included.add(codePoint);
}
}
if (included.isEmpty()) {
return Optional.empty();
}
List<String> includedList = included.stream() //
.map(i -> new String(new int[] { i }, 0, 1)) //
.collect(Collectors.toList());
return Optional.of(new ViolatedValue(includedList));
}, CODE_POINTS_NOT_INCLUDED, () -> new Object[] {}, VALID));
return this;
}
public CodePointsConstraint<T, E> asWhiteList() {
this.predicates().add(ConstraintPredicate.withViolatedValue(x -> {
Set<Integer> excludedFromWhiteList = this.codePoints.allExcludedCodePoints(x);
if (excludedFromWhiteList.isEmpty()) {
return Optional.empty();
}
List<String> excludedList = excludedFromWhiteList.stream() //
.map(i -> new String(new int[] { i }, 0, 1)) //
.collect(Collectors.toList());
return Optional.of(new ViolatedValue(excludedList));
}, CODE_POINTS_ALL_INCLUDED, () -> new Object[] {}, VALID));
return this;
}
@Override
public CodePointsConstraint<T, E> cast() {
return this;
}
public static class Builder<T, E extends CharSequence> {
private final CodePoints<E> codePoints;
private final CharSequenceConstraint<T, E> delegate;
public Builder(CharSequenceConstraint<T, E> delegate, CodePoints<E> codePoints) {
this.delegate = delegate;
this.codePoints = codePoints;
}
public CodePointsConstraint<T, E> asBlackList() {
return new CodePointsConstraint<>(this.delegate, this.codePoints).asBlackList();
}
public CodePointsConstraint<T, E> asWhiteList() {
return new CodePointsConstraint<>(this.delegate, this.codePoints).asWhiteList();
}
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/Emoji.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence;
import am.ik.yavi.constraint.charsequence.variant.StandardizedVariationSequence;
import am.ik.yavi.jsr305.Nullable;
public class Emoji {
private static final String COMBINING_ENCLOSING_KEYCAP = new String(new int[] { 0x20E3 }, 0, 1);
private static final String DUMMY_REPLACEMENT = "X";
private static final String ELF = new String(new int[] { 0x1F9DD }, 0, 1);
private static final String E140_SKIN_RANGE = new String(new int[] { 0x1FAF0 }, 0, 1) + "-"
+ new String(new int[] { 0x1FAF6 }, 0, 1) + new String(new int[] { 0x1FAC3 }, 0, 1) + "-"
+ new String(new int[] { 0x1FAC5 }, 0, 1);
private static final String ENGLAND = new String(
new int[] { 0x1F3F4, 0xE0067, 0xE0062, 0xE0065, 0xE006E, 0xE0067, 0xE007F }, 0, 7);
private static final String PERSON = new String(new int[] { 0x1F9D1 }, 0, 1);
private static final String REGIONAL_INDICATOR_SYMBOL_LETTER_RANGE = new String(new int[] { 0x1F1E6 }, 0, 1) + "-"
+ new String(new int[] { 0x1F1FF }, 0, 1);
private static final String SCOTLAND = new String(
new int[] { 0x1F3F4, 0xE0067, 0xE0062, 0xE0073, 0xE0063, 0xE0074, 0xE007F }, 0, 7);
private static final String SKIN_TONE_SELECTOR_RANGE = new String(new int[] { 0x1F3FB }, 0, 1) + "-"
+ new String(new int[] { 0x1F3FF }, 0, 1);
private static final String SKUL_AND_CROSSBONES = new String(new int[] { 0x2620 }, 0, 1);
private static final String WALES = new String(
new int[] { 0x1F3F4, 0xE0067, 0xE0062, 0xE0077, 0xE006C, 0xE0073, 0xE007F }, 0, 7);
private static final String WHITE_UP_POINTING_INDEX = new String(new int[] { 0x261D }, 0, 1);
private static final String ADHESIVE_BANDAGE = new String(new int[] { 0x1FA79 }, 0, 1);
private static final String ZERO_WIDTH_JOINER = "\u200D";
/**
* Try to return the length of the given string.<br>
* This method does not grantee the exact length.
* @see <a href="https://unicode.org/Public/emoji/12.0/emoji-test.txt">Emoji 12.0</a>
* @param str
* @return the length of the given string which may be true
*/
public static int bestEffortCount(@Nullable String str) {
if (str == null || str.isEmpty()) {
return 0;
}
String s = str.replaceAll("[" + StandardizedVariationSequence.RANGE + COMBINING_ENCLOSING_KEYCAP + "]", "") //
.replaceAll("([" + WHITE_UP_POINTING_INDEX + "-" + ELF + E140_SKIN_RANGE + "][" + SKIN_TONE_SELECTOR_RANGE
+ "])", DUMMY_REPLACEMENT)
.replaceAll("([" + ZERO_WIDTH_JOINER + "][" + SKUL_AND_CROSSBONES + "-" + PERSON + ADHESIVE_BANDAGE + "])",
"") //
.replaceAll("([" + REGIONAL_INDICATOR_SYMBOL_LETTER_RANGE + "]{2})", DUMMY_REPLACEMENT) //
.replace(ENGLAND, DUMMY_REPLACEMENT) //
.replace(SCOTLAND, DUMMY_REPLACEMENT) //
.replace(WALES, DUMMY_REPLACEMENT) //
// Support emojis that contains two skin tone selectors introduced in 12
.replaceAll("(" + DUMMY_REPLACEMENT + ZERO_WIDTH_JOINER + DUMMY_REPLACEMENT + ")", DUMMY_REPLACEMENT);
return s.codePointCount(0, s.length());
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/EmojiConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence;
import java.text.Normalizer;
import static am.ik.yavi.core.NullAs.VALID;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_FIXED_SIZE;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_GREATER_THAN;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_GREATER_THAN_OR_EQUAL;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_LESS_THAN;
import static am.ik.yavi.core.ViolationMessage.Default.CONTAINER_LESS_THAN_OR_EQUAL;
import am.ik.yavi.constraint.CharSequenceConstraint;
import am.ik.yavi.constraint.charsequence.variant.VariantOptions;
import am.ik.yavi.core.ConstraintPredicate;
public class EmojiConstraint<T, E extends CharSequence> extends CharSequenceConstraint<T, E> {
public EmojiConstraint(CharSequenceConstraint<T, E> delegate, Normalizer.Form normalizerForm,
VariantOptions variantOptions) {
super(normalizerForm, variantOptions);
this.predicates().addAll(delegate.predicates());
}
@Override
public EmojiConstraint<T, E> fixedSize(int size) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) == size, this::size),
CONTAINER_FIXED_SIZE, () -> new Object[] { size }, VALID));
return this;
}
@Override
public EmojiConstraint<T, E> greaterThan(int min) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) > min, this::size),
CONTAINER_GREATER_THAN, () -> new Object[] { min }, VALID));
return this;
}
@Override
public EmojiConstraint<T, E> greaterThanOrEqual(int min) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) >= min, this::size),
CONTAINER_GREATER_THAN_OR_EQUAL, () -> new Object[] { min }, VALID));
return this;
}
@Override
public EmojiConstraint<T, E> lessThan(int max) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) < max, this::size),
CONTAINER_LESS_THAN, () -> new Object[] { max }, VALID));
return this;
}
@Override
public EmojiConstraint<T, E> lessThanOrEqual(int max) {
this.predicates()
.add(ConstraintPredicate.withViolatedValue(this.checkSizePredicate(x -> size(x) <= max, this::size),
CONTAINER_LESS_THAN_OR_EQUAL, () -> new Object[] { max }, VALID));
return this;
}
private int size(E x) {
return Emoji.bestEffortCount(this.normalize(x.toString()));
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint.charsequence;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/codepoints/AsciiCodePoints.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence.codepoints;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import am.ik.yavi.constraint.charsequence.CodePoints;
public enum AsciiCodePoints implements CodePoints<String> {
ASCII_PRINTABLE_CHARS((CodePointsRanges<String>) () -> {
return Collections.singletonList(Range.of(0x0020 /* */, 0x007E /* ~ */));
}), //
ASCII_CONTROL_CHARS((CodePointsRanges<String>) () -> {
return Arrays.asList(Range.of(0x0000 /* NULL */, 0x001F /* UNIT SEPARATOR */),
Range.single(0x007F /* DELETE */));
}), //
CRLF((CodePointsSet<String>) () -> {
return new HashSet<>(
Arrays.asList(0x000A /* LINE FEED */, 0x000D /* CARRIAGE RETURN */));
});
private final CodePoints<String> delegate;
AsciiCodePoints(CodePoints<String> delegate) {
this.delegate = delegate;
}
@Override
public Set<Integer> allExcludedCodePoints(String s) {
return this.delegate.allExcludedCodePoints(s);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/codepoints/CompositeCodePoints.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence.codepoints;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import am.ik.yavi.constraint.charsequence.CodePoints;
public class CompositeCodePoints<E extends CharSequence> implements CodePoints<E> {
private final List<CodePoints<E>> composite = new ArrayList<>();
@SafeVarargs
public CompositeCodePoints(CodePoints<E>... codePoints) {
final Set<Integer> codePointsSet = new LinkedHashSet<>();
final List<Range> ranges = new ArrayList<>();
for (CodePoints<E> points : codePoints) {
if (points instanceof CodePointsSet) {
codePointsSet.addAll(((CodePointsSet<E>) points).asSet());
}
else if (points instanceof CodePointsRanges) {
ranges.addAll(((CodePointsRanges<E>) points).asRanges());
}
else {
composite.add(points);
}
}
if (!codePointsSet.isEmpty()) {
composite.add((CodePointsSet<E>) () -> codePointsSet);
}
if (!ranges.isEmpty()) {
composite.add((CodePointsRanges<E>) () -> ranges);
}
if (composite.isEmpty()) {
throw new IllegalArgumentException("No code point is included");
}
}
@Override
public Set<Integer> allExcludedCodePoints(E s) {
Set<Integer> excluded = null;
for (CodePoints<E> codePoints : this.composite) {
Set<Integer> e = codePoints.allExcludedCodePoints(s);
if (e.isEmpty()) {
return e;
}
if (excluded == null) {
excluded = e;
}
else {
excluded.retainAll(e);
}
}
return excluded == null ? Collections.emptySet() : excluded;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/codepoints/UnicodeCodePoints.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence.codepoints;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import am.ik.yavi.constraint.charsequence.CodePoints;
public enum UnicodeCodePoints implements CodePoints<String> {
/**
* Hiragana listed in https://www.unicode.org/charts/nameslist/c_3040.html<br>
* Note that this is a bit different from JIS X 0208's row 4 (Hiragana, 0x3041-0x3093)
*/
HIRAGANA((CodePointsRanges<String>) () -> {
return Collections.singletonList(Range.of(0x3041 /* ぁ */, 0x309F /* ゟ */));
}), //
/**
* Katakana and Katakana Phonetic Extensions listed in
* <ul>
* <li>https://www.unicode.org/charts/nameslist/c_30A0.html</li>
* <li>https://www.unicode.org/charts/nameslist/c_31F0.html</li>
* </ul>
* Note that this is different from JIS X 0208's row 5 (Katanaka, 0x30A1-0x30F6)
*/
KATAKANA((CodePointsRanges<String>) () -> {
return Arrays.asList( //
Range.of(0x30A0 /* ゠ */, 0x30FF /* ヿ */),
Range.of(0x31F0 /* ㇰ */, 0x31FF /* ㇿ */));
});
private final CodePoints<String> delegate;
UnicodeCodePoints(CodePoints<String> delegate) {
this.delegate = delegate;
}
@Override
public Set<Integer> allExcludedCodePoints(String s) {
return this.delegate.allExcludedCodePoints(s);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/codepoints/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint.charsequence.codepoints;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/variant/IdeographicVariationSequence.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence.variant;
public enum IdeographicVariationSequence {
IGNORE(true), NOT_IGNORE(false);
public static final String RANGE = new String(new int[] { 0xE0100 }, 0, 1) + "-"
+ new String(new int[] { 0xE01EF }, 0, 1);
private final boolean ignore;
IdeographicVariationSequence(boolean ignore) {
this.ignore = ignore;
}
public boolean ignore() {
return this.ignore;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/variant/MongolianFreeVariationSelector.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence.variant;
public enum MongolianFreeVariationSelector {
IGNORE(true), NOT_IGNORE(false);
public static final String RANGE = "\u180B-\u180D";
private final boolean ignore;
MongolianFreeVariationSelector(boolean ignore) {
this.ignore = ignore;
}
public boolean ignore() {
return this.ignore;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/variant/StandardizedVariationSequence.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence.variant;
public enum StandardizedVariationSequence {
IGNORE(true), NOT_IGNORE(false);
public static final String RANGE = "\uFE00-\uFE0F";
private final boolean ignore;
StandardizedVariationSequence(boolean ignore) {
this.ignore = ignore;
}
public boolean ignore() {
return this.ignore;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/variant/VariantOptions.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.charsequence.variant;
import am.ik.yavi.jsr305.Nullable;
public class VariantOptions {
private final MongolianFreeVariationSelector fvs;
private final IdeographicVariationSequence ivs;
private final StandardizedVariationSequence svs;
public VariantOptions(StandardizedVariationSequence svs, IdeographicVariationSequence ivs,
MongolianFreeVariationSelector fvs) {
this.svs = svs;
this.ivs = ivs;
this.fvs = fvs;
}
public static Builder builder() {
return new Builder();
}
private boolean isNotIgnoreAll() {
return !this.svs.ignore() && !this.fvs.ignore() && !this.ivs.ignore();
}
public String ignored(@Nullable String s) {
if (s == null || s.isEmpty()) {
return "";
}
if (this.isNotIgnoreAll()) {
return s;
}
StringBuilder regex = new StringBuilder("[");
if (this.svs.ignore()) {
regex.append(StandardizedVariationSequence.RANGE);
}
if (this.ivs.ignore()) {
regex.append(IdeographicVariationSequence.RANGE);
}
if (this.fvs.ignore()) {
regex.append(MongolianFreeVariationSelector.RANGE);
}
regex.append("]");
return regex.length() == 2 ? s : s.replaceAll(regex.toString(), "");
}
public static class Builder {
private MongolianFreeVariationSelector fvs;
private IdeographicVariationSequence ivs;
private StandardizedVariationSequence svs;
Builder() {
this.notIgnoreAll();
}
public VariantOptions build() {
return new VariantOptions(this.svs, this.ivs, this.fvs);
}
public Builder fvs(MongolianFreeVariationSelector fvs) {
this.fvs = fvs;
return this;
}
public Builder ignoreAll() {
this.svs = StandardizedVariationSequence.IGNORE;
this.ivs = IdeographicVariationSequence.IGNORE;
this.fvs = MongolianFreeVariationSelector.IGNORE;
return this;
}
public Builder ivs(IdeographicVariationSequence ivs) {
this.ivs = ivs;
return this;
}
public Builder notIgnoreAll() {
this.svs = StandardizedVariationSequence.NOT_IGNORE;
this.ivs = IdeographicVariationSequence.NOT_IGNORE;
this.fvs = MongolianFreeVariationSelector.NOT_IGNORE;
return this;
}
public Builder svs(StandardizedVariationSequence svs) {
this.svs = svs;
return this;
}
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/charsequence/variant/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint.charsequence.variant;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/inetaddress/InetAddressUtils.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.inetaddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
/**
* @since 0.7.0
*/
public class InetAddressUtils {
public static final String IPV4_REGEX = "^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$";
private static final Pattern IPV4_PATTERN = Pattern.compile(IPV4_REGEX);
private static final int MAX_BYTE = 128;
private static final int MAX_UNSIGNED_SHORT = 0xffff;
private static final int BASE_16 = 16;
// Max number of hex groups (separated by :) in an IPV6 address
private static final int IPV6_MAX_HEX_GROUPS = 8;
// Max hex digits in each IPv6 group
private static final int IPV6_MAX_HEX_DIGITS_PER_GROUP = 4;
public static boolean isIpv4(String s) {
return IPV4_PATTERN.matcher(s).matches();
}
// https://github.com/apache/commons-validator/blob/master/src/main/java/org/apache/commons/validator/routines/InetAddressValidator.java
public static boolean isIpv6(String s) {
// remove prefix size. This will appear after the zone id (if any)
final String[] parts = s.split("/", -1);
if (parts.length > 2) {
return false; // can only have one prefix specifier
}
if (parts.length == 2) {
if (!parts[1].matches("\\d{1,3}")) {
return false; // not a valid number
}
final int bits = Integer.parseInt(parts[1]); // cannot fail because of RE
// check
if (bits < 0 || bits > MAX_BYTE) {
return false; // out of range
}
}
// remove zone-id
final String[] partsZoneIdRemoved = parts[0].split("%", -1);
if (partsZoneIdRemoved.length > 2) {
return false;
}
// The id syntax is implementation independent, but it presumably cannot allow:
// whitespace, '/' or '%'
if ((partsZoneIdRemoved.length == 2) && !partsZoneIdRemoved[1].matches("[^\\s/%]+")) {
return false; // invalid id
}
final String firstPart = partsZoneIdRemoved[0];
final boolean containsCompressedZeroes = firstPart.contains("::");
if (containsCompressedZeroes && (firstPart.indexOf("::") != firstPart.lastIndexOf("::"))) {
return false;
}
if ((firstPart.startsWith(":") && !firstPart.startsWith("::"))
|| (firstPart.endsWith(":") && !firstPart.endsWith("::"))) {
return false;
}
String[] octets = firstPart.split(":");
if (containsCompressedZeroes) {
final List<String> octetList = new ArrayList<>(Arrays.asList(octets));
if (firstPart.endsWith("::")) {
// String.split() drops ending empty segments
octetList.add("");
}
else if (firstPart.startsWith("::") && !octetList.isEmpty()) {
octetList.remove(0);
}
octets = octetList.toArray(new String[0]);
}
if (octets.length > IPV6_MAX_HEX_GROUPS) {
return false;
}
int validOctets = 0;
int emptyOctets = 0; // consecutive empty chunks
for (int index = 0; index < octets.length; index++) {
String octet = octets[index];
if (octet.isEmpty()) {
emptyOctets++;
if (emptyOctets > 1) {
return false;
}
}
else {
emptyOctets = 0;
// Is last chunk an IPv4 address?
if (index == octets.length - 1 && octet.contains(".")) {
if (!isIpv4(octet)) {
return false;
}
validOctets += 2;
continue;
}
if (octet.length() > IPV6_MAX_HEX_DIGITS_PER_GROUP) {
return false;
}
int octetInt = 0;
try {
octetInt = Integer.parseInt(octet, BASE_16);
}
catch (NumberFormatException e) {
return false;
}
if (octetInt < 0 || octetInt > MAX_UNSIGNED_SHORT) {
return false;
}
}
validOctets++;
}
if (validOctets > IPV6_MAX_HEX_GROUPS || (validOctets < IPV6_MAX_HEX_GROUPS && !containsCompressedZeroes)) {
return false;
}
return true;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/inetaddress/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint.inetaddress;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/password/CharSequencePasswordPoliciesBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.password;
import java.util.List;
import am.ik.yavi.core.ConstraintPredicate;
/**
* @since 0.7.0
*/
public final class CharSequencePasswordPoliciesBuilder<T, E extends CharSequence>
extends PasswordPoliciesBuilder<T, E, CharSequencePasswordPoliciesBuilder<T, E>> {
@Override
protected CharSequencePasswordPoliciesBuilder<T, E> cast() {
return this;
}
public CharSequencePasswordPoliciesBuilder<T, E> uppercase() {
return this.uppercase(1);
}
/**
* @since 0.8.1
*/
@SuppressWarnings("unchecked")
public CharSequencePasswordPoliciesBuilder<T, E> uppercase(int count) {
return super.required((PasswordPolicy<E>) PasswordPolicy.UPPERCASE.count(count));
}
public CharSequencePasswordPoliciesBuilder<T, E> lowercase() {
return this.lowercase(1);
}
/**
* @since 0.8.1
*/
@SuppressWarnings("unchecked")
public CharSequencePasswordPoliciesBuilder<T, E> lowercase(int count) {
return super.required((PasswordPolicy<E>) PasswordPolicy.LOWERCASE.count(count));
}
/**
* @since 0.8.1
*/
public CharSequencePasswordPoliciesBuilder<T, E> alphabets() {
return this.alphabets(1);
}
/**
* @since 0.8.1
*/
@SuppressWarnings("unchecked")
public CharSequencePasswordPoliciesBuilder<T, E> alphabets(int count) {
return super.required((PasswordPolicy<E>) PasswordPolicy.ALPHABETS.count(count));
}
public CharSequencePasswordPoliciesBuilder<T, E> numbers() {
return this.numbers(1);
}
/**
* @since 0.8.1
*/
@SuppressWarnings("unchecked")
public CharSequencePasswordPoliciesBuilder<T, E> numbers(int count) {
return super.required((PasswordPolicy<E>) PasswordPolicy.NUMBERS.count(count));
}
public CharSequencePasswordPoliciesBuilder<T, E> symbols() {
return this.symbols(1);
}
/**
* @since 0.8.1
*/
@SuppressWarnings("unchecked")
public CharSequencePasswordPoliciesBuilder<T, E> symbols(int count) {
return super.required((PasswordPolicy<E>) PasswordPolicy.SYMBOLS.count(count));
}
public List<ConstraintPredicate<E>> strong() {
return this.uppercase().lowercase().numbers().symbols().build();
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/password/ObjectPasswordPoliciesBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.password;
/**
* @since 0.7.0
*/
public class ObjectPasswordPoliciesBuilder<T, E>
extends PasswordPoliciesBuilder<T, E, ObjectPasswordPoliciesBuilder<T, E>> {
@Override
protected ObjectPasswordPoliciesBuilder<T, E> cast() {
return this;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/password/PasswordPoliciesBuilder.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.password;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import am.ik.yavi.core.ConstraintPredicate;
import am.ik.yavi.core.NullAs;
import am.ik.yavi.core.ViolationMessage.Default;
/**
* @since 0.7.0
*/
public abstract class PasswordPoliciesBuilder<T, E, B extends PasswordPoliciesBuilder<T, E, B>> {
private final Set<PasswordPolicy<E>> requiredPolicies = new LinkedHashSet<>();
private final Set<PasswordPolicy<E>> optionalPolicies = new LinkedHashSet<>();
private int minimumOptionalPoliciesRequirement;
protected abstract B cast();
public B required(PasswordPolicy<E> policy) {
this.requiredPolicies.add(policy);
return this.cast();
}
@SafeVarargs
public final B required(PasswordPolicy<E>... policies) {
this.requiredPolicies.addAll(Arrays.asList(policies));
return this.cast();
}
@SafeVarargs
public final B optional(int minimumRequirement, PasswordPolicy<E>... policies) {
this.optionalPolicies.addAll(Arrays.asList(policies));
this.minimumOptionalPoliciesRequirement = minimumRequirement;
return this.cast();
}
public List<ConstraintPredicate<E>> build() {
final List<ConstraintPredicate<E>> predicates = new ArrayList<>();
if (!requiredPolicies.isEmpty()) {
predicates.addAll(this.requiredConstraintPredicates());
}
if (!optionalPolicies.isEmpty()) {
predicates.add(this.optionalConstraintPredicate());
}
return predicates;
}
private List<ConstraintPredicate<E>> requiredConstraintPredicates() {
return this.requiredPolicies.stream()
.map(policy -> ConstraintPredicate.of(policy, Default.PASSWORD_REQUIRED,
() -> new Object[] { policy.name() }, NullAs.VALID))
.collect(Collectors.toList());
}
private ConstraintPredicate<E> optionalConstraintPredicate() {
final Predicate<E> predicate = input -> {
int matched = 0;
for (PasswordPolicy<E> policy : this.optionalPolicies) {
if (policy.test(input)) {
matched++;
}
}
return matched >= this.minimumOptionalPoliciesRequirement;
};
return ConstraintPredicate.of(predicate, Default.PASSWORD_OPTIONAL,
() -> new Object[] { this.minimumOptionalPoliciesRequirement,
this.optionalPolicies.stream().map(PasswordPolicy::name).collect(Collectors.toList()) },
NullAs.VALID);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/password/PasswordPolicy.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.constraint.password;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @param <T> target class
* @since 0.7.0
*/
public interface PasswordPolicy<T> extends Predicate<T> {
default String name() {
return this.getClass().getSimpleName().replace(PasswordPolicy.class.getSimpleName(), "");
}
/**
* Rename the password policy
* @param name new name
* @return renamed policy
* @since 0.8.1
*/
default PasswordPolicy<T> name(String name) {
return new PasswordPolicy<T>() {
@Override
public String name() {
return name;
}
@Override
public boolean test(T t) {
return PasswordPolicy.this.test(t);
}
};
}
static <T> PasswordPolicy<T> of(String name, Predicate<T> predicate) {
return new PasswordPolicy<T>() {
@Override
public boolean test(T t) {
return predicate.test(t);
}
@Override
public String name() {
return name;
}
};
}
static <T extends CharSequence> PatternPasswordPolicy<T> pattern(String name, String regex) {
return new PatternPasswordPolicy<>(name, regex);
}
/**
* @since 0.8.1
*/
class PatternPasswordPolicy<T extends CharSequence> implements PasswordPolicy<T> {
private final String name;
private final String regex;
private final Pattern pattern;
private final int count;
public PatternPasswordPolicy(String name, String regex) {
this(name, regex, 1);
}
public PatternPasswordPolicy(String name, String regex, int count) {
if (count <= 0) {
throw new IllegalArgumentException("'count' must be greater than 0");
}
this.name = name;
this.regex = regex;
this.pattern = Pattern.compile(regex);
this.count = count;
}
@Override
public String name() {
return this.name;
}
@Override
public boolean test(T input) {
final Matcher matcher = this.pattern.matcher(input);
int count = 0;
while (matcher.find()) {
if (++count >= this.count) {
return true;
}
}
return false;
}
/**
* Change the count of the policy
* @param count new count
* @return new policy
*/
public PatternPasswordPolicy<T> count(int count) {
if (this.count == count) {
return this;
}
return new PatternPasswordPolicy<>(this.name, this.regex, count);
}
}
PatternPasswordPolicy<String> UPPERCASE = PasswordPolicy.pattern("Uppercase", "[A-Z]");
PatternPasswordPolicy<String> LOWERCASE = PasswordPolicy.pattern("Lowercase", "[a-z]");
/**
* @since 0.8.1
*/
PatternPasswordPolicy<String> ALPHABETS = PasswordPolicy.pattern("Alphabets", "[a-zA-Z]");
PatternPasswordPolicy<String> NUMBERS = PasswordPolicy.pattern("Numbers", "[0-9]");
PatternPasswordPolicy<String> SYMBOLS = PasswordPolicy.pattern("Symbols", "[!-/:-@\\[-`{-\\~]");
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/constraint/password/package-info.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.
*/
@NonNullApi
package am.ik.yavi.constraint.password;
import am.ik.yavi.jsr305.NonNullApi;
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ApplicativeValidator.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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;
/**
* Applicative validator class
*
* @param <T> Target class
* @since 0.6.0
*/
@FunctionalInterface
public interface ApplicativeValidator<T> extends ValueValidator<T, T> {
} |
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/CollectionValidator.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Collection;
import java.util.function.Function;
public class CollectionValidator<T, N extends Collection<E>, E> {
private final String name;
private final Function<T, N> toCollection;
private final Validator<E> validator;
public CollectionValidator(Function<T, N> toCollection, String name, Validator<E> validator) {
this.toCollection = toCollection;
this.name = name;
this.validator = validator;
}
public String name() {
return this.name;
}
public Function<T, N> toCollection() {
return this.toCollection;
}
public Validator<E> validator() {
return this.validator;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/Constraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Collection;
import java.util.Deque;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.function.Supplier;
import am.ik.yavi.jsr305.Nullable;
import static am.ik.yavi.core.ViolationMessage.Default.OBJECT_EQUAL_TO;
import static am.ik.yavi.core.ViolationMessage.Default.OBJECT_IS_NULL;
import static am.ik.yavi.core.ViolationMessage.Default.OBJECT_NOT_NULL;
import static am.ik.yavi.core.ViolationMessage.Default.OBJECT_NOT_ONE_OF;
import static am.ik.yavi.core.ViolationMessage.Default.OBJECT_ONE_OF;
public interface Constraint<T, V, C extends Constraint<T, V, C>> {
C cast();
default C isNull() {
this.predicates()
.add(ConstraintPredicate.of(Objects::isNull, OBJECT_IS_NULL, () -> new Object[] {}, NullAs.INVALID));
return this.cast();
}
/**
* @since 0.10.0
*/
default C equalTo(@Nullable V other) {
this.predicates()
.add(ConstraintPredicate.of(Predicate.isEqual(other), OBJECT_EQUAL_TO, () -> new Object[] { other },
NullAs.VALID));
return this.cast();
}
/**
* @since 0.10.0
*/
default C oneOf(Collection<V> values) {
this.predicates()
.add(ConstraintPredicate.of(values::contains, OBJECT_ONE_OF, () -> new Object[] { values }, NullAs.VALID));
return this.cast();
}
/**
* @since 0.14.1
*/
default C notOneOf(Collection<V> values) {
Predicate<V> notOneOf = v -> !values.contains(v);
this.predicates()
.add(ConstraintPredicate.of(notOneOf, OBJECT_NOT_ONE_OF, () -> new Object[] { values }, NullAs.VALID));
return this.cast();
}
default C message(String message) {
ConstraintPredicate<V> predicate = this.predicates().pollLast();
if (predicate == null) {
throw new IllegalStateException("no constraint found to override!");
}
this.predicates().addLast(predicate.overrideMessage(message));
return this.cast();
}
default C message(ViolationMessage message) {
ConstraintPredicate<V> predicate = this.predicates().pollLast();
if (predicate == null) {
throw new IllegalStateException("no constraint found to override!");
}
this.predicates().addLast(predicate.overrideMessage(message));
return this.cast();
}
default C notNull() {
this.predicates()
.add(ConstraintPredicate.of(Objects::nonNull, OBJECT_NOT_NULL, () -> new Object[] {}, NullAs.INVALID));
return this.cast();
}
default C predicate(Predicate<V> predicate, ViolationMessage violationMessage) {
final Supplier<Object[]> arguments = ViolatedArguments.supplyArguments(predicate);
this.predicates().add(ConstraintPredicate.of(predicate, violationMessage, arguments, NullAs.VALID));
return this.cast();
}
/**
* @since 0.8.2
*/
default C predicate(Predicate<V> predicate, String messageKey, String defaultMessageFormat) {
return this.predicate(predicate, ViolationMessage.of(messageKey, defaultMessageFormat));
}
default C predicate(CustomConstraint<V> constraint) {
return this.predicate(constraint, constraint);
}
default C predicateNullable(Predicate<V> predicate, ViolationMessage violationMessage) {
final Supplier<Object[]> arguments = ViolatedArguments.supplyArguments(predicate);
this.predicates().add(ConstraintPredicate.of(predicate, violationMessage, arguments, NullAs.INVALID));
return this.cast();
}
/**
* @since 0.8.2
*/
default C predicateNullable(Predicate<V> predicate, String messageKey, String defaultMessageFormat) {
return this.predicateNullable(predicate, ViolationMessage.of(messageKey, defaultMessageFormat));
}
default C predicateNullable(CustomConstraint<V> constraint) {
return this.predicateNullable(constraint, constraint);
}
Deque<ConstraintPredicate<V>> predicates();
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintCondition.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.BiPredicate;
@FunctionalInterface
public interface ConstraintCondition<T> extends BiPredicate<T, ConstraintContext> {
/**
* @since 0.11.0
*/
static <T> ConstraintCondition<T> hasAttribute(String key) {
return (t, context) -> context.attribute(key).exists();
}
/**
* @since 0.11.0
*/
static <T> ConstraintCondition<T> hasAttributeWithValue(String key, Object value) {
return (t, context) -> context.attribute(key).isEqualTo(value);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintContext.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Map;
import java.util.Objects;
import java.util.function.Function;
import am.ik.yavi.jsr305.Nullable;
/**
* Constraint Context that contains the name and attributes.
*
* @since 0.11.0
*/
public interface ConstraintContext {
/**
* Returns the attribute for the given key.
* @param key key
* @return the attribute
*/
Attribute attribute(String key);
/**
* Returns the context name.<br>
* This method exists on this interface for backwards compatibility with YAVI 0.10 and
* earlier. <br>
* It is effectively used in the lower interface <code>ConstraintGroup</code>.
* @return context name
*/
String name();
static ConstraintContext from(Map<String, ?> map) {
return new ConstraintContext() {
@Override
public Attribute attribute(String key) {
return () -> map.get(key);
}
@Override
public String name() {
return "ConstraintContextFromMap";
}
};
}
static ConstraintContext from(Function<String, ?> function) {
return new ConstraintContext() {
@Override
public Attribute attribute(String key) {
return () -> function.apply(key);
}
@Override
public String name() {
return "ConstraintContextFromFunction";
}
};
}
@FunctionalInterface
interface Attribute {
/**
* Returns the attribute value. <code>null</code> is returned if the attribute
* does not exist.
* @return value
*/
@Nullable
Object value();
/**
* Returns the typed attribute value
* @param clazz the type of the attribute value
* @return value
*/
@Nullable
default <T> T value(Class<T> clazz) {
return clazz.cast(this.value());
}
/**
* Returns whether the attribute value exists
* @return whether the attribute value exists
*/
default boolean exists() {
return this.value() != null;
}
/**
* Return whether the attribute value is equal to the given value.
* @param value value
* @return whether the attribute value is equal to the given value.
*/
default boolean isEqualTo(Object value) {
return Objects.equals(this.value(), value);
}
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintGroup.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Objects;
/**
* <code>ConstraintGroup</code> is a specialized <code>ConstraintContext</code> with only
* the name, attributes is empty.
*/
@FunctionalInterface
public interface ConstraintGroup extends ConstraintContext {
ConstraintGroup DEFAULT = ConstraintGroup.of("DEFAULT");
static ConstraintGroup of(String name) {
return new ConstraintGroup() {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof ConstraintGroup)) {
return false;
}
ConstraintGroup cg = (ConstraintGroup) obj;
return Objects.equals(this.name(), cg.name());
}
@Override
public int hashCode() {
return Objects.hashCode(this.name());
}
@Override
public String name() {
return name;
}
};
}
@Override
default Attribute attribute(String key) {
return () -> null;
}
default <T> ConstraintCondition<T> toCondition() {
return (target, group) -> Objects.equals(name(), group.name());
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintPredicate.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import am.ik.yavi.jsr305.Nullable;
public class ConstraintPredicate<V> {
private final Supplier<Object[]> args;
private final String defaultMessageFormat;
private final String messageKey;
private final NullAs nullAs;
private final Predicate<V> predicate;
private ConstraintPredicate(Predicate<V> predicate, ViolationMessage violationMessage, Supplier<Object[]> args,
NullAs nullAs) {
this(predicate, violationMessage.messageKey(), violationMessage.defaultMessageFormat(), args, nullAs);
}
private ConstraintPredicate(Predicate<V> predicate, String messageKey, String defaultMessageFormat,
Supplier<Object[]> args, NullAs nullAs) {
this.predicate = predicate;
this.messageKey = messageKey;
this.defaultMessageFormat = defaultMessageFormat;
this.args = args;
this.nullAs = nullAs;
}
public static <V> ConstraintPredicate<V> of(Predicate<V> predicate, ViolationMessage violationMessage,
Supplier<Object[]> args, NullAs nullAs) {
return new ConstraintPredicate<>(predicate, violationMessage, args, nullAs);
}
public static <V> ConstraintPredicate<V> withViolatedValue(Function<V, Optional<ViolatedValue>> violatedValue,
ViolationMessage violationMessage, Supplier<Object[]> args, NullAs nullAs) {
return new ConstraintPredicate<V>(v -> !violatedValue.apply(v).isPresent(), violationMessage, args, nullAs) {
@Override
public Optional<ViolatedValue> violatedValue(@Nullable V target) {
return violatedValue.apply(target);
}
};
}
public Supplier<Object[]> args() {
return this.args;
}
public final String defaultMessageFormat() {
return this.defaultMessageFormat;
}
public String messageKey() {
return this.messageKey;
}
public final NullAs nullValidity() {
return this.nullAs;
}
public ConstraintPredicate<V> overrideMessage(ViolationMessage message) {
return new ConstraintPredicate<>(this.predicate, message, this.args, this.nullAs);
}
public ConstraintPredicate<V> overrideMessage(String message) {
return new ConstraintPredicate<V>(this.predicate, this.messageKey, message, this.args, this.nullAs) {
@Override
public Optional<ViolatedValue> violatedValue(@Nullable V target) {
return ConstraintPredicate.this.violatedValue(target);
}
};
}
public final Predicate<V> predicate() {
return this.predicate;
}
public Optional<ViolatedValue> violatedValue(@Nullable V target) {
Predicate<V> predicate = this.predicate();
if (predicate.test(target)) {
return Optional.empty();
}
else {
// violated
return Optional.of(new ViolatedValue(target));
}
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintPredicates.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Deque;
import java.util.function.Function;
public class ConstraintPredicates<T, V> {
private final String name;
private final Deque<ConstraintPredicate<V>> predicates;
private final Function<T, V> toValue;
public ConstraintPredicates(Function<T, V> toValue, String name, Deque<ConstraintPredicate<V>> predicates) {
this.toValue = toValue;
this.name = name;
this.predicates = predicates;
}
public final String name() {
return this.name;
}
public final Deque<ConstraintPredicate<V>> predicates() {
return this.predicates;
}
public final Function<T, V> toValue() {
return this.toValue;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintViolation.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.jsr305.Nullable;
import am.ik.yavi.message.MessageFormatter;
import am.ik.yavi.message.SimpleMessageFormatter;
import java.util.Arrays;
import java.util.Locale;
import java.util.function.Function;
/**
* Represents a single constraint violation that occurs during validation.
*
* <p>
* This class encapsulates details about a validation failure, including:
* <ul>
* <li>The field or property name that failed validation</li>
* <li>The message key used for internationalization</li>
* <li>The default message format to use when no localized message is found</li>
* <li>Any arguments needed for message formatting</li>
* <li>The message formatter and locale to use for message formatting</li>
* </ul>
*
* <p>
* 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;
/**
* Creates a new constraint violation.
* @param name the field or property name that this constraint violation applies to
* @param messageKey the key used to look up localized messages
* @param defaultMessageFormat the default message format to use when no localized
* message is found
* @param args the arguments to be used when formatting the message
* @param messageFormatter the message formatter to be used
* @param locale the locale to be used for message localization
* @deprecated Use {@link #builder()} instead for a more fluent and type-safe API
*/
@Deprecated
public ConstraintViolation(String name, String messageKey, String defaultMessageFormat, @Nullable Object[] args,
@Nullable MessageFormatter messageFormatter, @Nullable Locale locale) {
this.name = name;
this.messageKey = messageKey;
this.defaultMessageFormat = defaultMessageFormat;
this.args = args == null ? new Object[0] : args;
this.messageFormatter = messageFormatter == null ? SimpleMessageFormatter.getInstance() : messageFormatter;
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.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* Example usage: <pre>{@code
* // Using a custom message formatter for specific formatting needs
* ConstraintViolation violation = // ... obtain violation
* CustomMessageFormatter formatter = new CustomMessageFormatter();
* String formattedMessage = violation.message(formatter);
* }</pre>
* @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.
*
* <p>
* 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.
*
* <p>
* 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];
}
/**
* Returns a new ConstraintViolation with the name transformed using the provided
* function. If the arguments array is not empty, the first element will be updated
* with the new name.
* @param rename the function to transform the current name
* @return a new ConstraintViolation with the renamed name
* @since 0.7.0
*/
public ConstraintViolation rename(Function<? super String, String> rename) {
final String newName = rename.apply(name);
final Object[] newArgs = this.args().clone();
if (newArgs.length > 0) {
newArgs[0] = newName;
}
return new ConstraintViolation(newName, this.messageKey, this.defaultMessageFormat, newArgs,
this.messageFormatter, this.locale);
}
/**
* Returns a new ConstraintViolation with the name indexed by appending "[index]" to
* the current name.
* @param index the index to append to the name
* @return a new ConstraintViolation with the indexed name
* @since 0.7.0
*/
public ConstraintViolation indexed(int index) {
return this.rename(name -> name + "[" + index + "]");
}
/**
* Creates a new builder for constructing ConstraintViolation instances using a
* fluent, type-safe API. This builder implements a staged builder pattern to enforce
* required properties while making optional properties truly optional.
* @return the first stage of the builder which requires setting the name property
* @since 0.15.0
*/
public static StagedBuilders.Name builder() {
return new Builder();
}
/**
* Implementation of the staged builder pattern for creating ConstraintViolation
* instances. This builder class implements all the staged interfaces to provide a
* fluent and type-safe way to construct ConstraintViolation objects.
*
* @since 0.15.0
*/
public static class Builder implements StagedBuilders.Name, StagedBuilders.MessageKey,
StagedBuilders.DefaultMessageFormat, StagedBuilders.Optionals {
/** The field name that the constraint violation applies to */
private String name;
/** The message key for internationalization */
private String messageKey;
/** The default message format if no localized message is found */
private String defaultMessageFormat;
/** The arguments to be used when formatting the message */
private Object[] args;
/** The message formatter to be used for formatting the message */
private MessageFormatter messageFormatter;
/** The locale to be used for message localization */
private Locale locale;
/**
* Private constructor to prevent direct instantiation. Use
* {@link ConstraintViolation#builder()} instead.
*/
private Builder() {
}
/**
* Sets the name of the field or property that this constraint violation applies
* to.
* @param name the field or property name
* @return the next stage of the builder for method chaining
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* Sets the message key for internationalization lookup.
* @param messageKey the key used to look up localized messages
* @return the next stage of the builder for method chaining
*/
public Builder messageKey(String messageKey) {
this.messageKey = messageKey;
return this;
}
/**
* Sets the default message format to use when no localized message is found.
* @param defaultMessageFormat the default message format string
* @return the next stage of the builder for method chaining
*/
public Builder defaultMessageFormat(String defaultMessageFormat) {
this.defaultMessageFormat = defaultMessageFormat;
return this;
}
/**
* Sets the arguments to be used when formatting the message.
* @param args the arguments to be used in message formatting
* @return this builder for method chaining
*/
public Builder args(Object... args) {
this.args = args;
return this;
}
/**
* 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.
* @param args the arguments to be used in message formatting (excluding the name)
* @return this builder for method chaining
*/
public Builder argsWithPrependedName(Object... args) {
Object[] argsWithName = new Object[args.length + 1];
argsWithName[0] = this.name;
System.arraycopy(args, 0, argsWithName, 1, args.length);
this.args = argsWithName;
return this;
}
/**
* 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.
* @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
* value is retrieved by calling value() method
* @return this builder for method chaining
*/
public Builder argsWithPrependedNameAndAppendedViolatedValue(Object[] args, ViolatedValue violatedValue) {
Object[] completeArgs = new Object[args.length + 2];
completeArgs[0] = this.name;
System.arraycopy(args, 0, completeArgs, 1, args.length);
completeArgs[args.length + 1] = violatedValue.value();
this.args = completeArgs;
return this;
}
/**
* Sets the message formatter to be used for message formatting. If not specified,
* a default {@link SimpleMessageFormatter} will be used.
* @param messageFormatter the message formatter to use
* @return this builder for method chaining
*/
public Builder messageFormatter(MessageFormatter messageFormatter) {
this.messageFormatter = messageFormatter;
return this;
}
/**
* Sets the locale to be used for message localization. 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
*/
public Builder locale(Locale locale) {
this.locale = locale;
return this;
}
/**
* Builds a new {@link ConstraintViolation} instance with the configured
* properties.
* @return a new {@link ConstraintViolation} instance
*/
public ConstraintViolation build() {
return new ConstraintViolation(name, messageKey, defaultMessageFormat, args, messageFormatter, locale);
}
}
/**
* Container interface for the staged builder interfaces used in the
* ConstraintViolation's builder pattern.
*
* <p>
* 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.
*
* <p>
* The staged building process follows this sequence:
* <ol>
* <li>First, set the name property ({@link Name})</li>
* <li>Then, set the message key property ({@link MessageKey})</li>
* <li>Next, set the default message format property
* ({@link DefaultMessageFormat})</li>
* <li>Finally, optionally set any additional properties and build
* ({@link Optionals})</li>
* </ol>
*
* <p>
* 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.
*
* <p>
* 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 {
/**
* Sets the name of the field or property that this constraint violation
* applies to.
* @param name the field or property name
* @return the next stage of the builder which requires setting the message
* key
*/
MessageKey name(String name);
}
/**
* Second stage of the builder which requires setting the message key property.
*
* <p>
* 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.
*
* <p>
* 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
*/
DefaultMessageFormat messageKey(String messageKey);
/**
* Convenient shortcut builder method that creates a complete constraint
* violation in a single call. This method automatically:
* <ul>
* <li>Sets the message key to the default value
* ({@link #DEFAULT_MESSAGE_KEY})</li>
* <li>Uses the provided message as the default message format</li>
* <li>Prepends the field name as the first argument in the argument list</li>
* <li>Builds and returns the final ConstraintViolation object</li>
* </ul>
*
* <p>
* This method is particularly useful for simple constraint violations where
* complex message formatting or internationalization is not required.
* @param message the message text to be used as the default message format
* @return a fully constructed {@link ConstraintViolation} instance with the
* specified message
* @since 0.15.0
*/
default ConstraintViolation message(String message) {
return this.messageKey(DEFAULT_MESSAGE_KEY)
.defaultMessageFormat(message)
.argsWithPrependedName()
.build();
}
}
/**
* Third stage of the builder which requires setting the default message format
* property.
*
* <p>
* 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.
*
* <p>
* 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
*/
Optionals defaultMessageFormat(String defaultMessageFormat);
}
/**
* Final stage of the builder where all remaining properties are optional. The
* build() method can be called at any point from this stage.
*
* <p>
* 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.
*
* <p>
* 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
*/
Optionals args(Object... args);
/**
* Sets the arguments to be used when formatting the message, automatically
* including the name as the first argument.
*
* <p>
* 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. It automatically prepends the field or property
* name to the beginning of the arguments array.
*
* <p>
* 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
*/
Optionals 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.
*
* <p>
* This method provides a complete solution for the most common constraint
* violation formatting pattern by automatically handling both the name and
* violated value positioning in the arguments array.
*
* <p>
* 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"].
*
* <p>
* 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
* value is retrieved by calling value() method
* @return this builder for method chaining
*/
Optionals argsWithPrependedNameAndAppendedViolatedValue(Object[] args, ViolatedValue violatedValue);
/**
* Sets the message formatter to be used for message formatting.
*
* <p>
* 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.
*
* <p>
* 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.
*
* <p>
* The locale affects how messages are looked up and formatted, especially for
* internationalized applications that support multiple languages.
*
* <p>
* 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
*/
Optionals locale(Locale locale);
/**
* Builds a new {@link ConstraintViolation} instance with the configured
* properties.
*
* <p>
* 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();
}
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintViolations.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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
*
* 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,
* 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.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ConstraintViolations implements List<ConstraintViolation> {
private final List<ConstraintViolation> delegate;
/**
* Constructs with the constraintViolations to delegate. If the given value is
* <code>ConstraintViolations</code> itself, cast and return it.
* @param delegate constraintViolations to delegate
* @since 0.6.0
*/
public static ConstraintViolations of(List<ConstraintViolation> delegate) {
if (delegate instanceof ConstraintViolations) {
return (ConstraintViolations) delegate;
}
return new ConstraintViolations(delegate);
}
/**
* Constructs an empty list with an initial capacity of ten.
*/
public ConstraintViolations() {
this.delegate = new ArrayList<>();
}
/**
* Constructs with the constraintViolations to delegate
* @param delegate constraintViolations to delegate
* @since 0.6.0
*/
public ConstraintViolations(List<ConstraintViolation> delegate) {
this.delegate = delegate;
}
/**
* Appends the specified element to the end of this list (optional operation).
*
* <p>
* Lists that support this operation may place limitations on what elements may be
* added to this list. In particular, some lists will refuse to add null elements, and
* others will impose restrictions on the type of elements that may be added. List
* 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 <code>true</code> (as specified by {@link Collection#add})
* @throws UnsupportedOperationException if the <code>add</code> operation is not
* supported by this list
* @throws ClassCastException if the class of the specified element prevents it from
* being added to this list
* @throws NullPointerException if the specified element is null and this list does
* not permit null elements
* @throws IllegalArgumentException if some property of this element prevents it from
* being added to this list
*/
@Override
public final boolean add(ConstraintViolation constraintViolation) {
return this.delegate.add(constraintViolation);
}
/**
* Inserts the specified element at the specified position in this list (optional
* operation). Shifts the element currently at that position (if any) and any
* 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 <code>add</code> operation is not
* supported by this list
* @throws ClassCastException if the class of the specified element prevents it from
* being added to this list
* @throws NullPointerException if the specified element is null and this list does
* not permit null elements
* @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
* (<code>index < 0 || index > size()</code>)
*/
@Override
public final void add(int index, ConstraintViolation element) {
this.delegate.add(index, element);
}
/**
* Appends all of the elements in the specified collection to the end of this list, in
* the order that they are returned by the specified collection's iterator (optional
* operation). The behavior of this operation is undefined if the specified collection
* 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 <code>true</code> if this list changed as a result of the call
* @throws UnsupportedOperationException if the <code>addAll</code> 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
* @throws NullPointerException if the specified collection contains one or more null
* elements and this list does not permit null elements, or if the specified
* collection is null
* @throws IllegalArgumentException if some property of an element of the specified
* collection prevents it from being added to this list
* @see #add(Object)
*/
@Override
public final boolean addAll(Collection<? extends ConstraintViolation> c) {
return this.delegate.addAll(c);
}
/**
* Inserts all of the elements in the specified collection into this list at the
* specified position (optional operation). Shifts the element currently at that
* position (if any) and any subsequent elements to the right (increases their
* indices). The new elements will appear in this list in the order that they are
* returned by the specified collection's iterator. The behavior of this operation is
* undefined if the specified collection 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 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 <code>true</code> if this list changed as a result of the call
* @throws UnsupportedOperationException if the <code>addAll</code> 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
* @throws NullPointerException if the specified collection contains one or more null
* elements and this list does not permit null elements, or if the specified
* collection is null
* @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
* (<code>index < 0 || index > size()</code>)
*/
@Override
public final boolean addAll(int index, Collection<? extends ConstraintViolation> c) {
return this.delegate.addAll(c);
}
/**
* This method is intended to be used with Spring MVC
*
* <strong>sample</strong>
*
* <pre>
* <code>@PostMapping("users")
* public String createUser(Model model, UserForm userForm, BindingResult bindingResult) {
* return validator.validateToEither(userForm)
* .fold(violations -> {
* violations.apply(bindingResult::rejectValue);
* return "userForm";
* }, form -> {
* // ...
* return "redirect:/";
* });
* }</code> </pre>
* @param callback
*/
public ConstraintViolations apply(Callback callback) {
this.forEach(v -> callback.apply(v.name(), v.messageKey(), v.args(), v.message()));
return this;
}
/**
* Removes all of the elements from this list (optional operation). The list will be
* empty after this call returns.
* @throws UnsupportedOperationException if the <code>clear</code> operation is not
* supported by this list
*/
@Override
public final void clear() {
this.delegate.clear();
}
/**
* Returns <code>true</code> if this list contains the specified element. More
* formally, returns <code>true</code> if and only if this list contains at least one
* element <code>e</code> such that
* <code>(o==null ? e==null : o.equals(e))</code>.
* @param o element whose presence in this list is to be tested
* @return <code>true</code> if this list contains the specified element
* @throws ClassCastException if the type of the specified element is incompatible
* with this list (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified element is null and this list does
* not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>)
*/
@Override
public final boolean contains(Object o) {
return this.delegate.contains(o);
}
/**
* Returns <code>true</code> if this list contains all of the elements of the
* specified collection.
* @param c collection to be checked for containment in this list
* @return <code>true</code> 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
* (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified collection contains one or more null
* elements and this list does not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>), or if the specified
* collection is null
* @see #contains(Object)
*/
@Override
public final boolean containsAll(Collection<?> c) {
return this.delegate.containsAll(c);
}
public List<ViolationDetail> details() {
return this.delegate.stream().map(ConstraintViolation::detail).collect(Collectors.toList());
}
/**
* Returns the element at the specified position in this list.
* @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
* (<code>index < 0 || index >= size()</code>)
*/
@Override
public final ConstraintViolation get(int index) {
return this.delegate.get(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 <code>i</code> such that
* <code>(o==null ? get(i)==null : o.equals(get(i)))</code>, 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
* @throws ClassCastException if the type of the specified element is incompatible
* with this list (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified element is null and this list does
* not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>)
*/
@Override
public final int indexOf(Object o) {
return this.delegate.indexOf(o);
}
/**
* Returns <code>true</code> if this list contains no elements.
* @return <code>true</code> if this list contains no elements
*/
@Override
public final boolean isEmpty() {
return this.delegate.isEmpty();
}
public final boolean isValid() {
return this.delegate.isEmpty();
}
/**
* Returns an iterator over the elements in this list in proper sequence.
* @return an iterator over the elements in this list in proper sequence
*/
@Override
public final Iterator<ConstraintViolation> iterator() {
return this.delegate.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 <code>i</code> such that
* <code>(o==null ? get(i)==null : o.equals(get(i)))</code>, 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
* @throws ClassCastException if the type of the specified element is incompatible
* with this list (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified element is null and this list does
* not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>)
*/
@Override
public final int lastIndexOf(Object o) {
return this.delegate.lastIndexOf(o);
}
/**
* Returns a list iterator over the elements in this list (in proper sequence).
* @return a list iterator over the elements in this list (in proper sequence)
*/
@Override
public final ListIterator<ConstraintViolation> listIterator() {
return this.delegate.listIterator();
}
/**
* Returns a list iterator over the elements in this list (in proper sequence),
* starting at the specified position in the list. The specified index indicates the
* first element that would be returned by an initial call to {@link ListIterator#next
* next}. An initial call to {@link ListIterator#previous previous} would return the
* element with the specified index minus one.
* @param index index of the first element to be returned from the list iterator (by a
* call to {@link ListIterator#next next})
* @return a list iterator over the elements in this list (in proper sequence),
* starting at the specified position in the list
* @throws IndexOutOfBoundsException if the index is out of range
* ({@code index < 0 || index > size()})
*/
@Override
public final ListIterator<ConstraintViolation> listIterator(int index) {
return this.delegate.listIterator(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 <code>i</code>
* such that
* <code>(o==null ? get(i)==null : o.equals(get(i)))</code> (if
* such an element exists). Returns <code>true</code> 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 <code>true</code> if this list contained the specified element
* @throws ClassCastException if the type of the specified element is incompatible
* with this list (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if the specified element is null and this list does
* not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws UnsupportedOperationException if the <code>remove</code> operation is not
* supported by this list
*/
@Override
public final boolean remove(Object o) {
return this.delegate.remove(o);
}
/**
* Removes the element at the specified position in this list (optional operation).
* Shifts any subsequent elements to the left (subtracts one from their indices).
* 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 <code>remove</code> operation is not
* supported by this list
* @throws IndexOutOfBoundsException if the index is out of range
* (<code>index < 0 || index >= size()</code>)
*/
@Override
public final ConstraintViolation remove(int index) {
return this.delegate.remove(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 <code>true</code> if this list changed as a result of the call
* @throws UnsupportedOperationException if the <code>removeAll</code> operation is
* not supported by this list
* @throws ClassCastException if the class of an element of this list is incompatible
* with the specified collection
* (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if this list contains a null element and the specified
* collection does not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>), or if the specified
* collection is null
* @see #remove(Object)
* @see #contains(Object)
*/
@Override
public final boolean removeAll(Collection<?> c) {
return this.delegate.removeAll(c);
}
/**
* Retains only the elements in this list that are contained in the specified
* 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 <code>true</code> if this list changed as a result of the call
* @throws UnsupportedOperationException if the <code>retainAll</code> operation is
* not supported by this list
* @throws ClassCastException if the class of an element of this list is incompatible
* with the specified collection
* (<a href="Collection.html#optional-restrictions">optional</a>)
* @throws NullPointerException if this list contains a null element and the specified
* collection does not permit null elements
* (<a href="Collection.html#optional-restrictions">optional</a>), or if the specified
* collection is null
* @see #remove(Object)
* @see #contains(Object)
*/
@Override
public final boolean retainAll(Collection<?> c) {
return this.delegate.retainAll(c);
}
/**
* Replaces the element at the specified position in this list with the specified
* element (optional operation).
* @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 <code>set</code> operation is not
* supported by this list
* @throws ClassCastException if the class of the specified element prevents it from
* being added to this list
* @throws NullPointerException if the specified element is null and this list does
* not permit null elements
* @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
* (<code>index < 0 || index >= size()</code>)
*/
@Override
public final ConstraintViolation set(int index, ConstraintViolation element) {
return this.delegate.set(index, element);
}
/**
* Returns the number of elements in this list. If this list contains more than
* <code>Integer.MAX_VALUE</code> elements, returns <code>Integer.MAX_VALUE</code>.
* @return the number of elements in this list
*/
@Override
public final int size() {
return this.delegate.size();
}
/**
* Returns a view of the portion of this list between the specified
* <code>fromIndex</code>, inclusive, and <code>toIndex</code>, exclusive. (If
* <code>fromIndex</code> and <code>toIndex</code> 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.
* <p>
* <p>
* This method eliminates the need for explicit range operations (of the sort that
* commonly exist for arrays). Any operation that expects a list can be used as a
* range operation by passing a subList view instead of a whole list. For example, the
* following idiom removes a range of elements from a list:
*
* <pre>
* {@code
* list.subList(from, to).clear();
* }
* </pre>
*
* Similar idioms may be constructed for <code>indexOf</code> and
* <code>lastIndexOf</code>, and all of the algorithms in the <code>Collections</code>
* class can be applied to a subList.
* <p>
* <p>
* The semantics of the list returned by this method become undefined if the backing
* list (i.e., this list) is <i>structurally modified</i> in any way other than via
* the returned list. (Structural modifications are those that change the size of this
* list, or otherwise perturb it in such a fashion that iterations in progress may
* yield incorrect results.)
* @param fromIndex low endpoint (inclusive) of the subList
* @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
* (<code>fromIndex < 0 || toIndex > size ||
* fromIndex > toIndex</code>)
*/
@Override
public final List<ConstraintViolation> subList(int fromIndex, int toIndex) {
return this.delegate.subList(fromIndex, toIndex);
}
public final <E extends RuntimeException> void throwIfInvalid(Function<ConstraintViolations, E> toException)
throws E {
if (!isValid()) {
throw toException.apply(this);
}
}
/**
* Returns an array containing all of the elements in this list in proper sequence
* (from first to last element).
*
* <p>
* The returned array will be "safe" in that no references to it are maintained by
* this list. (In other words, this method must allocate a new array even if this list
* is backed by an array). The caller is thus free to modify the returned array.
*
* <p>
* This method acts as bridge between array-based and collection-based APIs.
* @return an array containing all of the elements in this list in proper sequence
* @see Arrays#asList(Object[])
*/
@Override
public final Object[] toArray() {
return this.delegate.toArray();
}
/**
* Returns an array containing all of the elements in this list in proper sequence
* (from first to last element); the runtime type of the returned array is that of the
* specified array. If the list fits in the specified array, it is returned therein.
* Otherwise, a new array is allocated with the runtime type of the specified array
* and the size of this list.
*
* <p>
* 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 <code>null</code>. (This is useful in determining the
* length of the list <i>only</i> if the caller knows that the list does not contain
* any null elements.)
*
* <p>
* Like the {@link #toArray()} method, this method acts as bridge between array-based
* and collection-based APIs. Further, this method allows precise control over the
* runtime type of the output array, and may, under certain circumstances, be used to
* save allocation costs.
*
* <p>
* Suppose <code>x</code> is a list known to contain only strings. The following code
* can be used to dump the list into a newly allocated array of <code>String</code>:
*
* <pre>
* {
* @code
* String[] y = x.toArray(new String[0]);
* }
* </pre>
* <p>
* Note that <code>toArray(new Object[0])</code> is identical in function to
* <code>toArray()</code>.
* @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.
* @return an array containing the elements of this list
* @throws ArrayStoreException if the runtime type of the specified array is not a
* supertype of the runtime type of every element in this list
* @throws NullPointerException if the specified array is null
*/
@Override
public final <T> T[] toArray(T[] a) {
return this.delegate.toArray(a);
}
@Override
public String toString() {
return this.delegate.toString();
}
public final List<ConstraintViolation> violations() {
return Collections.unmodifiableList(this.delegate);
}
@FunctionalInterface
public interface Callback {
void apply(String name, String messageKey, Object[] args, String defaultMessage);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ConstraintViolationsException.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.List;
import java.util.stream.Collectors;
/**
* @since 0.3.0
*/
public class ConstraintViolationsException extends RuntimeException {
private final ConstraintViolations violations;
public ConstraintViolationsException(String message, List<ConstraintViolation> violations) {
super(message);
this.violations = ConstraintViolations.of(violations);
}
public ConstraintViolationsException(List<ConstraintViolation> violations) {
this("Constraint violations found!" + System.lineSeparator()
+ ConstraintViolations.of(violations)
.violations()
.stream()
.map(ConstraintViolation::message)
.map(s -> "* " + s)
.collect(Collectors.joining(System.lineSeparator())),
violations);
}
public ConstraintViolations violations() {
return violations;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/CustomConstraint.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Objects;
import java.util.function.Predicate;
import am.ik.yavi.jsr305.Nullable;
public interface CustomConstraint<V> extends Predicate<V>, ViolationMessage, ViolatedArguments<V> {
Objects[] EMPTY_ARRAY = new Objects[0];
@Override
default Object[] arguments(@Nullable V violatedValue) {
return EMPTY_ARRAY;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/ErrorHandler.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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;
/**
* @param <E> error type
* @since 0.13.0
*/
public interface ErrorHandler<E> {
void handleError(E errors, String name, String messageKey, Object[] args, String defaultMessage);
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/NestedCollectionValidator.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Collection;
import java.util.function.Function;
import am.ik.yavi.jsr305.Nullable;
public class NestedCollectionValidator<T, C extends Collection<E>, E, N> extends CollectionValidator<T, C, E> {
private final Function<T, N> nested;
public NestedCollectionValidator(Function<T, C> toCollection, String name, Validator<E> validator,
Function<T, N> nested) {
super(toCollection, name, validator);
this.nested = nested;
}
@Nullable
public N nestedCollection(T target) {
return nested.apply(target);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/NestedConstraintCondition.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Function;
public class NestedConstraintCondition<T, N> implements ConstraintCondition<T> {
private final Function<T, N> nested;
private final ConstraintCondition<N> constraintCondition;
public NestedConstraintCondition(Function<T, N> nested, ConstraintCondition<N> constraintCondition) {
this.nested = nested;
this.constraintCondition = constraintCondition;
}
@Override
public boolean test(T t, ConstraintContext constraintContext) {
final N n = this.nested.apply(t);
if (n == null) {
return false;
}
return this.constraintCondition.test(n, constraintContext);
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/NestedConstraintPredicates.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Deque;
import java.util.function.Function;
import am.ik.yavi.jsr305.Nullable;
public class NestedConstraintPredicates<T, V, N> extends ConstraintPredicates<T, V> {
private final Function<T, N> nested;
private final boolean failFast;
public NestedConstraintPredicates(Function<T, V> toValue, String name,
Deque<ConstraintPredicate<V>> constraintPredicates, Function<T, N> nested, boolean failFast) {
super(toValue, name, constraintPredicates);
this.nested = nested;
this.failFast = failFast;
}
@Nullable
public N nestedValue(T target) {
return nested.apply(target);
}
/**
* Returns whether it is failFast.
* @return whether it is failFast
* @since 0.13.0
*/
public boolean isFailFast() {
return this.failFast;
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/NestedValidator.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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.Locale;
import java.util.function.Function;
public class NestedValidator<T, N> implements Validatable<T> {
private final Function<T, N> nested;
private final Validatable<N> validator;
private final String prefix;
public NestedValidator(Function<T, N> nested, Validatable<N> validator, String prefix) {
this.nested = nested;
this.prefix = prefix;
this.validator = prefixedValidatorIfNeeded(validator, prefix);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private Validatable<N> prefixedValidatorIfNeeded(Validatable<N> validator, String prefix) {
if (validator instanceof NestedValidator) {
final NestedValidator<?, N> nestedValidator = (NestedValidator<?, N>) validator;
return new NestedValidator(nestedValidator.nested, nestedValidator.validator, prefix);
}
return (validator instanceof Validator) ? ((Validator<N>) validator).prefixed(prefix) : validator;
}
@Override
public ConstraintViolations validate(T target, Locale locale, ConstraintContext constraintContext) {
final N n = this.nested.apply(target);
if (n != null) {
return this.validator.validate(n, locale, constraintContext);
}
else {
return new ConstraintViolations();
}
}
public String getPrefix() {
return prefix;
}
/**
* @since 0.13.1
*/
@Override
public Validatable<T> failFast(boolean failFast) {
final Validatable<N> validatable = this.validator.failFast(failFast);
return new NestedValidator<>(this.nested, validatable, prefix);
}
/**
* @since 0.13.1
*/
@Override
public boolean isFailFast() {
return this.validator.isFailFast();
}
}
|
0 | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi | java-sources/am/ik/yavi/yavi/0.16.0/am/ik/yavi/core/NullAs.java | /*
* Copyright (C) 2018-2025 Toshiaki Maki <makingx@gmail.com>
*
* 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;
public enum NullAs {
INVALID(false), VALID(true);
private final boolean skipNull;
NullAs(boolean skipNull) {
this.skipNull = skipNull;
}
public boolean skipNull() {
return this.skipNull;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.