package com.eden.room.common.enums; /** * 租赁状态枚举 */ public enum RentalStatusEnum { /** 待租 */ WAITING("1","待租"), /** 已租 */ RENTED("2","已租"); /** 下架 */ private final String key; private final String value; public String getKey() { return key; } public String getValue() { return value; } RentalStatusEnum(String key, String value) { this.value = value; this.key = key; } /** * 根据值获取枚举 * * @param value 枚举值 * @return 枚举 */ public static String getByValue(String value) { for (RentalStatusEnum status : values()) { if (status.getValue().equals(value)) { return status.getKey(); } } return null; } /** * 根据枚举获取值 * * @param key * @return 枚举 */ public static String getValue(String key) { for (RentalStatusEnum status : values()) { if (status.getKey().equals(key)) { return status.getValue(); } } return null; } /** * 校验枚举值是否有效 * * @param key 枚举值 * @return 是否有效 */ public static boolean isValid(String key) { for (RentalStatusEnum status : values()) { if (status.getKey().equals(key)) { return true; } } return false; } }