forked from plusone/plusone-commons
Reviewed-on: plusone/plusone-commons#42 Co-authored-by: ZhouXY108 <luquanlion@outlook.com> Co-committed-by: ZhouXY108 <luquanlion@outlook.com>
91 lines
2.2 KiB
Java
91 lines
2.2 KiB
Java
/*
|
|
* Copyright 2024-2025 the original author or authors.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
package xyz.zhouxy.plusone.commons.model;
|
|
|
|
import xyz.zhouxy.plusone.commons.base.IWithIntCode;
|
|
import xyz.zhouxy.plusone.commons.util.AssertTools;
|
|
|
|
/**
|
|
* 性别
|
|
*
|
|
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
|
|
*/
|
|
public enum Gender implements IWithIntCode {
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* 根据码值获取对应枚举
|
|
*
|
|
* @param value 码值
|
|
* @return 枚举值
|
|
*/
|
|
public static Gender of(int value) {
|
|
AssertTools.checkCondition(0 <= value && value < VALUES.length,
|
|
() -> new EnumConstantNotPresentException(Gender.class, String.valueOf(value)));
|
|
return VALUES[value];
|
|
}
|
|
|
|
/**
|
|
* 获取枚举码值
|
|
*
|
|
* @return 码值
|
|
*/
|
|
public int getValue() {
|
|
return value;
|
|
}
|
|
|
|
/**
|
|
* 枚举名称
|
|
*
|
|
* @return 枚举名称
|
|
*/
|
|
public String getDisplayName() {
|
|
return displayName;
|
|
}
|
|
|
|
/**
|
|
* 枚举中文名称
|
|
*
|
|
* @return 枚举中文名称
|
|
*/
|
|
public String getDisplayNameZh() {
|
|
return displayNameZh;
|
|
}
|
|
|
|
@Override
|
|
public int getCode() {
|
|
return getValue();
|
|
}
|
|
|
|
}
|