net.croz.nrich.validation.api.constraint.ValidRange Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2020-2023 CROZ d.o.o, the original author or authors.
*
* 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
*
* https://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 net.croz.nrich.validation.api.constraint;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Annotated element from property must be less than (or equal to if inclusive is true) to property.
*/
@SuppressWarnings("unused")
@Target({ ANNOTATION_TYPE, TYPE_USE, TYPE })
@Retention(RUNTIME)
@Repeatable(ValidRange.List.class)
@Documented
@Constraint(validatedBy = {})
public @interface ValidRange {
String message() default "{nrich.constraint.range.invalid.message}";
Class>[] groups() default {};
Class extends Payload>[] payload() default {};
/**
* Name of from property.
*
* @return name of from property
*/
String fromPropertyName();
/**
* Name of to property.
*
* @return name of to property
*/
String toPropertyName();
/**
* Whether from property can be equal to property.
*
* @return whether property from can be equal to property
*/
boolean inclusive() default false;
/**
* Defines several {@link ValidRange} annotations on the same element.
*
* @see ValidRange
*/
@Target({ ANNOTATION_TYPE, TYPE_USE, TYPE })
@Retention(RUNTIME)
@Documented
@interface List {
ValidRange[] value();
}
}