Skip to content

Commit

Permalink
Minor simplifications of VersionRange.hashCode()/equals()
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Oct 18, 2024
1 parent 775774f commit 29e2a6d
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.Serializable;
import java.lang.ref.SoftReference;
import java.util.Objects;
import java.util.WeakHashMap;
import org.eclipse.equinox.internal.p2.metadata.*;
import org.eclipse.osgi.util.NLS;
Expand Down Expand Up @@ -77,11 +78,10 @@ private static int copyEscaped(String vr, int pos, String breakChars, StringBuil
*/
public VersionRange(Version minVersion, boolean includeMin, Version maxVersion, boolean includeMax) {
if (minVersion == null) {
minVersion = Version.emptyVersion;
if (maxVersion == null) {
minVersion = Version.emptyVersion;
maxVersion = Version.MAX_VERSION;
} else
minVersion = Version.emptyVersion;
}
} else {
if (maxVersion == null)
maxVersion = Version.MAX_VERSION;
Expand Down Expand Up @@ -419,21 +419,14 @@ public boolean isOSGiCompatible() {

@Override
public boolean equals(Object object) {
if (!(object instanceof VersionRange))
return false;
VersionRange vr = (VersionRange) object;
return includeMin == vr.includeMin && includeMax == vr.includeMax && minVersion.equals(vr.getMinimum()) && maxVersion.equals(vr.getMaximum());
return object instanceof VersionRange vr //
&& includeMin == vr.includeMin && includeMax == vr.includeMax //
&& minVersion.equals(vr.getMinimum()) && maxVersion.equals(vr.getMaximum());
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + maxVersion.hashCode();
result = prime * result + minVersion.hashCode();
result = prime * result + (includeMax ? 1231 : 1237);
result = prime * result + (includeMin ? 1231 : 1237);
return result;
return Objects.hash(maxVersion, minVersion, includeMax, includeMin);
}

@Override
Expand Down

0 comments on commit 29e2a6d

Please sign in to comment.