-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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; } } ```
- Loading branch information
Showing
1 changed file
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters