@Test public void parse() throws Exception { BtcFormat coin = BtcFormat.getCoinInstance(Locale.US); assertEquals(Coin.COIN, coin.parseObject("1")); assertEquals(Coin.COIN, coin.parseObject("1.")); assertEquals(Coin.COIN, coin.parseObject("1.0")); assertEquals(Coin.COIN, BtcFormat.getCoinInstance(Locale.GERMANY).parseObject("1,0")); assertEquals(Coin.COIN, coin.parseObject("01.0000000000")); assertEquals(Coin.COIN.negate(), coin.parseObject("-1")); assertEquals(Coin.COIN.negate(), coin.parseObject("-1.0")); assertEquals(Coin.CENT, coin.parseObject(".01")); BtcFormat milli = BtcFormat.getMilliInstance(Locale.US); assertEquals(Coin.MILLICOIN, milli.parseObject("1")); assertEquals(Coin.MILLICOIN, milli.parseObject("1.0")); assertEquals(Coin.MILLICOIN, milli.parseObject("01.0000000000")); assertEquals(Coin.MILLICOIN.negate(), milli.parseObject("-1")); assertEquals(Coin.MILLICOIN.negate(), milli.parseObject("-1.0")); BtcFormat micro = BtcFormat.getMicroInstance(Locale.US); assertEquals(Coin.MICROCOIN, micro.parseObject("1")); assertEquals(Coin.MICROCOIN, micro.parseObject("1.0")); assertEquals(Coin.MICROCOIN, micro.parseObject("01.0000000000")); assertEquals(Coin.MICROCOIN.negate(), micro.parseObject("-1")); assertEquals(Coin.MICROCOIN.negate(), micro.parseObject("-1.0")); }
public Coin parse(String source, ParsePosition pos) { DecimalFormatSymbols anteSigns = null; int parseScale = COIN_SCALE; Coin coin = null; synchronized (numberFormat) { if (numberFormat.toPattern().contains("¤")) { for(ScaleMatcher d : denomMatchers()) { Matcher matcher = d.pattern.matcher(source); if (matcher.find()) { anteSigns = setSymbolAndCode(numberFormat, matcher.group()); parseScale = d.scale; break; } } if (parseScale == COIN_SCALE) { Matcher matcher = coinPattern.matcher(source); matcher.find(); anteSigns = setSymbolAndCode(numberFormat, matcher.group()); } } else parseScale = scale(); Number number = numberFormat.parse(source, pos); if (number != null) try { coin = Coin.valueOf( ((BigDecimal)number).movePointRight(offSatoshis(parseScale)).setScale(0, HALF_UP).longValue() ); } catch (IllegalArgumentException e) { pos.setIndex(0); } if (anteSigns != null) numberFormat.setDecimalFormatSymbols(anteSigns); } return coin; }
BtcFormat extends Format { public Coin parse(String source, ParsePosition pos) { DecimalFormatSymbols anteSigns = null; int parseScale = COIN_SCALE; Coin coin = null; synchronized (numberFormat) { if (numberFormat.toPattern().contains("¤")) { for(ScaleMatcher d : denomMatchers()) { Matcher matcher = d.pattern.matcher(source); if (matcher.find()) { anteSigns = setSymbolAndCode(numberFormat, matcher.group()); parseScale = d.scale; break; } } if (parseScale == COIN_SCALE) { Matcher matcher = coinPattern.matcher(source); matcher.find(); anteSigns = setSymbolAndCode(numberFormat, matcher.group()); } } else parseScale = scale(); Number number = numberFormat.parse(source, pos); if (number != null) try { coin = Coin.valueOf( ((BigDecimal)number).movePointRight(offSatoshis(parseScale)).setScale(0, HALF_UP).longValue() ); } catch (IllegalArgumentException e) { pos.setIndex(0); } if (anteSigns != null) numberFormat.setDecimalFormatSymbols(anteSigns); } return coin; } }
BtcFormat extends Format { public Coin parse(String source, ParsePosition pos) { DecimalFormatSymbols anteSigns = null; int parseScale = COIN_SCALE; Coin coin = null; synchronized (numberFormat) { if (numberFormat.toPattern().contains("¤")) { for(ScaleMatcher d : denomMatchers()) { Matcher matcher = d.pattern.matcher(source); if (matcher.find()) { anteSigns = setSymbolAndCode(numberFormat, matcher.group()); parseScale = d.scale; break; } } if (parseScale == COIN_SCALE) { Matcher matcher = coinPattern.matcher(source); matcher.find(); anteSigns = setSymbolAndCode(numberFormat, matcher.group()); } } else parseScale = scale(); Number number = numberFormat.parse(source, pos); if (number != null) try { coin = Coin.valueOf( ((BigDecimal)number).movePointRight(offSatoshis(parseScale)).setScale(0, HALF_UP).longValue() ); } catch (IllegalArgumentException e) { pos.setIndex(0); } if (anteSigns != null) numberFormat.setDecimalFormatSymbols(anteSigns); } return coin; } protected  BtcFormat(DecimalFormat numberFormat, int minDecimals, List<Integer> groups); }
BtcFormat extends Format { public Coin parse(String source, ParsePosition pos) { DecimalFormatSymbols anteSigns = null; int parseScale = COIN_SCALE; Coin coin = null; synchronized (numberFormat) { if (numberFormat.toPattern().contains("¤")) { for(ScaleMatcher d : denomMatchers()) { Matcher matcher = d.pattern.matcher(source); if (matcher.find()) { anteSigns = setSymbolAndCode(numberFormat, matcher.group()); parseScale = d.scale; break; } } if (parseScale == COIN_SCALE) { Matcher matcher = coinPattern.matcher(source); matcher.find(); anteSigns = setSymbolAndCode(numberFormat, matcher.group()); } } else parseScale = scale(); Number number = numberFormat.parse(source, pos); if (number != null) try { coin = Coin.valueOf( ((BigDecimal)number).movePointRight(offSatoshis(parseScale)).setScale(0, HALF_UP).longValue() ); } catch (IllegalArgumentException e) { pos.setIndex(0); } if (anteSigns != null) numberFormat.setDecimalFormatSymbols(anteSigns); } return coin; } protected  BtcFormat(DecimalFormat numberFormat, int minDecimals, List<Integer> groups); static Builder builder(); static BtcFormat getInstance(); static BtcFormat getSymbolInstance(); static BtcFormat getCodeInstance(); static BtcFormat getSymbolInstance(int fractionPlaces); static BtcFormat getCodeInstance(int minDecimals); static BtcFormat getInstance(Locale locale); static BtcFormat getCodeInstance(Locale locale); static BtcFormat getInstance(Locale locale, int minDecimals); static BtcFormat getCodeInstance(Locale locale, int minDecimals); static BtcFormat getSymbolInstance(Locale locale); static BtcFormat getSymbolInstance(Locale locale, int fractionPlaces); static BtcFormat getInstance(Style style); static BtcFormat getInstance(Style style, int fractionPlaces); static BtcFormat getInstance(Style style, Locale locale); static BtcFormat getInstance(Style style, Locale locale, int fractionPlaces); static BtcFormat getCoinInstance(); static BtcFormat getCoinInstance(int minFractionPlaces, int... groups); static BtcFormat getCoinInstance(Locale locale); static BtcFormat getCoinInstance(Locale locale, int scale, int... groups); static BtcFormat getMilliInstance(); static BtcFormat getMilliInstance(Locale locale); static BtcFormat getMilliInstance(int scale, int... groups); static BtcFormat getMilliInstance(Locale locale, int scale, int... groups); static BtcFormat getMicroInstance(); static BtcFormat getMicroInstance(Locale locale); static BtcFormat getMicroInstance(int scale, int... groups); static BtcFormat getMicroInstance(Locale locale, int scale, int... groups); static BtcFormat getInstance(int scale, int minDecimals, int... groups); static BtcFormat getInstance(int scale); static BtcFormat getInstance(int scale, Locale locale); static BtcFormat getInstance(int scale, Locale locale, int minDecimals, int... groups); static BtcFormat getInstance(int scale, Locale locale, int minDecimals, List<Integer> groups); @Override AttributedCharacterIterator formatToCharacterIterator(Object obj); @Override StringBuffer format(Object qty, StringBuffer toAppendTo, FieldPosition pos); String format(Object qty, int minDecimals, int... fractionGroups); StringBuffer format(Object qty, StringBuffer toAppendTo, FieldPosition pos,
                                            int minDecimals, int... fractionGroups); @Override final Object parseObject(String source, ParsePosition pos); Coin parse(String source, ParsePosition pos); Coin parse(String source); static Locale[] getAvailableLocales(); String coinSymbol(); String coinCode(); String pattern(); DecimalFormatSymbols symbols(); @Override boolean equals(Object o); @Override int hashCode(); }
BtcFormat extends Format { public Coin parse(String source, ParsePosition pos) { DecimalFormatSymbols anteSigns = null; int parseScale = COIN_SCALE; Coin coin = null; synchronized (numberFormat) { if (numberFormat.toPattern().contains("¤")) { for(ScaleMatcher d : denomMatchers()) { Matcher matcher = d.pattern.matcher(source); if (matcher.find()) { anteSigns = setSymbolAndCode(numberFormat, matcher.group()); parseScale = d.scale; break; } } if (parseScale == COIN_SCALE) { Matcher matcher = coinPattern.matcher(source); matcher.find(); anteSigns = setSymbolAndCode(numberFormat, matcher.group()); } } else parseScale = scale(); Number number = numberFormat.parse(source, pos); if (number != null) try { coin = Coin.valueOf( ((BigDecimal)number).movePointRight(offSatoshis(parseScale)).setScale(0, HALF_UP).longValue() ); } catch (IllegalArgumentException e) { pos.setIndex(0); } if (anteSigns != null) numberFormat.setDecimalFormatSymbols(anteSigns); } return coin; } protected  BtcFormat(DecimalFormat numberFormat, int minDecimals, List<Integer> groups); static Builder builder(); static BtcFormat getInstance(); static BtcFormat getSymbolInstance(); static BtcFormat getCodeInstance(); static BtcFormat getSymbolInstance(int fractionPlaces); static BtcFormat getCodeInstance(int minDecimals); static BtcFormat getInstance(Locale locale); static BtcFormat getCodeInstance(Locale locale); static BtcFormat getInstance(Locale locale, int minDecimals); static BtcFormat getCodeInstance(Locale locale, int minDecimals); static BtcFormat getSymbolInstance(Locale locale); static BtcFormat getSymbolInstance(Locale locale, int fractionPlaces); static BtcFormat getInstance(Style style); static BtcFormat getInstance(Style style, int fractionPlaces); static BtcFormat getInstance(Style style, Locale locale); static BtcFormat getInstance(Style style, Locale locale, int fractionPlaces); static BtcFormat getCoinInstance(); static BtcFormat getCoinInstance(int minFractionPlaces, int... groups); static BtcFormat getCoinInstance(Locale locale); static BtcFormat getCoinInstance(Locale locale, int scale, int... groups); static BtcFormat getMilliInstance(); static BtcFormat getMilliInstance(Locale locale); static BtcFormat getMilliInstance(int scale, int... groups); static BtcFormat getMilliInstance(Locale locale, int scale, int... groups); static BtcFormat getMicroInstance(); static BtcFormat getMicroInstance(Locale locale); static BtcFormat getMicroInstance(int scale, int... groups); static BtcFormat getMicroInstance(Locale locale, int scale, int... groups); static BtcFormat getInstance(int scale, int minDecimals, int... groups); static BtcFormat getInstance(int scale); static BtcFormat getInstance(int scale, Locale locale); static BtcFormat getInstance(int scale, Locale locale, int minDecimals, int... groups); static BtcFormat getInstance(int scale, Locale locale, int minDecimals, List<Integer> groups); @Override AttributedCharacterIterator formatToCharacterIterator(Object obj); @Override StringBuffer format(Object qty, StringBuffer toAppendTo, FieldPosition pos); String format(Object qty, int minDecimals, int... fractionGroups); StringBuffer format(Object qty, StringBuffer toAppendTo, FieldPosition pos,
                                            int minDecimals, int... fractionGroups); @Override final Object parseObject(String source, ParsePosition pos); Coin parse(String source, ParsePosition pos); Coin parse(String source); static Locale[] getAvailableLocales(); String coinSymbol(); String coinCode(); String pattern(); DecimalFormatSymbols symbols(); @Override boolean equals(Object o); @Override int hashCode(); static final int COIN_SCALE; static final int MILLICOIN_SCALE; static final int MICROCOIN_SCALE; }