91 lines
2.2 KiB
Java
Raw Normal View History

2024-10-12 00:57:35 +08:00
/*
* Copyright 2024-2025 the original author or authors.
2024-10-12 00:57:35 +08:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2024-10-11 21:19:28 +08:00
package xyz.zhouxy.plusone.commons.model;
2024-12-16 09:38:52 +08:00
import xyz.zhouxy.plusone.commons.base.IWithIntCode;
2024-10-11 21:19:28 +08:00
import xyz.zhouxy.plusone.commons.util.AssertTools;
/**
* 性别
2024-10-21 23:17:52 +08:00
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
2024-10-11 21:19:28 +08:00
*/
2024-12-16 09:38:52 +08:00
public enum Gender implements IWithIntCode {
2024-10-11 21:19:28 +08:00
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;
}
2025-04-03 10:09:18 +08:00
/**
* 根据码值获取对应枚举
*
* @param value 码值
* @return 枚举值
*/
2024-10-11 21:19:28 +08:00
public static Gender of(int value) {
AssertTools.checkCondition(0 <= value && value < VALUES.length,
() -> new EnumConstantNotPresentException(Gender.class, String.valueOf(value)));
return VALUES[value];
}
2025-04-03 10:09:18 +08:00
/**
* 获取枚举码值
*
* @return 码值
*/
2024-10-11 21:19:28 +08:00
public int getValue() {
return value;
}
2025-04-03 10:09:18 +08:00
/**
* 枚举名称
*
* @return 枚举名称
*/
2024-10-11 21:19:28 +08:00
public String getDisplayName() {
return displayName;
}
2025-04-03 10:09:18 +08:00
/**
* 枚举中文名称
*
* @return 枚举中文名称
*/
2024-10-11 21:19:28 +08:00
public String getDisplayNameZh() {
return displayNameZh;
}
2024-12-16 09:38:52 +08:00
@Override
public int getCode() {
return getValue();
}
2024-10-11 21:19:28 +08:00
}