From 96f7eac10abdfca7ef5f134ae8bf9f4ca33c1756 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 28 Nov 2024 16:36:01 +0800 Subject: [PATCH] =?UTF-8?q?Gender=20=E6=94=BE=E5=88=B0=20constant=20?= =?UTF-8?q?=E5=8C=85=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/{model => constant}/Gender.java | 10 ++++++++-- .../commons/model/Chinese2ndGenIDCardNumber.java | 4 ++++ .../xyz/zhouxy/plusone/commons/model/IDCardNumber.java | 2 ++ .../commons/model/Chinese2ndGenIDCardNumberTests.java | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) rename src/main/java/xyz/zhouxy/plusone/commons/{model => constant}/Gender.java (88%) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/model/Gender.java b/src/main/java/xyz/zhouxy/plusone/commons/constant/Gender.java similarity index 88% rename from src/main/java/xyz/zhouxy/plusone/commons/model/Gender.java rename to src/main/java/xyz/zhouxy/plusone/commons/constant/Gender.java index 24dbeb9..630ec4d 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/model/Gender.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/constant/Gender.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package xyz.zhouxy.plusone.commons.model; +package xyz.zhouxy.plusone.commons.constant; +import xyz.zhouxy.plusone.commons.base.IWithIntCode; import xyz.zhouxy.plusone.commons.util.AssertTools; /** @@ -23,7 +24,7 @@ import xyz.zhouxy.plusone.commons.util.AssertTools; * * @author ZhouXY */ -public enum Gender { +public enum Gender implements IWithIntCode { UNKNOWN(0, "Unknown", "未知"), MALE(1, "Male", "男"), FEMALE(2, "Female", "女"), @@ -52,6 +53,11 @@ public enum Gender { return value; } + @Override + public int getCode() { + return value; + } + public String getDisplayName() { return displayName; } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumber.java b/src/main/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumber.java index c6ad7a7..8023dd6 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumber.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumber.java @@ -25,10 +25,14 @@ import java.util.regex.Pattern; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; +import com.google.errorprone.annotations.Immutable; + +import xyz.zhouxy.plusone.commons.constant.Gender; /** * 中国第二代居民身份证号 */ +@Immutable public class Chinese2ndGenIDCardNumber extends IDCardNumber { /** 省份编码 */ diff --git a/src/main/java/xyz/zhouxy/plusone/commons/model/IDCardNumber.java b/src/main/java/xyz/zhouxy/plusone/commons/model/IDCardNumber.java index f6e3114..43ad618 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/model/IDCardNumber.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/model/IDCardNumber.java @@ -23,6 +23,8 @@ import java.util.regex.Pattern; import javax.annotation.Nonnull; +import xyz.zhouxy.plusone.commons.constant.Gender; + /** * 身份证号 */ diff --git a/src/test/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumberTests.java b/src/test/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumberTests.java index 7002115..2f40ed0 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumberTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/model/Chinese2ndGenIDCardNumberTests.java @@ -26,6 +26,7 @@ import java.util.regex.Matcher; import org.junit.jupiter.api.Test; import lombok.extern.slf4j.Slf4j; +import xyz.zhouxy.plusone.commons.constant.Gender; @Slf4j public class Chinese2ndGenIDCardNumberTests {