Function 不限制字段的类型。
This commit is contained in:
parent
a61869b6b2
commit
0e2dc01cf7
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>xyz.zhouxy.plusone</groupId>
|
||||
<artifactId>plusone-validator</artifactId>
|
||||
<artifactId>plusone-validator-for-mfp</artifactId>
|
||||
<version>0.1.3-SNAPSHOT</version>
|
||||
|
||||
<name>plusone-validator</name>
|
||||
|
@ -39,25 +39,25 @@ public class BaseValidator<T> {
|
||||
return validValueHolder;
|
||||
}
|
||||
|
||||
protected final IntValidator<T> ruleForInt(Function<T, Integer> getter) {
|
||||
protected final IntValidator<T> ruleForInt(Function<T, ?> getter) {
|
||||
IntValidator<T> validValueHolder = new IntValidator<>(getter);
|
||||
propertyValidators.add(validValueHolder);
|
||||
return validValueHolder;
|
||||
}
|
||||
|
||||
protected final DoubleValidator<T> ruleForDouble(Function<T, Double> getter) {
|
||||
protected final DoubleValidator<T> ruleForDouble(Function<T, ?> getter) {
|
||||
DoubleValidator<T> validValueHolder = new DoubleValidator<>(getter);
|
||||
propertyValidators.add(validValueHolder);
|
||||
return validValueHolder;
|
||||
}
|
||||
|
||||
protected final BoolValidator<T> ruleForBool(Function<T, Boolean> getter) {
|
||||
protected final BoolValidator<T> ruleForBool(Function<T, ?> getter) {
|
||||
BoolValidator<T> validValueHolder = new BoolValidator<>(getter);
|
||||
propertyValidators.add(validValueHolder);
|
||||
return validValueHolder;
|
||||
}
|
||||
|
||||
protected final StringValidator<T> ruleForString(Function<T, String> getter) {
|
||||
protected final StringValidator<T> ruleForString(Function<T, ?> getter) {
|
||||
StringValidator<T> validValueHolder = new StringValidator<>(getter);
|
||||
propertyValidators.add(validValueHolder);
|
||||
return validValueHolder;
|
||||
|
@ -7,7 +7,7 @@ import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
public class BoolValidator<DTO> extends PropertyValidator<DTO, Boolean, BoolValidator<DTO>> {
|
||||
|
||||
BoolValidator(Function<DTO, Boolean> getter) {
|
||||
BoolValidator(Function<DTO, ?> getter) {
|
||||
super(getter);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import java.util.function.Supplier;
|
||||
|
||||
public class DoubleValidator<DTO> extends PropertyValidator<DTO, Double, DoubleValidator<DTO>> {
|
||||
|
||||
DoubleValidator(Function<DTO, Double> getter) {
|
||||
DoubleValidator(Function<DTO, ?> getter) {
|
||||
super(getter);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import java.util.function.Supplier;
|
||||
|
||||
public class IntValidator<DTO> extends PropertyValidator<DTO, Integer, IntValidator<DTO>> {
|
||||
|
||||
IntValidator(Function<DTO, Integer> getter) {
|
||||
IntValidator(Function<DTO, ?> getter) {
|
||||
super(getter);
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,10 @@ import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
abstract class PropertyValidator<DTO, PROPERTY, THIS> {
|
||||
Function<DTO, PROPERTY> getter;
|
||||
Function<DTO, ?> getter;
|
||||
Validator<PROPERTY> validator = new Validator<>();
|
||||
|
||||
PropertyValidator(Function<DTO, PROPERTY> getter) {
|
||||
PropertyValidator(Function<DTO, ?> getter) {
|
||||
this.getter = getter;
|
||||
}
|
||||
|
||||
@ -137,8 +137,9 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
|
||||
|
||||
// ========================================================================
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
void validate(DTO obj) {
|
||||
PROPERTY value = this.getter.apply(obj);
|
||||
PROPERTY value = (PROPERTY) this.getter.apply(obj);
|
||||
this.validator.validate(value);
|
||||
}
|
||||
|
||||
@ -150,6 +151,6 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
|
||||
Supplier<E> exceptionSupplier) {
|
||||
return value -> exceptionSupplier.get();
|
||||
}
|
||||
|
||||
|
||||
protected abstract THIS thisObject();
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import xyz.zhouxy.plusone.commons.util.RegexUtil;
|
||||
|
||||
public class StringValidator<DTO> extends PropertyValidator<DTO, String, StringValidator<DTO>> {
|
||||
|
||||
StringValidator(Function<DTO, String> getter) {
|
||||
StringValidator(Function<DTO, ?> getter) {
|
||||
super(getter);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user