Author: [email protected]
Date: Tue Jun 23 20:13:51 2009
New Revision: 5620
Added:
trunk/user/test/com/google/gwt/i18n/client/impl/CurrencyTest.java
Modified:
trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyData.java
trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyList.java
trunk/user/src/com/google/gwt/i18n/rebind/CurrencyListGenerator.java
trunk/user/test/com/google/gwt/i18n/I18NSuite.java
trunk/user/test/com/google/gwt/i18n/client/NumberFormat_en_Test.java
Log:
Add support for deprecated currencies. They can be found by lookup,
but the default iterator will not return them.
Patch by: jat
Review by: andreasst
Modified: trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyData.java
==============================================================================
--- trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyData.java
(original)
+++ trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyData.java Tue
Jun 23 20:13:51 2009
@@ -43,9 +43,11 @@
public static final int PRECISION_MASK = 7;
public static final int SPACE_FORCED_FLAG = 32;
public static final int SPACING_FIXED_FLAG = 64;
+ public static final int DEPRECATED_FLAG = 128;
protected CurrencyData() {
}
+
/**
* @return the ISO4217 code for this currency
*/
@@ -74,6 +76,10 @@
return this[3] || this[1];
}-*/;
+ public boolean isDeprecated() {
+ return (getFlagsAndPrecision() & DEPRECATED_FLAG) != 0;
+ }
+
public boolean isSpaceForced() {
return (getFlagsAndPrecision() & SPACE_FORCED_FLAG) != 0;
}
Modified: trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyList.java
==============================================================================
--- trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyList.java
(original)
+++ trunk/user/src/com/google/gwt/i18n/client/impl/CurrencyList.java Tue
Jun 23 20:13:51 2009
@@ -44,6 +44,12 @@
return CurrencyListInstance.instance;
}
+ // This helper method exists because we can't call JSO instance methods
+ // directly from JSNI.
+ protected static boolean isDeprecated(CurrencyData currencyData) {
+ return currencyData.isDeprecated();
+ }
+
/**
* JS Object which contains a map of currency codes to CurrencyData
* objects. Each currency code is prefixed with a ':' to allow
@@ -60,7 +66,7 @@
* no prefix is added to currency codes in this map.
*/
protected JavaScriptObject namesMap;
-
+
/**
* Return the default currency data for this locale.
*
@@ -72,11 +78,23 @@
/**
* Returns an iterator for the list of currencies.
+ *
+ * Deprecated currencies will not be included.
*/
public final Iterator<CurrencyData> iterator() {
+ return iterator(false);
+ }
+
+ /**
+ * Returns an iterator for the list of currencies, optionally including
+ * deprecated ones.
+ *
+ * @param includeDeprecated true if deprecated currencies should be
included
+ */
+ public final Iterator<CurrencyData> iterator(boolean includeDeprecated) {
ensureCurrencyMap();
ArrayList<String> keys = new ArrayList<String>();
- loadCurrencyKeys(keys);
+ loadCurrencyKeys(keys, includeDeprecated);
final Iterator<String> it = keys.iterator();
return new Iterator<CurrencyData>() {
@@ -93,7 +111,7 @@
}
};
}
-
+
/**
* Lookup a currency based on the ISO4217 currency code.
*
@@ -133,7 +151,7 @@
loadNamesMap();
}
}
-
+
/**
* Directly reference an entry in the currency map JSO.
*
@@ -217,11 +235,15 @@
/**
* Add currency codes contained in the map to an ArrayList.
*/
- private native void loadCurrencyKeys(ArrayList<String> keys) /*-{
+ private native void loadCurrencyKeys(ArrayList<String> keys,
+ boolean includeDeprecated) /*-{
var map = [email protected]::dataMap;
for (var key in map) {
if (map.hasOwnProperty(key)) {
- [email protected]::add(Ljava/lang/Object;)(key);
+ if (includeDeprecated
+ |
|
[email protected]::isDeprecated(Lcom/google/gwt/i18n/client/impl/CurrencyData;)(map[key]))
{
+ [email protected]::add(Ljava/lang/Object;)(key);
+ }
}
}
}-*/;
Modified:
trunk/user/src/com/google/gwt/i18n/rebind/CurrencyListGenerator.java
==============================================================================
--- trunk/user/src/com/google/gwt/i18n/rebind/CurrencyListGenerator.java
(original)
+++ trunk/user/src/com/google/gwt/i18n/rebind/CurrencyListGenerator.java
Tue Jun 23 20:13:51 2009
@@ -134,6 +134,9 @@
currencyObsolete = Integer.valueOf(currencySplit[3]) != 0;
}
int currencyFlags = currencyFractionDigits;
+ if (currencyObsolete) {
+ currencyFlags |= CurrencyData.DEPRECATED_FLAG;
+ }
String currencyPortableSymbol = "";
if (extraData != null) {
// CurrencyExtra contains up to 3 fields separated by |
@@ -631,9 +634,6 @@
boolean needHeader = true;
for (String currencyCode : currencies) {
CurrencyInfo currencyInfo = allCurrencyData.get(currencyCode);
- if (currencyInfo.isObsolete()) {
- continue;
- }
if (needHeader) {
needHeader = false;
writer.println();
@@ -680,9 +680,6 @@
boolean needHeader = true;
for (String currencyCode : currencies) {
CurrencyInfo currencyInfo = allCurrencyData.get(currencyCode);
- if (currencyInfo.isObsolete()) {
- continue;
- }
String displayName = currencyInfo.getDisplayName();
if (displayName != null && !currencyCode.equals(displayName)) {
if (needHeader) {
Modified: trunk/user/test/com/google/gwt/i18n/I18NSuite.java
==============================================================================
--- trunk/user/test/com/google/gwt/i18n/I18NSuite.java (original)
+++ trunk/user/test/com/google/gwt/i18n/I18NSuite.java Tue Jun 23 20:13:51
2009
@@ -37,6 +37,7 @@
import com.google.gwt.i18n.client.RuntimeLocalesTest;
import com.google.gwt.i18n.client.TimeZoneInfoTest;
import com.google.gwt.i18n.client.TimeZoneTest;
+import com.google.gwt.i18n.client.impl.CurrencyTest;
import com.google.gwt.i18n.rebind.MessageFormatParserTest;
import com.google.gwt.i18n.server.GwtLocaleTest;
import com.google.gwt.i18n.server.RegionInheritanceTest;
@@ -55,6 +56,7 @@
suite.addTestSuite(ArabicPluralsTest.class);
suite.addTestSuite(AnnotationsTest.class);
suite.addTestSuite(ConstantMapTest.class);
+ suite.addTestSuite(CurrencyTest.class);
suite.addTestSuite(DateTimeFormat_de_Test.class);
suite.addTestSuite(DateTimeFormat_en_Test.class);
suite.addTestSuite(DateTimeParse_en_Test.class);
Modified:
trunk/user/test/com/google/gwt/i18n/client/NumberFormat_en_Test.java
==============================================================================
--- trunk/user/test/com/google/gwt/i18n/client/NumberFormat_en_Test.java
(original)
+++ trunk/user/test/com/google/gwt/i18n/client/NumberFormat_en_Test.java
Tue Jun 23 20:13:51 2009
@@ -94,6 +94,11 @@
assertEquals("BRL 1,234.56", str);
str = formatter.format(-1234.56);
assertEquals("(BRL 1,234.56)", str);
+
+ // Test using a deprecated currency.
+ formatter = NumberFormat.getCurrencyFormat("ITL");
+ str = formatter.format(1234.556);
+ assertEquals("₤1,235", str);
}
public void testExponential() {
Added: trunk/user/test/com/google/gwt/i18n/client/impl/CurrencyTest.java
==============================================================================
--- (empty file)
+++ trunk/user/test/com/google/gwt/i18n/client/impl/CurrencyTest.java Tue
Jun 23 20:13:51 2009
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.i18n.client.impl;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+import java.util.Iterator;
+
+/**
+ * Tests for CurrencyList and CurrencyData (in addition to locale-specific
+ * tests in I18N_*Test).
+ */
+public class CurrencyTest extends GWTTestCase {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.i18n.I18NTest_es_MX";
+ }
+
+ public void testIterator() {
+ CurrencyList list = CurrencyList.get();
+ boolean found = false;
+ for (CurrencyData data : list) {
+ String code = data.getCurrencyCode();
+ if ("USD".equals(code)) {
+ found = true;
+ } else if ("ITL".equals(code)) {
+ fail("ITL in undeprecated list");
+ }
+ }
+ assertTrue("USD not found in currency list", found);
+ Iterator<CurrencyData> it = list.iterator(true);
+ found = false;
+ while (it.hasNext()) {
+ CurrencyData data = it.next();
+ String code = data.getCurrencyCode();
+ if ("ITL".equals(code)) {
+ found = true;
+ }
+ }
+ assertTrue("ITL not found in deprecated currency list", found);
+ }
+
+ public void testLookup() {
+ CurrencyList list = CurrencyList.get();
+ assertNotNull("USD lookup failed", list.lookup("USD"));
+ assertNotNull("ITL lookup failed", list.lookup("ITL"));
+ assertEquals("dólar estadounidense", list.lookupName("USD"));
+ assertEquals("lira italiana", list.lookupName("ITL"));
+ }
+}
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.i18n.client.impl;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+import java.util.Iterator;
+
+/**
+ * Tests for CurrencyList and CurrencyData (in addition to locale-specific
+ * tests in I18N_*Test).
+ */
+public class CurrencyTest extends GWTTestCase {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.i18n.I18NTest_es_MX";
+ }
+
+ public void testIterator() {
+ CurrencyList list = CurrencyList.get();
+ boolean found = false;
+ for (CurrencyData data : list) {
+ String code = data.getCurrencyCode();
+ if ("USD".equals(code)) {
+ found = true;
+ } else if ("ITL".equals(code)) {
+ fail("ITL in undeprecated list");
+ }
+ }
+ assertTrue("USD not found in currency list", found);
+ Iterator<CurrencyData> it = list.iterator(true);
+ found = false;
+ while (it.hasNext()) {
+ CurrencyData data = it.next();
+ String code = data.getCurrencyCode();
+ if ("ITL".equals(code)) {
+ found = true;
+ }
+ }
+ assertTrue("ITL not found in deprecated currency list", found);
+ }
+
+ public void testLookup() {
+ CurrencyList list = CurrencyList.get();
+ assertNotNull("USD lookup failed", list.lookup("USD"));
+ assertNotNull("ITL lookup failed", list.lookup("ITL"));
+ assertNotNull("USD name lookup failed", list.lookupName("USD"));
+ assertNotNull("ITL name lookup failed", list.lookupName("ITL"));
+ }
+}
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---