Skip to content

Commit a5e3348

Browse files
committed
[MPIR-436] Don't use DecimalFormat which is identical with String#valueOf(long)
This closes #49
1 parent c031699 commit a5e3348

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/main/java/org/apache/maven/report/projectinfo/dependencies/renderer/DependenciesRenderer.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ public class DependenciesRenderer extends AbstractProjectInfoRenderer {
7575
/** URL for the 'close.gif' image */
7676
private static final String IMG_CLOSE_URL = "./images/close.gif";
7777

78-
/** Used to format decimal values in the "Dependency File Details" table */
79-
protected static final DecimalFormat DEFAULT_DECIMAL_FORMAT = new DecimalFormat("###0");
80-
8178
private static final Set<String> JAR_SUBTYPE;
8279

8380
private final DependencyNode dependencyNode;
@@ -181,10 +178,6 @@ public DependenciesRenderer(
181178
this.projectBuilder = projectBuilder;
182179
this.buildingRequest = buildingRequest;
183180
this.licenseMappings = licenseMappings;
184-
185-
// Using the right set of symbols depending of the locale
186-
DEFAULT_DECIMAL_FORMAT.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
187-
188181
this.fileLengthDecimalFormat = new FileDecimalFormat(i18n, locale);
189182
this.fileLengthDecimalFormat.setDecimalFormatSymbols(new DecimalFormatSymbols(locale));
190183
}
@@ -501,14 +494,14 @@ private void renderSectionDependencyFileDetails() {
501494

502495
startTable(justification, false);
503496

504-
TotalCell totaldeps = new TotalCell(DEFAULT_DECIMAL_FORMAT);
497+
TotalCell totaldeps = new TotalCell();
505498
TotalCell totaldepsize = new TotalCell(fileLengthDecimalFormat);
506-
TotalCell totalentries = new TotalCell(DEFAULT_DECIMAL_FORMAT);
507-
TotalCell totalclasses = new TotalCell(DEFAULT_DECIMAL_FORMAT);
508-
TotalCell totalpackages = new TotalCell(DEFAULT_DECIMAL_FORMAT);
499+
TotalCell totalentries = new TotalCell();
500+
TotalCell totalclasses = new TotalCell();
501+
TotalCell totalpackages = new TotalCell();
509502
double highestJavaVersion = 0.0;
510-
TotalCell totalDebugInformation = new TotalCell(DEFAULT_DECIMAL_FORMAT);
511-
TotalCell totalsealed = new TotalCell(DEFAULT_DECIMAL_FORMAT);
503+
TotalCell totalDebugInformation = new TotalCell();
504+
TotalCell totalsealed = new TotalCell();
512505

513506
boolean hasSealed = hasSealed(alldeps);
514507

@@ -579,9 +572,9 @@ private void renderSectionDependencyFileDetails() {
579572
tableRow(hasSealed, new String[] {
580573
name,
581574
fileLength,
582-
DEFAULT_DECIMAL_FORMAT.format(jarDetails.getNumEntries()),
583-
DEFAULT_DECIMAL_FORMAT.format(jarDetails.getNumClasses()),
584-
DEFAULT_DECIMAL_FORMAT.format(jarDetails.getNumPackages()),
575+
String.valueOf(jarDetails.getNumEntries()),
576+
String.valueOf(jarDetails.getNumClasses()),
577+
String.valueOf(jarDetails.getNumPackages()),
585578
jarDetails.getJdkRevision(),
586579
debugInformationCellValue,
587580
sealedCellValue
@@ -1143,7 +1136,7 @@ private String getString(String key) {
11431136
static class TotalCell {
11441137
static final int SCOPES_COUNT = 5;
11451138

1146-
final DecimalFormat decimalFormat;
1139+
DecimalFormat decimalFormat;
11471140

11481141
long total = 0;
11491142

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

11581151
long totalSystemScope = 0;
11591152

1153+
TotalCell() {}
1154+
11601155
TotalCell(DecimalFormat decimalFormat) {
11611156
this.decimalFormat = decimalFormat;
11621157
}
@@ -1210,7 +1205,12 @@ String getTotalString(int index) {
12101205
if (index >= 0) {
12111206
sb.append(getScope(index)).append(": ");
12121207
}
1213-
sb.append(decimalFormat.format(getTotal(index)));
1208+
if (decimalFormat != null) {
1209+
sb.append(decimalFormat.format(getTotal(index)));
1210+
} else {
1211+
sb.append(getTotal(index));
1212+
}
1213+
12141214
return sb.toString();
12151215
}
12161216

@@ -1233,7 +1233,12 @@ void addTotal(long add, String scope) {
12331233
/** {@inheritDoc} */
12341234
public String toString() {
12351235
StringBuilder sb = new StringBuilder();
1236-
sb.append(decimalFormat.format(total));
1236+
if (decimalFormat != null) {
1237+
sb.append(decimalFormat.format(total));
1238+
} else {
1239+
sb.append(total);
1240+
}
1241+
12371242
sb.append(" (");
12381243

12391244
boolean needSeparator = false;

0 commit comments

Comments
 (0)