Enum on steroids – java

Hi was reviewing some java code this week and came across this wonderful way of establishing structured enums.

Code

//Declaration
private enum ServerType {
        DEV("
https://server1:8001", "customservicesuser", "xzy"),
        TEST("
http://server2:8001", "customservicesuser", "xzy"),
        PROD("
http://server3:8001", "customservicesuser", "xzy"),
        LOCALHOST("
http://localhost:8001", "customservicesuser", "xzy");

        private String serverUrl;
        private String username;
        private String password;

        ServerType(String serverUrl, String username, String password) {
            this.serverUrl = serverUrl;
            this.username = username;
            this.password = password;
        }
}

// Usage
        try {
            serverType = ServerType.valueOf(server);
        } catch (Exception e) {
            System.out.println("Unable to get the server info, options are: 
                DEV, TEST, PROD, LOCALHOST");
        }

Enjoy!

Recent Tweets

Note: For Customization and Configuration, CheckOut Recent Tweets Documentation

Calendar

<<  September 2017  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar

Month List