Source Code Cross Referenced for Currency.java in  » Apache-Harmony-Java-SE » java-package » java » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package java.util;
019:
020:        import java.io.Serializable;
021:
022:        /**
023:         * This class represents a currency as identified in the ISO 4217 currency
024:         * codes.
025:         */
026:        public final class Currency implements  Serializable {
027:
028:            private static final long serialVersionUID = -158308464356906721L;
029:
030:            private static Hashtable<String, Currency> codesToCurrencies = new Hashtable<String, Currency>();
031:
032:            private String currencyCode;
033:
034:            /**
035:             * @param currencyCode
036:             */
037:            private Currency(String currencyCode) {
038:                this .currencyCode = currencyCode;
039:            }
040:
041:            /**
042:             * Returns the Currency instance for this currency code.
043:             * <p>
044:             * 
045:             * @param currencyCode
046:             *            java.lang.String
047:             * @return currency java.util.Currency
048:             * 
049:             * @throws java.lang.IllegalArgumentException
050:             *             if the currency code is not a supported ISO 4217 currency
051:             *             code
052:             */
053:            public static Currency getInstance(String currencyCode) {
054:                Currency currency = codesToCurrencies.get(currencyCode);
055:
056:                if (currency == null) {
057:                    currency = new Currency(currencyCode);
058:                    codesToCurrencies.put(currencyCode, currency);
059:                }
060:
061:                return currency;
062:            }
063:
064:            /***************************************************************************
065:             * Returns the Currency instance for the given locale.
066:             * 
067:             * @param locale
068:             *            java.util.Locale
069:             * @return currency java.util.Currency
070:             * 
071:             * @throws java.lang.IllegalArgumentException
072:             *             if the locale's country is not a supported ISO 3166 Country
073:             */
074:            public static Currency getInstance(Locale locale) {
075:                com.ibm.icu.util.Currency currency = null;
076:                try {
077:                    currency = com.ibm.icu.util.Currency.getInstance(locale);
078:                } catch (IllegalArgumentException e) {
079:                    return null;
080:                }
081:                if (currency == null) {
082:                    throw new IllegalArgumentException(locale.getCountry());
083:                }
084:                String currencyCode = currency.getCurrencyCode();
085:
086:                if (currencyCode.equals("None")) { //$NON-NLS-1$
087:                    return null;
088:                }
089:
090:                return getInstance(currencyCode);
091:            }
092:
093:            /**
094:             * Returns this currency's ISO 4217 currency code.
095:             * 
096:             * @return this currency's ISO 4217 currency code
097:             */
098:            public String getCurrencyCode() {
099:                return currencyCode;
100:            }
101:
102:            /**
103:             * Returns the currency symbol for the default locale.
104:             * 
105:             * Equivalent to <code>getSymbol(Locale.getDefault())</code>
106:             * 
107:             * @return the currency symbol for the default locale.
108:             */
109:            public String getSymbol() {
110:                return getSymbol(Locale.getDefault());
111:            }
112:
113:            /**
114:             * Returns the currency symbol for the given locale.
115:             * <p>
116:             * 
117:             * If the locale doesn't have any countries (e.g.
118:             * <code>Locale.JAPANESE, new Locale("en","")</code>), currencyCode is
119:             * returned.
120:             * <p>
121:             * First the locale bundle is checked, if the locale has the same currency,
122:             * the CurrencySymbol in this locale bundle is returned.
123:             * <p>
124:             * Then a currency bundle for this locale is searched.
125:             * <p>
126:             * If a currency bundle for this locale does not exist, or there is no
127:             * symbol for this currency in this bundle, than <code>currencyCode</code>
128:             * is returned.
129:             * <p>
130:             * 
131:             * @param locale
132:             *            the locale
133:             * @return symbol the representation of this Currency's symbol in this
134:             *         locale
135:             */
136:            public String getSymbol(Locale locale) {
137:                if (locale.getCountry().equals("")) { //$NON-NLS-1$
138:                    return currencyCode;
139:                }
140:                return com.ibm.icu.util.Currency.getInstance(currencyCode)
141:                        .getSymbol(locale);
142:            }
143:
144:            /**
145:             * Returns the default number of fraction digits for this currency (i.e. the
146:             * number of digits after the decimal point). For pseudo currencies this
147:             * method returns -1.
148:             * 
149:             * @return the default number of fraction digits for this currency
150:             */
151:            public int getDefaultFractionDigits() {
152:                return com.ibm.icu.util.Currency.getInstance(currencyCode)
153:                        .getDefaultFractionDigits();
154:            }
155:
156:            /**
157:             * Returns this currency's ISO 4217 currency code.
158:             * 
159:             * @return this currency's ISO 4217 currency code
160:             */
161:            @Override
162:            public String toString() {
163:                return currencyCode;
164:            }
165:
166:            private Object readResolve() {
167:                return getInstance(currencyCode);
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.