ValidatableStringRecord 移动到 plusone-commons 并优化。
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
package xyz.zhouxy.plusone.domain;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
/**
|
||||
* 带校验的字符串值对象
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
public abstract class ValidatableStringRecord implements IValueObject {
|
||||
|
||||
protected String value;
|
||||
protected final Pattern format;
|
||||
|
||||
protected ValidatableStringRecord(Pattern format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
protected boolean isValid() {
|
||||
return format.matcher(value).matches();
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String getValueOrNull(Optional<? extends ValidatableStringRecord> s) {
|
||||
return s.isPresent() ? s.get().value() : null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user