incorporated code review feedback: optimized LazilyParsedNumber.equals/hashcode() by utilizing the fact that value is never passed as null.

This commit is contained in:
Inderjeet Singh 2015-09-27 13:58:01 -07:00
parent 3aec173243
commit 96b2ada79a

View File

@ -26,6 +26,7 @@ import java.math.BigDecimal;
public final class LazilyParsedNumber extends Number { public final class LazilyParsedNumber extends Number {
private final String value; private final String value;
/** @param value must not be null */
public LazilyParsedNumber(String value) { public LazilyParsedNumber(String value) {
this.value = value; this.value = value;
} }
@ -78,7 +79,7 @@ public final class LazilyParsedNumber extends Number {
@Override @Override
public int hashCode() { public int hashCode() {
return value == null ? 0 : value.hashCode(); return value.hashCode();
} }
@Override @Override
@ -86,15 +87,10 @@ public final class LazilyParsedNumber extends Number {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null || !(obj instanceof LazilyParsedNumber)) { if (obj instanceof LazilyParsedNumber) {
return false; LazilyParsedNumber other = (LazilyParsedNumber) obj;
return value == other.value || value.equals(other.value);
} }
LazilyParsedNumber other = (LazilyParsedNumber) obj; return false;
return equals(value, other.value);
}
private static boolean equals(Object obj1, Object obj2) {
if (obj1 == null) return obj2 == null;
return obj1 == obj2 || obj1.equals(obj2);
} }
} }