Skip to content

Commit

Permalink
Reformat source code (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
jodastephen authored Sep 23, 2022
1 parent 536487d commit 786545a
Show file tree
Hide file tree
Showing 14 changed files with 615 additions and 163 deletions.
399 changes: 399 additions & 0 deletions src/eclipse/JodaMoneyFormatter.xml

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions src/main/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
<module name="EmptyBlock">
<property name="tokens" value="LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_IF,LITERAL_FOR,LITERAL_TRY,LITERAL_WHILE,STATIC_INIT"/>
</module>
<module name="EmptyForInitializerPad">
<property name="option" value="space"/>
</module>
<module name="EmptyForIteratorPad">
<property name="option" value="space"/>
</module>
<module name="EmptyForInitializerPad"/>
<module name="EmptyForIteratorPad"/>
<module name="EqualsHashCode"/>
<module name="IllegalImport"/>
<module name="IllegalInstantiation">
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/org/joda/money/CurrencyUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public final class CurrencyUnit implements Comparable<CurrencyUnit>, Serializabl
try {
try {
String clsName = System.getProperty(
"org.joda.money.CurrencyUnitDataProvider", "org.joda.money.DefaultCurrencyUnitDataProvider");
"org.joda.money.CurrencyUnitDataProvider",
"org.joda.money.DefaultCurrencyUnitDataProvider");
Class<? extends CurrencyUnitDataProvider> cls =
CurrencyUnit.class.getClassLoader().loadClass(clsName).asSubclass(CurrencyUnitDataProvider.class);
cls.getDeclaredConstructor().newInstance().registerCurrencies();
Expand Down Expand Up @@ -159,7 +160,11 @@ public final class CurrencyUnit implements Comparable<CurrencyUnit>, Serializabl
* specified data is invalid
*/
public static synchronized CurrencyUnit registerCurrency(
String currencyCode, int numericCurrencyCode, int decimalPlaces, List<String> countryCodes) {
String currencyCode,
int numericCurrencyCode,
int decimalPlaces,
List<String> countryCodes) {

return registerCurrency(currencyCode, numericCurrencyCode, decimalPlaces, countryCodes, false);
}

Expand Down Expand Up @@ -192,7 +197,12 @@ public static synchronized CurrencyUnit registerCurrency(
* or if the specified data is invalid
*/
public static synchronized CurrencyUnit registerCurrency(
String currencyCode, int numericCurrencyCode, int decimalPlaces, List<String> countryCodes, boolean force) {
String currencyCode,
int numericCurrencyCode,
int decimalPlaces,
List<String> countryCodes,
boolean force) {

MoneyUtils.checkNotNull(currencyCode, "Currency code must not be null");
if (currencyCode.length() != 3) {
throw new IllegalArgumentException("Invalid string code, must be length 3");
Expand All @@ -207,7 +217,7 @@ public static synchronized CurrencyUnit registerCurrency(
throw new IllegalArgumentException("Invalid number of decimal places");
}
MoneyUtils.checkNotNull(countryCodes, "Country codes must not be null");

CurrencyUnit currency = new CurrencyUnit(currencyCode, (short) numericCurrencyCode, (short) decimalPlaces);
if (force) {
currenciesByCode.remove(currencyCode);
Expand Down Expand Up @@ -263,9 +273,9 @@ public static synchronized CurrencyUnit registerCurrency(
* or if the specified data is invalid
*/
public static synchronized CurrencyUnit registerCurrency(
String currencyCode,
String currencyCode,
int numericCurrencyCode,
int decimalPlaces,
int decimalPlaces,
boolean force) {

List<String> countryCodes = Collections.emptyList();
Expand Down Expand Up @@ -367,12 +377,14 @@ public static CurrencyUnit ofNumericCode(String numericCurrencyCode) {
case 1:
return ofNumericCode(numericCurrencyCode.charAt(0) - '0');
case 2:
return ofNumericCode((numericCurrencyCode.charAt(0) - '0') * 10 +
numericCurrencyCode.charAt(1) - '0');
return ofNumericCode(
(numericCurrencyCode.charAt(0) - '0') * 10 +
numericCurrencyCode.charAt(1) - '0');
case 3:
return ofNumericCode((numericCurrencyCode.charAt(0) - '0') * 100 +
(numericCurrencyCode.charAt(1) - '0') * 10 +
numericCurrencyCode.charAt(2) - '0');
return ofNumericCode(
(numericCurrencyCode.charAt(0) - '0') * 100 +
(numericCurrencyCode.charAt(1) - '0') * 10 +
numericCurrencyCode.charAt(2) - '0');
default:
throw new IllegalCurrencyException("Unknown currency '" + numericCurrencyCode + '\'');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DefaultCurrencyUnitDataProvider extends CurrencyUnitDataProvider {
* Registers all the currencies known by this provider.
*
* @throws Exception if an error occurs
*/
*/
@Override
protected void registerCurrencies() throws Exception {
parseCurrencies(loadFromFile("/org/joda/money/CurrencyData.csv"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void parse(MoneyParseContext context) {
}
}
boolean lastWasGroup = false;
for ( ; pos < len; pos++) {
for (; pos < len; pos++) {
char ch = context.getText().charAt(pos);
if (ch >= activeStyle.getZeroCharacter() && ch < activeStyle.getZeroCharacter() + 10) {
buf[bufPos++] = (char) ('0' + ch - activeStyle.getZeroCharacter());
Expand Down
48 changes: 27 additions & 21 deletions src/main/java/org/joda/money/format/MoneyAmountStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,54 +55,54 @@ public final class MoneyAmountStyle implements Serializable {
* Forced decimal point is disabled.
*/
public static final MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_COMMA =
new MoneyAmountStyle('0', '+', '-', '.', GroupingStyle.FULL, ',', 3, 0, false, false);
new MoneyAmountStyle('0', '+', '-', '.', GroupingStyle.FULL, ',', 3, 0, false, false);
/**
* A style that uses ASCII digits/negative sign, the decimal point
* and groups large amounts in 3's using a space.
* Forced decimal point is disabled.
*/
public static final MoneyAmountStyle ASCII_DECIMAL_POINT_GROUP3_SPACE =
new MoneyAmountStyle('0', '+', '-', '.', GroupingStyle.FULL, ' ', 3, 0, false, false);
new MoneyAmountStyle('0', '+', '-', '.', GroupingStyle.FULL, ' ', 3, 0, false, false);
/**
* A style that uses ASCII digits/negative sign, the decimal point
* and no grouping of large amounts.
* Forced decimal point is disabled.
*/
public static final MoneyAmountStyle ASCII_DECIMAL_POINT_NO_GROUPING =
new MoneyAmountStyle('0', '+', '-', '.', GroupingStyle.NONE, ',', 3, 0, false, false);
new MoneyAmountStyle('0', '+', '-', '.', GroupingStyle.NONE, ',', 3, 0, false, false);
/**
* A style that uses ASCII digits/negative sign, the decimal comma
* and groups large amounts in 3's using a dot.
* Forced decimal point is disabled.
*/
public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_DOT =
new MoneyAmountStyle('0', '+', '-', ',', GroupingStyle.FULL, '.', 3, 0, false, false);
new MoneyAmountStyle('0', '+', '-', ',', GroupingStyle.FULL, '.', 3, 0, false, false);
/**
* A style that uses ASCII digits/negative sign, the decimal comma
* and groups large amounts in 3's using a space.
* Forced decimal point is disabled.
*/
public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_GROUP3_SPACE =
new MoneyAmountStyle('0', '+', '-', ',', GroupingStyle.FULL, ' ', 3, 0, false, false);
new MoneyAmountStyle('0', '+', '-', ',', GroupingStyle.FULL, ' ', 3, 0, false, false);
/**
* A style that uses ASCII digits/negative sign, the decimal point
* and no grouping of large amounts.
* Forced decimal point is disabled.
*/
public static final MoneyAmountStyle ASCII_DECIMAL_COMMA_NO_GROUPING =
new MoneyAmountStyle('0', '+', '-', ',', GroupingStyle.NONE, '.', 3, 0, false, false);
new MoneyAmountStyle('0', '+', '-', ',', GroupingStyle.NONE, '.', 3, 0, false, false);
/**
* A style that will be filled in with localized values using the locale of the formatter.
* Grouping is enabled. Forced decimal point is disabled.
*/
public static final MoneyAmountStyle LOCALIZED_GROUPING =
new MoneyAmountStyle(-1, -1, -1, -1, GroupingStyle.FULL, -1, -1, -1, false, false);
new MoneyAmountStyle(-1, -1, -1, -1, GroupingStyle.FULL, -1, -1, -1, false, false);
/**
* A style that will be filled in with localized values using the locale of the formatter.
* Grouping is disabled. Forced decimal point is disabled.
*/
public static final MoneyAmountStyle LOCALIZED_NO_GROUPING =
new MoneyAmountStyle(-1, -1, -1, -1, GroupingStyle.NONE, -1, -1, -1, false, false);
new MoneyAmountStyle(-1, -1, -1, -1, GroupingStyle.NONE, -1, -1, -1, false, false);
/**
* Cache of localized styles.
*/
Expand Down Expand Up @@ -184,11 +184,17 @@ public static MoneyAmountStyle of(Locale locale) {
* @param absValue true to output the absolute value rather than the signed value
*/
private MoneyAmountStyle(
int zeroCharacter,
int positiveCharacter, int negativeCharacter,
int decimalPointCharacter, GroupingStyle groupingStyle,
int groupingCharacter, int groupingSize, int extendedGroupingSize,
boolean forceDecimalPoint, boolean absValue) {
int zeroCharacter,
int positiveCharacter,
int negativeCharacter,
int decimalPointCharacter,
GroupingStyle groupingStyle,
int groupingCharacter,
int groupingSize,
int extendedGroupingSize,
boolean forceDecimalPoint,
boolean absValue) {

this.zeroCharacter = zeroCharacter;
this.positiveCharacter = positiveCharacter;
this.negativeCharacter = negativeCharacter;
Expand Down Expand Up @@ -272,14 +278,14 @@ private static MoneyAmountStyle getLocalizedStyle(Locale locale) {
size = size <= 0 ? 3 : size;
protoStyle = new MoneyAmountStyle(
symbols.getZeroDigit(),
'+',
'+',
symbols.getMinusSign(),
symbols.getMonetaryDecimalSeparator(),
GroupingStyle.FULL,
symbols.getGroupingSeparator(),
size,
0,
false,
symbols.getGroupingSeparator(),
size,
0,
false,
false);
LOCALIZED_CACHE.putIfAbsent(locale, protoStyle);
}
Expand Down Expand Up @@ -666,9 +672,9 @@ public int hashCode() {
@Override
public String toString() {
return "MoneyAmountStyle['" + getZeroCharacter() + "','" + getPositiveSignCharacter() + "','" +
getNegativeSignCharacter() + "','" + getDecimalPointCharacter() + "','" +
getGroupingStyle() + "," + getGroupingCharacter() + "','" + getGroupingSize() + "'," +
isForcedDecimalPoint() + "'," + isAbsValue() + "]";
getNegativeSignCharacter() + "','" + getDecimalPointCharacter() + "','" +
getGroupingStyle() + "," + getGroupingCharacter() + "','" + getGroupingSize() + "'," +
isForcedDecimalPoint() + "'," + isAbsValue() + "]";
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/joda/money/format/MoneyFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void printIO(Appendable appendable, BigMoneyProvider moneyProvider) throw
if (isPrinter() == false) {
throw new UnsupportedOperationException("MoneyFomatter has not been configured to be able to print");
}

BigMoney money = BigMoney.of(moneyProvider);
MoneyPrintContext context = new MoneyPrintContext(locale);
printerParser.print(context, appendable, money);
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/joda/money/format/MoneyFormatterBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ public MoneyFormatterBuilder append(MoneyPrinter printer, MoneyParser parser) {
* @param whenNegative the formatter to use when the amount is negative
* @return this for chaining, never null
*/
public MoneyFormatterBuilder appendSigned(
MoneyFormatter whenPositiveOrZero, MoneyFormatter whenNegative) {
public MoneyFormatterBuilder appendSigned(MoneyFormatter whenPositiveOrZero, MoneyFormatter whenNegative) {
return appendSigned(whenPositiveOrZero, whenPositiveOrZero, whenNegative);
}

Expand All @@ -241,8 +240,7 @@ public MoneyFormatterBuilder appendSigned(
* @param whenNegative the formatter to use when the amount is negative
* @return this for chaining, never null
*/
public MoneyFormatterBuilder appendSigned(
MoneyFormatter whenPositive, MoneyFormatter whenZero, MoneyFormatter whenNegative) {
public MoneyFormatterBuilder appendSigned(MoneyFormatter whenPositive, MoneyFormatter whenZero, MoneyFormatter whenNegative) {
MoneyFormatter.checkNotNull(whenPositive, "MoneyFormatter whenPositive must not be null");
MoneyFormatter.checkNotNull(whenZero, "MoneyFormatter whenZero must not be null");
MoneyFormatter.checkNotNull(whenNegative, "MoneyFormatter whenNegative must not be null");
Expand Down Expand Up @@ -314,6 +312,7 @@ private static enum Singletons implements MoneyPrinter, MoneyParser {
public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException {
appendable.append(money.getCurrencyUnit().getCode());
}

@Override
public void parse(MoneyParseContext context) {
int endPos = context.getIndex() + 3;
Expand All @@ -335,6 +334,7 @@ public void parse(MoneyParseContext context) {
public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException {
appendable.append(money.getCurrencyUnit().getNumeric3Code());
}

@Override
public void parse(MoneyParseContext context) {
int endPos = context.getIndex() + 3;
Expand All @@ -356,10 +356,11 @@ public void parse(MoneyParseContext context) {
public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException {
appendable.append(Integer.toString(money.getCurrencyUnit().getNumericCode()));
}

@Override
public void parse(MoneyParseContext context) {
int count = 0;
for ( ; count < 3 && context.getIndex() + count < context.getTextLength(); count++) {
for (; count < 3 && context.getIndex() + count < context.getTextLength(); count++) {
char ch = context.getText().charAt(context.getIndex() + count);
if (ch < '0' || ch > '9') {
break;
Expand All @@ -375,10 +376,13 @@ public void parse(MoneyParseContext context) {
}
}
};

private final String toString;

private Singletons(String toString) {
this.toString = toString;
}

@Override
public String toString() {
return toString;
Expand All @@ -391,10 +395,12 @@ public String toString() {
*/
private static enum SingletonPrinters implements MoneyPrinter {
LOCALIZED_SYMBOL;

@Override
public void print(MoneyPrintContext context, Appendable appendable, BigMoney money) throws IOException {
appendable.append(money.getCurrencyUnit().getSymbol(context.getLocale()));
}

@Override
public String toString() {
return "${symbolLocalized}";
Expand Down
Loading

0 comments on commit 786545a

Please sign in to comment.