From d1b12236b89941400ec16c276e96201a190253d1 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Thu, 9 Jan 2025 15:33:32 -0800 Subject: [PATCH] Changed MpqFileHandle equality contact to match only MpqFileHandle#path() and not FileHandle#type which is not set by MpqFileHandle --- .../riiablo/mpq_bytebuf/MpqFileHandle.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/src/main/java/com/riiablo/mpq_bytebuf/MpqFileHandle.java b/core/src/main/java/com/riiablo/mpq_bytebuf/MpqFileHandle.java index af254917..9c219a5f 100644 --- a/core/src/main/java/com/riiablo/mpq_bytebuf/MpqFileHandle.java +++ b/core/src/main/java/com/riiablo/mpq_bytebuf/MpqFileHandle.java @@ -21,6 +21,7 @@ import java.io.Reader; import java.io.Writer; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; +import java.util.Objects; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; @@ -129,6 +130,26 @@ public final class MpqFileHandle extends FileHandle implements ReferenceCounted this.archive = mpq.map().slice(offset, CSize); } + /** + * Matches FileHandle irrespective of {@link FileHandle#type} + */ + @Override + public boolean equals(Object o) { + if (o instanceof MpqFileHandle) { + MpqFileHandle other = (MpqFileHandle) o; + return Objects.equals(filename, other.path()); + } else { + if (!(o instanceof FileHandle)) return false; + FileHandle other = (FileHandle) o; + return super.equals(other); + } + } + + @Override + public int hashCode() { + return filename.hashCode(); + } + @Override public String toString() { return toString == null