修改方法名。

0.4.x 0.1.1-SNAPSHOT
ZhouXY108 2023-01-05 14:56:17 +08:00
parent 2768e4eb2b
commit 40f30f88a1
9 changed files with 17 additions and 21 deletions

View File

@ -6,7 +6,7 @@
<groupId>xyz.zhouxy.plusone</groupId> <groupId>xyz.zhouxy.plusone</groupId>
<artifactId>plusone-validator</artifactId> <artifactId>plusone-validator</artifactId>
<version>0.1.0-SNAPSHOT</version> <version>0.1.1-SNAPSHOT</version>
<name>plusone-validator</name> <name>plusone-validator</name>
<url>http://zhouxy.xyz</url> <url>http://zhouxy.xyz</url>

View File

@ -50,7 +50,7 @@ public class BoolValidator<DTO> extends PropertyValidator<DTO, Boolean, BoolVali
} }
@Override @Override
protected BoolValidator<DTO> returnThis() { protected BoolValidator<DTO> thisObject() {
return this; return this;
} }
} }

View File

@ -53,7 +53,7 @@ public class CollectionValidator<DTO, T> extends PropertyValidator<DTO, Collecti
} }
@Override @Override
protected CollectionValidator<DTO, T> returnThis() { protected CollectionValidator<DTO, T> thisObject() {
return this; return this;
} }
} }

View File

@ -29,7 +29,7 @@ public class DoubleValidator<DTO> extends PropertyValidator<DTO, Double, DoubleV
} }
@Override @Override
protected DoubleValidator<DTO> returnThis() { protected DoubleValidator<DTO> thisObject() {
return this; return this;
} }
} }

View File

@ -29,7 +29,7 @@ public class IntValidator<DTO> extends PropertyValidator<DTO, Integer, IntValida
} }
@Override @Override
protected IntValidator<DTO> returnThis() { protected IntValidator<DTO> thisObject() {
return this; return this;
} }
} }

View File

@ -9,7 +9,7 @@ public class ObjectValidator<DTO, T> extends PropertyValidator<DTO, T, ObjectVal
} }
@Override @Override
protected ObjectValidator<DTO, T> returnThis() { protected ObjectValidator<DTO, T> thisObject() {
return this; return this;
} }
} }

View File

@ -47,7 +47,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
public <E extends RuntimeException> THIS notNull(Function<PROPERTY, E> exceptionCreator) { public <E extends RuntimeException> THIS notNull(Function<PROPERTY, E> exceptionCreator) {
withRule(Objects::nonNull, exceptionCreator); withRule(Objects::nonNull, exceptionCreator);
return returnThis(); return thisObject();
} }
// ====== isNull ===== // ====== isNull =====
@ -62,7 +62,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
public <E extends RuntimeException> THIS isNull(Function<PROPERTY, E> exceptionCreator) { public <E extends RuntimeException> THIS isNull(Function<PROPERTY, E> exceptionCreator) {
withRule(Objects::isNull, exceptionCreator); withRule(Objects::isNull, exceptionCreator);
return returnThis(); return thisObject();
} }
// ===== equals ===== // ===== equals =====
@ -83,7 +83,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
public <E extends RuntimeException> THIS equalsThat( public <E extends RuntimeException> THIS equalsThat(
Object that, Function<PROPERTY, E> exceptionCreator) { Object that, Function<PROPERTY, E> exceptionCreator) {
withRule(value -> Objects.equals(value, that), exceptionCreator); withRule(value -> Objects.equals(value, that), exceptionCreator);
return returnThis(); return thisObject();
} }
// ===== state ===== // ===== state =====
@ -106,7 +106,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
Predicate<PROPERTY> condition, Predicate<PROPERTY> condition,
Function<PROPERTY, E> exceptionCreator) { Function<PROPERTY, E> exceptionCreator) {
withRule(condition, exceptionCreator); withRule(condition, exceptionCreator);
return returnThis(); return thisObject();
} }
// ======================================================================== // ========================================================================
@ -125,5 +125,5 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
return value -> exceptionSupplier.get(); return value -> exceptionSupplier.get();
} }
protected abstract THIS returnThis(); protected abstract THIS thisObject();
} }

View File

@ -173,7 +173,7 @@ public class StringValidator<DTO> extends PropertyValidator<DTO, String, StringV
} }
@Override @Override
protected StringValidator<DTO> returnThis() { protected StringValidator<DTO> thisObject() {
return this; return this;
} }
} }

View File

@ -8,15 +8,16 @@ import org.junit.Test;
import xyz.zhouxy.plusone.constant.RegexConsts; import xyz.zhouxy.plusone.constant.RegexConsts;
import xyz.zhouxy.plusone.validator.BaseValidator; import xyz.zhouxy.plusone.validator.BaseValidator;
import xyz.zhouxy.plusone.validator.IValidateRequired; import xyz.zhouxy.plusone.validator.ValidateUtil;
public class BaseValidatorTest { public class BaseValidatorTest {
@Test @Test
public void testRuleFor() { public void testValidate() {
RegisterCommand registerCommand = new RegisterCommand("zhouxy108", "luquanlion@outlook.com", "22336", "A1b2C3d4", RegisterCommand registerCommand = new RegisterCommand("zhouxy108", "luquanlion@outlook.com", "22336", "A1b2C3d4",
"A1b2C3d4", "A1b2C3d4",
Arrays.asList(new String[] { "admin", "editor" })); Arrays.asList(new String[] { "admin", "editor" }));
registerCommand.validate(); RegisterCommandValidator.INSTANCE.validate(registerCommand);
ValidateUtil.validate(registerCommand, RegisterCommandValidator.INSTANCE);
System.out.println(registerCommand); System.out.println(registerCommand);
} }
} }
@ -50,7 +51,7 @@ class RegisterCommandValidator extends BaseValidator<RegisterCommand> {
/** /**
* RegisterCommand * RegisterCommand
*/ */
class RegisterCommand implements IValidateRequired { class RegisterCommand {
private String username; private String username;
private String account; private String account;
@ -59,11 +60,6 @@ class RegisterCommand implements IValidateRequired {
private String password2; private String password2;
private List<String> roles; private List<String> roles;
@Override
public void validate() {
RegisterCommandValidator.INSTANCE.validate(this);
}
public RegisterCommand() { public RegisterCommand() {
} }