by
0
6
2,097
0
Top 1% !
Popular
Famous
Tagged
Specified
Refined
Popularity: 10019th place
This snippet is Public
Architecturex86_64
InputName0code
InputType0int
JVMjre5
LanguageJava
LicenseMIT_X11
MethodNameget
OSLinux
OSWindows
OutputTypeErrorCodes

Enum as a configuration structure

This structure for the enumeration let the developer specify some properties for each element of the enumeration.
In this way, the enumeration becomes a container for a set of profiles to be used in the application. E.g. it is possible to specify a code (e.g. for serialization purpose) and then to specify other characteristics related to the same enum value.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/330/Enum-as-a-configuration-structure?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public enum ErrorCodes { OK (0), FAIL (-1); private final int code; ErrorCodes(int code) { this.code = code; } /** * Retrieves the integer code related to this component */ public int toInt() { return code; } /** * Looks up for the enumeration value corresponding to the given code * @param code internal code of the enumeration * @return enumeration value corresponding to the given code; null if not found */ public static ErrorCodes get(int code){ for (ErrorCodes p : ErrorCodes.values()) { if(p.toInt() == code) return p; } return null; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus