From 6eb5ada623d3a320904b2cc17754ebdaab114650 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 11 Oct 2024 21:19:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9E=9A=E4=B8=BE=E2=80=9CGe?= =?UTF-8?q?nder=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/commons/model/Gender.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/model/Gender.java diff --git a/src/main/java/xyz/zhouxy/plusone/commons/model/Gender.java b/src/main/java/xyz/zhouxy/plusone/commons/model/Gender.java new file mode 100644 index 0000000..ccac5c0 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/model/Gender.java @@ -0,0 +1,45 @@ +package xyz.zhouxy.plusone.commons.model; + +import xyz.zhouxy.plusone.commons.util.AssertTools; + +/** + * 性别 + */ +public enum Gender { + UNKNOWN(0, "Unknown", "未知"), + MALE(1, "Male", "男"), + FEMALE(2, "Female", "女"), + + ; + + private static final Gender[] VALUES = new Gender[] { UNKNOWN, MALE, FEMALE }; + + private final int value; + private final String displayName; + private final String displayNameZh; + + Gender(int value, String displayName, String displayNameZh) { + this.value = value; + this.displayName = displayName; + this.displayNameZh = displayNameZh; + } + + public static Gender of(int value) { + AssertTools.checkCondition(0 <= value && value < VALUES.length, + () -> new EnumConstantNotPresentException(Gender.class, String.valueOf(value))); + return VALUES[value]; + } + + public int getValue() { + return value; + } + + public String getDisplayName() { + return displayName; + } + + public String getDisplayNameZh() { + return displayNameZh; + } + +}