]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/text/CurrencyFormat.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / text / CurrencyFormat.java
1 /*\r
2 **********************************************************************\r
3 * Copyright (c) 2004-2010, International Business Machines\r
4 * Corporation and others.  All Rights Reserved.\r
5 **********************************************************************\r
6 * Author: Alan Liu\r
7 * Created: April 20, 2004\r
8 * Since: ICU 3.0\r
9 **********************************************************************\r
10 */\r
11 package com.ibm.icu.text;\r
12 \r
13 import java.text.FieldPosition;\r
14 import java.text.ParsePosition;\r
15 \r
16 import com.ibm.icu.util.CurrencyAmount;\r
17 import com.ibm.icu.util.ULocale;\r
18 \r
19 /**\r
20  * Temporary internal concrete subclass of MeasureFormat implementing\r
21  * parsing and formatting of CurrencyAmount objects.  This class is\r
22  * likely to be redesigned and rewritten in the near future.\r
23  *\r
24  * <p>This class currently delegates to DecimalFormat for parsing and\r
25  * formatting.\r
26  *\r
27  * @see com.ibm.icu.text.UFormat\r
28  * @see com.ibm.icu.text.DecimalFormat\r
29  * @author Alan Liu\r
30  */\r
31 class CurrencyFormat extends MeasureFormat {\r
32     // Generated by serialver from JDK 1.4.1_01\r
33     static final long serialVersionUID = -931679363692504634L;\r
34     \r
35     private NumberFormat fmt;\r
36 \r
37     public CurrencyFormat(ULocale locale) {\r
38         fmt = NumberFormat.getCurrencyInstance(locale.toLocale());\r
39     }\r
40 \r
41     /**\r
42      * Override Format.format().\r
43      * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)\r
44      */\r
45     public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {\r
46         try {\r
47             CurrencyAmount currency = (CurrencyAmount) obj;\r
48             fmt.setCurrency(currency.getCurrency());\r
49             return fmt.format(currency.getNumber(), toAppendTo, pos);\r
50         } catch (ClassCastException e) {\r
51             throw new IllegalArgumentException("Invalid type: " + obj.getClass().getName());\r
52         }\r
53     }\r
54 \r
55     /**\r
56      * Override Format.parseObject().\r
57      * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)\r
58      */\r
59     public Object parseObject(String source, ParsePosition pos) {\r
60         return fmt.parseCurrency(source, pos);\r
61     }\r
62 }\r