From 2cd857dd3668a6767100e91223cdffbf3807940f Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Sat, 18 Apr 2015 14:34:04 +0200 Subject: [PATCH] If we compare IVs, they of course must properly implement the equals method This fixes the bug where we would request objects again that were already stored. --- .../entity/valueobject/InventoryVector.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/domain/src/main/java/ch/dissem/bitmessage/entity/valueobject/InventoryVector.java b/domain/src/main/java/ch/dissem/bitmessage/entity/valueobject/InventoryVector.java index 2b56e62..48667e5 100644 --- a/domain/src/main/java/ch/dissem/bitmessage/entity/valueobject/InventoryVector.java +++ b/domain/src/main/java/ch/dissem/bitmessage/entity/valueobject/InventoryVector.java @@ -21,6 +21,7 @@ import ch.dissem.bitmessage.utils.Strings; import java.io.IOException; import java.io.OutputStream; +import java.util.Arrays; /** * Created by chris on 13.03.15. @@ -31,6 +32,22 @@ public class InventoryVector implements Streamable { */ private final byte[] hash; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof InventoryVector)) return false; + + InventoryVector that = (InventoryVector) o; + + return Arrays.equals(hash, that.hash); + + } + + @Override + public int hashCode() { + return hash != null ? Arrays.hashCode(hash) : 0; + } + public byte[] getHash() { return hash; }