VarInt: implement equals() and hashCode()

`originallyEncodedSize` is not considered on purpose, because it is only
relevant for serialization.
This commit is contained in:
Andreas Schildbach 2023-03-27 16:23:39 +02:00
parent 2faaf9febc
commit 301c8e4a76

View File

@ -21,6 +21,7 @@ import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Objects;
import static org.bitcoinj.base.internal.Preconditions.check;
@ -177,4 +178,17 @@ public class VarInt {
}
return buf;
}
@Override
public boolean equals(Object o) {
// originallyEncodedSize is not considered on purpose
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return value == ((VarInt) o).value;
}
@Override
public int hashCode() {
return Objects.hash(value);
}
}