Skip to content

Commit d63f001

Browse files
committed
Update NumberFormat.java
1 parent 0bcb0c7 commit d63f001

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main/java/lol/hyper/toolstats/tools/NumberFormat.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public class NumberFormat {
3131
private DecimalFormat COMMA_FORMAT;
3232
private SimpleDateFormat DATE_FORMAT;
3333

34+
/**
35+
* Utility class to format different numbers
36+
* @param toolStats Plugin instance.
37+
*/
3438
public NumberFormat(ToolStats toolStats) {
3539

3640
String dateFormat = toolStats.config.getString("date-format");
@@ -39,6 +43,7 @@ public NumberFormat(ToolStats toolStats) {
3943
String commaFormat = toolStats.config.getString("number-formats.comma-format");
4044
String decimalFormat = toolStats.config.getString("number-formats.decimal-format");
4145

46+
// if these config values are missing, use the default ones
4247
if (dateFormat == null) {
4348
dateFormat = "M/dd/yyyy";
4449
toolStats.logger.warning("date-format is missing! Using default American English format.");
@@ -64,6 +69,7 @@ public NumberFormat(ToolStats toolStats) {
6469
toolStats.logger.warning("number-formats.comma-separator is missing! Using default #,###.00 instead.");
6570
}
6671

72+
// test the date format
6773
try {
6874
DATE_FORMAT = new SimpleDateFormat(dateFormat, Locale.getDefault());
6975
} catch (NullPointerException | IllegalArgumentException exception) {
@@ -72,11 +78,13 @@ public NumberFormat(ToolStats toolStats) {
7278
DATE_FORMAT = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
7379
}
7480

81+
// set the separators
7582
DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(Locale.getDefault());
7683
formatSymbols.setDecimalSeparator(decimalSeparator.charAt(0));
7784
formatSymbols.setGroupingSeparator(commaSeparator.charAt(0));
7885

7986

87+
// test the comma format
8088
try {
8189
COMMA_FORMAT = new DecimalFormat(commaFormat, formatSymbols);
8290
} catch (NullPointerException | IllegalArgumentException exception) {
@@ -85,6 +93,7 @@ public NumberFormat(ToolStats toolStats) {
8593
COMMA_FORMAT = new DecimalFormat("#,###", formatSymbols);
8694
}
8795

96+
// test the decimal format
8897
try {
8998
DECIMAL_FORMAT = new DecimalFormat(decimalFormat, formatSymbols);
9099
} catch (NullPointerException | IllegalArgumentException exception) {

0 commit comments

Comments
 (0)