Merge pull request #275 from typesafehub/serialized-config-tostring

Implement non-exploding toString/equals/hashCode on SerializedConfigValu...
This commit is contained in:
Havoc Pennington 2015-03-06 10:00:46 -05:00
commit 5e0be760c7
2 changed files with 29 additions and 1 deletions

View File

@ -312,7 +312,7 @@ abstract class AbstractConfigValue implements ConfigValue, MergeableValue {
}
@Override
public final String toString() {
public String toString() {
StringBuilder sb = new StringBuilder();
render(sb, 0, true /* atRoot */, null /* atKey */, ConfigRenderOptions.concise());
return getClass().getSimpleName() + "(" + sb.toString() + ")";

View File

@ -497,4 +497,32 @@ class SerializedConfigValue extends AbstractConfigValue implements Externalizabl
protected SerializedConfigValue newCopy(ConfigOrigin origin) {
throw shouldNotBeUsed();
}
@Override
public final String toString() {
return getClass().getSimpleName() + "(value=" + value + ",wasConfig=" + wasConfig + ")";
}
@Override
public boolean equals(Object other) {
// there's no reason we will ever call this equals(), but
// the one in AbstractConfigValue would explode due to
// calling unwrapped() above, so we just give some
// safe-to-call implementation to avoid breaking the
// contract of java.lang.Object
if (other instanceof SerializedConfigValue) {
return canEqual(other)
&& (this.wasConfig == ((SerializedConfigValue) other).wasConfig)
&& (this.value.equals(((SerializedConfigValue) other).value));
} else {
return false;
}
}
@Override
public int hashCode() {
int h = 41 * (41 + value.hashCode());
h = 41 * (h + (wasConfig ? 1 : 0));
return h;
}
}