Don't override toString() on enums

It is a bad idea to override toString() on enums to return something other than
the actual name of the enum.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133318012
This commit is contained in:
mcilwain 2016-09-15 15:43:45 -07:00 committed by Ben McIlwain
parent 4a723576d5
commit 823bdc721f

View file

@ -133,8 +133,7 @@ public class RdapJsonFormatter {
this.rfc7483String = rfc7483String; this.rfc7483String = rfc7483String;
} }
@Override public String getDisplayName() {
public String toString() {
return rfc7483String; return rfc7483String;
} }
} }
@ -211,8 +210,7 @@ public class RdapJsonFormatter {
this.rfc7483String = rfc7483String; this.rfc7483String = rfc7483String;
} }
@Override public String getDisplayName() {
public String toString() {
return rfc7483String; return rfc7483String;
} }
} }
@ -821,7 +819,7 @@ public class RdapJsonFormatter {
private static ImmutableMap<String, Object> makeEvent( private static ImmutableMap<String, Object> makeEvent(
RdapEventAction eventAction, @Nullable String eventActor, DateTime eventDate) { RdapEventAction eventAction, @Nullable String eventActor, DateTime eventDate) {
ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>(); ImmutableMap.Builder<String, Object> builder = new ImmutableMap.Builder<>();
builder.put("eventAction", eventAction.toString()); builder.put("eventAction", eventAction.getDisplayName());
if (eventActor != null) { if (eventActor != null) {
builder.put("eventActor", eventActor); builder.put("eventActor", eventActor);
} }
@ -901,7 +899,11 @@ public class RdapJsonFormatter {
return FluentIterable return FluentIterable
.from(statusValues) .from(statusValues)
.transform(Functions.forMap(statusToRdapStatusMap, RdapStatus.OBSCURED)) .transform(Functions.forMap(statusToRdapStatusMap, RdapStatus.OBSCURED))
.transform(Functions.toStringFunction()) .transform(new Function<RdapStatus, String>() {
@Override
public String apply(RdapStatus status) {
return status.getDisplayName();
}})
.toSortedSet(Ordering.natural()) .toSortedSet(Ordering.natural())
.asList(); .asList();
} }