Fix VersionNumber.equals() and hashCode() may not be consistent

This commit is contained in:
yushijinhun 2018-10-02 21:25:29 +08:00
parent 223c2bc7c7
commit e21f315239
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
4 changed files with 7 additions and 20 deletions

View File

@ -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("-"));

View File

@ -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("."));

View File

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

View File

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