forked from plusone/plusone-validator
refactor: 修改类型参数名称
This commit is contained in:
parent
e38be765a7
commit
9f2ade6252
@ -21,13 +21,10 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
import com.google.common.collect.Range;
|
import com.google.common.collect.Range;
|
||||||
|
|
||||||
public abstract
|
public abstract class BaseComparablePropertyValidator<T, TProperty extends Comparable<TProperty>, TPropertyValidator extends BaseComparablePropertyValidator<T, TProperty, TPropertyValidator>>
|
||||||
class BaseComparablePropertyValidator<TObj,
|
extends BasePropertyValidator<T, TProperty, TPropertyValidator> {
|
||||||
TProperty extends Comparable<TProperty>,
|
|
||||||
TPropertyValidator extends BaseComparablePropertyValidator<TObj, TProperty, TPropertyValidator>>
|
|
||||||
extends BasePropertyValidator<TObj, TProperty, TPropertyValidator> {
|
|
||||||
|
|
||||||
BaseComparablePropertyValidator(Function<TObj, ? extends TProperty> getter) {
|
BaseComparablePropertyValidator(Function<T, ? extends TProperty> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,16 +25,13 @@ import java.util.function.Function;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public abstract class BasePropertyValidator< //
|
public abstract class BasePropertyValidator<T, TProperty, TPropertyValidator extends BasePropertyValidator<T, TProperty, TPropertyValidator>> {
|
||||||
TObj, //
|
|
||||||
TProperty, //
|
|
||||||
TPropertyValidator extends BasePropertyValidator<TObj, TProperty, TPropertyValidator>> {
|
|
||||||
|
|
||||||
private final Function<TObj, ? extends TProperty> getter;
|
private final Function<T, ? extends TProperty> getter;
|
||||||
|
|
||||||
private final List<Consumer<? super TProperty>> consumers = new LinkedList<>();
|
private final List<Consumer<? super TProperty>> consumers = new LinkedList<>();
|
||||||
|
|
||||||
protected BasePropertyValidator(Function<TObj, ? extends TProperty> getter) {
|
protected BasePropertyValidator(Function<T, ? extends TProperty> getter) {
|
||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +59,7 @@ public abstract class BasePropertyValidator< //
|
|||||||
return thisObject();
|
return thisObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final <T extends TObj> void validate(T obj) {
|
public final void validate(T obj) {
|
||||||
for (Consumer<? super TProperty> consumer : consumers) {
|
for (Consumer<? super TProperty> consumer : consumers) {
|
||||||
consumer.accept(getter.apply(obj));
|
consumer.accept(getter.apply(obj));
|
||||||
}
|
}
|
||||||
|
@ -19,28 +19,28 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class BoolPropertyValidator<DTO> extends BasePropertyValidator<DTO, Boolean, BoolPropertyValidator<DTO>> {
|
public class BoolPropertyValidator<T> extends BasePropertyValidator<T, Boolean, BoolPropertyValidator<T>> {
|
||||||
|
|
||||||
BoolPropertyValidator(Function<DTO, Boolean> getter) {
|
BoolPropertyValidator(Function<T, Boolean> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====== isTrueValue ======
|
// ====== isTrueValue ======
|
||||||
|
|
||||||
public BoolPropertyValidator<DTO> isTrueValue() {
|
public BoolPropertyValidator<T> isTrueValue() {
|
||||||
return isTrueValue("The value must be true.");
|
return isTrueValue("The value must be true.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoolPropertyValidator<DTO> isTrueValue(String errMsg) {
|
public BoolPropertyValidator<T> isTrueValue(String errMsg) {
|
||||||
return isTrueValue(convertExceptionCreator(errMsg));
|
return isTrueValue(convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> BoolPropertyValidator<DTO> isTrueValue(
|
public <E extends RuntimeException> BoolPropertyValidator<T> isTrueValue(
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return isTrueValue(convertExceptionCreator(exceptionCreator));
|
return isTrueValue(convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> BoolPropertyValidator<DTO> isTrueValue(
|
public <E extends RuntimeException> BoolPropertyValidator<T> isTrueValue(
|
||||||
Function<Boolean, E> exceptionCreator) {
|
Function<Boolean, E> exceptionCreator) {
|
||||||
withRule(Boolean.TRUE::equals, exceptionCreator);
|
withRule(Boolean.TRUE::equals, exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -48,27 +48,27 @@ public class BoolPropertyValidator<DTO> extends BasePropertyValidator<DTO, Boole
|
|||||||
|
|
||||||
// ====== isFalseValue ======
|
// ====== isFalseValue ======
|
||||||
|
|
||||||
public BoolPropertyValidator<DTO> isFalseValue() {
|
public BoolPropertyValidator<T> isFalseValue() {
|
||||||
return isFalseValue("The value must be false.");
|
return isFalseValue("The value must be false.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoolPropertyValidator<DTO> isFalseValue(String errMsg) {
|
public BoolPropertyValidator<T> isFalseValue(String errMsg) {
|
||||||
return isFalseValue(convertExceptionCreator(errMsg));
|
return isFalseValue(convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> BoolPropertyValidator<DTO> isFalseValue(
|
public <E extends RuntimeException> BoolPropertyValidator<T> isFalseValue(
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return isFalseValue(convertExceptionCreator(exceptionCreator));
|
return isFalseValue(convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> BoolPropertyValidator<DTO> isFalseValue(
|
public <E extends RuntimeException> BoolPropertyValidator<T> isFalseValue(
|
||||||
Function<Boolean, E> exceptionCreator) {
|
Function<Boolean, E> exceptionCreator) {
|
||||||
withRule(Boolean.FALSE::equals, exceptionCreator);
|
withRule(Boolean.FALSE::equals, exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BoolPropertyValidator<DTO> thisObject() {
|
protected BoolPropertyValidator<T> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,47 +22,47 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.collection.CollectionTools;
|
import xyz.zhouxy.plusone.commons.collection.CollectionTools;
|
||||||
|
|
||||||
public class CollectionPropertyValidator<DTO, T>
|
public class CollectionPropertyValidator<T, TElement>
|
||||||
extends BasePropertyValidator<DTO, Collection<T>, CollectionPropertyValidator<DTO, T>> {
|
extends BasePropertyValidator<T, Collection<TElement>, CollectionPropertyValidator<T, TElement>> {
|
||||||
|
|
||||||
CollectionPropertyValidator(Function<DTO, Collection<T>> getter) {
|
CollectionPropertyValidator(Function<T, Collection<TElement>> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====== notEmpty =====
|
// ====== notEmpty =====
|
||||||
|
|
||||||
public CollectionPropertyValidator<DTO, T> notEmpty(String errMsg) {
|
public CollectionPropertyValidator<T, TElement> notEmpty(String errMsg) {
|
||||||
return notEmpty(convertExceptionCreator(errMsg));
|
return notEmpty(convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> notEmpty(Supplier<E> exceptionCreator) {
|
public <E extends RuntimeException> CollectionPropertyValidator<T, TElement> notEmpty(Supplier<E> exceptionCreator) {
|
||||||
return notEmpty(convertExceptionCreator(exceptionCreator));
|
return notEmpty(convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> notEmpty(
|
public <E extends RuntimeException> CollectionPropertyValidator<T, TElement> notEmpty(
|
||||||
Function<Collection<T>, E> exceptionCreator) {
|
Function<Collection<TElement>, E> exceptionCreator) {
|
||||||
withRule(CollectionTools::isNotEmpty, exceptionCreator);
|
withRule(CollectionTools::isNotEmpty, exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====== isEmpty =====
|
// ====== isEmpty =====
|
||||||
|
|
||||||
public CollectionPropertyValidator<DTO, T> isEmpty(String errMsg) {
|
public CollectionPropertyValidator<T, TElement> isEmpty(String errMsg) {
|
||||||
return isEmpty(convertExceptionCreator(errMsg));
|
return isEmpty(convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> isEmpty(Supplier<E> exceptionCreator) {
|
public <E extends RuntimeException> CollectionPropertyValidator<T, TElement> isEmpty(Supplier<E> exceptionCreator) {
|
||||||
return isEmpty(convertExceptionCreator(exceptionCreator));
|
return isEmpty(convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> isEmpty(
|
public <E extends RuntimeException> CollectionPropertyValidator<T, TElement> isEmpty(
|
||||||
Function<Collection<T>, E> exceptionCreator) {
|
Function<Collection<TElement>, E> exceptionCreator) {
|
||||||
withRule(CollectionTools::isEmpty, exceptionCreator);
|
withRule(CollectionTools::isEmpty, exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected CollectionPropertyValidator<DTO, T> thisObject() {
|
protected CollectionPropertyValidator<T, TElement> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,15 +18,15 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ComparablePropertyValidator<TObj, TProperty extends Comparable<TProperty>>
|
public class ComparablePropertyValidator<T, TProperty extends Comparable<TProperty>>
|
||||||
extends BaseComparablePropertyValidator<TObj, TProperty, ComparablePropertyValidator<TObj, TProperty>> {
|
extends BaseComparablePropertyValidator<T, TProperty, ComparablePropertyValidator<T, TProperty>> {
|
||||||
|
|
||||||
ComparablePropertyValidator(Function<TObj, ? extends TProperty> getter) {
|
ComparablePropertyValidator(Function<T, ? extends TProperty> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ComparablePropertyValidator<TObj, TProperty> thisObject() {
|
protected ComparablePropertyValidator<T, TProperty> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class DoublePropertyValidator<DTO>
|
public class DoublePropertyValidator<T>
|
||||||
extends BaseComparablePropertyValidator<DTO, Double, DoublePropertyValidator<DTO>> {
|
extends BaseComparablePropertyValidator<T, Double, DoublePropertyValidator<T>> {
|
||||||
|
|
||||||
DoublePropertyValidator(Function<DTO, Double> getter) {
|
DoublePropertyValidator(Function<T, Double> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,20 +30,20 @@ public class DoublePropertyValidator<DTO>
|
|||||||
// #region - greater than
|
// #region - greater than
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> gt(double min) {
|
public DoublePropertyValidator<T> gt(double min) {
|
||||||
return gt(min, String.format("The value should be greater than %s", min));
|
return gt(min, String.format("The value should be greater than %s", min));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> gt(double min, String errMsg) {
|
public DoublePropertyValidator<T> gt(double min, String errMsg) {
|
||||||
return gt(min, convertExceptionCreator(errMsg));
|
return gt(min, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> gt(
|
public <E extends RuntimeException> DoublePropertyValidator<T> gt(
|
||||||
double min, Supplier<E> exceptionCreator) {
|
double min, Supplier<E> exceptionCreator) {
|
||||||
return gt(min, convertExceptionCreator(exceptionCreator));
|
return gt(min, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> gt(
|
public <E extends RuntimeException> DoublePropertyValidator<T> gt(
|
||||||
double min, Function<Double, E> exceptionCreator) {
|
double min, Function<Double, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value > min), exceptionCreator);
|
withRule(value -> (value != null && value > min), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -57,20 +57,20 @@ public class DoublePropertyValidator<DTO>
|
|||||||
// #region - greater than or equal to
|
// #region - greater than or equal to
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> ge(double min) {
|
public DoublePropertyValidator<T> ge(double min) {
|
||||||
return ge(min, String.format("The value should be greater than or equal to %s", min));
|
return ge(min, String.format("The value should be greater than or equal to %s", min));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> ge(double min, String errMsg) {
|
public DoublePropertyValidator<T> ge(double min, String errMsg) {
|
||||||
return ge(min, convertExceptionCreator(errMsg));
|
return ge(min, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> ge(
|
public <E extends RuntimeException> DoublePropertyValidator<T> ge(
|
||||||
double min, Supplier<E> exceptionCreator) {
|
double min, Supplier<E> exceptionCreator) {
|
||||||
return ge(min, convertExceptionCreator(exceptionCreator));
|
return ge(min, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> ge(
|
public <E extends RuntimeException> DoublePropertyValidator<T> ge(
|
||||||
double min, Function<Double, E> exceptionCreator) {
|
double min, Function<Double, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value >= min), exceptionCreator);
|
withRule(value -> (value != null && value >= min), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -84,20 +84,20 @@ public class DoublePropertyValidator<DTO>
|
|||||||
// #region - less than
|
// #region - less than
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> lt(double max) {
|
public DoublePropertyValidator<T> lt(double max) {
|
||||||
return lt(max, String.format("The value should be less than %s", max));
|
return lt(max, String.format("The value should be less than %s", max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> lt(double max, String errMsg) {
|
public DoublePropertyValidator<T> lt(double max, String errMsg) {
|
||||||
return lt(max, convertExceptionCreator(errMsg));
|
return lt(max, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> lt(
|
public <E extends RuntimeException> DoublePropertyValidator<T> lt(
|
||||||
double max, Supplier<E> exceptionCreator) {
|
double max, Supplier<E> exceptionCreator) {
|
||||||
return lt(max, convertExceptionCreator(exceptionCreator));
|
return lt(max, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> lt(
|
public <E extends RuntimeException> DoublePropertyValidator<T> lt(
|
||||||
double max, Function<Double, E> exceptionCreator) {
|
double max, Function<Double, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value < max), exceptionCreator);
|
withRule(value -> (value != null && value < max), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -111,20 +111,20 @@ public class DoublePropertyValidator<DTO>
|
|||||||
// #region - less than or equal to
|
// #region - less than or equal to
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> le(double max) {
|
public DoublePropertyValidator<T> le(double max) {
|
||||||
return le(max, String.format("The value should be less than or equal to %s", max));
|
return le(max, String.format("The value should be less than or equal to %s", max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoublePropertyValidator<DTO> le(double max, String errMsg) {
|
public DoublePropertyValidator<T> le(double max, String errMsg) {
|
||||||
return le(max, convertExceptionCreator(errMsg));
|
return le(max, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> le(
|
public <E extends RuntimeException> DoublePropertyValidator<T> le(
|
||||||
double max, Supplier<E> exceptionCreator) {
|
double max, Supplier<E> exceptionCreator) {
|
||||||
return le(max, convertExceptionCreator(exceptionCreator));
|
return le(max, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> DoublePropertyValidator<DTO> le(
|
public <E extends RuntimeException> DoublePropertyValidator<T> le(
|
||||||
double max, Function<Double, E> exceptionCreator) {
|
double max, Function<Double, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value <= max), exceptionCreator);
|
withRule(value -> (value != null && value <= max), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -135,7 +135,7 @@ public class DoublePropertyValidator<DTO>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DoublePropertyValidator<DTO> thisObject() {
|
protected DoublePropertyValidator<T> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class IntPropertyValidator<DTO>
|
public class IntPropertyValidator<T>
|
||||||
extends BaseComparablePropertyValidator<DTO, Integer, IntPropertyValidator<DTO>> {
|
extends BaseComparablePropertyValidator<T, Integer, IntPropertyValidator<T>> {
|
||||||
|
|
||||||
IntPropertyValidator(Function<DTO, Integer> getter) {
|
IntPropertyValidator(Function<T, Integer> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,20 +30,20 @@ public class IntPropertyValidator<DTO>
|
|||||||
// #region - greater than
|
// #region - greater than
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> gt(int min) {
|
public IntPropertyValidator<T> gt(int min) {
|
||||||
return gt(min, String.format("The value should be greater than %d", min));
|
return gt(min, String.format("The value should be greater than %d", min));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> gt(int min, String errMsg) {
|
public IntPropertyValidator<T> gt(int min, String errMsg) {
|
||||||
return gt(min, convertExceptionCreator(errMsg));
|
return gt(min, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> gt(
|
public <E extends RuntimeException> IntPropertyValidator<T> gt(
|
||||||
int min, Supplier<E> exceptionCreator) {
|
int min, Supplier<E> exceptionCreator) {
|
||||||
return gt(min, convertExceptionCreator(exceptionCreator));
|
return gt(min, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> gt(
|
public <E extends RuntimeException> IntPropertyValidator<T> gt(
|
||||||
int min, Function<Integer, E> exceptionCreator) {
|
int min, Function<Integer, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value > min), exceptionCreator);
|
withRule(value -> (value != null && value > min), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -57,20 +57,20 @@ public class IntPropertyValidator<DTO>
|
|||||||
// #region - greater than or equal to
|
// #region - greater than or equal to
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> ge(int min) {
|
public IntPropertyValidator<T> ge(int min) {
|
||||||
return ge(min, String.format("The value should be greater than or equal to %d", min));
|
return ge(min, String.format("The value should be greater than or equal to %d", min));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> ge(int min, String errMsg) {
|
public IntPropertyValidator<T> ge(int min, String errMsg) {
|
||||||
return ge(min, convertExceptionCreator(errMsg));
|
return ge(min, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> ge(
|
public <E extends RuntimeException> IntPropertyValidator<T> ge(
|
||||||
int min, Supplier<E> exceptionCreator) {
|
int min, Supplier<E> exceptionCreator) {
|
||||||
return ge(min, convertExceptionCreator(exceptionCreator));
|
return ge(min, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> ge(
|
public <E extends RuntimeException> IntPropertyValidator<T> ge(
|
||||||
int min, Function<Integer, E> exceptionCreator) {
|
int min, Function<Integer, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value >= min), exceptionCreator);
|
withRule(value -> (value != null && value >= min), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -84,20 +84,20 @@ public class IntPropertyValidator<DTO>
|
|||||||
// #region - less than
|
// #region - less than
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> lt(int max) {
|
public IntPropertyValidator<T> lt(int max) {
|
||||||
return lt(max, String.format("The value should be less than %d", max));
|
return lt(max, String.format("The value should be less than %d", max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> lt(int max, String errMsg) {
|
public IntPropertyValidator<T> lt(int max, String errMsg) {
|
||||||
return lt(max, convertExceptionCreator(errMsg));
|
return lt(max, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> lt(
|
public <E extends RuntimeException> IntPropertyValidator<T> lt(
|
||||||
int max, Supplier<E> exceptionCreator) {
|
int max, Supplier<E> exceptionCreator) {
|
||||||
return lt(max, convertExceptionCreator(exceptionCreator));
|
return lt(max, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> lt(
|
public <E extends RuntimeException> IntPropertyValidator<T> lt(
|
||||||
int max, Function<Integer, E> exceptionCreator) {
|
int max, Function<Integer, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value < max), exceptionCreator);
|
withRule(value -> (value != null && value < max), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -111,20 +111,20 @@ public class IntPropertyValidator<DTO>
|
|||||||
// #region - less than or equal to
|
// #region - less than or equal to
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> le(int max) {
|
public IntPropertyValidator<T> le(int max) {
|
||||||
return le(max, String.format("The value should be less than or equal to %d", max));
|
return le(max, String.format("The value should be less than or equal to %d", max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPropertyValidator<DTO> le(int max, String errMsg) {
|
public IntPropertyValidator<T> le(int max, String errMsg) {
|
||||||
return le(max, convertExceptionCreator(errMsg));
|
return le(max, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> le(
|
public <E extends RuntimeException> IntPropertyValidator<T> le(
|
||||||
int max, Supplier<E> exceptionCreator) {
|
int max, Supplier<E> exceptionCreator) {
|
||||||
return le(max, convertExceptionCreator(exceptionCreator));
|
return le(max, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> IntPropertyValidator<DTO> le(
|
public <E extends RuntimeException> IntPropertyValidator<T> le(
|
||||||
int max, Function<Integer, E> exceptionCreator) {
|
int max, Function<Integer, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value <= max), exceptionCreator);
|
withRule(value -> (value != null && value <= max), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -135,7 +135,7 @@ public class IntPropertyValidator<DTO>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IntPropertyValidator<DTO> thisObject() {
|
protected IntPropertyValidator<T> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,10 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class LongPropertyValidator<DTO>
|
public class LongPropertyValidator<T>
|
||||||
extends BaseComparablePropertyValidator<DTO, Long, LongPropertyValidator<DTO>> {
|
extends BaseComparablePropertyValidator<T, Long, LongPropertyValidator<T>> {
|
||||||
|
|
||||||
LongPropertyValidator(Function<DTO, Long> getter) {
|
LongPropertyValidator(Function<T, Long> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,20 +30,20 @@ public class LongPropertyValidator<DTO>
|
|||||||
// #region - greater than
|
// #region - greater than
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> gt(long min) {
|
public LongPropertyValidator<T> gt(long min) {
|
||||||
return gt(min, String.format("The value should be greater than %d", min));
|
return gt(min, String.format("The value should be greater than %d", min));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> gt(long min, String errMsg) {
|
public LongPropertyValidator<T> gt(long min, String errMsg) {
|
||||||
return gt(min, convertExceptionCreator(errMsg));
|
return gt(min, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> gt(
|
public <E extends RuntimeException> LongPropertyValidator<T> gt(
|
||||||
long min, Supplier<E> exceptionCreator) {
|
long min, Supplier<E> exceptionCreator) {
|
||||||
return gt(min, convertExceptionCreator(exceptionCreator));
|
return gt(min, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> gt(
|
public <E extends RuntimeException> LongPropertyValidator<T> gt(
|
||||||
long min, Function<Long, E> exceptionCreator) {
|
long min, Function<Long, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value > min), exceptionCreator);
|
withRule(value -> (value != null && value > min), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -57,20 +57,20 @@ public class LongPropertyValidator<DTO>
|
|||||||
// #region - greater than or equal to
|
// #region - greater than or equal to
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> ge(long min) {
|
public LongPropertyValidator<T> ge(long min) {
|
||||||
return ge(min, String.format("The value should be greater than or equal to %d", min));
|
return ge(min, String.format("The value should be greater than or equal to %d", min));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> ge(long min, String errMsg) {
|
public LongPropertyValidator<T> ge(long min, String errMsg) {
|
||||||
return ge(min, convertExceptionCreator(errMsg));
|
return ge(min, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> ge(
|
public <E extends RuntimeException> LongPropertyValidator<T> ge(
|
||||||
long min, Supplier<E> exceptionCreator) {
|
long min, Supplier<E> exceptionCreator) {
|
||||||
return ge(min, convertExceptionCreator(exceptionCreator));
|
return ge(min, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> ge(
|
public <E extends RuntimeException> LongPropertyValidator<T> ge(
|
||||||
long min, Function<Long, E> exceptionCreator) {
|
long min, Function<Long, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value >= min), exceptionCreator);
|
withRule(value -> (value != null && value >= min), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -84,20 +84,20 @@ public class LongPropertyValidator<DTO>
|
|||||||
// #region - less than
|
// #region - less than
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> lt(long max) {
|
public LongPropertyValidator<T> lt(long max) {
|
||||||
return lt(max, String.format("The value should be less than %d", max));
|
return lt(max, String.format("The value should be less than %d", max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> lt(long max, String errMsg) {
|
public LongPropertyValidator<T> lt(long max, String errMsg) {
|
||||||
return lt(max, convertExceptionCreator(errMsg));
|
return lt(max, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> lt(
|
public <E extends RuntimeException> LongPropertyValidator<T> lt(
|
||||||
long max, Supplier<E> exceptionCreator) {
|
long max, Supplier<E> exceptionCreator) {
|
||||||
return lt(max, convertExceptionCreator(exceptionCreator));
|
return lt(max, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> lt(
|
public <E extends RuntimeException> LongPropertyValidator<T> lt(
|
||||||
long max, Function<Long, E> exceptionCreator) {
|
long max, Function<Long, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value < max), exceptionCreator);
|
withRule(value -> (value != null && value < max), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -111,20 +111,20 @@ public class LongPropertyValidator<DTO>
|
|||||||
// #region - less than or equal to
|
// #region - less than or equal to
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> le(long max) {
|
public LongPropertyValidator<T> le(long max) {
|
||||||
return le(max, String.format("The value should be less than or equal to %d", max));
|
return le(max, String.format("The value should be less than or equal to %d", max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LongPropertyValidator<DTO> le(long max, String errMsg) {
|
public LongPropertyValidator<T> le(long max, String errMsg) {
|
||||||
return le(max, convertExceptionCreator(errMsg));
|
return le(max, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> le(
|
public <E extends RuntimeException> LongPropertyValidator<T> le(
|
||||||
long max, Supplier<E> exceptionCreator) {
|
long max, Supplier<E> exceptionCreator) {
|
||||||
return le(max, convertExceptionCreator(exceptionCreator));
|
return le(max, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> LongPropertyValidator<DTO> le(
|
public <E extends RuntimeException> LongPropertyValidator<T> le(
|
||||||
long max, Function<Long, E> exceptionCreator) {
|
long max, Function<Long, E> exceptionCreator) {
|
||||||
withRule(value -> (value != null && value <= max), exceptionCreator);
|
withRule(value -> (value != null && value <= max), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -135,7 +135,7 @@ public class LongPropertyValidator<DTO>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LongPropertyValidator<DTO> thisObject() {
|
protected LongPropertyValidator<T> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,14 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ObjectPropertyValidator<DTO, T> extends BasePropertyValidator<DTO, T, ObjectPropertyValidator<DTO, T>> {
|
public class ObjectPropertyValidator<T, TProperty> extends BasePropertyValidator<T, TProperty, ObjectPropertyValidator<T, TProperty>> {
|
||||||
|
|
||||||
ObjectPropertyValidator(Function<DTO, T> getter) {
|
ObjectPropertyValidator(Function<T, TProperty> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ObjectPropertyValidator<DTO, T> thisObject() {
|
protected ObjectPropertyValidator<T, TProperty> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,9 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidator<DTO, String, StringPropertyValidator<DTO>> {
|
public class StringPropertyValidator<T> extends BaseComparablePropertyValidator<T, String, StringPropertyValidator<T>> {
|
||||||
|
|
||||||
StringPropertyValidator(Function<DTO, String> getter) {
|
StringPropertyValidator(Function<T, String> getter) {
|
||||||
super(getter);
|
super(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,17 +46,17 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// #region - matches
|
// #region - matches
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> matches(Pattern regex, String errMsg) {
|
public StringPropertyValidator<T> matches(Pattern regex, String errMsg) {
|
||||||
return matches(regex, convertExceptionCreator(errMsg));
|
return matches(regex, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matches(
|
public <E extends RuntimeException> StringPropertyValidator<T> matches(
|
||||||
Pattern regex,
|
Pattern regex,
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return matches(regex, convertExceptionCreator(exceptionCreator));
|
return matches(regex, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matches(
|
public <E extends RuntimeException> StringPropertyValidator<T> matches(
|
||||||
Pattern regex,
|
Pattern regex,
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
withRule(input -> (input == null || RegexTools.matches(input, regex)), exceptionCreator);
|
withRule(input -> (input == null || RegexTools.matches(input, regex)), exceptionCreator);
|
||||||
@ -71,34 +71,34 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// #region - matchesOne
|
// #region - matchesOne
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> matchesOne(Pattern[] regexs, String errMsg) {
|
public StringPropertyValidator<T> matchesOne(Pattern[] regexs, String errMsg) {
|
||||||
return matchesOne(regexs, convertExceptionCreator(errMsg));
|
return matchesOne(regexs, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesOne(
|
||||||
Pattern[] regexs,
|
Pattern[] regexs,
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
|
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesOne(
|
||||||
Pattern[] regexs,
|
Pattern[] regexs,
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
withRule(input -> RegexTools.matchesOne(input, regexs), exceptionCreator);
|
withRule(input -> RegexTools.matchesOne(input, regexs), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> matchesOne(List<Pattern> regexs, String errMsg) {
|
public StringPropertyValidator<T> matchesOne(List<Pattern> regexs, String errMsg) {
|
||||||
return matchesOne(regexs, convertExceptionCreator(errMsg));
|
return matchesOne(regexs, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesOne(
|
||||||
List<Pattern> regexs,
|
List<Pattern> regexs,
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
|
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesOne(
|
||||||
List<Pattern> regexs,
|
List<Pattern> regexs,
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
withRule(input -> input == null || RegexTools.matchesOne(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
|
withRule(input -> input == null || RegexTools.matchesOne(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
|
||||||
@ -113,34 +113,34 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// #region - matchesAll
|
// #region - matchesAll
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> matchesAll(Pattern[] regexs, String errMsg) {
|
public StringPropertyValidator<T> matchesAll(Pattern[] regexs, String errMsg) {
|
||||||
return matchesAll(regexs, convertExceptionCreator(errMsg));
|
return matchesAll(regexs, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
Pattern[] regexs,
|
Pattern[] regexs,
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
|
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
Pattern[] regexs,
|
Pattern[] regexs,
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
withRule(input -> RegexTools.matchesAll(input, regexs), exceptionCreator);
|
withRule(input -> RegexTools.matchesAll(input, regexs), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> matchesAll(Collection<Pattern> regexs, String errMsg) {
|
public StringPropertyValidator<T> matchesAll(Collection<Pattern> regexs, String errMsg) {
|
||||||
return matchesAll(regexs, convertExceptionCreator(errMsg));
|
return matchesAll(regexs, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
Collection<Pattern> regexs,
|
Collection<Pattern> regexs,
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
|
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
|
public <E extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
Collection<Pattern> regexs,
|
Collection<Pattern> regexs,
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
withRule(input -> input == null || RegexTools.matchesAll(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
|
withRule(input -> input == null || RegexTools.matchesAll(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
|
||||||
@ -155,19 +155,19 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// #region - notBlank
|
// #region - notBlank
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> notBlank() {
|
public StringPropertyValidator<T> notBlank() {
|
||||||
return notBlank("The value must have text; it must not be null, empty, or blank.");
|
return notBlank("The value must have text; it must not be null, empty, or blank.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> notBlank(String errMsg) {
|
public StringPropertyValidator<T> notBlank(String errMsg) {
|
||||||
return notBlank(convertExceptionCreator(errMsg));
|
return notBlank(convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> notBlank(Supplier<E> exceptionCreator) {
|
public <E extends RuntimeException> StringPropertyValidator<T> notBlank(Supplier<E> exceptionCreator) {
|
||||||
return notBlank(convertExceptionCreator(exceptionCreator));
|
return notBlank(convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> notBlank(
|
public <E extends RuntimeException> StringPropertyValidator<T> notBlank(
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
withRule(StringTools::isNotBlank, exceptionCreator);
|
withRule(StringTools::isNotBlank, exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -181,20 +181,20 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// #region - emailAddress
|
// #region - emailAddress
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> emailAddress() {
|
public StringPropertyValidator<T> emailAddress() {
|
||||||
return emailAddress("The value is not an email address.");
|
return emailAddress("The value is not an email address.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> emailAddress(String errMsg) {
|
public StringPropertyValidator<T> emailAddress(String errMsg) {
|
||||||
return emailAddress(convertExceptionCreator(errMsg));
|
return emailAddress(convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> emailAddress(
|
public <E extends RuntimeException> StringPropertyValidator<T> emailAddress(
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return emailAddress(convertExceptionCreator(exceptionCreator));
|
return emailAddress(convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> emailAddress(
|
public <E extends RuntimeException> StringPropertyValidator<T> emailAddress(
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
return matches(PatternConsts.EMAIL, exceptionCreator);
|
return matches(PatternConsts.EMAIL, exceptionCreator);
|
||||||
}
|
}
|
||||||
@ -207,19 +207,19 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// #region - notEmpty
|
// #region - notEmpty
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> notEmpty() {
|
public StringPropertyValidator<T> notEmpty() {
|
||||||
return notEmpty("The value must not be empty.");
|
return notEmpty("The value must not be empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> notEmpty(String errMsg) {
|
public StringPropertyValidator<T> notEmpty(String errMsg) {
|
||||||
return notEmpty(convertExceptionCreator(errMsg));
|
return notEmpty(convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> notEmpty(Supplier<E> exceptionCreator) {
|
public <E extends RuntimeException> StringPropertyValidator<T> notEmpty(Supplier<E> exceptionCreator) {
|
||||||
return notEmpty(convertExceptionCreator(exceptionCreator));
|
return notEmpty(convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> notEmpty(
|
public <E extends RuntimeException> StringPropertyValidator<T> notEmpty(
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
withRule(s -> s != null && !s.isEmpty(), exceptionCreator);
|
withRule(s -> s != null && !s.isEmpty(), exceptionCreator);
|
||||||
return this;
|
return this;
|
||||||
@ -233,16 +233,16 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// #region - length
|
// #region - length
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> length(int length, String errMsg) {
|
public StringPropertyValidator<T> length(int length, String errMsg) {
|
||||||
return length(length, convertExceptionCreator(errMsg));
|
return length(length, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int length,
|
public <E extends RuntimeException> StringPropertyValidator<T> length(int length,
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return length(length, convertExceptionCreator(exceptionCreator));
|
return length(length, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int length,
|
public <E extends RuntimeException> StringPropertyValidator<T> length(int length,
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
AssertTools.checkArgument(length >= 0,
|
AssertTools.checkArgument(length >= 0,
|
||||||
"The required length must be greater than or equal to 0.");
|
"The required length must be greater than or equal to 0.");
|
||||||
@ -258,16 +258,16 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
return len >= min && len <= max;
|
return len >= min && len <= max;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringPropertyValidator<DTO> length(int min, int max, String errMsg) {
|
public StringPropertyValidator<T> length(int min, int max, String errMsg) {
|
||||||
return length(min, max, convertExceptionCreator(errMsg));
|
return length(min, max, convertExceptionCreator(errMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int min, int max,
|
public <E extends RuntimeException> StringPropertyValidator<T> length(int min, int max,
|
||||||
Supplier<E> exceptionCreator) {
|
Supplier<E> exceptionCreator) {
|
||||||
return length(min, max, convertExceptionCreator(exceptionCreator));
|
return length(min, max, convertExceptionCreator(exceptionCreator));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int min, int max,
|
public <E extends RuntimeException> StringPropertyValidator<T> length(int min, int max,
|
||||||
Function<String, E> exceptionCreator) {
|
Function<String, E> exceptionCreator) {
|
||||||
AssertTools.checkArgument(min >= 0, "The minimum value must be greater than equal to 0.");
|
AssertTools.checkArgument(min >= 0, "The minimum value must be greater than equal to 0.");
|
||||||
AssertTools.checkArgument(min < max, "The minimum value must be less than the maximum value.");
|
AssertTools.checkArgument(min < max, "The minimum value must be less than the maximum value.");
|
||||||
@ -280,7 +280,7 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected StringPropertyValidator<DTO> thisObject() {
|
protected StringPropertyValidator<T> thisObject() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user