Enhance naming of enums - #1532
Conversation
Add `NamedEnum` interface, to mark standard enums Add `EnumNames` to ensure more lenient and consistent parsing Enhanced performance of parse and format
brianweller89
left a comment
There was a problem hiding this comment.
Looks fine - assuming the loss of custom parsing logic in the two highlighted enums is expected and known
|
|
||
| // restricted constructor | ||
| private EnumNames(Class<T> enumType, boolean specialToString) { | ||
| ArgChecker.notNull(enumType, "enumType"); |
There was a problem hiding this comment.
Should use consistent naming when referring to the overridden toString() functionality; currently using "manualToString" in the method name and "specialToString" as the variable name (overriddenToString another option)
| map.put(formatted.toUpperCase(Locale.ENGLISH), value); | ||
| map.put(formatted.toLowerCase(Locale.ENGLISH), value); | ||
| formattedSet.add(formatted); | ||
| formatMap.put(value, formatted); |
There was a problem hiding this comment.
Can we move these 5 duplicate lines outside of the if/else? Declaring the String outside the if un-itilialised may look abit nasty but IMO in simple cases like this it is better than carrying the risk of having somebody updating one block of code whilst forgetting to update the duplicate.
| * @return the enum value | ||
| */ | ||
| public T parse(String name) { | ||
| ArgChecker.notNull(name, "name"); |
There was a problem hiding this comment.
NotEmpty would be a tighter check here.
There was a problem hiding this comment.
True, but this way users get a better error message
| String str = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, uniqueName); | ||
| if (str.endsWith("I_S_D_A")) { | ||
| str = "ORIGINAL_ISDA"; | ||
| } |
There was a problem hiding this comment.
Assume we are happy for this endsWith logic to be completely removed?
There was a problem hiding this comment.
That was a hack that is now supported properly.
| ArgChecker.notNull(uniqueName, "uniqueName"); | ||
| return valueOf(uniqueName.replace('-', '_').replace("/", "").toUpperCase(Locale.ENGLISH)); | ||
| public static FixedCouponBondYieldConvention of(String name) { | ||
| return NAMES.parse(name); |
There was a problem hiding this comment.
Again we're losing some custom parsing logic here.
There was a problem hiding this comment.
That was a hack that is now supported properly.
Add
NamedEnuminterface, to mark standard enumsAdd
EnumNamesto ensure more lenient and consistent parsingEnhanced performance of parse and format