mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-30 14:39:56 +08:00
Fix VersionNumber.equals() and hashCode() may not be consistent
This commit is contained in:
parent
223c2bc7c7
commit
e21f315239
@ -19,7 +19,6 @@ package org.jackhuang.hmcl.util.versioning;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -43,11 +42,6 @@ public final class ComposedVersionNumber extends VersionNumber {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(composed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return composed.stream().map(VersionNumber::toString).collect(Collectors.joining("-"));
|
||||
|
@ -19,7 +19,6 @@ package org.jackhuang.hmcl.util.versioning;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
@ -65,11 +64,6 @@ public final class IntVersionNumber extends VersionNumber {
|
||||
return version.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return version.stream().map(Object::toString).collect(Collectors.joining("."));
|
||||
|
@ -38,11 +38,6 @@ public final class StringVersionNumber extends VersionNumber {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return version.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return version;
|
||||
|
@ -52,9 +52,13 @@ public abstract class VersionNumber implements Comparable<VersionNumber> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
else return toString().equals(obj.toString());
|
||||
public boolean equals(Object another) {
|
||||
return another instanceof VersionNumber && this.toString().equals(another.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
private static <T extends Comparable<T>> int compareTo(List<T> a, List<T> b) {
|
||||
|
Loading…
Reference in New Issue
Block a user