You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate enums as interface + enum + class for unknown values
The new generated enum is represented as an interface with two nested classes:
- enum class Known with the list of known enumeration values
- class Unknown which represents any not-known value
The enum `enum` would be generated as:
```java
// interface to abstract known and unknown values
interface IEnum extends IKaitaiEnum {
// Storage for unknown values
public static class Unknown extends IKaitaiEnum.Unknown implements IEnum {
Unknown(long id) { super(id); }
@OverRide
public String toString() { return "Enum(" + this.id + ")"; }
}
}
// Storage for known values
class Enum implements IEnum {
VARIANT_1(1),
VARIANT_2(2),
VARIANT_3(3);
private final long id;
private static HashMap<Long, IEnum> variants = new HashMap<>(3);
static {
for (final Enum e : values()) {
variants.put(e.id, e);
}
}
public static IEnum byId(final long id) {
return variants.computeIfAbsent(id, _id -> new IEnum.Unknown(id));
}
private Enum(long id) { this.id = id; }
@OverRide
public long id() { return this.id; }
}
```
0 commit comments