Skip to content

Commit

Permalink
fix(base.version): fix HVersion hashcode
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Jul 28, 2023
1 parent 90d18c8 commit 06629b5
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/main/java/org/auioc/mcmod/arnicalib/base/version/HVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ public class HVersion {
public final boolean isDirty;
public final boolean isDev;

public HVersion(String main, String full) {
this.main = main;
this.full = full;
this.revisionHash = getRevisionHash(full);
this.buildNumber = getBuildNumber(full);
this.isDev = full.contains("-dev-");
this.isDirty = full.contains("-dirty");
}

public HVersion(String main, String full, String revisionHash, int buildNumber, boolean isDirty, boolean isDev) {
this.main = main;
this.full = full;
Expand All @@ -32,27 +23,38 @@ public HVersion(String main, String full, String revisionHash, int buildNumber,
this.isDev = isDev;
}

public HVersion(String main, String full) {
this(
main, full,
getRevisionHash(full),
getBuildNumber(full),
full.contains("-dirty"),
full.contains("-dev-")
);
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj instanceof HVersion other) return main.equals(other.main) && full.equals(other.full);
if (obj instanceof HVersion other) {
return this.main.equals(other.main) && this.full.equals(other.full);
}
return false;
}

@Override
public int hashCode() {
return main.hashCode() + full.hashCode();
return 31 * this.main.hashCode() + this.full.hashCode();
}

// ====================================================================== //

private static final Pattern PATTERN_REVISION_HASH = Pattern.compile("(?<=rev\\.)[0-9a-fA-F]{7}");
private static final Pattern PATTERN_BUILD_NUMBER = Pattern.compile("(?<=build\\.)\\d+");


private static String getRevisionHash(String fullVersion) {
Matcher matcher = PATTERN_REVISION_HASH.matcher(fullVersion);
return (matcher.find()) ? matcher.group() : "";
return (matcher.find()) ? matcher.group().toLowerCase() : "";
}

private static int getBuildNumber(String fullVersion) {
Expand Down

0 comments on commit 06629b5

Please sign in to comment.