forked from Upstream/Velocitab
Simplify string comparable weight logic to fix issues with low weight diffs
This commit is contained in:
parent
f616a5e08a
commit
c16fbf40ab
@ -40,25 +40,10 @@ public class Role implements Comparable<Role> {
|
|||||||
return Optional.ofNullable(name);
|
return Optional.ofNullable(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public String getStringComparableWeight(int maximumPossibleWeight, int lowestPossibleWeight) {
|
public String getStringComparableWeight(int maximumPossibleWeight, int lowestPossibleWeight) {
|
||||||
// Calculate the weight range and the ratio of the input weight to the weight range
|
return String.format("%0" + String.valueOf(maximumPossibleWeight).length() + "d", weight - lowestPossibleWeight)
|
||||||
int weightRange = maximumPossibleWeight - lowestPossibleWeight;
|
.replace(" ", "0")
|
||||||
double weightRatio = (double) (maximumPossibleWeight - weight) / weightRange;
|
.replace("-", "0");
|
||||||
|
|
||||||
// Convert the weight ratio to a string with 3 decimal places and remove the decimal point
|
|
||||||
String weightString = String.format("%.3f", weightRatio).replace(".", "");
|
|
||||||
|
|
||||||
// Pad the weight string with leading zeros to a length of 6 characters
|
|
||||||
weightString = String.format("%6s", weightString).replace(' ', '0');
|
|
||||||
|
|
||||||
// Prepend a minus sign for negative weights
|
|
||||||
if (weight < 0) {
|
|
||||||
weightString = "-" + weightString.substring(1);
|
|
||||||
} else {
|
|
||||||
// Reverse the weight string for non-negative weights
|
|
||||||
weightString = new StringBuilder(weightString).reverse().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return weightString;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user