Skip to content

Commit

Permalink
[MPIR-436] Don't use DecimalFormat which is identical with String#val…
Browse files Browse the repository at this point in the history
…ueOf(long)

This closes #49
  • Loading branch information
michael-o committed May 12, 2023
1 parent c031699 commit a5e3348
Showing 1 changed file with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ public class DependenciesRenderer extends AbstractProjectInfoRenderer {
/** URL for the 'close.gif' image */
private static final String IMG_CLOSE_URL = "./images/close.gif";

/** Used to format decimal values in the "Dependency File Details" table */
protected static final DecimalFormat DEFAULT_DECIMAL_FORMAT = new DecimalFormat("###0");

private static final Set<String> JAR_SUBTYPE;

private final DependencyNode dependencyNode;
Expand Down Expand Up @@ -181,10 +178,6 @@ public DependenciesRenderer(
this.projectBuilder = projectBuilder;
this.buildingRequest = buildingRequest;
this.licenseMappings = licenseMappings;

// Using the right set of symbols depending of the locale
DEFAULT_DECIMAL_FORMAT.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));

this.fileLengthDecimalFormat = new FileDecimalFormat(i18n, locale);
this.fileLengthDecimalFormat.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
}
Expand Down Expand Up @@ -501,14 +494,14 @@ private void renderSectionDependencyFileDetails() {

startTable(justification, false);

TotalCell totaldeps = new TotalCell(DEFAULT_DECIMAL_FORMAT);
TotalCell totaldeps = new TotalCell();
TotalCell totaldepsize = new TotalCell(fileLengthDecimalFormat);
TotalCell totalentries = new TotalCell(DEFAULT_DECIMAL_FORMAT);
TotalCell totalclasses = new TotalCell(DEFAULT_DECIMAL_FORMAT);
TotalCell totalpackages = new TotalCell(DEFAULT_DECIMAL_FORMAT);
TotalCell totalentries = new TotalCell();
TotalCell totalclasses = new TotalCell();
TotalCell totalpackages = new TotalCell();
double highestJavaVersion = 0.0;
TotalCell totalDebugInformation = new TotalCell(DEFAULT_DECIMAL_FORMAT);
TotalCell totalsealed = new TotalCell(DEFAULT_DECIMAL_FORMAT);
TotalCell totalDebugInformation = new TotalCell();
TotalCell totalsealed = new TotalCell();

boolean hasSealed = hasSealed(alldeps);

Expand Down Expand Up @@ -579,9 +572,9 @@ private void renderSectionDependencyFileDetails() {
tableRow(hasSealed, new String[] {
name,
fileLength,
DEFAULT_DECIMAL_FORMAT.format(jarDetails.getNumEntries()),
DEFAULT_DECIMAL_FORMAT.format(jarDetails.getNumClasses()),
DEFAULT_DECIMAL_FORMAT.format(jarDetails.getNumPackages()),
String.valueOf(jarDetails.getNumEntries()),
String.valueOf(jarDetails.getNumClasses()),
String.valueOf(jarDetails.getNumPackages()),
jarDetails.getJdkRevision(),
debugInformationCellValue,
sealedCellValue
Expand Down Expand Up @@ -1143,7 +1136,7 @@ private String getString(String key) {
static class TotalCell {
static final int SCOPES_COUNT = 5;

final DecimalFormat decimalFormat;
DecimalFormat decimalFormat;

long total = 0;

Expand All @@ -1157,6 +1150,8 @@ static class TotalCell {

long totalSystemScope = 0;

TotalCell() {}

TotalCell(DecimalFormat decimalFormat) {
this.decimalFormat = decimalFormat;
}
Expand Down Expand Up @@ -1210,7 +1205,12 @@ String getTotalString(int index) {
if (index >= 0) {
sb.append(getScope(index)).append(": ");
}
sb.append(decimalFormat.format(getTotal(index)));
if (decimalFormat != null) {
sb.append(decimalFormat.format(getTotal(index)));
} else {
sb.append(getTotal(index));
}

return sb.toString();
}

Expand All @@ -1233,7 +1233,12 @@ void addTotal(long add, String scope) {
/** {@inheritDoc} */
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(decimalFormat.format(total));
if (decimalFormat != null) {
sb.append(decimalFormat.format(total));
} else {
sb.append(total);
}

sb.append(" (");

boolean needSeparator = false;
Expand Down

0 comments on commit a5e3348

Please sign in to comment.