Emun 단순 인스턴스

1007 단어 인스턴스
public enum PlayerType {
    ANONYMOUS(1, "AnonymousPatron"),
    PATRON(2, "Patron"),
    UNREGISTERED(3, "UnregisteredPlayer");
   
    private int code;
    private String description;

    private static final Map<Integer, PlayerType> codeToEnum = new HashMap<Integer, PlayerType>();
   
    static {
        for (PlayerType PlayerType : values()) {
            codeToEnum.put(PlayerType.getCode(), PlayerType);
        }
    }

    PlayerType(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static PlayerType fromCode(int code){
        return codeToEnum.get( code );
    }
}

좋은 웹페이지 즐겨찾기