New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance naming of enums #1532

Merged
merged 2 commits into from Jul 24, 2017

Conversation

Projects
None yet
2 participants
@jodastephen
Member

jodastephen commented Jul 20, 2017

Add NamedEnum interface, to mark standard enums
Add EnumNames to ensure more lenient and consistent parsing
Enhanced performance of parse and format

Enhance naming of enums
Add `NamedEnum` interface, to mark standard enums
Add `EnumNames` to ensure more lenient and consistent parsing
Enhanced performance of parse and format

@jodastephen jodastephen requested a review from brianweller89 Jul 20, 2017

@brianweller89

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");

This comment has been minimized.

@brianweller89

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)

map.put(formatted.toUpperCase(Locale.ENGLISH), value);
map.put(formatted.toLowerCase(Locale.ENGLISH), value);
formattedSet.add(formatted);
formatMap.put(value, formatted);

This comment has been minimized.

@brianweller89

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.

* @return the enum value
*/
public T parse(String name) {
ArgChecker.notNull(name, "name");

This comment has been minimized.

@brianweller89

brianweller89 Jul 21, 2017

Contributor

NotEmpty would be a tighter check here.

This comment has been minimized.

@jodastephen

jodastephen Jul 24, 2017

Member

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";
}

This comment has been minimized.

@brianweller89

brianweller89 Jul 21, 2017

Contributor

Assume we are happy for this endsWith logic to be completely removed?

This comment has been minimized.

@jodastephen

jodastephen Jul 24, 2017

Member

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);

This comment has been minimized.

@brianweller89

brianweller89 Jul 21, 2017

Contributor

Again we're losing some custom parsing logic here.

This comment has been minimized.

@jodastephen

jodastephen Jul 24, 2017

Member

That was a hack that is now supported properly.

@jodastephen jodastephen merged commit 85c814f into master Jul 24, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@jodastephen jodastephen deleted the topic/enum-names branch Jul 24, 2017

@jodastephen jodastephen modified the milestone: v1.4 Jul 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment