1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ********************************************************************** 5 * Copyright (c) 2004-2014, International Business Machines 6 * Corporation and others. All Rights Reserved. 7 ********************************************************************** 8 * Author: Alan Liu 9 * Created: April 20, 2004 10 * Since: ICU 3.0 11 ********************************************************************** 12 */ 13 package com.ibm.icu.text; 14 15 import java.io.ObjectStreamException; 16 import java.text.FieldPosition; 17 import java.text.ParsePosition; 18 19 import com.ibm.icu.util.CurrencyAmount; 20 import com.ibm.icu.util.ULocale; 21 22 /** 23 * Temporary internal concrete subclass of MeasureFormat implementing parsing and formatting of 24 * CurrencyAmount objects. This class is likely to be redesigned and rewritten in the near future. 25 * 26 * <p> 27 * This class currently delegates to DecimalFormat for parsing and formatting. 28 * 29 * @see com.ibm.icu.text.UFormat 30 * @see com.ibm.icu.text.DecimalFormat 31 * @author Alan Liu 32 */ 33 class CurrencyFormat extends MeasureFormat { 34 // Generated by serialver from JDK 1.4.1_01 35 static final long serialVersionUID = -931679363692504634L; 36 CurrencyFormat(ULocale locale)37 public CurrencyFormat(ULocale locale) { 38 super(locale, FormatWidth.DEFAULT_CURRENCY); 39 } 40 41 /** 42 * Override Format.format(). 43 * 44 * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) 45 */ 46 @Override format(Object obj, StringBuffer toAppendTo, FieldPosition pos)47 public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { 48 if (!(obj instanceof CurrencyAmount)) { 49 throw new IllegalArgumentException("Invalid type: " + obj.getClass().getName()); 50 } 51 return super.format(obj, toAppendTo, pos); 52 } 53 54 /** 55 * Override Format.parseObject(). 56 * 57 * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition) 58 */ 59 @Override parseObject(String source, ParsePosition pos)60 public CurrencyAmount parseObject(String source, ParsePosition pos) { 61 return getNumberFormatInternal().parseCurrency(source, pos); 62 } 63 64 // Serialization 65 writeReplace()66 private Object writeReplace() throws ObjectStreamException { 67 return toCurrencyProxy(); 68 } 69 70 // Preserve backward serialize backward compatibility. readResolve()71 private Object readResolve() throws ObjectStreamException { 72 return new CurrencyFormat(getLocale(ULocale.ACTUAL_LOCALE)); 73 } 74 } 75