by
1
5
202k
0
Top 1% !
Popular
Pearl of Wisdom
Tagged
OpenSource
Popularity: 7961st place

Published on:

InputName0code
InputType0int
LicenseMIT_X11
MethodNameget
OutputTypeMyComponent

Java enum definition

This is the classic enum definition with a member and the static getter to parse from the internal code
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/115/Java-enum-definition?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
/** * This enumeration defines ....<br/> */ public enum MyComponent { Comp1 (1), API (2), unknown (0); private int code; private MyComponent (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; unknown if not found */ public static MyComponent get(int code){ for (MyComponent p : MyComponent.values()) { if(p.toInt() == code) return p; } return MyComponent.unknown; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus