Changed MpqFileHandle equality contact to match only MpqFileHandle#path() and not FileHandle#type which is not set by MpqFileHandle

This commit is contained in:
Collin Smith 2025-01-09 15:33:32 -08:00
parent 187ffe190b
commit d1b12236b8

View File

@ -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