Enhance naming of enums #1532
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
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"); |
brianweller89
Jul 21, 2017
Contributor
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)
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); |
brianweller89
Jul 21, 2017
Contributor
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.
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"); |
brianweller89
Jul 21, 2017
Contributor
NotEmpty would be a tighter check here.
NotEmpty would be a tighter check here.
jodastephen
Jul 24, 2017
Author
Member
True, but this way users get a better error message
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"; | ||
} |
brianweller89
Jul 21, 2017
Contributor
Assume we are happy for this endsWith logic to be completely removed?
Assume we are happy for this endsWith logic to be completely removed?
jodastephen
Jul 24, 2017
Author
Member
That was a hack that is now supported properly.
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); |
brianweller89
Jul 21, 2017
Contributor
Again we're losing some custom parsing logic here.
Again we're losing some custom parsing logic here.
jodastephen
Jul 24, 2017
Author
Member
That was a hack that is now supported properly.
That was a hack that is now supported properly.
Add
NamedEnum
interface, to mark standard enumsAdd
EnumNames
to ensure more lenient and consistent parsingEnhanced performance of parse and format