From bca3719ab2dfa872bd647e43fef1db5274923072 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Thu, 14 Apr 2016 10:04:43 +0200 Subject: [PATCH] proper equals and hashCode --- .../openapi/util/io/ByteSequence.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/platform/util/src/com/intellij/openapi/util/io/ByteSequence.java b/platform/util/src/com/intellij/openapi/util/io/ByteSequence.java index 9f4416075566..120a1cbdf4b1 100644 --- a/platform/util/src/com/intellij/openapi/util/io/ByteSequence.java +++ b/platform/util/src/com/intellij/openapi/util/io/ByteSequence.java @@ -48,4 +48,36 @@ public class ByteSequence { public int getLength() { return myLen; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ByteSequence sequence = (ByteSequence)o; + int len = myLen; + if (len != sequence.myLen) return false; + + final byte[] thisBytes = myBytes; + final byte[] thatBytes = sequence.myBytes; + for (int i = 0, j = myOffset, k = sequence.myOffset; i < len; i++) { + if (thisBytes[j] != thatBytes[k]) { + return false; + } + } + + return true; + } + + @Override + public int hashCode() { + final int len = myLen; + final byte[] thisBytes = myBytes; + + int result = 1; + for (int i = 0, j = myOffset; i < len; i++) { + result = result * 31 + thisBytes[j]; + } + return result; + } }