-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathEnum.java
More file actions
34 lines (27 loc) · 963 Bytes
/
Enum.java
File metadata and controls
34 lines (27 loc) · 963 Bytes
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
<%page args="package,classname,items,value_type='int'"/>
package com.rethinkdb.gen.${package};
import org.jetbrains.annotations.Nullable;
public enum ${classname} {
${",\n ".join("{k}({v})".format(k=key, v=val) for key, val in items)};
public final ${value_type} value;
private ${classname}(${value_type} value) {
this.value = value;
}
public static ${classname} fromValue(${value_type} value) {
switch (value) {
% for key, val in items:
case ${val}: return ${classname}.${key};
% endfor
default:
throw new IllegalArgumentException(String.format("%s is not a legal value for ${classname}", value));
}
}
public static @Nullable ${classname} maybeFromValue(${value_type} value) {
try {
return fromValue(value);
} catch (IllegalArgumentException iae) {
return null;
}
}
<%block name="custom_methods"/>
}