Skip to content

Commit

Permalink
use Objects.hashCode
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Feb 13, 2024
1 parent cff2482 commit 39305f9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
Expand Down Expand Up @@ -114,12 +115,11 @@ public boolean equals(Object o)
return false;
}
BigIntegerNode otherNode = (BigIntegerNode) o;
return java.util.Objects.equals(otherNode._value, _value);
return Objects.equals(otherNode._value, _value);
}

@Override
public int hashCode() {
// we need a stable hash code for _value == null
return _value == null ? -1 : _value.hashCode();
return Objects.hashCode(_value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public boolean equals(Object o)
public int hashCode() {
if (_value == null) {
// we need a stable hash code for _value == null
return -1;
return 0;
}
return Double.valueOf(doubleValue()).hashCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ void testNullBigIntegerNode() {
assertEquals(new BigIntegerNode(null), new BigIntegerNode(null));
assertNotEquals(new BigIntegerNode(BigInteger.ZERO), new BigIntegerNode(null));
assertNotEquals(new BigIntegerNode(null), new BigIntegerNode(BigInteger.ZERO));
assertEquals(-1, new BigIntegerNode(null).hashCode());
assertEquals(0, new BigIntegerNode(null).hashCode());
}

@Test
void testNullDecimalNode() {
assertEquals(new DecimalNode(null), new DecimalNode(null));
assertNotEquals(new DecimalNode(BigDecimal.ZERO), new DecimalNode(null));
assertNotEquals( new DecimalNode(null), new DecimalNode(BigDecimal.ZERO));
assertEquals(-1, new DecimalNode(null).hashCode());
assertEquals(0, new DecimalNode(null).hashCode());
}
}

0 comments on commit 39305f9

Please sign in to comment.