KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > text > CurrencyFormat


1 /*
2 **********************************************************************
3 * Copyright (c) 2004-2005, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Author: Alan Liu
7 * Created: April 20, 2004
8 * Since: ICU 3.0
9 **********************************************************************
10 */

11 package com.ibm.icu.text;
12
13 import java.text.FieldPosition JavaDoc;
14 import java.text.ParsePosition JavaDoc;
15
16 import com.ibm.icu.util.CurrencyAmount;
17 import com.ibm.icu.util.ULocale;
18
19 /**
20  * Temporary internal concrete subclass of MeasureFormat implementing
21  * parsing and formatting of CurrencyAmount objects. This class is
22  * likely to be redesigned and rewritten in the near future.
23  *
24  * <p>This class currently delegates to DecimalFormat for parsing and
25  * formatting.
26  *
27  * @see com.ibm.icu.text.UFormat
28  * @see com.ibm.icu.text.DecimalFormat
29  * @author Alan Liu
30  * @internal
31  */

32 class CurrencyFormat extends MeasureFormat {
33     // Generated by serialver from JDK 1.4.1_01
34
static final long serialVersionUID = -931679363692504634L;
35     
36     private NumberFormat fmt;
37
38     public CurrencyFormat(ULocale locale) {
39         fmt = NumberFormat.getCurrencyInstance(locale.toLocale());
40     }
41
42     /**
43      * Override Format.format().
44      * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
45      */

46     public StringBuffer JavaDoc format(Object JavaDoc obj, StringBuffer JavaDoc toAppendTo, FieldPosition JavaDoc pos) {
47         try {
48             CurrencyAmount currency = (CurrencyAmount) obj;
49             fmt.setCurrency(currency.getCurrency());
50             return fmt.format(currency.getNumber(), toAppendTo, pos);
51         } catch (ClassCastException JavaDoc e) {
52             throw new IllegalArgumentException JavaDoc("Invalid type: " + obj.getClass().getName());
53         }
54     }
55
56     /**
57      * Override Format.parseObject().
58      * @see java.text.Format#parseObject(java.lang.String, java.text.ParsePosition)
59      */

60     public Object JavaDoc parseObject(String JavaDoc source, ParsePosition JavaDoc pos) {
61         return fmt.parseCurrency(source, pos);
62     }
63 }
64
Popular Tags