MonetaryFormat { public Value parse(ValueType type, String str) throws NumberFormatException { return Value.valueOf(type, parseValue(str, type.getUnitExponent())); } MonetaryFormat(); private  MonetaryFormat(char negativeSign, char positiveSign, char zeroDigit, char decimalMark, int minDecimals,
                           List<Integer> decimalGroups, int shift, RoundingMode roundingMode, Map<Integer, String> codes,
                           char codeSeparator, boolean codePrefixed); MonetaryFormat negativeSign(char negativeSign); MonetaryFormat positiveSign(char positiveSign); MonetaryFormat digits(char zeroDigit); MonetaryFormat decimalMark(char decimalMark); MonetaryFormat minDecimals(int minDecimals); MonetaryFormat optionalDecimals(int... groups); MonetaryFormat repeatOptionalDecimals(int decimals, int repetitions); MonetaryFormat shift(int shift); MonetaryFormat roundingMode(RoundingMode roundingMode); MonetaryFormat noCode(); MonetaryFormat code(int codeShift, String code); MonetaryFormat codeSeparator(char codeSeparator); MonetaryFormat prefixCode(); MonetaryFormat postfixCode(); MonetaryFormat withLocale(Locale locale); CharSequence format(Monetary monetary); CharSequence format(Monetary monetary, int smallestUnitExponent); Value parse(ValueType type, String str); Value parseFiat(String currencyCode, String str); String code(); static final MonetaryFormat BTC; static final MonetaryFormat MBTC; static final MonetaryFormat UBTC; static final MonetaryFormat FIAT; static final String CODE_BTC; static final String CODE_MBTC; static final String CODE_UBTC; }
@Test public void parse() throws Exception { ValueType type = BitcoinMain.get(); Value coin = type.oneCoin(); Value cent = coin.divide(100); Value millicoin = coin.divide(1000); Value microcoin = millicoin.divide(1000); assertEquals(coin, NO_CODE.parse(type, "1")); assertEquals(coin, NO_CODE.parse(type, "1.")); assertEquals(coin, NO_CODE.parse(type, "1.0")); assertEquals(coin, NO_CODE.decimalMark(',').parse(type, "1,0")); assertEquals(coin, NO_CODE.parse(type, "01.0000000000")); assertEquals(coin, NO_CODE.positiveSign('+').parse(type, "+1.0")); assertEquals(coin.negate(), NO_CODE.parse(type, "-1")); assertEquals(coin.negate(), NO_CODE.parse(type, "-1.0")); assertEquals(cent, NO_CODE.parse(type, ".01")); assertEquals(millicoin, MonetaryFormat.MBTC.parse(type, "1")); assertEquals(millicoin, MonetaryFormat.MBTC.parse(type, "1.0")); assertEquals(millicoin, MonetaryFormat.MBTC.parse(type, "01.0000000000")); assertEquals(millicoin, MonetaryFormat.MBTC.positiveSign('+').parse(type, "+1.0")); assertEquals(millicoin.negate(), MonetaryFormat.MBTC.parse(type, "-1")); assertEquals(millicoin.negate(), MonetaryFormat.MBTC.parse(type, "-1.0")); assertEquals(microcoin, MonetaryFormat.UBTC.parse(type, "1")); assertEquals(microcoin, MonetaryFormat.UBTC.parse(type, "1.0")); assertEquals(microcoin, MonetaryFormat.UBTC.parse(type, "01.0000000000")); assertEquals(microcoin, MonetaryFormat.UBTC.positiveSign('+').parse(type, "+1.0")); assertEquals(microcoin.negate(), MonetaryFormat.UBTC.parse(type, "-1")); assertEquals(microcoin.negate(), MonetaryFormat.UBTC.parse(type, "-1.0")); assertEquals(cent, NO_CODE.withLocale(new Locale("hi", "IN")).parse(type, ".०१")); }
@Test(expected = NumberFormatException.class) public void parseInvalidEmpty() throws Exception { NO_CODE.parse(BitcoinMain.get(), ""); }
@Test(expected = NumberFormatException.class) public void parseInvalidWhitespaceBefore() throws Exception { NO_CODE.parse(BitcoinMain.get(), " 1"); }
@Test(expected = NumberFormatException.class) public void parseInvalidWhitespaceSign() throws Exception { NO_CODE.parse(BitcoinMain.get(), "- 1"); }
@Test(expected = NumberFormatException.class) public void parseInvalidWhitespaceAfter() throws Exception { NO_CODE.parse(BitcoinMain.get(), "1 "); }
@Test(expected = NumberFormatException.class) public void parseInvalidMultipleDecimalMarks() throws Exception { NO_CODE.parse(BitcoinMain.get(), "1.0.0"); }
@Test(expected = NumberFormatException.class) public void parseInvalidHugeNumber() throws Exception { NO_CODE.parse(BitcoinMain.get(), "99999999999999999999"); }
@Test(expected = NumberFormatException.class) public void parseInvalidHugeNegativeNumber() throws Exception { NO_CODE.parse(BitcoinMain.get(), "-99999999999999999999"); }