refactor!: 重命名不同属性的 validator #5

Merged
ZhouXY108 merged 1 commits from :refactor/rename into prepare/1.0.0 2025-05-18 13:11:04 +08:00
13 changed files with 139 additions and 141 deletions
Showing only changes of commit 0810082c96 - Show all commits

View File

@ -45,50 +45,50 @@ public abstract class BaseValidator<T> {
this.rules.add(rule);
}
protected final <R> ObjectValidator<T, R> ruleFor(Function<T, R> getter) {
ObjectValidator<T, R> validator = new ObjectValidator<>(getter);
protected final <R> ObjectPropertyValidator<T, R> ruleFor(Function<T, R> getter) {
ObjectPropertyValidator<T, R> validator = new ObjectPropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}
protected final <R extends Comparable<R>> DefaultValidatorOfComparable<T, R> ruleForComparable(Function<T, R> getter) {
DefaultValidatorOfComparable<T, R> validator = new DefaultValidatorOfComparable<>(getter);
protected final <R extends Comparable<R>> DefaultComparablePropertyValidator<T, R> ruleForComparable(Function<T, R> getter) {
DefaultComparablePropertyValidator<T, R> validator = new DefaultComparablePropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}
protected final IntValidator<T> ruleForInt(Function<T, Integer> getter) {
IntValidator<T> validator = new IntValidator<>(getter);
protected final IntPropertyValidator<T> ruleForInt(Function<T, Integer> getter) {
IntPropertyValidator<T> validator = new IntPropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}
protected final LongValidator<T> ruleForLong(Function<T, Long> getter) {
LongValidator<T> validator = new LongValidator<>(getter);
protected final LongPropertyValidator<T> ruleForLong(Function<T, Long> getter) {
LongPropertyValidator<T> validator = new LongPropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}
protected final DoubleValidator<T> ruleForDouble(Function<T, Double> getter) {
DoubleValidator<T> validator = new DoubleValidator<>(getter);
protected final DoublePropertyValidator<T> ruleForDouble(Function<T, Double> getter) {
DoublePropertyValidator<T> validator = new DoublePropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}
protected final BoolValidator<T> ruleForBool(Function<T, Boolean> getter) {
BoolValidator<T> validator = new BoolValidator<>(getter);
protected final BoolPropertyValidator<T> ruleForBool(Function<T, Boolean> getter) {
BoolPropertyValidator<T> validator = new BoolPropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}
protected final StringValidator<T> ruleForString(Function<T, String> getter) {
StringValidator<T> validator = new StringValidator<>(getter);
protected final StringPropertyValidator<T> ruleForString(Function<T, String> getter) {
StringPropertyValidator<T> validator = new StringPropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}
protected final <E> CollectionValidator<T, E> ruleForCollection(Function<T, Collection<E>> getter) {
CollectionValidator<T, E> validator = new CollectionValidator<>(getter);
protected final <E> CollectionPropertyValidator<T, E> ruleForCollection(Function<T, Collection<E>> getter) {
CollectionPropertyValidator<T, E> validator = new CollectionPropertyValidator<>(getter);
this.rules.add(validator::validate);
return validator;
}

View File

@ -3,27 +3,27 @@ package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
import java.util.function.Supplier;
public class BoolValidator<DTO> extends BasePropertyValidator<DTO, Boolean, BoolValidator<DTO>> {
public class BoolPropertyValidator<DTO> extends BasePropertyValidator<DTO, Boolean, BoolPropertyValidator<DTO>> {
BoolValidator(Function<DTO, Boolean> getter) {
BoolPropertyValidator(Function<DTO, Boolean> getter) {
super(getter);
}
// ====== isTrue ======
public BoolValidator<DTO> isTrue() {
public BoolPropertyValidator<DTO> isTrue() {
return isTrue("The value must be true.");
}
public BoolValidator<DTO> isTrue(String errMsg) {
public BoolPropertyValidator<DTO> isTrue(String errMsg) {
return isTrue(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> BoolValidator<DTO> isTrue(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> BoolPropertyValidator<DTO> isTrue(Supplier<E> exceptionCreator) {
return isTrue(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> BoolValidator<DTO> isTrue(
public <E extends RuntimeException> BoolPropertyValidator<DTO> isTrue(
Function<Boolean, E> exceptionCreator) {
withRule(Boolean.TRUE::equals, exceptionCreator);
return this;
@ -31,26 +31,26 @@ public class BoolValidator<DTO> extends BasePropertyValidator<DTO, Boolean, Bool
// ====== isFalse ======
public BoolValidator<DTO> isFalse() {
public BoolPropertyValidator<DTO> isFalse() {
return isFalse("The value must be false.");
}
public BoolValidator<DTO> isFalse(String errMsg) {
public BoolPropertyValidator<DTO> isFalse(String errMsg) {
return isFalse(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> BoolValidator<DTO> isFalse(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> BoolPropertyValidator<DTO> isFalse(Supplier<E> exceptionCreator) {
return isFalse(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> BoolValidator<DTO> isFalse(
public <E extends RuntimeException> BoolPropertyValidator<DTO> isFalse(
Function<Boolean, E> exceptionCreator) {
withRule(Boolean.FALSE::equals, exceptionCreator);
return this;
}
@Override
protected BoolValidator<DTO> thisObject() {
protected BoolPropertyValidator<DTO> thisObject() {
return this;
}
}

View File

@ -6,24 +6,24 @@ import java.util.function.Supplier;
import xyz.zhouxy.plusone.commons.collection.CollectionTools;
public class CollectionValidator<DTO, T>
extends BasePropertyValidator<DTO, Collection<T>, CollectionValidator<DTO, T>> {
public class CollectionPropertyValidator<DTO, T>
extends BasePropertyValidator<DTO, Collection<T>, CollectionPropertyValidator<DTO, T>> {
CollectionValidator(Function<DTO, Collection<T>> getter) {
CollectionPropertyValidator(Function<DTO, Collection<T>> getter) {
super(getter);
}
// ====== notEmpty =====
public CollectionValidator<DTO, T> notEmpty(String errMsg) {
public CollectionPropertyValidator<DTO, T> notEmpty(String errMsg) {
return notEmpty(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> CollectionValidator<DTO, T> notEmpty(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> notEmpty(Supplier<E> exceptionCreator) {
return notEmpty(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> CollectionValidator<DTO, T> notEmpty(
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> notEmpty(
Function<Collection<T>, E> exceptionCreator) {
withRule(CollectionTools::isNotEmpty, exceptionCreator);
return this;
@ -31,22 +31,22 @@ public class CollectionValidator<DTO, T>
// ====== isEmpty =====
public CollectionValidator<DTO, T> isEmpty(String errMsg) {
public CollectionPropertyValidator<DTO, T> isEmpty(String errMsg) {
return isEmpty(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> CollectionValidator<DTO, T> isEmpty(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> isEmpty(Supplier<E> exceptionCreator) {
return isEmpty(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> CollectionValidator<DTO, T> isEmpty(
public <E extends RuntimeException> CollectionPropertyValidator<DTO, T> isEmpty(
Function<Collection<T>, E> exceptionCreator) {
withRule(CollectionTools::isEmpty, exceptionCreator);
return this;
}
@Override
protected CollectionValidator<DTO, T> thisObject() {
protected CollectionPropertyValidator<DTO, T> thisObject() {
return this;
}
}

View File

@ -6,12 +6,12 @@ import java.util.function.Supplier;
import com.google.common.collect.Range;
public abstract
class ValidatorOfComparable<TObj,
TProperty extends Comparable<TProperty>,
TPropertyValidator extends ValidatorOfComparable<TObj, TProperty, TPropertyValidator>>
class ComparablePropertyValidator<TObj,
TProperty extends Comparable<TProperty>,
TPropertyValidator extends ComparablePropertyValidator<TObj, TProperty, TPropertyValidator>>
extends BasePropertyValidator<TObj, TProperty, TPropertyValidator> {
ValidatorOfComparable(Function<TObj, ? extends TProperty> getter) {
ComparablePropertyValidator(Function<TObj, ? extends TProperty> getter) {
super(getter);
}

View File

@ -0,0 +1,16 @@
package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
public class DefaultComparablePropertyValidator<TObj, TProperty extends Comparable<TProperty>>
extends ComparablePropertyValidator<TObj, TProperty, DefaultComparablePropertyValidator<TObj, TProperty>> {
DefaultComparablePropertyValidator(Function<TObj, ? extends TProperty> getter) {
super(getter);
}
@Override
protected DefaultComparablePropertyValidator<TObj, TProperty> thisObject() {
return this;
}
}

View File

@ -1,18 +0,0 @@
package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
public class DefaultValidatorOfComparable<
TObj,
TProperty extends Comparable<TProperty>
> extends ValidatorOfComparable<TObj, TProperty, DefaultValidatorOfComparable<TObj, TProperty>> {
DefaultValidatorOfComparable(Function<TObj, ? extends TProperty> getter) {
super(getter);
}
@Override
protected DefaultValidatorOfComparable<TObj, TProperty> thisObject() {
return this;
}
}

View File

@ -3,33 +3,33 @@ package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
import java.util.function.Supplier;
public class DoubleValidator<DTO> extends ValidatorOfComparable<DTO, Double, DoubleValidator<DTO>> {
public class DoublePropertyValidator<DTO> extends ComparablePropertyValidator<DTO, Double, DoublePropertyValidator<DTO>> {
DoubleValidator(Function<DTO, Double> getter) {
DoublePropertyValidator(Function<DTO, Double> getter) {
super(getter);
}
public DoubleValidator<DTO> between(double min, double max) {
public DoublePropertyValidator<DTO> between(double min, double max) {
return between(min, max, String.format("数值不在 %s 和 %s 之间", String.valueOf(min), String.valueOf(max)));
}
public DoubleValidator<DTO> between(double min, double max, String errMsg) {
public DoublePropertyValidator<DTO> between(double min, double max, String errMsg) {
return between(min, max, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> DoubleValidator<DTO> between(double min, double max,
public <E extends RuntimeException> DoublePropertyValidator<DTO> between(double min, double max,
Supplier<E> exceptionCreator) {
return between(min, max, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> DoubleValidator<DTO> between(double min, double max,
public <E extends RuntimeException> DoublePropertyValidator<DTO> between(double min, double max,
Function<Double, E> exceptionCreator) {
withRule(value -> (value >= min && value < max), exceptionCreator);
return this;
}
@Override
protected DoubleValidator<DTO> thisObject() {
protected DoublePropertyValidator<DTO> thisObject() {
return this;
}
}

View File

@ -3,33 +3,33 @@ package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
import java.util.function.Supplier;
public class IntValidator<DTO> extends ValidatorOfComparable<DTO, Integer, IntValidator<DTO>> {
public class IntPropertyValidator<DTO> extends ComparablePropertyValidator<DTO, Integer, IntPropertyValidator<DTO>> {
IntValidator(Function<DTO, Integer> getter) {
IntPropertyValidator(Function<DTO, Integer> getter) {
super(getter);
}
public IntValidator<DTO> between(int min, int max) {
public IntPropertyValidator<DTO> between(int min, int max) {
return between(min, max, String.format("数值不在 %d 和 %d 之间", min, max));
}
public IntValidator<DTO> between(int min, int max, String errMsg) {
public IntPropertyValidator<DTO> between(int min, int max, String errMsg) {
return between(min, max, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> IntValidator<DTO> between(int min, int max,
public <E extends RuntimeException> IntPropertyValidator<DTO> between(int min, int max,
Supplier<E> exceptionCreator) {
return between(min, max, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> IntValidator<DTO> between(int min, int max,
public <E extends RuntimeException> IntPropertyValidator<DTO> between(int min, int max,
Function<Integer, E> exceptionCreator) {
withRule(value -> (value >= min && value < max), exceptionCreator);
return this;
}
@Override
protected IntValidator<DTO> thisObject() {
protected IntPropertyValidator<DTO> thisObject() {
return this;
}
}

View File

@ -3,33 +3,33 @@ package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
import java.util.function.Supplier;
public class LongValidator<DTO> extends ValidatorOfComparable<DTO, Long, LongValidator<DTO>> {
public class LongPropertyValidator<DTO> extends ComparablePropertyValidator<DTO, Long, LongPropertyValidator<DTO>> {
LongValidator(Function<DTO, Long> getter) {
LongPropertyValidator(Function<DTO, Long> getter) {
super(getter);
}
public LongValidator<DTO> between(long min, long max) {
public LongPropertyValidator<DTO> between(long min, long max) {
return between(min, max, String.format("数值不在 %d 和 %d 之间", min, max));
}
public LongValidator<DTO> between(long min, long max, String errMsg) {
public LongPropertyValidator<DTO> between(long min, long max, String errMsg) {
return between(min, max, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> LongValidator<DTO> between(long min, long max,
public <E extends RuntimeException> LongPropertyValidator<DTO> between(long min, long max,
Supplier<E> exceptionCreator) {
return between(min, max, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> LongValidator<DTO> between(long min, long max,
public <E extends RuntimeException> LongPropertyValidator<DTO> between(long min, long max,
Function<Long, E> exceptionCreator) {
withRule(value -> (value >= min && value < max), exceptionCreator);
return this;
}
@Override
protected LongValidator<DTO> thisObject() {
protected LongPropertyValidator<DTO> thisObject() {
return this;
}
}

View File

@ -43,31 +43,31 @@ public abstract class MapValidator<K, V> extends BaseValidator<Map<K, V>> {
// ========== ruleFor ==========
protected final ObjectValidator<Map<K, V>, V> ruleFor(K key) {
protected final ObjectPropertyValidator<Map<K, V>, V> ruleFor(K key) {
return ruleFor(m -> m.get(key));
}
protected final IntValidator<Map<K, V>> ruleForInt(K key) {
protected final IntPropertyValidator<Map<K, V>> ruleForInt(K key) {
return ruleForInt(m -> (Integer) m.get(key));
}
protected final LongValidator<Map<K, V>> ruleForLong(K key) {
protected final LongPropertyValidator<Map<K, V>> ruleForLong(K key) {
return ruleForLong(m -> (Long) m.get(key));
}
protected final DoubleValidator<Map<K, V>> ruleForDouble(K key) {
protected final DoublePropertyValidator<Map<K, V>> ruleForDouble(K key) {
return ruleForDouble(m -> (Double) m.get(key));
}
protected final BoolValidator<Map<K, V>> ruleForBool(K key) {
protected final BoolPropertyValidator<Map<K, V>> ruleForBool(K key) {
return ruleForBool(m -> (Boolean) m.get(key));
}
protected final StringValidator<Map<K, V>> ruleForString(K key) {
protected final StringPropertyValidator<Map<K, V>> ruleForString(K key) {
return ruleForString(m -> (String) m.get(key));
}
protected final <E> CollectionValidator<Map<K, V>, E> ruleForCollection(K key) {
protected final <E> CollectionPropertyValidator<Map<K, V>, E> ruleForCollection(K key) {
@SuppressWarnings("unchecked")
Function<Map<K, V>, Collection<E>> getter = m -> (Collection<E>) m.get(key);
return ruleForCollection(getter);

View File

@ -0,0 +1,15 @@
package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
public class ObjectPropertyValidator<DTO, T> extends BasePropertyValidator<DTO, T, ObjectPropertyValidator<DTO, T>> {
ObjectPropertyValidator(Function<DTO, T> getter) {
super(getter);
}
@Override
protected ObjectPropertyValidator<DTO, T> thisObject() {
return this;
}
}

View File

@ -1,15 +0,0 @@
package xyz.zhouxy.plusone.validator;
import java.util.function.Function;
public class ObjectValidator<DTO, T> extends BasePropertyValidator<DTO, T, ObjectValidator<DTO, T>> {
ObjectValidator(Function<DTO, T> getter) {
super(getter);
}
@Override
protected ObjectValidator<DTO, T> thisObject() {
return this;
}
}

View File

@ -12,7 +12,7 @@ import xyz.zhouxy.plusone.commons.util.RegexTools;
import xyz.zhouxy.plusone.commons.util.StringTools;
/**
* StringValidator
* StringPropertyValidator
*
* <p>
* 针对文本字段的验证器
@ -20,9 +20,9 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/
public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, StringValidator<DTO>> {
public class StringPropertyValidator<DTO> extends ComparablePropertyValidator<DTO, String, StringPropertyValidator<DTO>> {
StringValidator(Function<DTO, String> getter) {
StringPropertyValidator(Function<DTO, String> getter) {
super(getter);
}
@ -30,17 +30,17 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - matches
// ================================
public StringValidator<DTO> matches(Pattern regex, String errMsg) {
public StringPropertyValidator<DTO> matches(Pattern regex, String errMsg) {
return matches(regex, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matches(
public <E extends RuntimeException> StringPropertyValidator<DTO> matches(
Pattern regex,
Supplier<E> exceptionCreator) {
return matches(regex, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matches(
public <E extends RuntimeException> StringPropertyValidator<DTO> matches(
Pattern regex,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matches(input, regex), exceptionCreator);
@ -55,34 +55,34 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - matchesOne
// ================================
public StringValidator<DTO> matchesOne(Pattern[] regexs, String errMsg) {
public StringPropertyValidator<DTO> matchesOne(Pattern[] regexs, String errMsg) {
return matchesOne(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
Pattern[] regexs,
Supplier<E> exceptionCreator) {
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
Pattern[] regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matchesOne(input, regexs), exceptionCreator);
return this;
}
public StringValidator<DTO> matchesOne(List<Pattern> regexs, String errMsg) {
public StringPropertyValidator<DTO> matchesOne(List<Pattern> regexs, String errMsg) {
return matchesOne(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
List<Pattern> regexs,
Supplier<E> exceptionCreator) {
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
List<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matchesOne(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
@ -97,34 +97,34 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - matchesAll
// ================================
public StringValidator<DTO> matchesAll(Pattern[] regexs, String errMsg) {
public StringPropertyValidator<DTO> matchesAll(Pattern[] regexs, String errMsg) {
return matchesAll(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
Pattern[] regexs,
Supplier<E> exceptionCreator) {
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
Pattern[] regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matchesAll(input, regexs), exceptionCreator);
return this;
}
public StringValidator<DTO> matchesAll(Collection<Pattern> regexs, String errMsg) {
public StringPropertyValidator<DTO> matchesAll(Collection<Pattern> regexs, String errMsg) {
return matchesAll(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
Collection<Pattern> regexs,
Supplier<E> exceptionCreator) {
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
Collection<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matchesAll(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
@ -139,19 +139,19 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - notBlank
// ================================
public StringValidator<DTO> notBlank() {
public StringPropertyValidator<DTO> notBlank() {
return notBlank("This String argument must have text; it must not be null, empty, or blank");
}
public StringValidator<DTO> notBlank(String errMsg) {
public StringPropertyValidator<DTO> notBlank(String errMsg) {
return notBlank(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> notBlank(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> StringPropertyValidator<DTO> notBlank(Supplier<E> exceptionCreator) {
return notBlank(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> notBlank(
public <E extends RuntimeException> StringPropertyValidator<DTO> notBlank(
Function<String, E> exceptionCreator) {
withRule(StringTools::isNotBlank, exceptionCreator);
return this;
@ -165,19 +165,19 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - email
// ================================
public StringValidator<DTO> email() {
public StringPropertyValidator<DTO> email() {
return email("The value is not an email address.");
}
public StringValidator<DTO> email(String errMsg) {
public StringPropertyValidator<DTO> email(String errMsg) {
return email(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> email(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> StringPropertyValidator<DTO> email(Supplier<E> exceptionCreator) {
return email(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> email(Function<String, E> exceptionCreator) {
public <E extends RuntimeException> StringPropertyValidator<DTO> email(Function<String, E> exceptionCreator) {
// TODO [优化] 优化 email 校验
return matches(PatternConsts.EMAIL, exceptionCreator);
}
@ -190,15 +190,15 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - notEmpty
// ================================
public StringValidator<DTO> notEmpty(String errMsg) {
public StringPropertyValidator<DTO> notEmpty(String errMsg) {
return notEmpty(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> notEmpty(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> StringPropertyValidator<DTO> notEmpty(Supplier<E> exceptionCreator) {
return notEmpty(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> notEmpty(
public <E extends RuntimeException> StringPropertyValidator<DTO> notEmpty(
Function<String, E> exceptionCreator) {
withRule(s -> s != null && !s.isEmpty(), exceptionCreator);
return this;
@ -212,15 +212,15 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - isNullOrEmpty
// ================================
public StringValidator<DTO> isNullOrEmpty(String errMsg) {
public StringPropertyValidator<DTO> isNullOrEmpty(String errMsg) {
return isNullOrEmpty(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> isNullOrEmpty(Supplier<E> exceptionCreator) {
public <E extends RuntimeException> StringPropertyValidator<DTO> isNullOrEmpty(Supplier<E> exceptionCreator) {
return isNullOrEmpty(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> isNullOrEmpty(
public <E extends RuntimeException> StringPropertyValidator<DTO> isNullOrEmpty(
Function<String, E> exceptionCreator) {
withRule(s -> s == null || s.isEmpty(), exceptionCreator);
return this;
@ -234,16 +234,16 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// #region - length
// ================================
public StringValidator<DTO> length(int length, String errMsg) {
public StringPropertyValidator<DTO> length(int length, String errMsg) {
return length(length, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> length(int length,
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int length,
Supplier<E> exceptionCreator) {
return length(length, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> length(int length,
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int length,
Function<String, E> exceptionCreator) {
AssertTools.checkArgument(length >= 0, "The minimum value must be less than the maximum value.");
withRule(s -> s != null && s.length() == length, exceptionCreator);
@ -258,16 +258,16 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
return len >= min && len < max;
}
public StringValidator<DTO> length(int min, int max, String errMsg) {
public StringPropertyValidator<DTO> length(int min, int max, String errMsg) {
return length(min, max, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> length(int min, int max,
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int min, int max,
Supplier<E> exceptionCreator) {
return length(min, max, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> length(int min, int max,
public <E extends RuntimeException> StringPropertyValidator<DTO> length(int min, int max,
Function<String, E> exceptionCreator) {
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.");
@ -280,7 +280,7 @@ public class StringValidator<DTO> extends ValidatorOfComparable<DTO, String, Str
// ================================
@Override
protected StringValidator<DTO> thisObject() {
protected StringPropertyValidator<DTO> thisObject() {
return this;
}
}