ABN ENUM :

My Enum ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
 * Copyright 2013. ABN Software. All Rights reserved.<br>
 * <br>
 * Homepage .... http://www.ABNsoft.info<br>
 * <br>
 * Project ..... RegMaster<br>
 * Package ..... RegMaster<br>
 * File name ... OnicEnumAction.java<br>
 * <br>
 * Author ...... Andre<br>
 * Created ..... 12.03.2013<br>
 * <br>
 */

package net.regmaster.onlinenic.enumtype;

/**
 * @author annik
 *
 */

public enum OnicEnumAction {

    GREETING("Greeting"),
    LOGIN("Login"),
    LOGOUT("Logout");

    private String key;

    private OnicEnumAction(String key) {
        this.key = key;
    }

    public String getValue() {
        return this.key;
    }

    /**
     * This method is simple Enum Factory by key.
     *
     * @param key
     * @return
     * @throws Exception
     */

    public static OnicEnumAction getEnum(String key) throws Exception {
        //
        OnicEnumAction res = null;

        for (OnicEnumAction action : OnicEnumAction.values()) {
            if (action.getValue().equals(key)) {
                res = action;
                break;
            }
        }
        //
        if (res == null) {
            throw new Exception("Unknow Enum key : " + key+". Check your Enum.");
        }
        return res;
    }

}
Tagged , . Bookmark the permalink.

Leave a Reply