Live2D

枚举类

使用场景:希望根据某个key得到value以及更多信息

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @Author NoDreamJava
 * @Date 2023-7-5 10:57
 * @Version 1.0
 */


@AllArgsConstructor
@NoArgsConstructor
@Getter
public enum SignOperation {
    UNION("union", "union all", "合并"),
    INTERSECT("intersect", "intersect", "交叉"),
    EXCEPT("except", "except", "排除");
    private String name;
    private String val;
    private String msg;

    public static SignOperation getByName(String name) {
        if (null != name) {
            for (SignOperation item : SignOperation.values()) {
                if (item.name.equals(name)) {
                    return item;
                }
            }
        }
        return null;
    }
}

class Test{
    public static void main(String[] args) {
        System.out.println(SignOperation.getByName("union").getMsg());
    }
}

posted @ 2023-07-05 11:09  没有梦想的java菜鸟  阅读(25)  评论(0编辑  收藏  举报