diff --git a/pom.xml b/pom.xml index 36417c9..3a58532 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,7 @@ UTF-8 + 8 1.8 1.8 2.13.5 diff --git a/src/main/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecord.java b/src/main/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecord.java index 0ff178b..5c3ac3c 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecord.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecord.java @@ -31,7 +31,8 @@ import xyz.zhouxy.plusone.commons.util.RegexUtil; * @author ZhouXY * @since 0.1.0 */ -public abstract class ValidatableStringRecord { +public abstract class ValidatableStringRecord + implements Comparable { private final String value; protected ValidatableStringRecord(String value, Pattern pattern) { @@ -51,6 +52,11 @@ public abstract class ValidatableStringRecord { return this.value; } + @Override + public int compareTo(ValidatableStringRecord o) { + return this.value.compareTo(o.value); + } + @Override public String toString() { return this.value(); diff --git a/src/test/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecordTests.java b/src/test/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecordTests.java index a21170e..d2a6727 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecordTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/domain/ValidatableStringRecordTests.java @@ -10,6 +10,11 @@ import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod; import xyz.zhouxy.plusone.commons.annotation.ValueObject; import xyz.zhouxy.plusone.commons.constant.PatternConsts; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + class ValidatableStringRecordTests { private static final Logger log = LoggerFactory.getLogger(ValidatableStringRecordTests.class); @@ -21,6 +26,16 @@ class ValidatableStringRecordTests { String usernameStr = username.value(); assertNotNull(usernameStr); log.info("usernameStr: {}", usernameStr); + + List usernames = Arrays.asList( + Username.of("ZhouXY108"), + Username.of("code_108"), + Username.of("Luquan"), + Username.of("Code108") + ); + log.info("{}", Collections.max(usernames)); + log.info("{}", Collections.max(usernames, + Comparator.comparing(o -> o.value().toLowerCase()))); } }