From 7af711a383eb84eabef5681eb3a05ae938ebdb59 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Tue, 26 Jan 2010 18:56:34 +0000 Subject: [PATCH] ICU-7027 Delete icu-eclipse directory for now. These files are coming from the previous release. But we no longer support old JDK compatibility implementation. X-SVN-Rev: 27420 --- .gitattributes | 1 - .../features/com.ibm.icu.base/.project | 17 - .../com.ibm.icu.base/build.properties | 19 - .../features/com.ibm.icu.base/feature.xml | 34 - .../features/com.ibm.icu.jse4/.project | 17 - .../com.ibm.icu.jse4/build.properties | 21 - .../features/com.ibm.icu.jse4/feature.xml | 35 - .../icu-eclipse/features/com.ibm.icu/.project | 17 - .../features/com.ibm.icu/build.properties | 20 - .../features/com.ibm.icu/feature.xml | 33 - icu4j/icu-eclipse/misc/ICUConfig.properties | 12 - icu4j/icu-eclipse/misc/about_icu.html | 54 - icu4j/icu-eclipse/misc/about_icu_base.html | 51 - icu4j/icu-eclipse/pdebuild/allElements.xml | 28 - icu4j/icu-eclipse/pdebuild/build.properties | 220 - icu4j/icu-eclipse/pdebuild/customTargets.xml | 161 - .../plugins/com.ibm.icu.base.tests/.classpath | 7 - .../plugins/com.ibm.icu.base.tests/.project | 28 - .../.settings/org.eclipse.jdt.core.prefs | 12 - .../.settings/org.eclipse.jdt.ui.prefs | 3 - .../META-INF/MANIFEST.MF | 12 - .../com.ibm.icu.base.tests/build.properties | 4 - .../com/ibm/icu/tests/BreakIteratorTest.java | 359 -- .../src/com/ibm/icu/tests/CalendarTest.java | 559 --- .../com/ibm/icu/tests/CollationKeyTest.java | 102 - .../src/com/ibm/icu/tests/CollatorTest.java | 205 - .../ibm/icu/tests/DateFormatSymbolsTest.java | 257 -- .../src/com/ibm/icu/tests/DateFormatTest.java | 443 -- .../icu/tests/DecimalFormatSymbolsTest.java | 344 -- .../com/ibm/icu/tests/DecimalFormatTest.java | 242 -- .../src/com/ibm/icu/tests/ICUTestCase.java | 286 -- .../com/ibm/icu/tests/MessageFormatTest.java | 307 -- .../com/ibm/icu/tests/NumberFormatTest.java | 441 -- .../ibm/icu/tests/SimpleDateFormatTest.java | 202 - .../src/com/ibm/icu/tests/TimeZoneTest.java | 235 - .../src/com/ibm/icu/tests/ULocaleTest.java | 748 ---- .../plugins/com.ibm.icu.base/.classpath | 7 - .../plugins/com.ibm.icu.base/.project | 28 - .../.settings/org.eclipse.jdt.core.prefs | 12 - .../.settings/org.eclipse.jdt.ui.prefs | 3 - .../com.ibm.icu.base/META-INF/MANIFEST.MF | 13 - .../plugins/com.ibm.icu.base/build.properties | 19 - .../com.ibm.icu.base/plugin.properties | 12 - .../src/com/ibm/icu/text/BreakIterator.java | 661 --- .../src/com/ibm/icu/text/CollationKey.java | 250 -- .../src/com/ibm/icu/text/Collator.java | 565 --- .../src/com/ibm/icu/text/DateFormat.java | 983 ----- .../com/ibm/icu/text/DateFormatSymbols.java | 302 -- .../src/com/ibm/icu/text/DecimalFormat.java | 903 ---- .../ibm/icu/text/DecimalFormatSymbols.java | 349 -- .../src/com/ibm/icu/text/MessageFormat.java | 1042 ----- .../src/com/ibm/icu/text/NumberFormat.java | 778 ---- .../com/ibm/icu/text/SimpleDateFormat.java | 382 -- .../src/com/ibm/icu/util/Calendar.java | 2118 --------- .../src/com/ibm/icu/util/TimeZone.java | 432 -- .../src/com/ibm/icu/util/ULocale.java | 3822 ----------------- .../plugins/com.ibm.icu.jse4/.classpath | 7 - .../plugins/com.ibm.icu.jse4/.project | 28 - .../.settings/org.eclipse.jdt.core.prefs | 12 - .../.settings/org.eclipse.jdt.ui.prefs | 3 - .../com.ibm.icu.jse4/META-INF/MANIFEST.MF | 12 - .../plugins/com.ibm.icu.jse4/build.properties | 19 - .../fragment-icu-jse4.properties | 12 - .../plugins/com.ibm.icu.tests/.classpath | 7 - .../plugins/com.ibm.icu.tests/.project | 28 - .../.settings/org.eclipse.jdt.core.prefs | 12 - .../.settings/org.eclipse.jdt.ui.prefs | 3 - .../com.ibm.icu.tests/META-INF/MANIFEST.MF | 11 - .../com.ibm.icu.tests/build.properties | 14 - .../src/com/ibm/icu/tests/UnitTest.java | 159 - .../plugins/com.ibm.icu/.classpath | 7 - .../icu-eclipse/plugins/com.ibm.icu/.project | 28 - .../.settings/org.eclipse.jdt.core.prefs | 12 - .../.settings/org.eclipse.jdt.ui.prefs | 3 - .../plugins/com.ibm.icu/META-INF/MANIFEST.MF | 24 - .../plugins/com.ibm.icu/build.properties | 19 - .../plugins/com.ibm.icu/plugin.properties | 12 - 77 files changed, 18649 deletions(-) delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu.base/.project delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu.base/build.properties delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu.base/feature.xml delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu.jse4/.project delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu.jse4/build.properties delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu.jse4/feature.xml delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu/.project delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu/build.properties delete mode 100644 icu4j/icu-eclipse/features/com.ibm.icu/feature.xml delete mode 100644 icu4j/icu-eclipse/misc/ICUConfig.properties delete mode 100644 icu4j/icu-eclipse/misc/about_icu.html delete mode 100644 icu4j/icu-eclipse/misc/about_icu_base.html delete mode 100644 icu4j/icu-eclipse/pdebuild/allElements.xml delete mode 100644 icu4j/icu-eclipse/pdebuild/build.properties delete mode 100644 icu4j/icu-eclipse/pdebuild/customTargets.xml delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.classpath delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.project delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/META-INF/MANIFEST.MF delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/build.properties delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/BreakIteratorTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CalendarTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollationKeyTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollatorTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatSymbolsTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatSymbolsTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ICUTestCase.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/MessageFormatTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/NumberFormatTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/SimpleDateFormatTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/TimeZoneTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ULocaleTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/.classpath delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/.project delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.core.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/META-INF/MANIFEST.MF delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/build.properties delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/plugin.properties delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/BreakIterator.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/CollationKey.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/Collator.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormat.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormatSymbols.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormat.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormatSymbols.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/MessageFormat.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/NumberFormat.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/SimpleDateFormat.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/Calendar.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/TimeZone.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/ULocale.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.classpath delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.project delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.core.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/META-INF/MANIFEST.MF delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/build.properties delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/fragment-icu-jse4.properties delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.classpath delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.project delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.core.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.tests/META-INF/MANIFEST.MF delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.tests/build.properties delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu.tests/src/com/ibm/icu/tests/UnitTest.java delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu/.classpath delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu/.project delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.core.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu/META-INF/MANIFEST.MF delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu/build.properties delete mode 100644 icu4j/icu-eclipse/plugins/com.ibm.icu/plugin.properties diff --git a/.gitattributes b/.gitattributes index cab63d76101..57a7188ff51 100644 --- a/.gitattributes +++ b/.gitattributes @@ -64,7 +64,6 @@ icu4c/source/test/testdata/old_l_testtypes.res -text icu4c/source/test/testdata/uni-text.bin -text icu4j/build.properties -text icu4j/demos/manifest.stub -text -icu4j/icu-eclipse/misc/ICUConfig.properties -text icu4j/main/classes/charset/.classpath -text icu4j/main/classes/charset/.project -text icu4j/main/classes/charset/.settings/org.eclipse.jdt.core.prefs -text diff --git a/icu4j/icu-eclipse/features/com.ibm.icu.base/.project b/icu4j/icu-eclipse/features/com.ibm.icu.base/.project deleted file mode 100644 index 7f1208b79a1..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu.base/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - com.ibm.icu.base-feature - - - - - - org.eclipse.pde.FeatureBuilder - - - - - - org.eclipse.pde.FeatureNature - - diff --git a/icu4j/icu-eclipse/features/com.ibm.icu.base/build.properties b/icu4j/icu-eclipse/features/com.ibm.icu.base/build.properties deleted file mode 100644 index ea9d11ff4ae..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu.base/build.properties +++ /dev/null @@ -1,19 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes =\ -epl-v10.html,\ -eclipse_update_120.jpg,\ -feature.xml,\ -feature.properties,\ -license.html -outputUpdateJars = true - -generate.plugin@com.ibm.icu.base.source=com.ibm.icu.base \ No newline at end of file diff --git a/icu4j/icu-eclipse/features/com.ibm.icu.base/feature.xml b/icu4j/icu-eclipse/features/com.ibm.icu.base/feature.xml deleted file mode 100644 index c6921c26e82..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu.base/feature.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - [Enter Feature Description here.] - - - - [Enter Copyright Description here.] - - - - [Enter License Description here.] - - - - - - - diff --git a/icu4j/icu-eclipse/features/com.ibm.icu.jse4/.project b/icu4j/icu-eclipse/features/com.ibm.icu.jse4/.project deleted file mode 100644 index 82740eb4036..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu.jse4/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - com.ibm.icu.jse4-feature - - - - - - org.eclipse.pde.FeatureBuilder - - - - - - org.eclipse.pde.FeatureNature - - diff --git a/icu4j/icu-eclipse/features/com.ibm.icu.jse4/build.properties b/icu4j/icu-eclipse/features/com.ibm.icu.jse4/build.properties deleted file mode 100644 index 6da5b4b2182..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu.jse4/build.properties +++ /dev/null @@ -1,21 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes =\ -epl-v10.html,\ -eclipse_update_120.jpg,\ -feature.xml,\ -feature.properties,\ -license.html -outputUpdateJars = true - -generate.plugin@com.ibm.icu.jse4.source=com.ibm.icu.jse4 - - diff --git a/icu4j/icu-eclipse/features/com.ibm.icu.jse4/feature.xml b/icu4j/icu-eclipse/features/com.ibm.icu.jse4/feature.xml deleted file mode 100644 index 9e8e716a75e..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu.jse4/feature.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - [Enter Feature Description here.] - - - - [Enter Copyright Description here.] - - - - [Enter License Description here.] - - - - - - - diff --git a/icu4j/icu-eclipse/features/com.ibm.icu/.project b/icu4j/icu-eclipse/features/com.ibm.icu/.project deleted file mode 100644 index d407fa0f079..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - com.ibm.icu-feature - - - - - - org.eclipse.pde.FeatureBuilder - - - - - - org.eclipse.pde.FeatureNature - - diff --git a/icu4j/icu-eclipse/features/com.ibm.icu/build.properties b/icu4j/icu-eclipse/features/com.ibm.icu/build.properties deleted file mode 100644 index e9000a47e50..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu/build.properties +++ /dev/null @@ -1,20 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -bin.includes =\ -epl-v10.html,\ -eclipse_update_120.jpg,\ -feature.xml,\ -feature.properties,\ -license.html -outputUpdateJars = true - -generate.plugin@com.ibm.icu.source=com.ibm.icu - diff --git a/icu4j/icu-eclipse/features/com.ibm.icu/feature.xml b/icu4j/icu-eclipse/features/com.ibm.icu/feature.xml deleted file mode 100644 index 417e65b570b..00000000000 --- a/icu4j/icu-eclipse/features/com.ibm.icu/feature.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - [Enter Feature Description here.] - - - - [Enter Copyright Description here.] - - - - [Enter License Description here.] - - - - - - - diff --git a/icu4j/icu-eclipse/misc/ICUConfig.properties b/icu4j/icu-eclipse/misc/ICUConfig.properties deleted file mode 100644 index 26dad40e215..00000000000 --- a/icu4j/icu-eclipse/misc/ICUConfig.properties +++ /dev/null @@ -1,12 +0,0 @@ -#****************************************************************************** -# Copyright (C) 2008-2009, International Business Machines Corporation and * -# others. All Rights Reserved. * -#****************************************************************************** -# This is the properties contains ICU runtime configuration for eclispe plug-in -# - -# -# The default TimeZone implementation type used by the ICU TimeZone -# factory method. [ ICU | JDK ] -# -com.ibm.icu.util.TimeZone.DefaultTimeZoneType = JDK diff --git a/icu4j/icu-eclipse/misc/about_icu.html b/icu4j/icu-eclipse/misc/about_icu.html deleted file mode 100644 index 1f8623121f5..00000000000 --- a/icu4j/icu-eclipse/misc/about_icu.html +++ /dev/null @@ -1,54 +0,0 @@ - - - - -About - - -

About This Content

- -

May 8, 2009

-

License

- -

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at http://www.eclipse.org/legal/epl-v10.html. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at http://www.eclipse.org.

- - -

Third Party Content

-

The Content includes items that have been sourced from third parties as set out below. If you - did not receive this Content directly from the Eclipse Foundation, the following is provided - for informational purposes only, and you should look to the Redistributor's license for - terms and conditions of use.

- -

ICU4J 4.2

- The plug-in includes software ("ICU4J") developed by International Business Machines - Corporation and others. -

- ICU4J is: -

- Copyright (c) 1995-2009 International Business Machines Corporation and others
- All rights reserved. -
-

- Your use of ICU4J is subject to the terms and conditions of the ICU4J license. A copy of the - license is contained in the file about_files/license.html.

-

- ICU4J bundles data files imported from the Unicode Character Database and the Locale Data. A copy of the - Unicode Data and Software license is contained in the file about_files/ucdterms.txt.

-

- The project information including source code, documentations and demo programs are available on - the ICU public web site.

- - - diff --git a/icu4j/icu-eclipse/misc/about_icu_base.html b/icu4j/icu-eclipse/misc/about_icu_base.html deleted file mode 100644 index 844bf6cf037..00000000000 --- a/icu4j/icu-eclipse/misc/about_icu_base.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - -About - - -

About This Content

- -

May 8, 2009

-

License

- -

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise -indicated below, the Content is provided to you under the terms and conditions of the -Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available -at http://www.eclipse.org/legal/epl-v10.html. -For purposes of the EPL, "Program" will mean the Content.

- -

If you did not receive this Content directly from the Eclipse Foundation, the Content is -being redistributed by another party ("Redistributor") and different terms and conditions may -apply to your use of any object code in the Content. Check the Redistributor's license that was -provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise -indicated below, the terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at http://www.eclipse.org.

- - -

Third Party Content

-

The Content includes items that have been sourced from third parties as set out below. If you - did not receive this Content directly from the Eclipse Foundation, the following is provided - for informational purposes only, and you should look to the Redistributor's license for - terms and conditions of use.

- -

ICU4J 4.2

- The plug-in includes software ("ICU4J") developed by International Business Machines - Corporation and others. -

- ICU4J is: -

- Copyright (c) 1995-2009 International Business Machines Corporation and others
- All rights reserved. -
-

- Your use of ICU4J is subject to the terms and conditions of the ICU4J license. A copy of the - license is contained in the file about_files/license.html.

-

- The project information including source code, documentations and demo programs are available on - the ICU public web site.

- - - diff --git a/icu4j/icu-eclipse/pdebuild/allElements.xml b/icu4j/icu-eclipse/pdebuild/allElements.xml deleted file mode 100644 index e4d661303b0..00000000000 --- a/icu4j/icu-eclipse/pdebuild/allElements.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/icu4j/icu-eclipse/pdebuild/build.properties b/icu4j/icu-eclipse/pdebuild/build.properties deleted file mode 100644 index 50fc9cb4ba6..00000000000 --- a/icu4j/icu-eclipse/pdebuild/build.properties +++ /dev/null @@ -1,220 +0,0 @@ -############################################################################### -# Copyright (c) 2003-2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -##################### -# Parameters describing how and where to execute the build. -# Typical users need only update the following properties: -# baseLocation - where things you are building against are installed -# bootclasspath - The base jars to compile against (typicaly rt.jar) -# configs - the list of {os, ws, arch} configurations to build. -# -# Of course any of the settings here can be overridden by spec'ing -# them on the command line (e.g., -DbaseLocation=d:/eclipse - -############# PRODUCT/PACKAGING CONTROL ############# -product=/plugin or feature id/path/to/.product -runPackager=true - -#Set the name of the archive that will result from the product build. -#archiveNamePrefix= - -# The prefix that will be used in the generated archive. -#archivePrefix= -archivePrefix= - -# The location underwhich all of the build output will be collected. -collectingFolder=${archivePrefix} - -# The list of {os, ws, arch} configurations to build. This -# value is a '&' separated list of ',' separate triples. For example, -# configs=win32,win32,x86 & linux,motif,x86 -# By default the value is *,*,* -#configs=win32, win32, x86 & \ -# linux, gtk, ppc &\ -# linux, gtk, x86 & \ -# linux, gtk, x86_64 & \ -# linux, motif, x86 & \ -# solaris, motif, sparc & \ -# solaris, gtk, sparc & \ -# aix, motif, ppc & \ -# hpux, motif, PA_RISC & \ -# macosx, carbon, ppc - -# By default PDE creates one archive (result) per entry listed in the configs property. -# Setting this value to try will cause PDE to only create one output containing all -# artifacts for all the platforms listed in the configs property. -#groupConfigurations=true - -#The format of the archive. By default a zip is created using antZip. -#The list can only contain the configuration for which the desired format is different than zip. -#archivesFormat=win32, win32, x86 - antZip& \ -# linux, gtk, ppc - antZip &\ -# linux, gtk, x86 - antZip& \ -# linux, gtk, x86_64 - antZip& \ -# linux, motif, x86 - antZip& \ -# solaris, motif, sparc - antZip& \ -# solaris, gtk, sparc - antZip& \ -# aix, motif, ppc - antZip& \ -# hpux, motif, PA_RISC - antZip& \ -# macosx, carbon, ppc - antZip - -#Set to true if you want the output to be ready for an update jar (no site.xml generated) -#outputUpdateJars = false - -#Set to true for Jnlp generation -#codebase should be a URL that will be used as the root of all relative URLs in the output. -#generateJnlp=false -#jnlp.codebase= -#jnlp.j2se= -#jnlp.locale= - -#Set to true if you want to sign jars -#signJars=false -#sign.alias= -#sign.keystore= -#sign.storepass= - -#Arguments to send to the zip executable -zipargs= - -#Arguments to send to the tar executable -tarargs= - -#Control the creation of a file containing the version included in each configuration - on by default -#generateVersionsLists=false - -############## BUILD NAMING CONTROL ################ -# The directory into which the build elements are fetched and where -# the build takes place. -buildDirectory=@BUILD_DIR@ - -# Type of build. Used in naming the build output. Typically this value is -# one of I, N, M, S, ... -buildType=@BUILD_TYPE@ - -# ID of the build. Used in naming the build output. -buildId=@BUILD_ID@ - -# Label for the build. Used in naming the build output -buildLabel=${buildType}.${buildId} - -# Timestamp for the build. Used in naming the build output -timestamp=007 - -#The value to be used for the qualifier of a plugin or feature when you want to override the value computed by pde. -#The value will only be applied to plugin or features indicating build.properties, qualifier = context -#forceContextQualifier= - -#Enable / disable the generation of a suffix for the features that use .qualifier. -#The generated suffix is computed according to the content of the feature -#generateFeatureVersionSuffix=true - -############# BASE CONTROL ############# -# Settings for the base Eclipse components and Java class libraries -# against which you are building. -# Base location for anything the build needs to compile against. For example, -# in most RCP app or a plug-in, the baseLocation should be the location of a previously -# installed Eclipse against which the application or plug-in code will be compiled and the RCP delta pack. - -base= -#baseLocation=${base}/eclipse -baseLocation=@BASE_LOCATION@ -#Os/Ws/Arch/nl of the eclipse specified by baseLocation -baseos=@BASE_OS@ -basews=@BASE_WS@ -basearch=@BASE_ARCH@ - -#this property indicates whether you want the set of plug-ins and features to be considered during the build to be limited to the ones reachable from the features / plugins being built -filteredDependencyCheck=false - -#pluginPath is a list of locations in which to find plugins and features. This list is separated by the platform file separator (; or :) -#a location is one of: -#- the location of the jar or folder that is the plugin or feature : /path/to/foo.jar or /path/to/foo -#- a directory that contains a /plugins or /features subdirectory -#- the location of a feature.xml, or for 2.1 style plugins, the plugin.xml or fragment.xml -#pluginPath= - -skipBase=true -eclipseURL= -eclipseBuildId= -eclipseBaseURL=${eclipseURL}/eclipse-platform-${eclipseBuildId}-win32.zip - - -############# MAP FILE CONTROL ################ -# This section defines CVS tags to use when fetching the map files from the repository. -# If you want to fetch the map file from repository / location, change the getMapFiles target in the customTargets.xml - -skipMaps=true -mapsRepo=:pserver:anonymous@example.com/path/to/repo -mapsRoot=path/to/maps -mapsCheckoutTag=HEAD - -#tagMaps=true -mapsTagTag=v${buildId} - - -############ REPOSITORY CONTROL ############### -# This section defines properties parameterizing the repositories where plugins, fragments -# bundles and features are being obtained from. - -# The tags to use when fetching elements to build. -# By default thebuilder will use whatever is in the maps. -# This value takes the form of a comma separated list of repository identifier (like used in the map files) and the -# overriding value -# For example fetchTag=CVS=HEAD, SVN=v20050101 -# fetchTag=HEAD -skipFetch=true - - -############# JAVA COMPILER OPTIONS ############## -# The location of the Java jars to compile against. Typically the rt.jar for your JDK/JRE -#bootclasspath=${java.home}/lib/rt.jar - -# specific JRE locations to compile against. These values are used to compile bundles specifying a -# Bundle-RequiredExecutionEnvironment. Uncomment and set values for environments that you support -#CDC-1.0/Foundation-1.0= /path/to/rt.jar -#CDC-1.1/Foundation-1.1= -#OSGi/Minimum-1.0= -#OSGi/Minimum-1.1= -#JRE-1.1= -#J2SE-1.2= -#J2SE-1.3= -#J2SE-1.4= -#J2SE-1.5= -#JavaSE-1.6= -#PersonalJava-1.1= -#PersonalJava-1.2= -#CDC-1.0/PersonalBasis-1.0= -#CDC-1.0/PersonalJava-1.0= -#CDC-1.1/PersonalBasis-1.1= -#CDC-1.1/PersonalJava-1.1= - -# Specify the output format of the compiler log when eclipse jdt is used -logExtension=.log - -# Whether or not to include debug info in the output jars -javacDebugInfo=true - -# Whether or not to fail the build if there are compiler errors -javacFailOnError=true - -# Enable or disable verbose mode of the compiler -javacVerbose=true - -# Extra arguments for the compiler. These are specific to the java compiler being used. -compilerArg=-inlineJSR -enableJavadoc -encoding ISO-8859-1 - -# Default value for the version of the source code. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacSource in build.properties -javacSource=1.3 - -# Default value for the version of the byte code targeted. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacTarget in build.properties. -javacTarget=1.1 - -individualSourceBundles=true diff --git a/icu4j/icu-eclipse/pdebuild/customTargets.xml b/icu4j/icu-eclipse/pdebuild/customTargets.xml deleted file mode 100644 index ae4266d683c..00000000000 --- a/icu4j/icu-eclipse/pdebuild/customTargets.xml +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.classpath b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.classpath deleted file mode 100644 index 751c8f2e504..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.project b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.project deleted file mode 100644 index 848567c54ef..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - com.ibm.icu.base.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.core.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 40047e616bc..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Dec 14 11:50:44 EST 2006 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.ui.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 34e9838c635..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Dec 14 11:50:44 EST 2006 -eclipse.preferences.version=1 -internal.default.compliance=default diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/META-INF/MANIFEST.MF b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/META-INF/MANIFEST.MF deleted file mode 100644 index 935db056d46..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: ICU4J Base test fragment -Bundle-SymbolicName: com.ibm.icu.base.tests -Bundle-Version: 1.0.0 -Bundle-Vendor: IBM -Bundle-Copyright: @COPYRIGHT@ -Fragment-Host: com.ibm.icu.base -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.3, - CDC-1.0/Foundation-1.0 -Require-Bundle: org.junit diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/build.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/build.properties deleted file mode 100644 index 34d2e4d2dad..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/BreakIteratorTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/BreakIteratorTest.java deleted file mode 100644 index 0bbc8b10502..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/BreakIteratorTest.java +++ /dev/null @@ -1,359 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.text.CharacterIterator; -import java.text.StringCharacterIterator; -import java.util.Locale; - -import com.ibm.icu.text.BreakIterator; -import com.ibm.icu.util.ULocale; - -public class BreakIteratorTest extends ICUTestCase { - // ICU behaves a bit differently with this text, but the tested values aren't - // affected. If Java changes behavior they might need to change. - private static final String text = "Mr. and Mrs. Mumblety-Peg paid $35.97 for a new 12\" cockatoo. " + - "When they got home they both cooed \"Isn't it lovely?\" and sighed softly. " + - "\"Let's name it u\u0308\u5098!\" they said with glee."; - private static int pos = text.indexOf("sn't"); - private static BreakIterator cbr; - private static BreakIterator wbr; - private static BreakIterator lbr; - private static BreakIterator sbr; - - static { - cbr = BreakIterator.getCharacterInstance(); - cbr.setText(text); - wbr = BreakIterator.getWordInstance(); - wbr.setText(text); - lbr = BreakIterator.getLineInstance(); - lbr.setText(text); - sbr = BreakIterator.getSentenceInstance(); - sbr.setText(text); - - // diagnostic - // dump(cbr); - // dump(wbr); - // dump(lbr); - // dump(sbr); - } - - // private static void dump(BreakIterator bi) { - // for (int ix = bi.first(), lim = text.length(); ix != lim;) { - // int nx = bi.next(); - // if (nx < 0) nx = lim; - // System.out.println(Integer.toString(ix) + ": " + text.substring(ix, nx)); - // ix = nx; - // } - // } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.hashCode()' - */ - public void testHashCode() { - BreakIterator br = BreakIterator.getWordInstance(); - br.setText(text); - BreakIterator brne = BreakIterator.getWordInstance(); - brne.setText(text + "X"); - wbr.first(); - testEHCS(br, wbr, brne); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.BreakIterator(BreakIterator)' - */ - public void testBreakIterator() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.first()' - */ - public void testFirst() { - assertEquals(0, cbr.first()); - assertEquals(0, wbr.first()); - assertEquals(0, lbr.first()); - assertEquals(0, sbr.first()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.last()' - */ - public void testLast() { - assertEquals(text.length(), cbr.last()); - assertEquals(text.length(), wbr.last()); - assertEquals(text.length(), lbr.last()); - assertEquals(text.length(), sbr.last()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.next(int)' - */ - public void testNextInt() { - cbr.first(); - wbr.first(); - lbr.first(); - sbr.first(); - assertEquals(2, cbr.next(2)); - assertEquals(3, wbr.next(2)); - assertEquals(8, lbr.next(2)); - assertEquals(62, sbr.next(2)); - - cbr.last(); - wbr.last(); - lbr.last(); - sbr.last(); - assertEquals(174, cbr.next(-2)); - assertEquals(171, wbr.next(-2)); - assertEquals(166, lbr.next(-2)); - assertEquals(135, sbr.next(-2)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.next()' - */ - public void testNext() { - cbr.first(); - wbr.first(); - lbr.first(); - sbr.first(); - assertEquals(1, cbr.next()); - assertEquals(2, wbr.next()); - assertEquals(4, lbr.next()); - assertEquals(13, sbr.next()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.previous()' - */ - public void testPrevious() { - cbr.last(); - wbr.last(); - lbr.last(); - sbr.last(); - assertEquals(175, cbr.previous()); - assertEquals(175, wbr.previous()); - assertEquals(171, lbr.previous()); - assertEquals(156, sbr.previous()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.following(int)' - */ - public void testFollowing() { - assertEquals(100, cbr.following(pos)); - assertEquals(103, wbr.following(pos)); - assertEquals(104, lbr.following(pos)); - assertEquals(116, sbr.following(pos)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.preceding(int)' - */ - public void testPreceding() { - assertEquals(98, cbr.preceding(pos)); - assertEquals(98, wbr.preceding(pos)); - assertEquals(97, lbr.preceding(pos)); - assertEquals(62, sbr.preceding(pos)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.isBoundary(int)' - */ - public void testIsBoundary() { - assertTrue(cbr.isBoundary(pos)); - assertFalse(wbr.isBoundary(pos)); - assertFalse(lbr.isBoundary(pos)); - assertFalse(sbr.isBoundary(pos)); - - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.current()' - */ - public void testCurrent() { - cbr.following(pos); - wbr.following(pos); - lbr.following(pos); - sbr.following(pos); - assertEquals(100, cbr.current()); - assertEquals(103, wbr.current()); - assertEquals(104, lbr.current()); - assertEquals(116, sbr.current()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getText()' - */ - public void testGetText() { - CharacterIterator ci = cbr.getText(); - StringBuffer buf = new StringBuffer(ci.getEndIndex() - ci.getBeginIndex()); - for (char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) { - buf.append(c); - } - String result = buf.toString(); - assertEquals(text, result); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.setText(String)' - */ - public void testSetTextString() { - // implicitly tested - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.setText(CharacterIterator)' - */ - public void testSetTextCharacterIterator() { - CharacterIterator ci = new StringCharacterIterator(text, pos); - BreakIterator bi = BreakIterator.getWordInstance(); - bi.setText(ci); - assertEquals(2, bi.next()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getWordInstance()' - */ - public void testGetWordInstance() { - // implicitly tested - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getWordInstance(Locale)' - */ - public void testGetWordInstanceLocale() { - assertNotNull(BreakIterator.getWordInstance(Locale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getWordInstance(ULocale)' - */ - public void testGetWordInstanceULocale() { - assertNotNull(BreakIterator.getWordInstance(ULocale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getLineInstance()' - */ - public void testGetLineInstance() { - // implicitly tested - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getLineInstance(Locale)' - */ - public void testGetLineInstanceLocale() { - assertNotNull(BreakIterator.getLineInstance(Locale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getLineInstance(ULocale)' - */ - public void testGetLineInstanceULocale() { - assertNotNull(BreakIterator.getLineInstance(ULocale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getCharacterInstance()' - */ - public void testGetCharacterInstance() { - // implicitly tested - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getCharacterInstance(Locale)' - */ - public void testGetCharacterInstanceLocale() { - assertNotNull(BreakIterator.getCharacterInstance(Locale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getCharacterInstance(ULocale)' - */ - public void testGetCharacterInstanceULocale() { - assertNotNull(BreakIterator.getCharacterInstance(ULocale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getSentenceInstance()' - */ - public void testGetSentenceInstance() { - // implicitly tested - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getSentenceInstance(Locale)' - */ - public void testGetSentenceInstanceLocale() { - assertNotNull(BreakIterator.getSentenceInstance(Locale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getSentenceInstance(ULocale)' - */ - public void testGetSentenceInstanceULocale() { - assertNotNull(BreakIterator.getSentenceInstance(ULocale.JAPAN)); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getTitleInstance()' - */ - public void testGetTitleInstance() { - // not implemented - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getTitleInstance(Locale)' - */ - public void testGetTitleInstanceLocale() { - // not implemented - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getTitleInstance(ULocale)' - */ - public void testGetTitleInstanceULocale() { - // not implemented - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getAvailableLocales()' - */ - public void testGetAvailableLocales() { - assertNotNull(BreakIterator.getAvailableLocales()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.getAvailableULocales()' - */ - public void testGetAvailableULocales() { - assertNotNull(BreakIterator.getAvailableULocales()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.toString()' - */ - public void testToString() { - assertNotNull(cbr.toString()); - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.clone()' - */ - public void testClone() { - // see testHashCode - } - - /* - * Test method for 'com.ibm.icu.text.BreakIterator.equals(Object)' - */ - public void testEqualsObject() { - // see testHashCode - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CalendarTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CalendarTest.java deleted file mode 100644 index fddf539b0b4..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CalendarTest.java +++ /dev/null @@ -1,559 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.text.DateFormat; -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.TimeZone; -import com.ibm.icu.util.ULocale; - -public class CalendarTest extends ICUTestCase { - - /* - * Test method for 'com.ibm.icu.util.Calendar.hashCode()' - */ - public void testHashCode() { - Calendar cal1 = Calendar.getInstance(); - Calendar cal2 = Calendar.getInstance(); - Calendar cal3 = Calendar.getInstance(); - cal3.setMinimalDaysInFirstWeek(cal3.getMinimalDaysInFirstWeek()+1); - testEHCS(cal1, cal2, cal3); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.Calendar(Calendar)' - */ - public void testCalendar() { - // tested implicitly everywhere - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getInstance()' - */ - public void testGetInstance() { - // tested by testEHCS - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getInstance(TimeZone)' - */ - public void testGetInstanceTimeZone() { - TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); - Calendar cal = Calendar.getInstance(tz); - assertNotNull(cal); - assertNotNull(cal.getTime()); - assertEquals(tz, cal.getTimeZone()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getInstance(Locale)' - */ - public void testGetInstanceLocale() { - Calendar cal = Calendar.getInstance(Locale.US); - assertNotNull(cal); - assertNotNull(cal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getInstance(ULocale)' - */ - public void testGetInstanceULocale() { - Calendar cal = Calendar.getInstance(ULocale.US); - assertNotNull(cal); - assertNotNull(cal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getInstance(TimeZone, Locale)' - */ - public void testGetInstanceTimeZoneLocale() { - TimeZone tz = TimeZone.getTimeZone("America/New_York"); - Calendar cal = Calendar.getInstance(tz, Locale.US); - assertNotNull(cal); - assertNotNull(cal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getInstance(TimeZone, ULocale)' - */ - public void testGetInstanceTimeZoneULocale() { - TimeZone tz = TimeZone.getTimeZone("America/New_York"); - Calendar cal = Calendar.getInstance(tz, ULocale.US); - assertNotNull(cal); - assertNotNull(cal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getAvailableLocales()' - */ - public void testGetAvailableLocales() { - assertNotNull(Calendar.getAvailableLocales()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getAvailableULocales()' - */ - public void testGetAvailableULocales() { - assertNotNull(Calendar.getAvailableULocales()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getTime()' - */ - public void testGetTime() { - Calendar cal = Calendar.getInstance(); - assertNotNull(cal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.setTime(Date)' - */ - public void testSetTime() { - Calendar cal = Calendar.getInstance(); - cal.clear(); - cal.set(2006, 0, 20, 9, 30, 0); - Date date = cal.getTime(); - cal = Calendar.getInstance(); - cal.setTime(date); - assertEquals(date, cal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getTimeInMillis()' - */ - public void testGetTimeInMillis() { - Calendar cal = Calendar.getInstance(); - assertTrue(0 != cal.getTimeInMillis()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.setTimeInMillis(long)' - */ - public void testSetTimeInMillis() { - Calendar cal = Calendar.getInstance(); - cal.clear(); - cal.set(2006, 0, 20, 9, 30, 0); - long millis = cal.getTimeInMillis(); - Date date = cal.getTime(); - - cal = Calendar.getInstance(); - cal.setTimeInMillis(millis); - - assertEquals(date, cal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.get(int)' - */ - public void testGet() { - Calendar cal = Calendar.getInstance(); - cal.clear(); - cal.set(2006, 0, 20, 9, 30, 0); - assertEquals(0, cal.get(Calendar.MONTH)); - assertEquals(20, cal.get(Calendar.DAY_OF_MONTH)); - assertEquals(30, cal.get(Calendar.MINUTE)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.set(int, int)' - */ - public void testSetIntInt() { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 1977); - assertEquals(1977, cal.get(Calendar.YEAR)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.set(int, int, int)' - */ - public void testSetIntIntInt() { - Calendar cal = Calendar.getInstance(); - cal.set(1997, 9, 15); - assertEquals(15, cal.get(Calendar.DATE)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.set(int, int, int, int, int)' - */ - public void testSetIntIntIntIntInt() { - Calendar cal = Calendar.getInstance(); - cal.set(1997, 9, 15, 14, 25); - assertEquals(25, cal.get(Calendar.MINUTE)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.set(int, int, int, int, int, int)' - */ - public void testSetIntIntIntIntIntInt() { - Calendar cal = Calendar.getInstance(); - cal.set(1997, 9, 15, 14, 25, 51); - assertEquals(51, cal.get(Calendar.SECOND)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.clear()' - */ - public void testClear() { - Calendar cal = Calendar.getInstance(); - cal.set(1997, 9, 15, 14, 25, 51); - cal.clear(); - assertEquals(0, cal.get(Calendar.MONTH)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.clear(int)' - */ - public void testClearInt() { - Calendar cal = Calendar.getInstance(); - cal.set(1997, 9, 15, 14, 25, 51); - assertTrue(cal.isSet(Calendar.DAY_OF_MONTH)); - cal.clear(Calendar.DAY_OF_MONTH); - assertFalse(cal.isSet(Calendar.DAY_OF_MONTH)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.isSet(int)' - */ - public void testIsSet() { - // see testClearInt - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.equals(Object)' - */ - public void testEqualsObject() { - // tested by testHashCode - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.isEquivalentTo(Calendar)' - */ - public void testIsEquivalentTo() { - Calendar cal = Calendar.getInstance(); - Calendar cal2 = Calendar.getInstance(); - cal2.set(1994, 6, 21, 8, 7); - assertTrue(cal.isEquivalentTo(cal2)); - cal.setTimeZone(TimeZone.getTimeZone("CST")); - cal2.setTimeZone(TimeZone.getTimeZone("PDT")); - assertFalse(cal.isEquivalentTo(cal2)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.before(Object)' - */ - public void testBefore() { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 1990); - assertTrue(cal.before(new Date())); - assertTrue(cal.before(Calendar.getInstance())); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.after(Object)' - */ - public void testAfter() { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 3058); - assertTrue(cal.after(new Date())); - assertTrue(cal.after(Calendar.getInstance())); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getActualMaximum(int)' - */ - public void testGetActualMaximum() { - Calendar cal = Calendar.getInstance(Locale.US); - assertEquals(11, cal.getActualMaximum(Calendar.MONTH)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getActualMinimum(int)' - */ - public void testGetActualMinimum() { - Calendar cal = Calendar.getInstance(Locale.US); - assertEquals(0, cal.getActualMinimum(Calendar.MONTH)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.roll(int, boolean)' - */ - public void testRollIntBoolean() { - Calendar cal = Calendar.getInstance(Locale.US); - cal.set(1997, 1, 27); - cal.roll(Calendar.DATE, true); - assertEquals(28, cal.get(Calendar.DATE)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.roll(int, int)' - */ - public void testRollIntInt() { - Calendar cal = Calendar.getInstance(Locale.US); - cal.set(1997, 1, 27); - cal.roll(Calendar.DATE, 3); - assertEquals(2, cal.get(Calendar.DATE)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.add(int, int)' - */ - public void testAdd() { - Calendar cal = Calendar.getInstance(Locale.US); - cal.set(1997, 1, 27); - cal.add(Calendar.DATE, 3); - assertEquals(2, cal.get(Calendar.DATE)); - assertEquals(2, cal.get(Calendar.MONTH)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getDisplayName(Locale)' - */ - public void testGetDisplayNameLocale() { - Calendar cal = Calendar.getInstance(); - assertEquals("Calendar", cal.getDisplayName(Locale.US)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getDisplayName(ULocale)' - */ - public void testGetDisplayNameULocale() { - Calendar cal = Calendar.getInstance(); - assertEquals("Calendar", cal.getDisplayName(ULocale.US)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.compareTo(Calendar)' - */ - public void testCompareToCalendar() { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 1990); - assertTrue(0 > cal.compareTo(Calendar.getInstance())); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.compareTo(Object)' - */ - public void testCompareToObject() { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 1990); - assertTrue(0 > cal.compareTo((Object)Calendar.getInstance())); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getDateTimeFormat(int, int, Locale)' - */ - public void testGetDateTimeFormatIntIntLocale() { - Calendar cal = Calendar.getInstance(); - cal.set(1990, 8, 16, 20, 3); - DateFormat df = cal.getDateTimeFormat(DateFormat.LONG, DateFormat.SHORT, Locale.US); - assertEquals("September 16, 1990 8:03 PM", df.format(cal)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getDateTimeFormat(int, int, ULocale)' - */ - public void testGetDateTimeFormatIntIntULocale() { - Calendar cal = Calendar.getInstance(); - cal.set(1990, 8, 16, 20, 3); - DateFormat df = cal.getDateTimeFormat(DateFormat.LONG, DateFormat.SHORT, ULocale.US); - assertEquals("September 16, 1990 8:03 PM", df.format(cal)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.fieldDifference(Date, int)' - */ - public void testFieldDifference() { - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.DAY_OF_MONTH, 0); - Date date = cal.getTime(); - cal.add(Calendar.DAY_OF_MONTH, 5); - assertEquals(-5, cal.fieldDifference(date, Calendar.DAY_OF_MONTH)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getTimeZone()' - */ - public void testGetTimeZone() { - Calendar cal = Calendar.getInstance(); - assertNotNull(cal.getTimeZone()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.setTimeZone(TimeZone)' - */ - public void testSetTimeZone() { - Calendar cal = Calendar.getInstance(); - TimeZone value1 = cal.getTimeZone(); - String tzn = "PDT".equals(value1.getID()) ? "CST" : "PDT"; - TimeZone value2 = TimeZone.getTimeZone(tzn); - cal.setTimeZone(value2); - TimeZone result = cal.getTimeZone(); - assertNotEqual(value1, result); - assertEquals(value2, result); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.setLenient(boolean)' - */ - public void testSetLenient() { - Calendar cal = Calendar.getInstance(); - boolean lenient = cal.isLenient(); - cal.setLenient(!lenient); - assertFalse(lenient == cal.isLenient()); - - // not testing if it has the expected effect - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.isLenient()' - */ - public void testIsLenient() { - // tested by testSetLenient - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.setFirstDayOfWeek(int)' - */ - public void testSetFirstDayOfWeek() { - Calendar cal = Calendar.getInstance(); - int firstDay = cal.getFirstDayOfWeek(); - cal.setFirstDayOfWeek(firstDay+1); - assertEquals(firstDay+1, cal.getFirstDayOfWeek()); - - // don't test functionality - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getFirstDayOfWeek()' - */ - public void testGetFirstDayOfWeek() { - // tested by testSetFirstDayOfWeek - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.setMinimalDaysInFirstWeek(int)' - */ - public void testSetMinimalDaysInFirstWeek() { - Calendar cal = Calendar.getInstance(); - int firstDay = cal.getMinimalDaysInFirstWeek(); - cal.setMinimalDaysInFirstWeek(firstDay+1); - assertEquals(firstDay+1, cal.getMinimalDaysInFirstWeek()); - - // don't test functionality - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getMinimalDaysInFirstWeek()' - */ - public void testGetMinimalDaysInFirstWeek() { - // tested by testSetMinimalDaysInFirstWeek - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getMinimum(int)' - */ - public void testGetMinimum() { - Calendar cal = Calendar.getInstance(); - assertEquals(1, cal.getMinimum(Calendar.DAY_OF_WEEK)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getMaximum(int)' - */ - public void testGetMaximum() { - Calendar cal = Calendar.getInstance(); - assertEquals(7, cal.getMaximum(Calendar.DAY_OF_WEEK)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getGreatestMinimum(int)' - */ - public void testGetGreatestMinimum() { - Calendar cal = Calendar.getInstance(); - assertEquals(1, cal.getGreatestMinimum(Calendar.DATE)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getLeastMaximum(int)' - */ - public void testGetLeastMaximum() { - Calendar cal = Calendar.getInstance(); - assertEquals(28, cal.getLeastMaximum(Calendar.DATE)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getDayOfWeekType(int)' - */ - public void testGetDayOfWeekType() { - Calendar cal = Calendar.getInstance(Locale.US); - assertEquals(Calendar.WEEKDAY, cal.getDayOfWeekType(Calendar.FRIDAY)); - assertEquals(Calendar.WEEKEND, cal.getDayOfWeekType(Calendar.SATURDAY)); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getWeekendTransition(int)' - */ - public void testGetWeekendTransition() { - Calendar cal = Calendar.getInstance(Locale.US); - try { - cal.getWeekendTransition(Calendar.WEEKEND_ONSET); - fail("expected IllegalArgumentException from getWeekendTransition"); - } - catch (IllegalArgumentException e) { - // ok - } - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.isWeekend(Date)' - */ - public void testIsWeekendDate() { - Calendar cal = Calendar.getInstance(Locale.US); - cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); - assertTrue(cal.isWeekend(cal.getTime())); - cal.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY); - assertFalse(cal.isWeekend(cal.getTime())); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.isWeekend()' - */ - public void testIsWeekend() { - Calendar cal = Calendar.getInstance(Locale.US); - cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); - assertTrue(cal.isWeekend()); - cal.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY); - assertFalse(cal.isWeekend()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.clone()' - */ - public void testClone() { - // tested by testHashCode - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.toString()' - */ - public void testToString() { - Calendar cal = Calendar.getInstance(); - assertNotNull(cal.toString()); - } - - /* - * Test method for 'com.ibm.icu.util.Calendar.getType()' - */ - public void testGetType() { - Calendar cal = Calendar.getInstance(Locale.US); - assertEquals("gregorian", cal.getType()); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollationKeyTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollationKeyTest.java deleted file mode 100644 index 9638984d2f0..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollationKeyTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import com.ibm.icu.text.CollationKey; -import com.ibm.icu.text.Collator; - -public class CollationKeyTest extends ICUTestCase { - - /* - * Test method for 'com.ibm.icu.text.CollationKey.hashCode()' - */ - public void testHashCode() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey("This"); - CollationKey k2 = c.getCollationKey("this"); - c.setStrength(Collator.TERTIARY); - CollationKey kn = c.getCollationKey("this"); - testEHCS(k1, k2, kn); - } - - /* - * Test method for 'com.ibm.icu.text.CollationKey.CollationKey(CollationKey)' - */ - public void testCollationKey() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.text.CollationKey.compareTo(CollationKey)' - */ - public void testCompareToCollationKey() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey("This"); - CollationKey k2 = c.getCollationKey("this"); - c.setStrength(Collator.TERTIARY); - CollationKey k3 = c.getCollationKey("this"); - assertTrue(0 == k1.compareTo(k2)); - assertFalse(0 == k1.compareTo(k3)); - } - - /* - * Test method for 'com.ibm.icu.text.CollationKey.compareTo(Object)' - */ - public void testCompareToObject() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey("This"); - CollationKey k2 = c.getCollationKey("this"); - assertTrue(0 == k1.compareTo((Object)k2)); - } - - /* - * Test method for 'com.ibm.icu.text.CollationKey.equals(Object)' - */ - public void testEqualsObject() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey("This"); - CollationKey k2 = c.getCollationKey("this"); - assertTrue(k1.equals((Object)k2)); - } - - /* - * Test method for 'com.ibm.icu.text.CollationKey.toString()' - */ - public void testToString() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey("This"); - assertNotNull(k1.toString()); - } - - /* - * Test method for 'com.ibm.icu.text.CollationKey.getSourceString()' - */ - public void testGetSourceString() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey("This"); - assertEquals("This", k1.getSourceString()); - } - - /* - * Test method for 'com.ibm.icu.text.CollationKey.toByteArray()' - */ - public void testToByteArray() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey("This"); - byte[] key = k1.toByteArray(); - assertNotNull(key); - assertTrue(0 < key.length); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollatorTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollatorTest.java deleted file mode 100644 index 7321d57e978..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollatorTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.util.Locale; - -import com.ibm.icu.text.CollationKey; -import com.ibm.icu.text.Collator; -import com.ibm.icu.util.ULocale; - -public class CollatorTest extends ICUTestCase { - private static final String s1 = "Fu\u0308nf"; // capital F + u + diaresis - private static final String s2 = "fu\u0308nf"; // u + diaresis - private static final String s3 = "f\u00fcnf"; // u-umlaut - private static final String s4 = "fu\u0308\u0316nf"; // u + diaresis above + grave below - private static final String s5 = "fu\u0316\u0308nf"; // u + grave below + diaresis above - - /* - * Test method for 'com.ibm.icu.text.Collator.hashCode()' - */ - public void testHashCode() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.SECONDARY); - Collator c2 = Collator.getInstance(); - c2.setStrength(Collator.SECONDARY); - Collator cn = Collator.getInstance(); - cn.setStrength(Collator.TERTIARY); - testEHCS(c, c2, cn); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.Collator(Collator)' - */ - public void testCollator() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.text.Collator.setStrength(int)' - */ - public void testSetStrength() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - assertTrue(0 == c.compare(s1, s2)); - c.setStrength(Collator.SECONDARY); - assertTrue(0 == c.compare(s1, s2)); - c.setStrength(Collator.TERTIARY); - assertTrue(0 < c.compare(s1, s2)); - assertTrue(0 == c.compare(s2, s3)); - c.setStrength(Collator.QUATERNARY); - assertTrue(0 > c.compare(s2, s3)); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.setDecomposition(int)' - */ - public void testSetDecomposition() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.TERTIARY); - assertTrue(0 != c.compare(s4, s5)); - c.setDecomposition(Collator.IDENTICAL); - assertTrue(0 == c.compare(s4, s5)); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getInstance()' - */ - public void testGetInstance() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getInstance(ULocale)' - */ - public void testGetInstanceULocale() { - Collator c = Collator.getInstance(ULocale.GERMANY); - assertNotNull(c); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getInstance(Locale)' - */ - public void testGetInstanceLocale() { - Collator c = Collator.getInstance(Locale.GERMANY); - assertNotNull(c); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getAvailableLocales()' - */ - public void testGetAvailableLocales() { - assertNotNull(Collator.getAvailableLocales()); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getAvailableULocales()' - */ - public void testGetAvailableULocales() { - assertNotNull(Collator.getAvailableULocales()); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getKeywords()' - */ - public void testGetKeywords() { - assertEquals(0, Collator.getKeywords().length); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getKeywordValues(String)' - */ - public void testGetKeywordValues() { - assertEquals(0, Collator.getKeywordValues("").length); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getStrength()' - */ - public void testGetStrength() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - assertEquals(Collator.PRIMARY, c.getStrength()); - c.setStrength(Collator.SECONDARY); - assertEquals(Collator.SECONDARY, c.getStrength()); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getDecomposition()' - */ - public void testGetDecomposition() { - Collator c = Collator.getInstance(); - c.setDecomposition(Collator.CANONICAL_DECOMPOSITION); - assertEquals(Collator.CANONICAL_DECOMPOSITION, c.getDecomposition()); - c.setDecomposition(Collator.NO_DECOMPOSITION); - assertEquals(Collator.NO_DECOMPOSITION, c.getDecomposition()); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.compare(Object, Object)' - */ - public void testCompareObjectObject() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - assertTrue(0 == c.compare((Object)s1, (Object)s2)); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.equals(String, String)' - */ - public void testEqualsStringString() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - assertTrue(c.equals(s1, s2)); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.compare(String, String)' - */ - public void testCompareStringString() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - assertTrue(0 == c.compare(s1, s2)); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.getCollationKey(String)' - */ - public void testGetCollationKey() { - Collator c = Collator.getInstance(); - c.setStrength(Collator.PRIMARY); - CollationKey k1 = c.getCollationKey(s1); - CollationKey k2 = c.getCollationKey(s2); - assertTrue(k1.equals(k2)); - c.setStrength(Collator.TERTIARY); - k1 = c.getCollationKey(s1); - k2 = c.getCollationKey(s2); - assertFalse(k1.equals(k2)); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.toString()' - */ - public void testToString() { - assertNotNull(Collator.getInstance().toString()); - } - - /* - * Test method for 'com.ibm.icu.text.Collator.clone()' - */ - public void testClone() { - // tested above - } - - /* - * Test method for 'com.ibm.icu.text.Collator.equals(Object)' - */ - public void testEqualsObject() { - // tested above - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatSymbolsTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatSymbolsTest.java deleted file mode 100644 index b7ffad5f454..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatSymbolsTest.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.util.Locale; - -import com.ibm.icu.text.DateFormatSymbols; -import com.ibm.icu.util.ULocale; - -public class DateFormatSymbolsTest extends ICUTestCase { - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.hashCode()' - */ - public void testHashCode() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - DateFormatSymbols dfs2 = new DateFormatSymbols(ULocale.US); - DateFormatSymbols dfsn = new DateFormatSymbols(Locale.US); - dfsn.setAmPmStrings(new String[] { "sw", "xw" }); - testEHCS(dfs, dfs2, dfsn); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.DateFormatSymbols(DateFormatSymbols)' - */ - public void testDateFormatSymbolsDateFormatSymbols() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.DateFormatSymbols()' - */ - public void testDateFormatSymbols() { - DateFormatSymbols dfs = new DateFormatSymbols(); - assertNotNull(dfs.getWeekdays()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.DateFormatSymbols(Locale)' - */ - public void testDateFormatSymbolsLocale() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getWeekdays()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.DateFormatSymbols(ULocale)' - */ - public void testDateFormatSymbolsULocale() { - DateFormatSymbols dfs = new DateFormatSymbols(ULocale.US); - assertNotNull(dfs.getWeekdays()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getEras()' - */ - public void testGetEras() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getEras()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setEras(String[])' - */ - public void testSetEras() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String[] oldvalue = dfs.getEras(); - String[] newvalue = (String[])oldvalue.clone(); - newvalue[0] = newvalue[0] + "!"; - dfs.setEras(newvalue); - String[] result = dfs.getEras(); - assertArraysNotEqual(oldvalue, result); - assertArraysEqual(newvalue, result); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getMonths()' - */ - public void testGetMonths() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getMonths()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setMonths(String[])' - */ - public void testSetMonths() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String[] oldvalue = dfs.getMonths(); - String[] newvalue = (String[])oldvalue.clone(); - newvalue[0] = newvalue[0] + "!"; - dfs.setMonths(newvalue); - String[] result = dfs.getMonths(); - assertArraysNotEqual(oldvalue, result); - assertArraysEqual(newvalue, result); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getShortMonths()' - */ - public void testGetShortMonths() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getShortMonths()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setShortMonths(String[])' - */ - public void testSetShortMonths() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String[] oldvalue = dfs.getShortMonths(); - String[] newvalue = (String[])oldvalue.clone(); - newvalue[0] = newvalue[0] + "!"; - dfs.setShortMonths(newvalue); - String[] result = dfs.getShortMonths(); - assertArraysNotEqual(oldvalue, result); - assertArraysEqual(newvalue, result); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getWeekdays()' - */ - public void testGetWeekdays() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getShortMonths()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setWeekdays(String[])' - */ - public void testSetWeekdays() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String[] oldvalue = dfs.getWeekdays(); - String[] newvalue = (String[])oldvalue.clone(); - newvalue[0] = newvalue[0] + "!"; - dfs.setWeekdays(newvalue); - String[] result = dfs.getWeekdays(); - assertArraysNotEqual(oldvalue, result); - assertArraysEqual(newvalue, result); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getShortWeekdays()' - */ - public void testGetShortWeekdays() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getShortWeekdays()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setShortWeekdays(String[])' - */ - public void testSetShortWeekdays() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String[] oldvalue = dfs.getShortWeekdays(); - String[] newvalue = (String[])oldvalue.clone(); - newvalue[0] = newvalue[0] + "!"; - dfs.setShortWeekdays(newvalue); - String[] result = dfs.getShortWeekdays(); - assertArraysNotEqual(oldvalue, result); - assertArraysEqual(newvalue, result); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getAmPmStrings()' - */ - public void testGetAmPmStrings() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getAmPmStrings()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setAmPmStrings(String[])' - */ - public void testSetAmPmStrings() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String[] oldvalue = dfs.getAmPmStrings(); - String[] newvalue = (String[])oldvalue.clone(); - newvalue[0] = newvalue[0] + "!"; - dfs.setAmPmStrings(newvalue); - String[] result = dfs.getAmPmStrings(); - assertArraysNotEqual(oldvalue, result); - assertArraysEqual(newvalue, result); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getZoneStrings()' - */ - public void testGetZoneStrings() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getZoneStrings()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setZoneStrings(String[][])' - */ - public void testSetZoneStrings() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String[][] oldvalue = dfs.getZoneStrings(); - String[][] newvalue = (String[][])cloneComplex(oldvalue); - newvalue[0][0] = newvalue[0][0] + "!"; - dfs.setZoneStrings(newvalue); - String[][] result = dfs.getZoneStrings(); - assertArraysNotEqual(oldvalue, result); - assertArraysEqual(newvalue, result); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.getLocalPatternChars()' - */ - public void testGetLocalPatternChars() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.getLocalPatternChars()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.setLocalPatternChars(String)' - */ - public void testSetLocalPatternChars() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - String pat = dfs.getLocalPatternChars(); - StringBuffer buf = new StringBuffer(pat); - buf.setCharAt(0, (char)(pat.charAt(0) + 1)); - String pat2 = buf.toString(); - dfs.setLocalPatternChars(pat2); - String pat3 = dfs.getLocalPatternChars(); - assertNotEqual(pat, pat2); - assertEquals(pat2, pat3); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.toString()' - */ - public void testToString() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - assertNotNull(dfs.toString()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.clone()' - */ - public void testClone() { - // tested by testHashCode - } - - /* - * Test method for 'com.ibm.icu.text.DateFormatSymbols.equals(Object)' - */ - public void testEqualsObject() { - // tested by testHashCode - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatTest.java deleted file mode 100644 index 4a4c0405f49..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatTest.java +++ /dev/null @@ -1,443 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.text.FieldPosition; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.text.DateFormat; -import com.ibm.icu.text.NumberFormat; -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.TimeZone; -import com.ibm.icu.util.ULocale; - -public class DateFormatTest extends ICUTestCase { - private Calendar aCal; - private Calendar anESTCal; - private Date aDate; - private String aDateString; - private String aTimeString; - private String anESTTimeString; - private String aDateTimeString; - private String aShortDateTimeString; - private String aDefaultESTDateTimeString; - private DateFormat aDF; - private StringBuffer aBuf; - private FieldPosition anFP; - - protected void setUp() throws Exception { - super.setUp(); - - java.util.GregorianCalendar gcal = new java.util.GregorianCalendar(); - gcal.clear(); - gcal.set(java.util.GregorianCalendar.YEAR, 1990); - gcal.set(java.util.GregorianCalendar.MONTH, java.util.GregorianCalendar.DECEMBER); - gcal.set(java.util.GregorianCalendar.DATE, 17); - gcal.set(java.util.GregorianCalendar.HOUR, 5); - gcal.set(java.util.GregorianCalendar.MINUTE, 17); - aCal = new Calendar(gcal); - anESTCal = Calendar.getInstance(); - anESTCal.setTimeZone(TimeZone.getTimeZone("EST")); - aDate = gcal.getTime(); - aDateString = "Dec 17, 1990"; // medium -- the default - aTimeString = "5:17:00 AM"; // medium - anESTTimeString = "8:17:00 AM"; - aDateTimeString = "Dec 17, 1990 5:17:00 AM"; // medium, medium - aDefaultESTDateTimeString = "Dec 17, 1990 8:17 AM"; // medium, short -- the default - aShortDateTimeString = "12/17/90 5:17 AM"; // short, short - aDF = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US); - aBuf = new StringBuffer(); - anFP = new FieldPosition(0); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.hashCode()' - */ - public final void testHashCode() { - DateFormat df = DateFormat.getInstance(); - DateFormat eq = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); - testEHCS(df, eq, aDF); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.DateFormat(DateFormat)' - */ - public final void testDateFormat() { - DateFormat df = new DateFormat(java.text.DateFormat.getInstance()); - assertEquals(DateFormat.getInstance(), df); - } - - private void assertEqualDateString(StringBuffer buf) { - assertEquals(aDateTimeString, buf.toString()); - } - - private void assertEqualDateString(String str) { - assertEquals(aDateTimeString, str); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.format(Object, StringBuffer, FieldPosition)' - */ - public final void testFormatObjectStringBufferFieldPosition() { - assertEqualDateString(aDF.format(aDate, aBuf, anFP)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.format(Calendar, StringBuffer, FieldPosition)' - */ - public final void testFormatCalendarStringBufferFieldPosition() { - assertEqualDateString(aDF.format(aCal, aBuf, anFP)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.format(Date, StringBuffer, FieldPosition)' - */ - public final void testFormatDateStringBufferFieldPosition() { - assertEqualDateString(aDF.format(aDate, aBuf, anFP)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.format(Date)' - */ - public final void testFormatDate() { - assertEqualDateString(aDF.format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.parse(String)' - */ - public final void testParseString() throws Exception { - assertEquals(aDate, aDF.parse(aDateTimeString)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.parse(String, Calendar, ParsePosition)' - */ - public final void testParseStringCalendarParsePosition() { - aDF.parse(aDateTimeString, aCal, new ParsePosition(0)); - assertEquals(aDate, aCal.getTime()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.parse(String, ParsePosition)' - */ - public final void testParseStringParsePosition() { - assertEquals(aDate, aDF.parse(aDateTimeString, new ParsePosition(0))); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.parseObject(String, ParsePosition)' - */ - public final void testParseObjectStringParsePosition() { - assertEquals(aDate, aDF.parseObject(aDateTimeString, new ParsePosition(0))); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeInstance()' - */ - public final void testGetTimeInstance() { - assertEquals(aTimeString, DateFormat.getTimeInstance().format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeInstance(int)' - */ - public final void testGetTimeInstanceInt() { - assertEquals(aTimeString, DateFormat.getTimeInstance(DateFormat.MEDIUM).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeInstance(int, Locale)' - */ - public final void testGetTimeInstanceIntLocale() { - assertEquals(aTimeString, DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeInstance(int, ULocale)' - */ - public final void testGetTimeInstanceIntULocale() { - assertEquals(aTimeString, DateFormat.getTimeInstance(DateFormat.MEDIUM, ULocale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateInstance()' - */ - public final void testGetDateInstance() { - assertEquals(aDateString, DateFormat.getDateInstance().format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateInstance(int)' - */ - public final void testGetDateInstanceInt() { - assertEquals(aDateString, DateFormat.getDateInstance(DateFormat.MEDIUM).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateInstance(int, Locale)' - */ - public final void testGetDateInstanceIntLocale() { - assertEquals(aDateString, DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateInstance(int, ULocale)' - */ - public final void testGetDateInstanceIntULocale() { - assertEquals(aDateString, DateFormat.getDateInstance(DateFormat.MEDIUM, ULocale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateTimeInstance()' - */ - public final void testGetDateTimeInstance() { - assertEquals(aDateTimeString, DateFormat.getDateTimeInstance().format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateTimeInstance(int, int)' - */ - public final void testGetDateTimeInstanceIntInt() { - assertEquals(aDateTimeString, - DateFormat.getDateTimeInstance( - DateFormat.MEDIUM, DateFormat.MEDIUM).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateTimeInstance(int, int, Locale)' - */ - public final void testGetDateTimeInstanceIntIntLocale() { - assertEquals(aDateTimeString, - DateFormat.getDateTimeInstance( - DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateTimeInstance(int, int, ULocale)' - */ - public final void testGetDateTimeInstanceIntIntULocale() { - assertEquals(aDateTimeString, - DateFormat.getDateTimeInstance( - DateFormat.MEDIUM, DateFormat.MEDIUM, ULocale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getInstance()' - */ - public final void testGetInstance() { - assertEquals(aShortDateTimeString, DateFormat.getInstance().format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getAvailableLocales()' - */ - public final void testGetAvailableLocales() { - Locale[] locales = DateFormat.getAvailableLocales(); - if (ICUTestCase.testingWrapper) { - ICUTestCase.assertArraysEqual(java.text.DateFormat.getAvailableLocales(), locales); - } else { - assertNotNull(locales); - } - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.setCalendar(Calendar)' - */ - public final void testSetCalendar() { - Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getTimeZone("EST")); - DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); - df.setCalendar(cal); - assertEquals("8:17 AM", df.format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getCalendar()' - */ - public final void testGetCalendar() { - Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TimeZone.getTimeZone("EST")); - DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); - df.setCalendar(cal); - assertEquals(cal, df.getCalendar()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.setNumberFormat(NumberFormat)' - */ - public final void testSetNumberFormat() { - // no easy way to test effect of setting the number format - NumberFormat nf = NumberFormat.getInstance(); - DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); - df.setNumberFormat(nf); - // note, can't actually USE the dateformat since it changes the calendar - assertEquals(nf, df.getNumberFormat()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getNumberFormat()' - */ - public final void testGetNumberFormat() { - // see testSetNumberFormat - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.setTimeZone(TimeZone)' - */ - public final void testSetTimeZone() { - DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); - TimeZone tz = TimeZone.getTimeZone("EST"); - df.setTimeZone(tz); - assertEquals("8:17 AM", df.format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeZone()' - */ - public final void testGetTimeZone() { - DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); - TimeZone tz = TimeZone.getTimeZone("EST"); - df.setTimeZone(tz); - assertEquals(tz, df.getTimeZone()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.setLenient(boolean)' - */ - public final void testSetLenient() throws Exception { - DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); - df.parse("2/31/90"); // succeeds, default is lenient - df.setLenient(false); - try { - df.parse("2/31/90"); - throw new Exception("strict parse should have failed"); - } - catch (ParseException e) { - // ok, this is what we expect - } - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.isLenient()' - */ - public final void testIsLenient() { - DateFormat df = DateFormat.getInstance(); - assertTrue(df.isLenient()); - df.setLenient(false); - assertFalse(df.isLenient()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateInstance(Calendar, int, Locale)' - */ - public final void testGetDateInstanceCalendarIntLocale() { - assertEquals(aDateString, DateFormat.getDateInstance(aCal, DateFormat.MEDIUM, Locale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateInstance(Calendar, int, ULocale)' - */ - public final void testGetDateInstanceCalendarIntULocale() { - assertEquals(aDateString, DateFormat.getDateInstance(aCal, DateFormat.MEDIUM, ULocale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeInstance(Calendar, int, Locale)' - */ - public final void testGetTimeInstanceCalendarIntLocale() { - assertEquals(anESTTimeString, DateFormat.getTimeInstance(anESTCal, DateFormat.MEDIUM, Locale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeInstance(Calendar, int, ULocale)' - */ - public final void testGetTimeInstanceCalendarIntULocale() { - assertEquals(anESTTimeString, DateFormat.getTimeInstance(anESTCal, DateFormat.MEDIUM, ULocale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateTimeInstance(Calendar, int, int, Locale)' - */ - public final void testGetDateTimeInstanceCalendarIntIntLocale() { - assertEquals(aDefaultESTDateTimeString, DateFormat.getDateTimeInstance(anESTCal, DateFormat.MEDIUM, DateFormat.SHORT, Locale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateTimeInstance(Calendar, int, int, ULocale)' - */ - public final void testGetDateTimeInstanceCalendarIntIntULocale() { - assertEquals(aDefaultESTDateTimeString, DateFormat.getDateTimeInstance(anESTCal, DateFormat.MEDIUM, DateFormat.SHORT, ULocale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getInstance(Calendar, Locale)' - */ - public final void testGetInstanceCalendarLocale() { - assertEquals(aDefaultESTDateTimeString, DateFormat.getInstance(anESTCal, Locale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getInstance(Calendar, ULocale)' - */ - public final void testGetInstanceCalendarULocale() { - assertEquals(aDefaultESTDateTimeString, DateFormat.getInstance(anESTCal, ULocale.US).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getInstance(Calendar)' - */ - public final void testGetInstanceCalendar() { - assertEquals(aDefaultESTDateTimeString, DateFormat.getInstance(anESTCal).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateInstance(Calendar, int)' - */ - public final void testGetDateInstanceCalendarInt() { - assertEquals(aDateString, DateFormat.getDateInstance(aCal, DateFormat.MEDIUM).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getTimeInstance(Calendar, int)' - */ - public final void testGetTimeInstanceCalendarInt() { - assertEquals(anESTTimeString, DateFormat.getTimeInstance(anESTCal, DateFormat.MEDIUM).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.getDateTimeInstance(Calendar, int, int)' - */ - public final void testGetDateTimeInstanceCalendarIntInt() { - assertEquals(aDefaultESTDateTimeString, DateFormat.getDateTimeInstance(anESTCal, DateFormat.MEDIUM, DateFormat.SHORT).format(aDate)); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.toString()' - */ - public final void testToString() { - assertNotNull(aDF.toString()); - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.clone()' - */ - public final void testClone() { - // see testHashCode - } - - /* - * Test method for 'com.ibm.icu.text.DateFormat.equals(Object)' - */ - public final void testEqualsObject() { - // see testHashCode - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatSymbolsTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatSymbolsTest.java deleted file mode 100644 index 5e9c87addcc..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatSymbolsTest.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.util.Locale; - -import com.ibm.icu.text.DecimalFormatSymbols; -import com.ibm.icu.util.ULocale; - -public class DecimalFormatSymbolsTest extends ICUTestCase { - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.hashCode()' - */ - public void testHashCode() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US); - DecimalFormatSymbols dfs2 = new DecimalFormatSymbols(ULocale.US); - DecimalFormatSymbols dfsn = new DecimalFormatSymbols(Locale.FRANCE); - testEHCS(dfs, dfs2, dfsn); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.DecimalFormatSymbols(DecimalFormatSymbols)' - */ - public void testDecimalFormatSymbolsDecimalFormatSymbols() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.DecimalFormatSymbols()' - */ - public void testDecimalFormatSymbols() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(); - assertTrue(-1 != dfs.getDecimalSeparator()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.DecimalFormatSymbols(Locale)' - */ - public void testDecimalFormatSymbolsLocale() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US); - assertTrue(-1 != dfs.getDecimalSeparator()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.DecimalFormatSymbols(ULocale)' - */ - public void testDecimalFormatSymbolsULocale() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertTrue(-1 != dfs.getDecimalSeparator()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getZeroDigit()' - */ - public void testGetZeroDigit() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals('0', dfs.getZeroDigit()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setZeroDigit(char)' - */ - public void testSetZeroDigit() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getZeroDigit(); - char value1 = (char)(value + 1); - dfs.setZeroDigit(value1); - char result = dfs.getZeroDigit(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getGroupingSeparator()' - */ - public void testGetGroupingSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals(',', dfs.getGroupingSeparator()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setGroupingSeparator(char)' - */ - public void testSetGroupingSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getGroupingSeparator(); - char value1 = (char)(value + 1); - dfs.setGroupingSeparator(value1); - char result = dfs.getGroupingSeparator(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getDecimalSeparator()' - */ - public void testGetDecimalSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals('.', dfs.getDecimalSeparator()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setDecimalSeparator(char)' - */ - public void testSetDecimalSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getDecimalSeparator(); - char value1 = (char)(value + 1); - dfs.setDecimalSeparator(value1); - char result = dfs.getDecimalSeparator(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getPerMill()' - */ - public void testGetPerMill() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals('\u2030', dfs.getPerMill()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setPerMill(char)' - */ - public void testSetPerMill() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getPerMill(); - char value1 = (char)(value + 1); - dfs.setPerMill(value1); - char result = dfs.getPerMill(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getPercent()' - */ - public void testGetPercent() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals('%', dfs.getPercent()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setPercent(char)' - */ - public void testSetPercent() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getPercent(); - char value1 = (char)(value + 1); - dfs.setPercent(value1); - char result = dfs.getPercent(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getDigit()' - */ - public void testGetDigit() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals('#', dfs.getDigit()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setDigit(char)' - */ - public void testSetDigit() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getDigit(); - char value1 = (char)(value + 1); - dfs.setDigit(value1); - char result = dfs.getDigit(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getPatternSeparator()' - */ - public void testGetPatternSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals(';', dfs.getPatternSeparator()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setPatternSeparator(char)' - */ - public void testSetPatternSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getPatternSeparator(); - char value1 = (char)(value + 1); - dfs.setPatternSeparator(value1); - char result = dfs.getPatternSeparator(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getInfinity()' - */ - public void testGetInfinity() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals("\u221e", dfs.getInfinity()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setInfinity(String)' - */ - public void testSetInfinity() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - String value = dfs.getInfinity(); - String value1 = value + "!"; - dfs.setInfinity(value1); - String result = dfs.getInfinity(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getNaN()' - */ - public void testGetNaN() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertNotNull(dfs.getNaN()); // java returns missing character??? - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setNaN(String)' - */ - public void testSetNaN() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - String value = dfs.getNaN(); - String value1 = value + "!"; - dfs.setNaN(value1); - String result = dfs.getNaN(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getMinusSign()' - */ - public void testGetMinusSign() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals('-', dfs.getMinusSign()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setMinusSign(char)' - */ - public void testSetMinusSign() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getMinusSign(); - char value1 = (char)(value + 1); - dfs.setMinusSign(value1); - char result = dfs.getMinusSign(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getCurrencySymbol()' - */ - public void testGetCurrencySymbol() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals("$", dfs.getCurrencySymbol()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setCurrencySymbol(String)' - */ - public void testSetCurrencySymbol() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - String value = dfs.getCurrencySymbol(); - String value1 = value + "!"; - dfs.setCurrencySymbol(value1); - String result = dfs.getCurrencySymbol(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getInternationalCurrencySymbol()' - */ - public void testGetInternationalCurrencySymbol() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals("USD", dfs.getInternationalCurrencySymbol()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setInternationalCurrencySymbol(String)' - */ - public void testSetInternationalCurrencySymbol() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - String value = dfs.getInternationalCurrencySymbol(); - String value1 = value + "!"; - dfs.setInternationalCurrencySymbol(value1); - String result = dfs.getInternationalCurrencySymbol(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.getMonetaryDecimalSeparator()' - */ - public void testGetMonetaryDecimalSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - assertEquals('.', dfs.getMonetaryDecimalSeparator()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.setMonetaryDecimalSeparator(char)' - */ - public void testSetMonetaryDecimalSeparator() { - DecimalFormatSymbols dfs = new DecimalFormatSymbols(ULocale.US); - char value = dfs.getMonetaryDecimalSeparator(); - char value1 = (char)(value + 1); - dfs.setMonetaryDecimalSeparator(value1); - char result = dfs.getMonetaryDecimalSeparator(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.clone()' - */ - public void testClone() { - // tested in testHashcode - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormatSymbols.equals(Object)' - */ - public void testEqualsObject() { - // tested in testHashcode - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatTest.java deleted file mode 100644 index a1a9f1e5518..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.util.Locale; - -import com.ibm.icu.text.DecimalFormat; -import com.ibm.icu.text.DecimalFormatSymbols; - -public class DecimalFormatTest extends ICUTestCase { - private static final long lmax = Long.MAX_VALUE; - private static final double dsmall = 23.33; - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.clone()' - */ - public void testClone() { - DecimalFormat df = new DecimalFormat("#,#0.00"); - DecimalFormat df2 = new DecimalFormat("#,#0.00"); - DecimalFormat dfn = new DecimalFormat("#,#0.00"); - dfn.setNegativePrefix(dfn.getNegativePrefix() + '!'); - testEHCS(df, df2, dfn); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.DecimalFormat(DecimalFormat)' - */ - public void testDecimalFormatDecimalFormat() { - // tested implicitly - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.DecimalFormat()' - */ - public void testDecimalFormat() { - DecimalFormat df = new DecimalFormat(); - assertEquals("9,223,372,036,854,775,807", df.format(lmax)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.DecimalFormat(String)' - */ - public void testDecimalFormatString() { - DecimalFormat df = new DecimalFormat("#,##0.000"); - assertEquals("23.330", df.format(dsmall)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.DecimalFormat(String, DecimalFormatSymbols)' - */ - public void testDecimalFormatStringDecimalFormatSymbols() { - DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.FRANCE); - DecimalFormat df = new DecimalFormat("#,##0.000", sym); - assertEquals("23,330", df.format(dsmall)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.getDecimalFormatSymbols()' - */ - public void testGetDecimalFormatSymbols() { - DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.FRANCE); - DecimalFormat df = new DecimalFormat("#,##0.000", sym); - assertEquals(sym, df.getDecimalFormatSymbols()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setDecimalFormatSymbols(DecimalFormatSymbols)' - */ - public void testSetDecimalFormatSymbols() { - DecimalFormat df = new DecimalFormat(); - df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.FRANCE)); - assertEquals("23,33", df.format(dsmall)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.getPositivePrefix()' - */ - public void testGetPositivePrefix() { - DecimalFormat df = new DecimalFormat("+#,##0.#;-#,##0.#"); - assertEquals("+", df.getPositivePrefix()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setPositivePrefix(String)' - */ - public void testSetPositivePrefix() { - DecimalFormat df = new DecimalFormat("+#,##0.#;-#,##0.#"); - df.setPositivePrefix("?"); - assertEquals("?23.3", df.format(dsmall)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.getNegativePrefix()' - */ - public void testGetNegativePrefix() { - DecimalFormat df = new DecimalFormat("+#,##0.#;-#,##0.#"); - assertEquals("-", df.getNegativePrefix()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setNegativePrefix(String)' - */ - public void testSetNegativePrefix() { - DecimalFormat df = new DecimalFormat("+#,##0.#;-#,##0.#"); - df.setNegativePrefix("~"); - assertEquals("~23.3", df.format(-dsmall)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.getPositiveSuffix()' - */ - public void testGetPositiveSuffix() { - DecimalFormat df = new DecimalFormat("+#,##0.#**;-#,##0.#~~"); - assertEquals("**", df.getPositiveSuffix()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setPositiveSuffix(String)' - */ - public void testSetPositiveSuffix() { - DecimalFormat df = new DecimalFormat("+#,##0.#;-#,##0.#"); - df.setPositiveSuffix("**"); - assertEquals("+23.3**", df.format(dsmall)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.getNegativeSuffix()' - */ - public void testGetNegativeSuffix() { - DecimalFormat df = new DecimalFormat("+#,##0.#**;-#,##0.#~~"); - assertEquals("~~", df.getNegativeSuffix()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setNegativeSuffix(String)' - */ - public void testSetNegativeSuffix() { - DecimalFormat df = new DecimalFormat("+#,##0.#;-#,##0.#"); - df.setNegativeSuffix("~~"); - assertEquals("-23.3~~", df.format(-dsmall)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.getMultiplier()' - */ - public void testGetMultiplier() { - DecimalFormat df = new DecimalFormat("%000"); - df.setMultiplier(1000); - assertEquals(1000, df.getMultiplier()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setMultiplier(int)' - */ - public void testSetMultiplier() { - DecimalFormat df = new DecimalFormat("%000"); - assertEquals("%012", df.format(.123)); - df.setMultiplier(1000); - assertEquals("%123", df.format(.123)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.getGroupingSize()' - */ - public void testGetGroupingSize() { - DecimalFormat df = new DecimalFormat("#,#0.#"); - assertEquals(2, df.getGroupingSize()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setGroupingSize(int)' - */ - public void testSetGroupingSize() { - DecimalFormat df = new DecimalFormat("#,##0.##"); - assertEquals("1,234,567.89", df.format(1234567.89)); - df.setGroupingSize(2); - assertEquals("1,23,45,67.89", df.format(1234567.89)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.isDecimalSeparatorAlwaysShown()' - */ - public void testIsDecimalSeparatorAlwaysShown() { - DecimalFormat df = new DecimalFormat("#.#"); - df.setDecimalSeparatorAlwaysShown(false); - assertEquals("1", df.format(1)); - assertEquals("1.2", df.format(1.2)); - df.setDecimalSeparatorAlwaysShown(true); - assertEquals("1.", df.format(1)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.setDecimalSeparatorAlwaysShown(boolean)' - */ - public void testSetDecimalSeparatorAlwaysShown() { - DecimalFormat df = new DecimalFormat("#.#"); - df.setDecimalSeparatorAlwaysShown(false); - assertFalse(df.isDecimalSeparatorAlwaysShown()); - df.setDecimalSeparatorAlwaysShown(true); - assertTrue(df.isDecimalSeparatorAlwaysShown()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.toPattern()' - */ - public void testToPattern() { - DecimalFormat df = new DecimalFormat("#,##0.##"); - assertEquals("#,##0.##", df.toPattern()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.toLocalizedPattern()' - */ - public void testToLocalizedPattern() { - DecimalFormat df = new DecimalFormat("#,##0.##", new DecimalFormatSymbols(Locale.FRANCE)); - assertEquals("#,##0.##", df.toPattern()); - assertEquals("#\u00a0##0,##", df.toLocalizedPattern()); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.applyPattern(String)' - */ - public void testApplyPattern() { - DecimalFormat df = new DecimalFormat("#,##0.##"); - df.applyPattern("#,0.#"); - assertEquals("1,2,3.4", df.format(123.4)); - } - - /* - * Test method for 'com.ibm.icu.text.DecimalFormat.applyLocalizedPattern(String)' - */ - public void testApplyLocalizedPattern() { - DecimalFormat df = new DecimalFormat("#,##0.##", new DecimalFormatSymbols(Locale.FRANCE)); - df.applyLocalizedPattern("#\u00a00,#"); - assertEquals("1\u00a02\u00a03,4", df.format(123.4)); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ICUTestCase.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ICUTestCase.java deleted file mode 100644 index 13f2003a0fa..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ICUTestCase.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Locale; - -import com.ibm.icu.util.TimeZone; -import com.ibm.icu.util.ULocale; - -import junit.framework.TestCase; - -/** - * Implement boilerplate tests. - * Currently there is only one method, testEHCS, which tests equals, hashCode, - * clone, and serialization. - */ -public abstract class ICUTestCase extends TestCase { - private static final Object[] EMPTY_ARGS = {}; - private static final Class[] EMPTY_CLASSES = {}; - - private static final Locale oldLocale = Locale.getDefault(); - private static final ULocale oldULocale = ULocale.getDefault(); - private static final java.util.TimeZone oldJTimeZone = java.util.TimeZone.getDefault(); - private static final TimeZone oldITimeZone = TimeZone.getDefault(); - - // TODO: what's the best way to check this? - public static final boolean testingWrapper = true; - - protected void setUp() throws Exception { - super.setUp(); - Locale.setDefault(Locale.US); - ULocale.setDefault(ULocale.US); - java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("PST")); - TimeZone.setDefault(TimeZone.getTimeZone("PST")); - } - - protected void tearDown() throws Exception { - ULocale.setDefault(oldULocale); - Locale.setDefault(oldLocale); - TimeZone.setDefault(oldITimeZone); - java.util.TimeZone.setDefault(oldJTimeZone); - super.tearDown(); - } - - private static final Object test = new Object(); - - /** - * Assert that two objects are _not_ equal. Curiously missing from Assert. - * @param lhs an object to test, may be null - * @param rhs an object to test, may be null - */ - public static void assertNotEqual(Object lhs, Object rhs) { - if (lhs == null) { - if (rhs == null) fail("null equals null"); - } else { - if (lhs.equals(rhs)) { - fail(lhs.toString() + " equals " + rhs); - } - } - } - - public static void assertNotEqual(long lhs, long rhs) { - if (lhs == rhs) { - fail("values are equal: " + lhs); - } - } - - /** - * Test whether equality, hashCode, clone, and serialization work as expected. - * Equals(Object) is assumed to return false (not throw an exception) if passed - * null or an object of an incompatible class. - * Hashcodes must be equal iff the two objects compare equal. No attempt is made to - * evaluate the quality of the hashcode distribution, so (in particular) degenerate - * hashcode implementations will pass this test. - * Clone will be tested if the method "clone" is public on the class of obj. - * It is assumed to return an object that compares equal to obj. - * Serialization will be tested if object implements Serializable or Externalizable. - * It is assumed the serialized/deserialized object compares equal to obj. - * @param obj the object to test - * @param eq an object that should compare equal to, but is not the same as, obj. - * it should be assignable to the class of obj. - * @param neq a non-null object that should not compare equal to obj. - * it should be assignable to the class of obj. - */ - public static void testEHCS(Object obj, Object eq, Object neq) { - if (obj == null || eq == null || neq == null) { - throw new NullPointerException(); - } - Class cls = obj.getClass(); - if (!(cls.isAssignableFrom(eq.getClass()) && cls.isAssignableFrom(neq.getClass()))) { - throw new IllegalArgumentException("unassignable classes"); - } - - // reflexive - assertEquals(obj, obj); - - // should return false, not throw exception - assertNotEqual(obj, test); - assertNotEqual(obj, null); - - // commutative - assertEquals(obj, eq); - assertEquals(eq, obj); - - assertNotEqual(obj, neq); - assertNotEqual(neq, obj); - - // equal objects MUST have equal hashes, unequal objects MAY have equal hashes - assertEquals(obj.hashCode(), eq.hashCode()); - - Object clone = null; - try { - // look for public clone method and call it if available - Method method_clone = cls.getMethod("clone", EMPTY_CLASSES); - clone = method_clone.invoke(obj, EMPTY_ARGS); - assertNotNull(clone); - } - catch(NoSuchMethodException e) { - // ok - } - catch(InvocationTargetException e) { - // ok - } - catch(IllegalAccessException e) { - // ok - } - - if (clone != null) { - assertEquals(obj, clone); - assertEquals(clone, obj); - } - - if (obj instanceof Serializable || obj instanceof Externalizable) { - Object ser = null; - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(clone); - oos.close(); - - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - ObjectInputStream ois = new ObjectInputStream(bis); - ser = ois.readObject(); - ois.close(); - } - catch(IOException e) { - System.err.println(e.getMessage()); - throw new RuntimeException(e); - } - catch(ClassNotFoundException e) { - System.err.println(e.getMessage()); - throw new RuntimeException(e); - } - - if (ser != null) { - assertEquals(obj, ser); - assertEquals(ser, obj); - assertEquals(obj.hashCode(), ser.hashCode()); - } - } - } - - /** - * Fail if the arrays are not equal. To be equal, the arrays must - * be the same length, and each element in the left array must compare - * equal to the corresponding element of the right array. - * Also fails if one of the objects is not an array. - * @param lhs the left array - * @param rhs the right array - */ - public static void assertArraysEqual(Object lhs, Object rhs) { - Class lcls = lhs.getClass(); - Class rcls = rhs.getClass(); - if (!(lcls.isArray() && rcls.isArray())) { - fail("objects are not arrays"); - } - String result = arraysAreEqual(lhs, rhs); - if (result != null) { - fail(result); - } - } - - /** - * Fail if the arrays are equal. Also fails if one or the other - * argument is not an array. - * @param lhs the left array - * @param rhs the right array - */ - public static void assertArraysNotEqual(Object lhs, Object rhs) { - Class lcls = lhs.getClass(); - Class rcls = rhs.getClass(); - if (!(lcls.isArray() && rcls.isArray())) { - fail("objects are not arrays"); - } - String result = arraysAreEqual(lhs, rhs); - if (result == null) { - fail("arrays are equal"); - } - } - - // slow but general - private static String arraysAreEqual(Object lhsa, Object rhsa) { - int lhsl = Array.getLength(lhsa); - int rhsl = Array.getLength(rhsa); - if (lhsl != rhsl) { - return "length " + lhsl + " != " + rhsl; - } - boolean lhsaA = lhsa.getClass().getComponentType().isArray(); - boolean rhsaA = rhsa.getClass().getComponentType().isArray(); - if (lhsaA != rhsaA) { - return (lhsaA ? "" : "non-") + "array != " + (rhsaA ? "" : "non-") + "array"; - } - for (int i = 0; i < lhsl; ++i) { - Object lhse = Array.get(lhsa, i); - Object rhse = Array.get(rhsa, i); - if (lhse == null) { - if (rhse != null) { - return "null != " + rhse; - } - } else { - if (lhsaA) { - String result = arraysAreEqual(lhse, rhse); - if (result != null) { - if (result.charAt(0) != '[') { - result = " " + result; - } - return "[" + i + "]" + result; - } - } else { - if (!lhse.equals(rhse)) { - return lhse.toString() + " != " + rhse; - } - } - } - } - return null; - } - - // much more painful and slow than it should be... partly because of the - // oddness of clone, partly because arrays don't provide a Method for - // 'clone' despite the fact that they implement it and make it public. - public static Object cloneComplex(Object obj) { - Object result = null; - if (obj != null) { - Class cls = obj.getClass(); - if (cls.isArray()) { - int len = Array.getLength(obj); - Class typ = cls.getComponentType(); - result = Array.newInstance(typ, len); - boolean prim = typ.isPrimitive(); - for (int i = 0; i < len; ++i) { - Object elem = Array.get(obj, i); - Array.set(result, i, prim ? elem : cloneComplex(elem)); - } - } else { - result = obj; // default - try { - Method cloneM = cls.getMethod("clone", null); - result = cloneM.invoke(obj, null); - } - catch (NoSuchMethodException e) { - } - catch (IllegalAccessException e) { - } - catch (InvocationTargetException e) { - } - } - } - return result; - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/MessageFormatTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/MessageFormatTest.java deleted file mode 100644 index c8390500a2e..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/MessageFormatTest.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ -package com.ibm.icu.tests; - -import java.text.FieldPosition; -import java.text.Format; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.text.DateFormat; -import com.ibm.icu.text.MessageFormat; -import com.ibm.icu.text.NumberFormat; -import com.ibm.icu.util.ULocale; - -public class MessageFormatTest extends ICUTestCase { - private final String pattern = "Deleted {0,number} files at {1,time,short} on {1,date}."; - private final String altPattern = "Deleted {0, number } files at {1, time, short} on {1, date}."; - private final Date date = new Date(716698890835L); - private final Number num = new Long(3456); - private final Object[] args = { num, date }; - private final Date dateOnly = new Date(716626800000L); - private final String englishTarget = "Deleted 3,456 files at 8:01 PM on Sep 16, 1992."; - private final String germanTarget = "Deleted 3.456 files at 20:01 on 16.09.1992."; - private final String modifiedTarget = "Deleted 3,456 files at 8:01:30 PM PDT on Sep 16, 1992."; - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.hashCode()' - */ - public void testHashCode() { - MessageFormat mf = new MessageFormat(pattern); - MessageFormat eq = new MessageFormat(altPattern); - MessageFormat ne = new MessageFormat("Deleted (0, number, currency} files at {1, time} on {1, date}."); - testEHCS(mf, eq, ne); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.MessageFormat(MessageFormat)' - */ - public void testMessageFormatMessageFormat() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.MessageFormat(String)' - */ - public void testMessageFormatString() { - MessageFormat mf = new MessageFormat(pattern); - assertEquals(englishTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.MessageFormat(String, Locale)' - */ - public void testMessageFormatStringLocale() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - assertEquals(englishTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.MessageFormat(String, ULocale)' - */ - public void testMessageFormatStringULocale() { - MessageFormat mf = new MessageFormat(pattern, ULocale.US); - assertEquals(englishTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.setLocale(Locale)' - */ - public void testSetLocaleLocale() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - mf.setLocale(Locale.GERMANY); - mf.applyPattern(pattern); - assertEquals(germanTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.setLocale(ULocale)' - */ - public void testSetLocaleULocale() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - mf.setLocale(ULocale.GERMANY); - mf.applyPattern(pattern); - assertEquals(germanTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.getLocale()' - */ - public void testGetLocale() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - mf.setLocale(Locale.GERMANY); - assertEquals(Locale.GERMANY, mf.getLocale()); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.getULocale()' - */ - public void testGetULocale() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - mf.setLocale(ULocale.GERMANY); - assertEquals(ULocale.GERMANY, mf.getULocale()); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.applyPattern(String)' - */ - public void testApplyPattern() { - MessageFormat mf = new MessageFormat("foo"); - mf.applyPattern(pattern); - assertEquals(englishTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.toPattern()' - */ - public void testToPattern() { - MessageFormat mf = new MessageFormat(altPattern); - assertEquals(pattern, mf.toPattern()); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.setFormatsByArgumentIndex(Format[])' - public void testSetFormatsByArgumentIndex() { - // this api is broken. if the same argument is used twice with two different - // formats, this can't be used, since it sets only one format per argument. - MessageFormat mf = new MessageFormat(pattern, Locale.US); - Format[] formats = { - NumberFormat.getIntegerInstance(), - DateFormat.getTimeInstance(DateFormat.SHORT), - DateFormat.getDateInstance(), - }; - mf.setFormatsByArgumentIndex(formats); - assertEquals(brokenButConformantTarget, mf.format(args)); - } - */ - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.setFormats(Format[])' - */ - public void testSetFormats() { - // this api, while it has the problem that the order of formats depends - // on the order in the string, at least lets you set all the formats. - - MessageFormat mf = new MessageFormat(pattern, Locale.US); - Format[] formats = { - NumberFormat.getIntegerInstance(), - DateFormat.getTimeInstance(DateFormat.SHORT), - DateFormat.getDateInstance(), - }; - mf.setFormats(formats); - assertEquals(englishTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.setFormatByArgumentIndex(int, Format)' - public void testSetFormatByArgumentIndex() { - // same problem, once you set a format for an argument, you've set all of them - - MessageFormat mf = new MessageFormat(pattern, Locale.US); - mf.setFormatByArgumentIndex(1, DateFormat.getTimeInstance(DateFormat.SHORT)); - assertEquals(brokenButConformantTarget, mf.format(args)); - - } - */ - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.setFormat(int, Format)' - */ - public void testSetFormat() { - // and ok again - MessageFormat mf = new MessageFormat(pattern, Locale.US); - mf.setFormat(1, DateFormat.getTimeInstance(DateFormat.LONG)); - assertEquals(modifiedTarget, mf.format(args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.getFormatsByArgumentIndex()' - public void testGetFormatsByArgumentIndex() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - Format[] formats = mf.getFormatsByArgumentIndex(); - NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); - assertEquals(formats[0], nf); - DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US); - assertEquals(formats[1], df); - } - */ - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.getFormats()' - */ - public void testGetFormats() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - Format[] formats = mf.getFormats(); - NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); - assertEquals(formats[0], nf); - DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); - assertEquals(formats[1], tf); - DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US); - assertEquals(formats[2], df); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.format(Object[], StringBuffer, FieldPosition)' - */ - public void testFormatObjectArrayStringBufferFieldPosition() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - StringBuffer buf = new StringBuffer(); - FieldPosition fp = new FieldPosition(0); - mf.format(args, buf, fp); - assertEquals(englishTarget, buf.toString()); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.format(String, Object[])' - */ - public void testFormatStringObjectArray() { - assertEquals(englishTarget, MessageFormat.format(pattern, args)); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.format(Object, StringBuffer, FieldPosition)' - */ - public void testFormatObjectStringBufferFieldPosition() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - StringBuffer buf = new StringBuffer(); - FieldPosition fp = new FieldPosition(0); - mf.format((Object)args, buf, fp); - assertEquals(englishTarget, buf.toString()); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.parse(String, ParsePosition)' - */ - public void testParseStringParsePosition() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - ParsePosition pp = new ParsePosition(1); - Object[] result = mf.parse("!" + englishTarget, pp); - assertEquals(num, result[0]); - assertEquals(dateOnly, result[1]); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.parse(String)' - */ - public void testParseString() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - try { - Object[] result = mf.parse(englishTarget); - assertEquals(num, result[0]); - assertEquals(dateOnly, result[1]); - } - catch (ParseException e) { - fail(e.getMessage()); - } - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.parseObject(String, ParsePosition)' - */ - public void testParseObjectStringParsePosition() { - MessageFormat mf = new MessageFormat(pattern, Locale.US); - ParsePosition pp = new ParsePosition(0); - Object result = mf.parseObject(englishTarget, pp); - assertEquals(num, ((Object[])result)[0]); - assertEquals(dateOnly, ((Object[])result)[1]); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.autoQuoteApostrophe(String)' - */ - public void testAutoQuoteApostrophe() { - String str = "Let's meet at {1,time,h 'o'' clock'} at l'Orange Bleue"; - String pat = MessageFormat.autoQuoteApostrophe(str); - MessageFormat mf = new MessageFormat(pat, Locale.US); - String result = mf.format(args); - assertEquals("Let's meet at 8 o' clock at l'Orange Bleue", result); - assertEquals("Let''s meet at {1,time,h 'o'' clock'} at l''Orange Bleue", pat); - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.clone()' - */ - public void testClone() { - // tested already in testHashcode - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.equals(Object)' - */ - public void testEqualsObject() { - // tested already in testHashcode - } - - /* - * Test method for 'com.ibm.icu.text.MessageFormat.toString()' - */ - public void testToString() { - // no need to test - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/NumberFormatTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/NumberFormatTest.java deleted file mode 100644 index 100b52cf3fd..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/NumberFormatTest.java +++ /dev/null @@ -1,441 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2007, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.math.BigInteger; -import java.text.FieldPosition; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Locale; - -import com.ibm.icu.text.NumberFormat; -import com.ibm.icu.util.ULocale; - -public class NumberFormatTest extends ICUTestCase { - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.NumberFormat(NumberFormat)' - */ - public void testNumberFormat() { - NumberFormat nf = new NumberFormat(java.text.NumberFormat.getInstance()); - assertEquals(nf, NumberFormat.getInstance()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.format(Object, StringBuffer, FieldPosition)' - */ - public void testFormatObjectStringBufferFieldPosition() { - Number num = new Long(1234L); - StringBuffer buf = new StringBuffer(); - FieldPosition fp = new FieldPosition(0); - NumberFormat.getInstance().format(num, buf, fp); - assertEquals("1,234", buf.toString()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.parseObject(String, ParsePosition)' - */ - public void testParseObjectStringParsePosition() { - ParsePosition pp = new ParsePosition(0); - Object result = NumberFormat.getInstance().parse("1,234", pp); - assertEquals(result, new Long(1234)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.format(double)' - */ - public void testFormatDouble() { - assertEquals("1,234.567", NumberFormat.getInstance().format(1234.567)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.format(long)' - */ - public void testFormatLong() { - assertEquals("1,234", NumberFormat.getInstance().format(1234L)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.format(BigInteger)' - */ - public void testFormatBigInteger() { - // note, java doesn't handle biginteger with full precision. - BigInteger bi = new BigInteger("123456"); - assertEquals("123,456", java.text.NumberFormat.getInstance().format(bi)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.format(double, StringBuffer, FieldPosition)' - */ - public void testFormatDoubleStringBufferFieldPosition() { - StringBuffer buf = new StringBuffer(); - FieldPosition fp = new FieldPosition(0); - assertEquals("123,456.789", NumberFormat.getInstance().format(123456.789, buf, fp).toString()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.format(long, StringBuffer, FieldPosition)' - */ - public void testFormatLongStringBufferFieldPosition() { - StringBuffer buf = new StringBuffer(); - FieldPosition fp = new FieldPosition(0); - assertEquals("123,456", NumberFormat.getInstance().format(123456L, buf, fp).toString()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.format(BigInteger, StringBuffer, FieldPosition)' - */ - public void testFormatBigIntegerStringBufferFieldPosition() { - // note, java doesn't handle biginteger with full precision. - StringBuffer buf = new StringBuffer(); - FieldPosition fp = new FieldPosition(0); - BigInteger bi = new BigInteger("123456"); - assertEquals("123,456", java.text.NumberFormat.getInstance().format(bi, buf, fp).toString()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.parse(String, ParsePosition)' - */ - public void testParseStringParsePosition() { - ParsePosition pp = new ParsePosition(3); - assertEquals(new Long(123456), NumberFormat.getInstance().parse("xxx123,456yyy", pp)); - assertEquals(10, pp.getIndex()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.parse(String)' - */ - public void testParseString() throws ParseException { - Number result = NumberFormat.getInstance().parse("123,456,yyy"); - assertEquals(new Long(123456), result); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.isParseIntegerOnly()' - */ - public void testIsParseIntegerOnly() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setParseIntegerOnly(true); - assertTrue(nf.isParseIntegerOnly()); - nf.setParseIntegerOnly(false); - assertFalse(nf.isParseIntegerOnly()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.setParseIntegerOnly(boolean)' - */ - public void testSetParseIntegerOnly() throws ParseException { - String str = "123.456,yyy"; - NumberFormat nf = NumberFormat.getInstance(); - assertEquals(new Double(123.456), nf.parse(str)); - nf.setParseIntegerOnly(true); - assertEquals(new Long(123), nf.parse(str)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getInstance()' - */ - public void testGetInstance() { - // used everywhere, no need to test - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getInstance(Locale)' - */ - public void testGetInstanceLocale() { - NumberFormat nf = NumberFormat.getInstance(Locale.GERMANY); - assertEquals("123,456", nf.format(123.456)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getInstance(ULocale)' - */ - public void testGetInstanceULocale() { - NumberFormat nf = NumberFormat.getInstance(ULocale.GERMANY); - assertEquals("123,456", nf.format(123.456)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getNumberInstance()' - */ - public void testGetNumberInstance() { - NumberFormat nf = NumberFormat.getNumberInstance(); - assertEquals("123,456.789", nf.format(123456.789)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getNumberInstance(Locale)' - */ - public void testGetNumberInstanceLocale() { - NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMANY); - assertEquals("123.456,789", nf.format(123456.789)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getNumberInstance(ULocale)' - */ - public void testGetNumberInstanceULocale() { - NumberFormat nf = NumberFormat.getNumberInstance(ULocale.GERMANY); - assertEquals("123.456,789", nf.format(123456.789)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getIntegerInstance()' - */ - public void testGetIntegerInstance() { - NumberFormat nf = NumberFormat.getIntegerInstance(); - assertEquals("123,457", nf.format(123456.789)); // rounds - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getIntegerInstance(Locale)' - */ - public void testGetIntegerInstanceLocale() { - NumberFormat nf = NumberFormat.getIntegerInstance(Locale.GERMANY); - assertEquals("123.457", nf.format(123456.789)); // rounds - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getIntegerInstance(ULocale)' - */ - public void testGetIntegerInstanceULocale() { - NumberFormat nf = NumberFormat.getIntegerInstance(ULocale.GERMANY); - assertEquals("123.457", nf.format(123456.789)); // rounds - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getCurrencyInstance()' - */ - public void testGetCurrencyInstance() { - NumberFormat nf = NumberFormat.getCurrencyInstance(); - assertEquals("$123,456.99", nf.format(123456.99)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getCurrencyInstance(Locale)' - */ - public void testGetCurrencyInstanceLocale() { - NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.GERMANY); - assertEquals("123.456,99 \u20AC", nf.format(123456.99)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getCurrencyInstance(ULocale)' - */ - public void testGetCurrencyInstanceULocale() { - NumberFormat nf = NumberFormat.getCurrencyInstance(ULocale.GERMANY); - assertEquals("123.456,99 \u20AC", nf.format(123456.99)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getPercentInstance()' - */ - public void testGetPercentInstance() { - NumberFormat nf = NumberFormat.getPercentInstance(); - assertEquals("123,456%", nf.format(1234.56)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getPercentInstance(Locale)' - */ - public void testGetPercentInstanceLocale() { - NumberFormat nf = NumberFormat.getPercentInstance(Locale.GERMANY); - assertEquals("123.456%", nf.format(1234.56)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getPercentInstance(ULocale)' - */ - public void testGetPercentInstanceULocale() { - NumberFormat nf = NumberFormat.getPercentInstance(ULocale.GERMANY); - assertEquals("123.456%", nf.format(1234.56)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getScientificInstance()' - */ - public void testGetScientificInstance() { - NumberFormat nf = NumberFormat.getScientificInstance(); - assertEquals(".123456E4", nf.format(1234.56)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getScientificInstance(Locale)' - */ - public void testGetScientificInstanceLocale() { - NumberFormat nf = NumberFormat.getScientificInstance(Locale.GERMANY); - assertEquals(",123456E4", nf.format(1234.56)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getScientificInstance(ULocale)' - */ - public void testGetScientificInstanceULocale() { - NumberFormat nf = NumberFormat.getScientificInstance(ULocale.GERMANY); - assertEquals(",123456E4", nf.format(1234.56)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getAvailableLocales()' - */ - public void testGetAvailableLocales() { - Locale[] ilocales = NumberFormat.getAvailableLocales(); - if (ICUTestCase.testingWrapper) { - Locale[] jlocales = java.text.NumberFormat.getAvailableLocales(); - for (int i = 0; i < ilocales.length; ++i) { - assertEquals(jlocales[i], ilocales[i]); - } - } - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getAvailableULocales()' - */ - public void testGetAvailableULocales() { - ULocale[] ulocales = NumberFormat.getAvailableULocales(); - if (ICUTestCase.testingWrapper) { - Locale[] jlocales = java.text.NumberFormat.getAvailableLocales(); - for (int i = 0; i < ulocales.length; ++i) { - assertEquals(jlocales[i], ulocales[i].toLocale()); - } - } - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.isGroupingUsed()' - */ - public void testIsGroupingUsed() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setGroupingUsed(true); - assertTrue(nf.isGroupingUsed()); - nf.setGroupingUsed(false); - assertFalse(nf.isGroupingUsed()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.setGroupingUsed(boolean)' - */ - public void testSetGroupingUsed() { - NumberFormat nf = NumberFormat.getInstance(); - assertEquals("123,456,789", nf.format(123456789)); - nf.setGroupingUsed(false); - assertEquals("123456789", nf.format(123456789)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getMaximumIntegerDigits()' - */ - public void testGetMaximumIntegerDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMaximumIntegerDigits(4); - assertEquals(4, nf.getMaximumIntegerDigits()); - nf.setMaximumIntegerDigits(6); - assertEquals(6, nf.getMaximumIntegerDigits()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.setMaximumIntegerDigits(int)' - */ - public void testSetMaximumIntegerDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMaximumIntegerDigits(4); - assertEquals("3,456", nf.format(123456)); // high digits truncated - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getMinimumIntegerDigits()' - */ - public void testGetMinimumIntegerDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMinimumIntegerDigits(4); - assertEquals(4, nf.getMinimumIntegerDigits()); - nf.setMinimumIntegerDigits(6); - assertEquals(6, nf.getMinimumIntegerDigits()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.setMinimumIntegerDigits(int)' - */ - public void testSetMinimumIntegerDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMinimumIntegerDigits(4); - assertEquals("0,012", nf.format(12)); // pad out with zero, grouping still used - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getMaximumFractionDigits()' - */ - public void testGetMaximumFractionDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMaximumFractionDigits(4); - assertEquals(4, nf.getMaximumFractionDigits()); - nf.setMaximumFractionDigits(6); - assertEquals(6, nf.getMaximumFractionDigits()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.setMaximumFractionDigits(int)' - */ - public void testSetMaximumFractionDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMaximumFractionDigits(4); - assertEquals("1.2346", nf.format(1.2345678)); // low digits rounded - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.getMinimumFractionDigits()' - */ - public void testGetMinimumFractionDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMinimumFractionDigits(4); - assertEquals(4, nf.getMinimumFractionDigits()); - nf.setMinimumFractionDigits(6); - assertEquals(6, nf.getMinimumFractionDigits()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.setMinimumFractionDigits(int)' - */ - public void testSetMinimumFractionDigits() { - NumberFormat nf = NumberFormat.getInstance(); - nf.setMinimumFractionDigits(4); - assertEquals("1.2000", nf.format(1.2)); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.toString()' - */ - public void testToString() { - assertNotNull(NumberFormat.getInstance().toString()); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.hashCode()' - */ - public void testHashCode() { - NumberFormat nf = NumberFormat.getInstance(); - NumberFormat eq = NumberFormat.getInstance(Locale.US); - NumberFormat neq = NumberFormat.getInstance(Locale.GERMANY); - - ICUTestCase.testEHCS(nf, eq, neq); - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.clone()' - */ - public void testClone() { - // see testHashCode - } - - /* - * Test method for 'com.ibm.icu.x.text.NumberFormat.equals(Object)' - */ - public void testEqualsObject() { - // see testHashCode - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/SimpleDateFormatTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/SimpleDateFormatTest.java deleted file mode 100644 index 6e09027eb86..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/SimpleDateFormatTest.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.text.FieldPosition; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.text.DateFormatSymbols; -import com.ibm.icu.text.SimpleDateFormat; -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.TimeZone; -import com.ibm.icu.util.ULocale; - -public class SimpleDateFormatTest extends ICUTestCase { - private static final String mdy = "MMM dd yyyy"; - private static final String md2 = "MMM dd yy"; - private static final String hmz = "'The time is' HH:mm:ss zzz"; - private static final String hmzmdy = hmz + " 'on' " + mdy; - private static final String hmzmdyStr = "The time is 15:05:20 CST on Jan 10 2006"; - - private static final TimeZone tzc = TimeZone.getTimeZone("CST"); - private static final TimeZone tzp = TimeZone.getTimeZone("PST"); - private static final Calendar cal = Calendar.getInstance(tzc); - private static final Date date; - static { - cal.clear(); - cal.set(2006, 0, 10, 15, 5, 20); // arrgh, doesn't clear millis - date = cal.getTime(); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.format(Calendar, StringBuffer, FieldPosition)' - */ - public void testFormatCalendarStringBufferFieldPosition() { - StringBuffer buf = new StringBuffer(); - FieldPosition fp = new FieldPosition(0); - SimpleDateFormat sdf = new SimpleDateFormat(hmzmdy); - sdf.format(cal, buf, fp); - assertEquals(hmzmdyStr, buf.toString()); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.parse(String, Calendar, ParsePosition)' - */ - public void testParseStringCalendarParsePosition() { - Calendar cal = Calendar.getInstance(tzp); - cal.clear(); - ParsePosition pp = new ParsePosition(0); - SimpleDateFormat sdf = new SimpleDateFormat(hmzmdy); - sdf.parse(hmzmdyStr, cal, pp); - assertEquals(date, cal.getTime()); - // note: java doesn't return the parsed time zone - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.clone()' - */ - public void testClone() { - - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.SimpleDateFormat()' - */ - public void testSimpleDateFormat() { - SimpleDateFormat sdf = new SimpleDateFormat(); - java.text.SimpleDateFormat jsdf = new java.text.SimpleDateFormat(); - assertEquals(jsdf.format(date), sdf.format(date)); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.SimpleDateFormat(String)' - */ - public void testSimpleDateFormatString() { - SimpleDateFormat sdf = new SimpleDateFormat(mdy); - java.text.SimpleDateFormat jsdf = new java.text.SimpleDateFormat(mdy); - assertEquals(jsdf.format(date), sdf.format(date)); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.SimpleDateFormat(String, Locale)' - */ - public void testSimpleDateFormatStringLocale() { - Locale l = Locale.JAPAN; - SimpleDateFormat sdf = new SimpleDateFormat(mdy, l); - java.text.SimpleDateFormat jsdf = new java.text.SimpleDateFormat(mdy, l); - assertEquals(jsdf.format(date), sdf.format(date)); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.SimpleDateFormat(String, ULocale)' - */ - public void testSimpleDateFormatStringULocale() { - ULocale l = ULocale.JAPAN; - SimpleDateFormat sdf = new SimpleDateFormat(mdy, l); - java.text.SimpleDateFormat jsdf = new java.text.SimpleDateFormat(mdy, l.toLocale()); - assertEquals(jsdf.format(date), sdf.format(date)); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.SimpleDateFormat(String, DateFormatSymbols)' - */ - public void testSimpleDateFormatStringDateFormatSymbols() { - Locale l = Locale.US; - DateFormatSymbols dfs = new DateFormatSymbols(l); - java.text.DateFormatSymbols jdfs = new java.text.DateFormatSymbols(l); - SimpleDateFormat sdf = new SimpleDateFormat(mdy, dfs); - java.text.SimpleDateFormat jsdf = new java.text.SimpleDateFormat(mdy, jdfs); - assertEquals(jsdf.format(date), sdf.format(date)); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.set2DigitYearStart(Date)' - */ - public void testSet2DigitYearStart() { - SimpleDateFormat sdf = new SimpleDateFormat(md2); - sdf.set2DigitYearStart(date); - try { - Date d = sdf.parse("Jan 15 04"); - assertNotEqual(-1, d.toString().indexOf("2104")); - } - catch (ParseException pe) { - fail(pe.getMessage()); - } - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.get2DigitYearStart()' - */ - public void testGet2DigitYearStart() { - SimpleDateFormat sdf = new SimpleDateFormat(md2); - sdf.set2DigitYearStart(date); - assertEquals(date, sdf.get2DigitYearStart()); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.toPattern()' - */ - public void testToPattern() { - SimpleDateFormat sdf = new SimpleDateFormat(mdy); - assertEquals(mdy, sdf.toPattern()); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.toLocalizedPattern()' - */ - public void testToLocalizedPattern() { - Locale l = Locale.getDefault(); - Locale.setDefault(Locale.US); - SimpleDateFormat sdf = new SimpleDateFormat(mdy); - assertEquals(mdy, sdf.toLocalizedPattern()); - Locale.setDefault(l); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.applyPattern(String)' - */ - public void testApplyPattern() { - SimpleDateFormat sdf = new SimpleDateFormat(); - sdf.setTimeZone(tzc); - sdf.applyPattern(hmzmdy); - assertEquals(hmzmdyStr, sdf.format(date)); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.applyLocalizedPattern(String)' - */ - public void testApplyLocalizedPattern() { - SimpleDateFormat sdf = new SimpleDateFormat(); - sdf.setTimeZone(tzc); - sdf.applyLocalizedPattern(hmzmdy); - assertEquals(hmzmdyStr, sdf.format(date)); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.getDateFormatSymbols()' - */ - public void testGetDateFormatSymbols() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.US); - SimpleDateFormat sdf = new SimpleDateFormat(mdy, dfs); - assertEquals(dfs, sdf.getDateFormatSymbols()); - } - - /* - * Test method for 'com.ibm.icu.text.SimpleDateFormat.setDateFormatSymbols(DateFormatSymbols)' - */ - public void testSetDateFormatSymbols() { - DateFormatSymbols dfs = new DateFormatSymbols(Locale.JAPAN); - SimpleDateFormat sdf = new SimpleDateFormat(hmzmdy); - sdf.setDateFormatSymbols(dfs); - // assumes Japanese symbols do not have gregorian month names - assertEquals(-1, sdf.format(date).indexOf("Jan")); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/TimeZoneTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/TimeZoneTest.java deleted file mode 100644 index 547a208d218..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/TimeZoneTest.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.TimeZone; -import com.ibm.icu.util.ULocale; - -public class TimeZoneTest extends ICUTestCase { - - /* - * Test method for 'com.ibm.icu.util.TimeZone.hashCode()' - */ - public void testHashCode() { - TimeZone tz1 = TimeZone.getTimeZone("PST"); - TimeZone tz2 = TimeZone.getTimeZone("PST"); - TimeZone tzn = TimeZone.getTimeZone("CST"); - testEHCS(tz1, tz2, tzn); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.TimeZone(TimeZone)' - */ - public void testTimeZone() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getOffset(int, int, int, int, int, int)' - */ - public void testGetOffset() { - TimeZone tz = TimeZone.getTimeZone("PST"); - int offset = tz.getOffset(1, 2004, 0, 01, 1, 0); - assertEquals(-28800000, offset); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.setRawOffset(int)' - */ - public void testSetRawOffset() { - TimeZone tz = TimeZone.getTimeZone("PST"); - int value = tz.getRawOffset(); - int value1 = value + 100000; - tz.setRawOffset(value1); - int result = tz.getRawOffset(); - assertNotEqual(value, result); - assertEquals(value1, result); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getRawOffset()' - */ - public void testGetRawOffset() { - TimeZone tz = TimeZone.getTimeZone("PST"); - int offset = tz.getRawOffset(); - assertEquals(-28800000, offset); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getID()' - */ - public void testGetID() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals("PST", tz.getID()); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.setID(String)' - */ - public void testSetID() { - TimeZone tz = TimeZone.getTimeZone("PST"); - String value1 = tz.getID(); - String value2 = value1 + "!"; - tz.setID(value2); - String result = tz.getID(); - assertNotEqual(value1, result); - assertEquals(value2, result); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName()' - */ - public void testGetDisplayName() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals("Pacific Standard Time", tz.getDisplayName()); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(Locale)' - */ - public void testGetDisplayNameLocale() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals("Pacific Standard Time", tz.getDisplayName(Locale.US)); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(ULocale)' - */ - public void testGetDisplayNameULocale() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals("Pacific Standard Time", tz.getDisplayName(ULocale.US)); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(boolean, int)' - */ - public void testGetDisplayNameBooleanInt() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals("PDT", tz.getDisplayName(true, TimeZone.SHORT)); - assertEquals("Pacific Daylight Time", tz.getDisplayName(true, TimeZone.LONG)); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(boolean, int, Locale)' - */ - public void testGetDisplayNameBooleanIntLocale() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals("PDT", tz.getDisplayName(true, TimeZone.SHORT, Locale.US)); - assertEquals("Pacific Daylight Time", tz.getDisplayName(true, TimeZone.LONG, Locale.US)); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDisplayName(boolean, int, ULocale)' - */ - public void testGetDisplayNameBooleanIntULocale() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals("PDT", tz.getDisplayName(true, TimeZone.SHORT, ULocale.US)); - assertEquals("Pacific Daylight Time", tz.getDisplayName(true, TimeZone.LONG, ULocale.US)); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDSTSavings()' - */ - public void testGetDSTSavings() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertEquals(3600000, tz.getDSTSavings()); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.useDaylightTime()' - */ - public void testUseDaylightTime() { - TimeZone tz = TimeZone.getTimeZone("PST"); - assertTrue(tz.useDaylightTime()); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.inDaylightTime(Date)' - */ - public void testInDaylightTime() { - TimeZone tz = TimeZone.getTimeZone("PST"); - Calendar cal = Calendar.getInstance(); - cal.set(2005, 0, 17); - Date date = cal.getTime(); - assertFalse(tz.inDaylightTime(date)); - cal.set(2005, 6, 17); - date = cal.getTime(); - assertTrue(tz.inDaylightTime(date)); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getTimeZone(String)' - */ - public void testGetTimeZone() { - // implicitly tested everywhere - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getAvailableIDs(int)' - */ - public void testGetAvailableIDsInt() { - String[] ids = TimeZone.getAvailableIDs(-28800000); - assertNotNull(ids); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getAvailableIDs()' - */ - public void testGetAvailableIDs() { - String[] ids = TimeZone.getAvailableIDs(); - assertNotNull(ids); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.getDefault()' - */ - public void testGetDefault() { - TimeZone tz = TimeZone.getDefault(); - assertNotNull(tz); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.setDefault(TimeZone)' - */ - public void testSetDefault() { - TimeZone tz1 = TimeZone.getDefault(); - String newCode = "PDT".equals(tz1.getID()) ? "CST" : "PDT"; - TimeZone tz2 = TimeZone.getTimeZone(newCode); - TimeZone.setDefault(tz2); - TimeZone result = TimeZone.getDefault(); - assertNotEqual(tz1, result); - assertEquals(tz2, result); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.hasSameRules(TimeZone)' - */ - public void testHasSameRules() { - TimeZone tz1 = TimeZone.getTimeZone("PST"); - TimeZone tz2 = TimeZone.getTimeZone("America/Los_Angeles"); - assertTrue(tz1.hasSameRules(tz2)); - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.clone()' - */ - public void testClone() { - // tested by testHashCode - } - - /* - * Test method for 'com.ibm.icu.util.TimeZone.equals(Object)' - */ - public void testEqualsObject() { - // tested by testHashCode - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ULocaleTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ULocaleTest.java deleted file mode 100644 index 8730d669b3d..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ULocaleTest.java +++ /dev/null @@ -1,748 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.tests; - -import java.util.Iterator; -import java.util.Locale; - -import com.ibm.icu.util.ULocale; - -public class ULocaleTest extends ICUTestCase { - private String sampleName; - private String longULocaleName; - private String longULocaleBasename; - private String nonNormalizedName; - private ULocale longULocale; - private Locale sampleLocale; - - /** - * @Override - */ - protected void setUp() throws Exception { - super.setUp(); - - sampleName = "ll_CC_VVVV"; - longULocaleName = "ll_Ssss_CC_VVVV@collation=phonebook;key=value"; - longULocaleBasename = longULocaleName.substring(0, longULocaleName.indexOf('@')); - nonNormalizedName = "LL_ssss_cc_VVVV@ Key = value ; Collation = phonebook ; "; - longULocale = new ULocale(longULocaleName); - sampleLocale = new ULocale(sampleName).toLocale(); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.hashCode()' - */ - public void testHashCode() { - ULocale obj = ULocale.GERMANY; - ULocale eq = new ULocale("de_DE"); - ULocale neq = new ULocale("de_DE_FRENCH"); - - ICUTestCase.testEHCS(obj, eq, neq); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.forLocale(Locale)' - */ - public void testForLocale() { - assertEquals(ULocale.GERMANY, ULocale.forLocale(Locale.GERMANY)); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String)' - */ - public void testULocaleString() { - assertEquals(ULocale.GERMAN, new ULocale("de")); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String)' - */ - public void testULocaleStringString() { - assertEquals(ULocale.GERMANY, new ULocale("de", "DE")); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.ULocale(String, String, String)' - */ - public void testULocaleStringStringString() { - assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.createCanonical(String)' - */ - public void testCreateCanonical() { - ULocale result = ULocale.createCanonical("de__PHONEBOOK"); - assertEquals(new ULocale("de@collation=phonebook"), result); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.toLocale()' - */ - public void testToLocale() { - assertEquals(sampleLocale, new ULocale("ll", "cc", "VVVV").toLocale()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDefault()' - */ - public void testGetDefault() { - assertEquals(Locale.getDefault(), ULocale.getDefault().toLocale()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.setDefault(ULocale)' - */ - public void testSetDefault() { - Locale oldLocale = Locale.getDefault(); - ULocale oldULocale = ULocale.getDefault(); - try { - ULocale.setDefault(longULocale); - ICUTestCase.assertNotEqual(Locale.getDefault(), oldLocale); - ICUTestCase.assertNotEqual(ULocale.getDefault(), oldULocale); - assertEquals(longULocale, ULocale.getDefault()); - assertEquals(sampleLocale, Locale.getDefault()); - } - finally { - ULocale.setDefault(oldULocale); - Locale.setDefault(oldLocale); // in case of some error - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.clone()' - */ - public void testClone() { - // see testHashcode - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.equals(Object)' - */ - public void testEqualsObject() { - // see testHashcode - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getAvailableLocales()' - */ - public void testGetAvailableLocales() { - ULocale[] ulocales = ULocale.getAvailableLocales(); - if (ICUTestCase.testingWrapper) { - Locale[] locales = Locale.getAvailableLocales(); - for (int i = 0; i < ulocales.length; ++i) { - assertEquals(ulocales[i].toLocale(), locales[i]); - } - } - // else nothing to test except that the function returned. - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getISOCountries()' - */ - public void testGetISOCountries() { - String[] ucountries = ULocale.getISOCountries(); - assertNotNull(ucountries); - if (ICUTestCase.testingWrapper) { - // keep our own data for now - // our data doesn't match java's so this test would fail - // TODO: enable if we decide to use java's data - // String[] countries = Locale.getISOCountries(); - // TestBoilerplate.assertArraysEqual(ucountries, countries); - } - // else nothing to test except that the function returned. - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getISOLanguages()' - */ - public void testGetISOLanguages() { - String[] ulanguages = ULocale.getISOLanguages(); - assertNotNull(ulanguages); - if (ICUTestCase.testingWrapper) { - // keep our own data for now - // our data doesn't match java's so this test would fail - // TODO: enable if we decide to use java's data - // String[] languages = Locale.getISOLanguages(); - // TestBoilerplate.assertArraysEqual(ulanguages, languages); - } - // else nothing to test except that the function returned. - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getLanguage()' - */ - public void testGetLanguage() { - assertEquals("ll", longULocale.getLanguage()); - assertEquals("ll", longULocale.toLocale().getLanguage()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getLanguage(String)' - */ - public void testGetLanguageString() { - assertEquals("ll", ULocale.getLanguage(longULocale.getName())); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getScript()' - */ - public void testGetScript() { - assertEquals("Ssss", longULocale.getScript()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getScript(String)' - */ - public void testGetScriptString() { - assertEquals("Ssss", ULocale.getScript(longULocale.getName())); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getCountry()' - */ - public void testGetCountry() { - assertEquals("CC", longULocale.getCountry()); - assertEquals("CC", longULocale.toLocale().getCountry()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getCountry(String)' - */ - public void testGetCountryString() { - assertEquals("CC", ULocale.getCountry(longULocale.getName())); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getVariant()' - */ - public void testGetVariant() { - assertEquals("VVVV", longULocale.getVariant()); - assertEquals("VVVV", longULocale.toLocale().getVariant()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getVariant(String)' - */ - public void testGetVariantString() { - assertEquals("VVVV", ULocale.getVariant(longULocale.getName())); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getFallback(String)' - */ - public void testGetFallbackString() { - assertEquals(ULocale.GERMAN, ULocale.getFallback(ULocale.GERMANY.getName())); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getFallback()' - */ - public void testGetFallback() { - assertEquals(ULocale.GERMAN, ULocale.GERMANY.getFallback()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getBaseName()' - */ - public void testGetBaseName() { - assertEquals(longULocaleBasename, longULocale.getBaseName()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getBaseName(String)' - */ - public void testGetBaseNameString() { - assertEquals(longULocaleBasename, longULocale.getBaseName()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getName()' - */ - public void testGetName() { - assertEquals(longULocaleName, longULocale.getName()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getName(String)' - */ - public void testGetNameString() { - assertEquals(longULocaleName, ULocale.getName(nonNormalizedName)); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.toString()' - */ - public void testToString() { - assertEquals(longULocaleName, longULocale.toString()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getKeywords()' - */ - public void testGetKeywords() { - Iterator iter = longULocale.getKeywords(); - assertEquals(iter.next(), "collation"); - assertEquals(iter.next(), "key"); - assertFalse(iter.hasNext()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getKeywords(String)' - */ - public void testGetKeywordsString() { - Iterator iter = ULocale.getKeywords(nonNormalizedName); - assertEquals(iter.next(), "collation"); - assertEquals(iter.next(), "key"); - assertFalse(iter.hasNext()); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getKeywordValue(String)' - */ - public void testGetKeywordValueString() { - assertEquals("value", longULocale.getKeywordValue("key")); - assertEquals("phonebook", longULocale.getKeywordValue("collation")); - assertNull(longULocale.getKeywordValue("zzyzx")); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getKeywordValue(String, String)' - */ - public void testGetKeywordValueStringString() { - assertEquals("value", ULocale.getKeywordValue(longULocaleName, "key")); - assertEquals("phonebook", ULocale.getKeywordValue(longULocaleName, "collation")); - assertNull(ULocale.getKeywordValue(longULocaleName, "zzyzx")); - - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.canonicalize(String)' - */ - public void testCanonicalize() { - assertEquals("de@collation=phonebook", ULocale.canonicalize("de__PHONEBOOK")); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.setKeywordValue(String, String)' - */ - public void testSetKeywordValueStringString() { - ULocale munged = longULocale.setKeywordValue("key", "C#"); - assertEquals("C#", munged.getKeywordValue("key")); - munged = munged.setKeywordValue("zzyzx", "grue"); - assertEquals("grue", munged.getKeywordValue("zzyzx")); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.setKeywordValue(String, String, String)' - */ - public void testSetKeywordValueStringStringString() { - String munged = ULocale.setKeywordValue(longULocaleName, "key", "C#"); - assertEquals("C#", ULocale.getKeywordValue(munged, "key")); - munged = ULocale.setKeywordValue(munged, "zzyzx", "grue"); - assertEquals("grue", ULocale.getKeywordValue(munged, "zzyzx")); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Language()' - */ - public void testGetISO3Language() { - String il = ULocale.GERMANY.getISO3Language(); - String jl = Locale.GERMANY.getISO3Language(); - assertEquals(il, jl); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Language(String)' - */ - public void testGetISO3LanguageString() { - String il = ULocale.getISO3Language(ULocale.GERMANY.getName()); - String jl = Locale.GERMANY.getISO3Language(); - assertEquals(il, jl); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Country()' - */ - public void testGetISO3Country() { - String ic = ULocale.GERMANY.getISO3Country(); - String jc = Locale.GERMANY.getISO3Country(); - assertEquals(ic, jc); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getISO3Country(String)' - */ - public void testGetISO3CountryString() { - String ic = ULocale.getISO3Country(ULocale.GERMANY.getName()); - String jc = Locale.GERMANY.getISO3Country(); - assertEquals(ic, jc); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage()' - */ - public void testGetDisplayLanguage() { - String idl = ULocale.GERMANY.getDisplayLanguage(); - String jdl = Locale.GERMANY.getDisplayLanguage(); - assertEquals(idl, jdl); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(ULocale)' - */ - public void testGetDisplayLanguageULocale() { - String idl = ULocale.GERMANY.getDisplayLanguage(ULocale.GERMANY); - String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY); - assertEquals(idl, jdl); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(String, String)' - */ - public void testGetDisplayLanguageStringString() { - String idl = ULocale.getDisplayLanguage(ULocale.GERMANY.getName(), "de_DE"); - String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY); - assertEquals(idl, jdl); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayLanguage(String, ULocale)' - */ - public void testGetDisplayLanguageStringULocale() { - String idl = ULocale.getDisplayLanguage(ULocale.GERMANY.getName(), ULocale.GERMANY); - String jdl = Locale.GERMANY.getDisplayLanguage(Locale.GERMANY); - assertEquals(idl, jdl); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript()' - */ - public void testGetDisplayScript() { - String is = ULocale.TRADITIONAL_CHINESE.getDisplayScript(); - if (ICUTestCase.testingWrapper) { - assertEquals("Hant", is); - } else { - assertEquals("Traditional Chinese", is); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(ULocale)' - */ - public void testGetDisplayScriptULocale() { - String is = ULocale.TRADITIONAL_CHINESE.getDisplayScript(ULocale.GERMANY); - if (ICUTestCase.testingWrapper) { - assertEquals("Hant", is); - } else { - // TODO: look up expected value - assertEquals("Hant", is); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(String, String)' - */ - public void testGetDisplayScriptStringString() { - String is = ULocale.getDisplayScript("zh_Hant", "de_DE"); - if (ICUTestCase.testingWrapper) { - assertEquals("Hant", is); - } else { - // TODO: look up expected value - assertEquals("Hant", is); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayScript(String, ULocale)' - */ - public void testGetDisplayScriptStringULocale() { - String is = ULocale.getDisplayScript("zh_Hant", ULocale.GERMANY); - if (ICUTestCase.testingWrapper) { - assertEquals("Hant", is); - } else { - // TODO: look up expected value - assertEquals("Hant", is); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry()' - */ - public void testGetDisplayCountry() { - String idc = ULocale.GERMANY.getDisplayCountry(); - String jdc = Locale.GERMANY.getDisplayCountry(); - assertEquals(idc, jdc); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(ULocale)' - */ - public void testGetDisplayCountryULocale() { - String idc = ULocale.GERMANY.getDisplayCountry(ULocale.GERMANY); - String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY); - assertEquals(idc, jdc); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(String, String)' - */ - public void testGetDisplayCountryStringString() { - String idc = ULocale.getDisplayCountry("de_DE", "de_DE"); - String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY); - assertEquals(idc, jdc); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayCountry(String, ULocale)' - */ - public void testGetDisplayCountryStringULocale() { - String idc = ULocale.getDisplayCountry("de_DE", ULocale.GERMANY); - String jdc = Locale.GERMANY.getDisplayCountry(Locale.GERMANY); - assertEquals(idc, jdc); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant()' - */ - public void testGetDisplayVariant() { - String idv = new ULocale("de_DE_PHONEBOOK").getDisplayVariant(); - String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(); - assertEquals(jdv, idv); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(ULocale)' - */ - public void testGetDisplayVariantULocale() { - String idv = new ULocale("de_DE_PHONEBOOK").getDisplayVariant(ULocale.GERMANY); - String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY); - assertEquals(jdv, idv); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(String, String)' - */ - public void testGetDisplayVariantStringString() { - String idv = ULocale.getDisplayVariant("de_DE_PHONEBOOK", "de_DE"); - String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY); - assertEquals(jdv, idv); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayVariant(String, ULocale)' - */ - public void testGetDisplayVariantStringULocale() { - String idv = ULocale.getDisplayVariant("de_DE_PHONEBOOK", ULocale.GERMANY); - String jdv = new Locale("de", "DE", "PHONEBOOK").getDisplayVariant(Locale.GERMANY); - assertEquals(jdv, idv); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String)' - */ - public void testGetDisplayKeywordString() { - String idk = ULocale.getDisplayKeyword("collation"); - assertEquals("collation", idk); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String, String)' - */ - public void testGetDisplayKeywordStringString() { - String idk = ULocale.getDisplayKeyword("collation", "de_DE"); - if (ICUTestCase.testingWrapper) { - assertEquals("collation", idk); - } else { - // TODO: find real value - assertEquals("collation", idk); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeyword(String, ULocale)' - */ - public void testGetDisplayKeywordStringULocale() { - String idk = ULocale.getDisplayKeyword("collation", ULocale.GERMANY); - if (ICUTestCase.testingWrapper) { - assertEquals("collation", idk); - } else { - // TODO: find real value - assertEquals("collation", idk); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String)' - */ - public void testGetDisplayKeywordValueString() { - ULocale ul = new ULocale("de_DE@collation=phonebook"); - String idk = ul.getDisplayKeywordValue("collation"); - if (ICUTestCase.testingWrapper) { - assertEquals("phonebook", idk); - } else { - // TODO: find real value - assertEquals("phonebook", idk); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, ULocale)' - */ - public void testGetDisplayKeywordValueStringULocale() { - ULocale ul = new ULocale("de_DE@collation=phonebook"); - String idk = ul.getDisplayKeywordValue("collation", ULocale.GERMANY); - if (ICUTestCase.testingWrapper) { - assertEquals("phonebook", idk); - } else { - // TODO: find real value - assertEquals("phonebook", idk); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, String, String)' - */ - public void testGetDisplayKeywordValueStringStringString() { - String idk = ULocale.getDisplayKeywordValue("de_DE@collation=phonebook", "collation", "de_DE"); - if (ICUTestCase.testingWrapper) { - assertEquals("phonebook", idk); - } else { - // TODO: find real value - assertEquals("phonebook", idk); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayKeywordValue(String, String, ULocale)' - */ - public void testGetDisplayKeywordValueStringStringULocale() { - String idk = ULocale.getDisplayKeywordValue("de_DE@collation=phonebook", "collation", ULocale.GERMANY); - if (ICUTestCase.testingWrapper) { - assertEquals("phonebook", idk); - } else { - // TODO: find real value - assertEquals("phonebook", idk); - } - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName()' - */ - public void testGetDisplayName() { - String idn = ULocale.GERMANY.getDisplayName(); - String jdn = Locale.GERMANY.getDisplayName(); - assertEquals(idn, jdn); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(ULocale)' - */ - public void testGetDisplayNameULocale() { - String idn = ULocale.GERMANY.getDisplayName(ULocale.GERMANY); - String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY); - assertEquals(idn, jdn); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(String, String)' - */ - public void testGetDisplayNameStringString() { - String idn = ULocale.getDisplayName("de_DE", "de_DE"); - String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY); - assertEquals(idn, jdn); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.getDisplayName(String, ULocale)' - */ - public void testGetDisplayNameStringULocale() { - String idn = ULocale.getDisplayName("de_DE", ULocale.GERMANY); - String jdn = Locale.GERMANY.getDisplayName(Locale.GERMANY); - assertEquals(idn, jdn); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(String, ULocale[], boolean[])' - */ - public void testAcceptLanguageStringULocaleArrayBooleanArray() { - boolean[] fallback = new boolean[1]; - ULocale[] locales = { - new ULocale("en_CA"), - new ULocale("es_US"), - }; - ULocale result = ULocale.acceptLanguage("en-US, en-GB, en-CA, es-US", locales, fallback); - assertEquals(new ULocale("en_CA"), result); - assertFalse(fallback[0]); - result = ULocale.acceptLanguage("en-US, en-GB, es-US-NEWMEXICO", locales, fallback); - assertEquals(new ULocale("es_US"), result); - assertTrue(fallback[0]); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(ULocale[], ULocale[], boolean[])' - */ - public void testAcceptLanguageULocaleArrayULocaleArrayBooleanArray() { - boolean[] fallback = new boolean[1]; - ULocale[] locales = { - new ULocale("en_CA"), - new ULocale("es_US"), - }; - ULocale[] accept_locales = { - new ULocale("en_US"), - new ULocale("en_GB"), - new ULocale("en_CA"), - new ULocale("es_US"), - }; - ULocale[] accept_locales2 = { - new ULocale("en_US"), - new ULocale("en_GB"), - new ULocale("es_US_NEWMEXICO"), - }; - ULocale result = ULocale.acceptLanguage(accept_locales, locales, fallback); - assertEquals(new ULocale("en_CA"), result); - assertFalse(fallback[0]); - result = ULocale.acceptLanguage(accept_locales2, locales, fallback); - assertEquals(new ULocale("es_US"), result); - assertTrue(fallback[0]); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(String, boolean[])' - */ - public void testAcceptLanguageStringBooleanArray() { - boolean[] fallback = new boolean[1]; - ULocale result = ULocale.acceptLanguage("en-CA, en-GB, es-US", fallback); - assertEquals(new ULocale("en_CA"), result); - assertFalse(fallback[0]); - result = ULocale.acceptLanguage("es-US-NEWMEXICO", fallback); - assertNotNull(result); // actual result depends on jdk - assertTrue(fallback[0]); - } - - /* - * Test method for 'com.ibm.icu.x.util.ULocale.acceptLanguage(ULocale[], boolean[])' - */ - public void testAcceptLanguageULocaleArrayBooleanArray() { - boolean[] fallback = new boolean[1]; - ULocale[] accept_locales = { - new ULocale("en_CA"), - new ULocale("en_GB"), - new ULocale("es_US"), - }; - ULocale[] accept_locales2 = { - new ULocale("es_US_NEWMEXICO"), - }; - ULocale result = ULocale.acceptLanguage(accept_locales, fallback); - assertEquals(new ULocale("en_CA"), result); - assertFalse(fallback[0]); - result = ULocale.acceptLanguage(accept_locales2, fallback); - assertNotNull(result); // actual result depends on jdk - assertTrue(fallback[0]); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.classpath b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.classpath deleted file mode 100644 index 751c8f2e504..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.project b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.project deleted file mode 100644 index 24d73b353ef..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - com.ibm.icu.base - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.core.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index c87a86d899b..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Dec 14 11:50:27 EST 2006 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.ui.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 96ae60969fe..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Dec 14 11:50:27 EST 2006 -eclipse.preferences.version=1 -internal.default.compliance=default diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/META-INF/MANIFEST.MF b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/META-INF/MANIFEST.MF deleted file mode 100644 index 2cc2322b9a9..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/META-INF/MANIFEST.MF +++ /dev/null @@ -1,13 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: com.ibm.icu.base; singleton:=true -Bundle-Version: @BUILD_VERSION@ -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Bundle-Copyright: @COPYRIGHT@ -Export-Package: com.ibm.icu.text;base=true;version="@IMPL_VERSION@", - com.ibm.icu.util;base=true;version="@IMPL_VERSION@" -Eclipse-LazyStart: true -Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, - J2SE-1.3 diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/build.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/build.properties deleted file mode 100644 index 8c108f29641..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/build.properties +++ /dev/null @@ -1,19 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -source.. = src/ -output.. = bin/ -src.includes = about.html,\ - about_files/ -bin.includes = .,\ - about.html,\ - about_files/,\ - plugin.properties,\ - META-INF/ diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/plugin.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/plugin.properties deleted file mode 100644 index b33400d7fb6..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = International Components for Unicode for Java (ICU4J) Replacement plug-in -providerName = IBM Corporation \ No newline at end of file diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/BreakIterator.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/BreakIterator.java deleted file mode 100644 index c95e217c867..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/BreakIterator.java +++ /dev/null @@ -1,661 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - -import java.text.CharacterIterator; -import java.text.StringCharacterIterator; -import java.util.Locale; - -import com.ibm.icu.util.ULocale; - -/** - * A class that locates boundaries in text. This class defines a protocol for - * objects that break up a piece of natural-language text according to a set - * of criteria. Instances or subclasses of BreakIterator can be provided, for - * example, to break a piece of text into words, sentences, or logical characters - * according to the conventions of some language or group of languages. - * - * We provide five built-in types of BreakIterator: - *
  • getTitleInstance() returns a BreakIterator that locates boundaries - * between title breaks. - *
  • getSentenceInstance() returns a BreakIterator that locates boundaries - * between sentences. This is useful for triple-click selection, for example. - *
  • getWordInstance() returns a BreakIterator that locates boundaries between - * words. This is useful for double-click selection or "find whole words" searches. - * This type of BreakIterator makes sure there is a boundary position at the - * beginning and end of each legal word. (Numbers count as words, too.) Whitespace - * and punctuation are kept separate from real words. - *
  • getLineInstance() returns a BreakIterator that locates positions where it is - * legal for a text editor to wrap lines. This is similar to word breaking, but - * not the same: punctuation and whitespace are generally kept with words (you don't - * want a line to start with whitespace, for example), and some special characters - * can force a position to be considered a line-break position or prevent a position - * from being a line-break position. - *
  • getCharacterInstance() returns a BreakIterator that locates boundaries between - * logical characters. Because of the structure of the Unicode encoding, a logical - * character may be stored internally as more than one Unicode code point. (A with an - * umlaut may be stored as an a followed by a separate combining umlaut character, - * for example, but the user still thinks of it as one character.) This iterator allows - * various processes (especially text editors) to treat as characters the units of text - * that a user would think of as characters, rather than the units of text that the - * computer sees as "characters".
- * - * BreakIterator's interface follows an "iterator" model (hence the name), meaning it - * has a concept of a "current position" and methods like first(), last(), next(), - * and previous() that update the current position. All BreakIterators uphold the - * following invariants: - *
  • The beginning and end of the text are always treated as boundary positions. - *
  • The current position of the iterator is always a boundary position (random- - * access methods move the iterator to the nearest boundary position before or - * after the specified position, not _to_ the specified position). - *
  • DONE is used as a flag to indicate when iteration has stopped. DONE is only - * returned when the current position is the end of the text and the user calls next(), - * or when the current position is the beginning of the text and the user calls - * previous(). - *
  • Break positions are numbered by the positions of the characters that follow - * them. Thus, under normal circumstances, the position before the first character - * is 0, the position after the first character is 1, and the position after the - * last character is 1 plus the length of the string. - *
  • The client can change the position of an iterator, or the text it analyzes, - * at will, but cannot change the behavior. If the user wants different behavior, he - * must instantiate a new iterator.
- * - * BreakIterator accesses the text it analyzes through a CharacterIterator, which makes - * it possible to use BreakIterator to analyze text in any text-storage vehicle that - * provides a CharacterIterator interface. - * - * NOTE: Some types of BreakIterator can take a long time to create, and - * instances of BreakIterator are not currently cached by the system. For - * optimal performance, keep instances of BreakIterator around as long as makes - * sense. For example, when word-wrapping a document, don't create and destroy a - * new BreakIterator for each line. Create one break iterator for the whole document - * (or whatever stretch of text you're wrapping) and use it to do the whole job of - * wrapping the text. - * - *

- * Examples:

- * Creating and using text boundaries - *

- *
- * public static void main(String args[]) {
- *      if (args.length == 1) {
- *          String stringToExamine = args[0];
- *          //print each word in order
- *          BreakIterator boundary = BreakIterator.getWordInstance();
- *          boundary.setText(stringToExamine);
- *          printEachForward(boundary, stringToExamine);
- *          //print each sentence in reverse order
- *          boundary = BreakIterator.getSentenceInstance(Locale.US);
- *          boundary.setText(stringToExamine);
- *          printEachBackward(boundary, stringToExamine);
- *          printFirst(boundary, stringToExamine);
- *          printLast(boundary, stringToExamine);
- *      }
- * }
- * 
- *
- * - * Print each element in order - *
- *
- * public static void printEachForward(BreakIterator boundary, String source) {
- *     int start = boundary.first();
- *     for (int end = boundary.next();
- *          end != BreakIterator.DONE;
- *          start = end, end = boundary.next()) {
- *          System.out.println(source.substring(start,end));
- *     }
- * }
- * 
- *
- * - * Print each element in reverse order - *
- *
- * public static void printEachBackward(BreakIterator boundary, String source) {
- *     int end = boundary.last();
- *     for (int start = boundary.previous();
- *          start != BreakIterator.DONE;
- *          end = start, start = boundary.previous()) {
- *         System.out.println(source.substring(start,end));
- *     }
- * }
- * 
- *
- * - * Print first element - *
- *
- * public static void printFirst(BreakIterator boundary, String source) {
- *     int start = boundary.first();
- *     int end = boundary.next();
- *     System.out.println(source.substring(start,end));
- * }
- * 
- *
- * - * Print last element - *
- *
- * public static void printLast(BreakIterator boundary, String source) {
- *     int end = boundary.last();
- *     int start = boundary.previous();
- *     System.out.println(source.substring(start,end));
- * }
- * 
- *
- * - * Print the element at a specified position - *
- *
- * public static void printAt(BreakIterator boundary, int pos, String source) {
- *     int end = boundary.following(pos);
- *     int start = boundary.previous();
- *     System.out.println(source.substring(start,end));
- * }
- * 
- *
- * - * Find the next word - *
- *
- * public static int nextWordStartAfter(int pos, String text) {
- *     BreakIterator wb = BreakIterator.getWordInstance();
- *     wb.setText(text);
- *     int last = wb.following(pos);
- *     int current = wb.next();
- *     while (current != BreakIterator.DONE) {
- *         for (int p = last; p < current; p++) {
- *             if (Character.isLetter(text.charAt(p))
- *                 return last;
- *         }
- *         last = current;
- *         current = wb.next();
- *     }
- *     return BreakIterator.DONE;
- * }
- * 
- * (The iterator returned by BreakIterator.getWordInstance() is unique in that - * the break positions it returns don't represent both the start and end of the - * thing being iterated over. That is, a sentence-break iterator returns breaks - * that each represent the end of one sentence and the beginning of the next. - * With the word-break iterator, the characters between two boundaries might be a - * word, or they might be the punctuation or whitespace between two words. The - * above code uses a simple heuristic to determine which boundary is the beginning - * of a word: If the characters between this boundary and the next boundary - * include at least one letter (this can be an alphabetical letter, a CJK ideograph, - * a Hangul syllable, a Kana character, etc.), then the text between this boundary - * and the next is a word; otherwise, it's the material between words.) - *
- * - * @see CharacterIterator - * @stable ICU 2.0 - * - */ -public abstract class BreakIterator implements Cloneable { - - protected BreakIterator() { - } - - /** - * Create a copy of this iterator - * @return A copy of this - */ - public Object clone() { - // this is here for subclass use. we must override it ourselves, though. - try { - return super.clone(); - } - catch (CloneNotSupportedException e) { - throw new InternalError(); - } - } - - /** - * DONE is returned by previous() and next() after all valid - * boundaries have been returned. - * @stable ICU 2.0 - */ - public static final int DONE = -1; - - /** - * Return the first boundary position. This is always the beginning - * index of the text this iterator iterates over. For example, if - * the iterator iterates over a whole string, this function will - * always return 0. This function also updates the iteration position - * to point to the beginning of the text. - * @return The character offset of the beginning of the stretch of text - * being broken. - * @stable ICU 2.0 - */ - public abstract int first(); - - /** - * Return the last boundary position. This is always the "past-the-end" - * index of the text this iterator iterates over. For example, if the - * iterator iterates over a whole string (call it "text"), this function - * will always return text.length(). This function also updated the - * iteration position to point to the end of the text. - * @return The character offset of the end of the stretch of text - * being broken. - * @stable ICU 2.0 - */ - public abstract int last(); - - /** - * Advances the specified number of steps forward in the text (a negative - * number, therefore, advances backwards). If this causes the iterator - * to advance off either end of the text, this function returns DONE; - * otherwise, this function returns the position of the appropriate - * boundary. Calling this function is equivalent to calling next() or - * previous() n times. - * @param n The number of boundaries to advance over (if positive, moves - * forward; if negative, moves backwards). - * @return The position of the boundary n boundaries from the current - * iteration position, or DONE if moving n boundaries causes the iterator - * to advance off either end of the text. - * @stable ICU 2.0 - */ - public abstract int next(int n); - - /** - * Advances the iterator forward one boundary. The current iteration - * position is updated to point to the next boundary position after the - * current position, and this is also the value that is returned. If - * the current position is equal to the value returned by last(), or to - * DONE, this function returns DONE and sets the current position to - * DONE. - * @return The position of the first boundary position following the - * iteration position. - * @stable ICU 2.0 - */ - public abstract int next(); - - /** - * Advances the iterator backward one boundary. The current iteration - * position is updated to point to the last boundary position before - * the current position, and this is also the value that is returned. If - * the current position is equal to the value returned by first(), or to - * DONE, this function returns DONE and sets the current position to - * DONE. - * @return The position of the last boundary position preceding the - * iteration position. - * @stable ICU 2.0 - */ - public abstract int previous(); - - /** - * Sets the iterator's current iteration position to be the first - * boundary position following the specified position. (Whether the - * specified position is itself a boundary position or not doesn't - * matter-- this function always moves the iteration position to the - * first boundary after the specified position.) If the specified - * position is the past-the-end position, returns DONE. - * @param offset The character position to start searching from. - * @return The position of the first boundary position following - * "offset" (whether or not "offset" itself is a boundary position), - * or DONE if "offset" is the past-the-end offset. - * @stable ICU 2.0 - */ - public abstract int following(int offset); - - /** - * Sets the iterator's current iteration position to be the last - * boundary position preceding the specified position. (Whether the - * specified position is itself a boundary position or not doesn't - * matter-- this function always moves the iteration position to the - * last boundary before the specified position.) If the specified - * position is the starting position, returns DONE. - * @param offset The character position to start searching from. - * @return The position of the last boundary position preceding - * "offset" (whether of not "offset" itself is a boundary position), - * or DONE if "offset" is the starting offset of the iterator. - * @stable ICU 2.0 - */ - public int preceding(int offset) { - int pos = following(offset); - while (pos >= offset && pos != DONE) { - pos = previous(); - } - return pos; - } - - /** - * Return true if the specfied position is a boundary position. If the - * function returns true, the current iteration position is set to the - * specified position; if the function returns false, the current - * iteration position is set as though following() had been called. - * @param offset the offset to check. - * @return True if "offset" is a boundary position. - * @stable ICU 2.0 - */ - public boolean isBoundary(int offset) { - return offset == 0 || following(offset - 1) == offset; - } - - /** - * Return the iterator's current position. - * @return The iterator's current position. - * @stable ICU 2.0 - */ - public abstract int current(); - - /** - * Returns a CharacterIterator over the text being analyzed. - * For at least some subclasses of BreakIterator, this is a reference - * to the actual iterator being used by the BreakIterator, - * and therefore, this function's return value should be treated as - * const. No guarantees are made about the current position - * of this iterator when it is returned. If you need to move that - * position to examine the text, clone this function's return value first. - * @return A CharacterIterator over the text being analyzed. - * @stable ICU 2.0 - */ - public abstract CharacterIterator getText(); - - /** - * Sets the iterator to analyze a new piece of text. The new - * piece of text is passed in as a String, and the current - * iteration position is reset to the beginning of the string. - * (The old text is dropped.) - * @param newText A String containing the text to analyze with - * this BreakIterator. - * @stable ICU 2.0 - */ - public void setText(String newText) { - setText(new StringCharacterIterator(newText)); - } - - /** - * Sets the iterator to analyze a new piece of text. The - * BreakIterator is passed a CharacterIterator through which - * it will access the text itself. The current iteration - * position is reset to the CharacterIterator's start index. - * (The old iterator is dropped.) - * @param newText A CharacterIterator referring to the text - * to analyze with this BreakIterator (the iterator's current - * position is ignored, but its other state is significant). - * @stable ICU 2.0 - */ - public abstract void setText(CharacterIterator newText); - - /** @stable ICU 2.4 */ - public static final int KIND_CHARACTER = 0; - /** @stable ICU 2.4 */ - public static final int KIND_WORD = 1; - /** @stable ICU 2.4 */ - public static final int KIND_LINE = 2; - /** @stable ICU 2.4 */ - public static final int KIND_SENTENCE = 3; - /** @stable ICU 2.4 */ - public static final int KIND_TITLE = 4; - - /** - * Returns a new instance of BreakIterator that locates word boundaries. - * This function assumes that the text being analyzed is in the default - * locale's language. - * @return An instance of BreakIterator that locates word boundaries. - * @stable ICU 2.0 - */ - public static BreakIterator getWordInstance() { - return getWordInstance(Locale.getDefault()); - } - - /** - * Returns a new instance of BreakIterator that locates word boundaries. - * @param where A locale specifying the language of the text to be - * analyzed. - * @return An instance of BreakIterator that locates word boundaries. - * @stable ICU 2.0 - */ - public static BreakIterator getWordInstance(Locale where) { - return getBreakInstance(where, KIND_WORD); - } - - /** - * Returns a new instance of BreakIterator that locates word boundaries. - * @param where A locale specifying the language of the text to be - * analyzed. - * @return An instance of BreakIterator that locates word boundaries. - * @stable ICU 3.4.3 - */ - public static BreakIterator getWordInstance(ULocale where) { - return getBreakInstance(where.toLocale(), KIND_WORD); - } - - /** - * Returns a new instance of BreakIterator that locates legal line- - * wrapping positions. This function assumes the text being broken - * is in the default locale's language. - * @return A new instance of BreakIterator that locates legal - * line-wrapping positions. - * @stable ICU 2.0 - */ - public static BreakIterator getLineInstance() { - return getLineInstance(Locale.getDefault()); - } - - /** - * Returns a new instance of BreakIterator that locates legal line- - * wrapping positions. - * @param where A Locale specifying the language of the text being broken. - * @return A new instance of BreakIterator that locates legal - * line-wrapping positions. - * @stable ICU 2.0 - */ - public static BreakIterator getLineInstance(Locale where) { - return getBreakInstance(where, KIND_LINE); - } - - /** - * Returns a new instance of BreakIterator that locates legal line- - * wrapping positions. - * @param where A Locale specifying the language of the text being broken. - * @return A new instance of BreakIterator that locates legal - * line-wrapping positions. - * @stable ICU 3.4.3 - */ - public static BreakIterator getLineInstance(ULocale where) { - return getBreakInstance(where.toLocale(), KIND_LINE); - } - - /** - * Returns a new instance of BreakIterator that locates logical-character - * boundaries. This function assumes that the text being analyzed is - * in the default locale's language. - * @return A new instance of BreakIterator that locates logical-character - * boundaries. - * @stable ICU 2.0 - */ - public static BreakIterator getCharacterInstance() { - return getCharacterInstance(Locale.getDefault()); - } - - /** - * Returns a new instance of BreakIterator that locates logical-character - * boundaries. - * @param where A Locale specifying the language of the text being analyzed. - * @return A new instance of BreakIterator that locates logical-character - * boundaries. - * @stable ICU 2.0 - */ - public static BreakIterator getCharacterInstance(Locale where) { - return getBreakInstance(where, KIND_CHARACTER); - } - - /** - * Returns a new instance of BreakIterator that locates logical-character - * boundaries. - * @param where A Locale specifying the language of the text being analyzed. - * @return A new instance of BreakIterator that locates logical-character - * boundaries. - * @stable ICU 3.2 - */ - public static BreakIterator getCharacterInstance(ULocale where) { - return getBreakInstance(where.toLocale(), KIND_CHARACTER); - } - - /** - * Returns a new instance of BreakIterator that locates sentence boundaries. - * This function assumes the text being analyzed is in the default locale's - * language. - * @return A new instance of BreakIterator that locates sentence boundaries. - * @stable ICU 2.0 - */ - public static BreakIterator getSentenceInstance() { - return getSentenceInstance(Locale.getDefault()); - } - - /** - * Returns a new instance of BreakIterator that locates sentence boundaries. - * @param where A Locale specifying the language of the text being analyzed. - * @return A new instance of BreakIterator that locates sentence boundaries. - * @stable ICU 2.0 - */ - public static BreakIterator getSentenceInstance(Locale where) { - return getBreakInstance(where, KIND_SENTENCE); - } - - /** - * Returns a new instance of BreakIterator that locates sentence boundaries. - * @param where A Locale specifying the language of the text being analyzed. - * @return A new instance of BreakIterator that locates sentence boundaries. - * @stable ICU 3.4.3 - */ - public static BreakIterator getSentenceInstance(ULocale where) { - return getBreakInstance(where.toLocale(), KIND_SENTENCE); - } - - private static BreakIterator getBreakInstance(Locale where, int kind) { - java.text.BreakIterator br = null; - switch(kind) { - case KIND_CHARACTER: br = java.text.BreakIterator.getCharacterInstance(where); break; - case KIND_WORD: br = java.text.BreakIterator.getWordInstance(where); break; - case KIND_LINE: br = java.text.BreakIterator.getLineInstance(where); break; - case KIND_SENTENCE: br = java.text.BreakIterator.getSentenceInstance(where); break; - case KIND_TITLE: throw new UnsupportedOperationException(); - } - return new BreakIteratorHandle(br); - } - - /** - * Returns a list of locales for which BreakIterators can be used. - * @return An array of Locales. All of the locales in the array can - * be used when creating a BreakIterator. - * @stable ICU 3.4.3 - */ - public static synchronized Locale[] getAvailableLocales() { - return java.text.BreakIterator.getAvailableLocales(); - } - - /** - * Returns a list of locales for which BreakIterators can be used. - * @return An array of ULocales. All of the locales in the array can - * be used when creating a BreakIterator. - * @stable ICU 3.4.3 - */ - public static synchronized ULocale[] getAvailableULocales() { - Locale[] locales = java.text.BreakIterator.getAvailableLocales(); - ULocale[] ulocales = new ULocale[locales.length]; - for (int i = 0; i < locales.length; ++i) { - ulocales[i] = ULocale.forLocale(locales[i]); - } - return ulocales; - } - - // forwarding implementation class - static final class BreakIteratorHandle extends BreakIterator { - /** - * @internal - */ - public final java.text.BreakIterator breakIterator; - - /** - * @internal - * @param delegate the BreakIterator to which to delegate - */ - public BreakIteratorHandle(java.text.BreakIterator delegate) { - this.breakIterator = delegate; - } - - public int first() { - return breakIterator.first(); - } - public int last() { - return breakIterator.last(); - } - public int next(int n) { - return breakIterator.next(n); - } - public int next() { - return breakIterator.next(); - } - public int previous() { - return breakIterator.previous(); - } - public int following(int offset) { - return breakIterator.following(offset); - } - public int preceding(int offset) { - return breakIterator.preceding(offset); - } - public boolean isBoundary(int offset) { - return breakIterator.isBoundary(offset); - } - public int current() { - return breakIterator.current(); - } - public CharacterIterator getText() { - return breakIterator.getText(); - } - public void setText(CharacterIterator newText) { - breakIterator.setText(newText); - } - - /** - * Return a string suitable for debugging. - * @return a string suitable for debugging - * @stable ICU 3.4.3 - */ - public String toString() { - return breakIterator.toString(); - } - - /** - * Return a clone of this BreakIterator. - * @return a clone of this BreakIterator - * @stable ICU 3.4.3 - */ - public Object clone() { - return new BreakIteratorHandle((java.text.BreakIterator)breakIterator.clone()); - } - - /** - * Return true if rhs is a BreakIterator with the same break behavior as this. - * @return true if rhs equals this - * @stable ICU 3.4.3 - */ - public boolean equals(Object rhs) { - try { - return breakIterator.equals(((BreakIteratorHandle)rhs).breakIterator); - } - catch (Exception e) { - return false; - } - } - - /** - * Return a hashCode. - * @return a hashCode - * @stable ICU 3.4.3 - */ - public int hashCode() { - return breakIterator.hashCode(); - } - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/CollationKey.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/CollationKey.java deleted file mode 100644 index fde7b4cede9..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/CollationKey.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - -/** - *

A CollationKey represents a String - * under the rules of a specific Collator - * object. Comparing two CollationKeys returns the - * relative order of the Strings they represent.

- * - *

Since the rule set of Collators can differ, the - * sort orders of the same string under two different - * Collators might differ. Hence comparing - * CollationKeys generated from different - * Collators can give incorrect results.

- - *

Both the method - * CollationKey.compareTo(CollationKey) and the method - * Collator.compare(String, String) compare two strings - * and returns their relative order. The performance characterictics - * of these two approaches can differ.

- * - *

During the construction of a CollationKey, the - * entire source string is examined and processed into a series of - * bits terminated by a null, that are stored in the CollationKey. - * When CollationKey.compareTo(CollationKey) executes, it - * performs bitwise comparison on the bit sequences. This can incurs - * startup cost when creating the CollationKey, but once - * the key is created, binary comparisons are fast. This approach is - * recommended when the same strings are to be compared over and over - * again.

- * - *

On the other hand, implementations of - * Collator.compare(String, String) can examine and - * process the strings only until the first characters differing in - * order. This approach is recommended if the strings are to be - * compared only once.

- * - *

More information about the composition of the bit sequence can - * be found in the - * - * user guide.

- * - *

The following example shows how CollationKeys can be used - * to sort a list of Strings.

- *
- *
- * // Create an array of CollationKeys for the Strings to be sorted.
- * Collator myCollator = Collator.getInstance();
- * CollationKey[] keys = new CollationKey[3];
- * keys[0] = myCollator.getCollationKey("Tom");
- * keys[1] = myCollator.getCollationKey("Dick");
- * keys[2] = myCollator.getCollationKey("Harry");
- * sort( keys );
- * 
- * //... - *
- * // Inside body of sort routine, compare keys this way - * if( keys[i].compareTo( keys[j] ) > 0 ) - * // swap keys[i] and keys[j] - *
- * //... - *
- * // Finally, when we've returned from sort. - * System.out.println( keys[0].getSourceString() ); - * System.out.println( keys[1].getSourceString() ); - * System.out.println( keys[2].getSourceString() ); - *
- *
- *

- *

- * This class is not subclassable - *

- * @see Collator - * @see RuleBasedCollator - * @stable ICU 2.8 - */ -public final class CollationKey implements Comparable { - /** - * @internal - */ - final java.text.CollationKey key; - - /** - * @internal - */ - CollationKey(java.text.CollationKey delegate) { - this.key = delegate; - } - - /** - * Return the source string that this CollationKey represents. - * @return source string that this CollationKey represents - * @stable ICU 2.8 - */ - public String getSourceString() { - return key.getSourceString(); - } - - /** - *

Duplicates and returns the value of this CollationKey as a sequence - * of big-endian bytes terminated by a null.

- * - *

If two CollationKeys can be legitimately compared, then one can - * compare the byte arrays of each to obtain the same result, e.g. - *

-     * byte key1[] = collationkey1.toByteArray();
-     * byte key2[] = collationkey2.toByteArray();
-     * int key, targetkey;
-     * int i = 0;
-     * do {
-     *       key = key1[i] & 0xFF;
-     *     targetkey = key2[i] & 0xFF;
-     *     if (key < targetkey) {
-     *         System.out.println("String 1 is less than string 2");
-     *         return;
-     *     }
-     *     if (targetkey < key) {
-     *         System.out.println("String 1 is more than string 2");
-     *     }
-     *     i ++;
-     * } while (key != 0 && targetKey != 0);
-     *
-     * System.out.println("Strings are equal.");
-     * 
- *

- * @return CollationKey value in a sequence of big-endian byte bytes - * terminated by a null. - * @stable ICU 2.8 - */ - public byte[] toByteArray() { - return key.toByteArray(); - } - - /** - *

Compare this CollationKey to another CollationKey. The - * collation rules of the Collator that created this key are - * applied.

- * - *

Note: Comparison between CollationKeys - * created by different Collators might return incorrect - * results. See class documentation.

- * - * @param target target CollationKey - * @return an integer value. If the value is less than zero this CollationKey - * is less than than target, if the value is zero they are equal, and - * if the value is greater than zero this CollationKey is greater - * than target. - * @exception NullPointerException is thrown if argument is null. - * @see Collator#compare(String, String) - * @stable ICU 2.8 - */ - public int compareTo(CollationKey target) { - return key.compareTo(target.key); - } - - /** - *

Compare this CollationKey with the specified Object. The - * collation rules of the Collator that created this key are - * applied.

- * - *

See note in compareTo(CollationKey) for warnings about possible - * incorrect results.

- * - * @param obj the Object to be compared to. - * @return Returns a negative integer, zero, or a positive integer - * respectively if this CollationKey is less than, equal to, or - * greater than the given Object. - * @exception ClassCastException is thrown when the argument is not - * a CollationKey. NullPointerException is thrown when the argument - * is null. - * @see #compareTo(CollationKey) - * @stable ICU 2.8 - */ - public int compareTo(Object o) { - return compareTo((CollationKey)o); - } - - /** - *

Compare this CollationKey and the specified Object for - * equality. The collation rules of the Collator that created - * this key are applied.

- * - *

See note in compareTo(CollationKey) for warnings about - * possible incorrect results.

- * - * @param target the object to compare to. - * @return true if the two keys compare as equal, false otherwise. - * @see #compareTo(CollationKey) - * @exception ClassCastException is thrown when the argument is not - * a CollationKey. NullPointerException is thrown when the argument - * is null. - * @stable ICU 2.8 - */ - public boolean equals(Object target) { - try { - return key.equals(((CollationKey)target).key); - } - catch (Exception e) { - return false; - } - } - - /** - *

- * Compare this CollationKey and the argument target CollationKey for - * equality. - * The collation - * rules of the Collator object which created these objects are applied. - *

- *

- * See note in compareTo(CollationKey) for warnings of incorrect results - *

- * @param target the CollationKey to compare to. - * @return true if two objects are equal, false otherwise. - * @exception NullPointerException is thrown when the argument is null. - * @stable ICU 2.8 - */ - public boolean equals(CollationKey target) { - return key.equals(target.key); - } - - /** - *

Returns a hash code for this CollationKey. The hash value is calculated - * on the key itself, not the String from which the key was created. Thus - * if x and y are CollationKeys, then x.hashCode(x) == y.hashCode() - * if x.equals(y) is true. This allows language-sensitive comparison in a - * hash table. - *

- * @return the hash value. - * @stable ICU 2.8 - */ - public int hashCode() { - return key.hashCode(); - } - - /** - * Return a description of the CollationKey. - * @return a description of the CollationKey, used for debugging - * @stable ICU 3.4.2 - */ - public String toString() { - return key.toString(); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/Collator.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/Collator.java deleted file mode 100644 index 38f680d01e9..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/Collator.java +++ /dev/null @@ -1,565 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - -import java.util.Comparator; -import java.util.Locale; - -import com.ibm.icu.util.ULocale; - -/** -*

Collator performs locale-sensitive string comparison.

-* -*

Following the Unicode -* Consortium's specifications for the -* Unicode Collation -* Algorithm (UCA), there are 5 different levels of strength used -* in comparisons: -* -*

    -*
  • PRIMARY strength: Typically, this is used to denote differences between -* base characters (for example, "a" < "b"). -* It is the strongest difference. For example, dictionaries are divided -* into different sections by base character. -*
  • SECONDARY strength: Accents in the characters are considered secondary -* differences (for example, "as" < "às" < "at"). Other -* differences -* between letters can also be considered secondary differences, depending -* on the language. A secondary difference is ignored when there is a -* primary difference anywhere in the strings. -*
  • TERTIARY strength: Upper and lower case differences in characters are -* distinguished at tertiary strength (for example, "ao" < "Ao" < -* "aò"). In addition, a variant of a letter differs from the base -* form on the tertiary strength (such as "A" and "Ⓐ"). Another -* example is the -* difference between large and small Kana. A tertiary difference is ignored -* when there is a primary or secondary difference anywhere in the strings. -*
  • QUATERNARY strength: When punctuation is ignored -* -* (see Ignoring Punctuations in the user guide) at PRIMARY to TERTIARY -* strength, an additional strength level can -* be used to distinguish words with and without punctuation (for example, -* "ab" < "a-b" < "aB"). -* This difference is ignored when there is a PRIMARY, SECONDARY or TERTIARY -* difference. The QUATERNARY strength should only be used if ignoring -* punctuation is required. -*
  • IDENTICAL strength: -* When all other strengths are equal, the IDENTICAL strength is used as a -* tiebreaker. The Unicode code point values of the NFD form of each string -* are compared, just in case there is no difference. -* For example, Hebrew cantellation marks are only distinguished at this -* strength. This strength should be used sparingly, as only code point -* value differences between two strings is an extremely rare occurrence. -* Using this strength substantially decreases the performance for both -* comparison and collation key generation APIs. This strength also -* increases the size of the collation key. -*
-* -* Unlike the JDK, ICU4J's Collator deals only with 2 decomposition modes, -* the canonical decomposition mode and one that does not use any decomposition. -* The compatibility decomposition mode, java.text.Collator.FULL_DECOMPOSITION -* is not supported here. If the canonical -* decomposition mode is set, the Collator handles un-normalized text properly, -* producing the same results as if the text were normalized in NFD. If -* canonical decomposition is turned off, it is the user's responsibility to -* ensure that all text is already in the appropriate form before performing -* a comparison or before getting a CollationKey.

-* -*

For more information about the collation service see the -* users -* guide.

-* -*

Examples of use -*

-* // Get the Collator for US English and set its strength to PRIMARY
-* Collator usCollator = Collator.getInstance(Locale.US);
-* usCollator.setStrength(Collator.PRIMARY);
-* if (usCollator.compare("abc", "ABC") == 0) {
-*     System.out.println("Strings are equivalent");
-* }
-*
-* The following example shows how to compare two strings using the
-* Collator for the default locale.
-*
-* // Compare two strings in the default locale
-* Collator myCollator = Collator.getInstance();
-* myCollator.setDecomposition(NO_DECOMPOSITION);
-* if (myCollator.compare("à\u0325", "a\u0325̀") != 0) {
-*     System.out.println("à\u0325 is not equals to a\u0325̀ without decomposition");
-*     myCollator.setDecomposition(CANONICAL_DECOMPOSITION);
-*     if (myCollator.compare("à\u0325", "a\u0325̀") != 0) {
-*         System.out.println("Error: à\u0325 should be equals to a\u0325̀ with decomposition");
-*     }
-*     else {
-*         System.out.println("à\u0325 is equals to a\u0325̀ with decomposition");
-*     }
-* }
-* else {
-*     System.out.println("Error: à\u0325 should be not equals to a\u0325̀ without decomposition");
-* }
-* 
-*

-* @see CollationKey -* @author Syn Wee Quek -* @stable ICU 2.8 -*/ -public class Collator implements Comparator, Cloneable -{ - /** - * @internal - */ - private final java.text.Collator collator; - - /** - * @internal - */ - private Collator(java.text.Collator delegate) { - this.collator = delegate; - } - - /** - * Create a collator with a null delegate. - * For use by possible subclassers. This is present since - * the original Collator is abstract, and so, in theory - * subclassable. All member APIs must be overridden. - */ - protected Collator() { - this.collator = null; - } - - // public data members --------------------------------------------------- - - /** - * Strongest collator strength value. Typically used to denote differences - * between base characters. See class documentation for more explanation. - * @see #setStrength - * @see #getStrength - * @stable ICU 2.8 - */ - public final static int PRIMARY = java.text.Collator.PRIMARY; - - /** - * Second level collator strength value. - * Accents in the characters are considered secondary differences. - * Other differences between letters can also be considered secondary - * differences, depending on the language. - * See class documentation for more explanation. - * @see #setStrength - * @see #getStrength - * @stable ICU 2.8 - */ - public final static int SECONDARY = java.text.Collator.SECONDARY; - - /** - * Third level collator strength value. - * Upper and lower case differences in characters are distinguished at this - * strength level. In addition, a variant of a letter differs from the base - * form on the tertiary level. - * See class documentation for more explanation. - * @see #setStrength - * @see #getStrength - * @stable ICU 2.8 - */ - public final static int TERTIARY = java.text.Collator.TERTIARY; - - /** - * Fourth level collator strength value. - * When punctuation is ignored - * - * (see Ignoring Punctuations in the user guide) at PRIMARY to TERTIARY - * strength, an additional strength level can - * be used to distinguish words with and without punctuation. - * See class documentation for more explanation. - * @see #setStrength - * @see #getStrength - * @stable ICU 2.8 - */ - public final static int QUATERNARY = java.text.Collator.IDENTICAL; - - /** - *

- * Smallest Collator strength value. When all other strengths are equal, - * the IDENTICAL strength is used as a tiebreaker. The Unicode code point - * values of the NFD form of each string are compared, just in case there - * is no difference. - * See class documentation for more explanation. - *

- *

- * Note this value is different from JDK's - *

- * @stable ICU 2.8 - */ - public final static int IDENTICAL = java.text.Collator.FULL_DECOMPOSITION; - - /** - * This is for backwards compatibility with Java APIs only. It - * should not be used, IDENTICAL should be used instead. ICU's - * collation does not support Java's FULL_DECOMPOSITION mode. - * @stable ICU 3.4 - * @deprecated Backwards compatibility with Java only. - */ - public final static int FULL_DECOMPOSITION = java.text.Collator.FULL_DECOMPOSITION; - - /** - *

Decomposition mode value. With NO_DECOMPOSITION set, Strings - * will not be decomposed for collation. This is the default - * decomposition setting unless otherwise specified by the locale - * used to create the Collator.

- * - *

Note this value is different from the JDK's.

- * @see #CANONICAL_DECOMPOSITION - * @see #getDecomposition - * @see #setDecomposition - * @stable ICU 2.8 - */ - public final static int NO_DECOMPOSITION = java.text.Collator.NO_DECOMPOSITION; - - /** - *

Decomposition mode value. With CANONICAL_DECOMPOSITION set, - * characters that are canonical variants according to the Unicode standard - * will be decomposed for collation.

- * - *

CANONICAL_DECOMPOSITION corresponds to Normalization Form D as - * described in - * Unicode Technical Report #15. - *

- * @see #NO_DECOMPOSITION - * @see #getDecomposition - * @see #setDecomposition - * @stable ICU 2.8 - */ - public final static int CANONICAL_DECOMPOSITION = java.text.Collator.CANONICAL_DECOMPOSITION; - - // public methods -------------------------------------------------------- - - // public setters -------------------------------------------------------- - - /** - *

Sets this Collator's strength property. The strength property - * determines the minimum level of difference considered significant - * during comparison.

- * - *

The default strength for the Collator is TERTIARY, unless specified - * otherwise by the locale used to create the Collator.

- * - *

See the Collator class description for an example of use.

- * @param newStrength the new strength value. - * @see #getStrength - * @see #PRIMARY - * @see #SECONDARY - * @see #TERTIARY - * @see #QUATERNARY - * @see #IDENTICAL - * @exception IllegalArgumentException if the new strength value is not one - * of PRIMARY, SECONDARY, TERTIARY, QUATERNARY or IDENTICAL. - * @stable ICU 2.8 - */ - public void setStrength(int newStrength) { - collator.setStrength(newStrength); - } - - /** - *

Set the decomposition mode of this Collator. Setting this - * decomposition property with CANONICAL_DECOMPOSITION allows the - * Collator to handle un-normalized text properly, producing the - * same results as if the text were normalized. If - * NO_DECOMPOSITION is set, it is the user's responsibility to - * insure that all text is already in the appropriate form before - * a comparison or before getting a CollationKey. Adjusting - * decomposition mode allows the user to select between faster and - * more complete collation behavior.

- * - *

Since a great many of the world's languages do not require - * text normalization, most locales set NO_DECOMPOSITION as the - * default decomposition mode.

- * - * The default decompositon mode for the Collator is - * NO_DECOMPOSITON, unless specified otherwise by the locale used - * to create the Collator.

- * - *

See getDecomposition for a description of decomposition - * mode.

- * - * @param decomposition the new decomposition mode - * @see #getDecomposition - * @see #NO_DECOMPOSITION - * @see #CANONICAL_DECOMPOSITION - * @exception IllegalArgumentException If the given value is not a valid - * decomposition mode. - * @stable ICU 2.8 - */ - public void setDecomposition(int decomposition) { - collator.setDecomposition(decomposition); - } - - // public getters -------------------------------------------------------- - - /** - * Gets the Collator for the current default locale. - * The default locale is determined by java.util.Locale.getDefault(). - * @return the Collator for the default locale (for example, en_US) if it - * is created successfully. Otherwise if there is no Collator - * associated with the current locale, the default UCA collator - * will be returned. - * @see java.util.Locale#getDefault() - * @see #getInstance(Locale) - * @stable ICU 2.8 - */ - public static final Collator getInstance() { - return new Collator(java.text.Collator.getInstance()); - } - - /** - * Gets the Collator for the desired locale. - * @param locale the desired locale. - * @return Collator for the desired locale if it is created successfully. - * Otherwise if there is no Collator - * associated with the current locale, a default UCA collator will - * be returned. - * @see java.util.Locale - * @see java.util.ResourceBundle - * @see #getInstance(Locale) - * @see #getInstance() - * @stable ICU 3.4.3 - */ - public static final Collator getInstance(ULocale locale) { - return getInstance(locale.toLocale()); - } - - /** - * Gets the Collator for the desired locale. - * @param locale the desired locale. - * @return Collator for the desired locale if it is created successfully. - * Otherwise if there is no Collator - * associated with the current locale, a default UCA collator will - * be returned. - * @see java.util.Locale - * @see java.util.ResourceBundle - * @see #getInstance(ULocale) - * @see #getInstance() - * @stable ICU 2.8 - */ - public static final Collator getInstance(Locale locale) { - return new Collator(java.text.Collator.getInstance(locale)); - } - - /** - * Get the set of locales, as Locale objects, for which collators - * are installed. Note that Locale objects do not support RFC 3066. - * @return the list of locales in which collators are installed. - * This list includes any that have been registered, in addition to - * those that are installed with ICU4J. - * @stable ICU 2.4 - */ - public static Locale[] getAvailableLocales() { - return java.text.Collator.getAvailableLocales(); - } - - /** - * Get the set of locales, as ULocale objects, for which collators - * are installed. ULocale objects support RFC 3066. - * @return the list of locales in which collators are installed. - * This list includes any that have been registered, in addition to - * those that are installed with ICU4J. - * @stable ICU 3.4.3 - */ - public static final ULocale[] getAvailableULocales() { - Locale[] locales = java.text.Collator.getAvailableLocales(); - ULocale[] ulocales = new ULocale[locales.length]; - for (int i = 0; i < locales.length; ++i) { - ulocales[i] = ULocale.forLocale(locales[i]); - } - return ulocales; - } - - /** - * Return an array of all possible keywords that are relevant to - * collation. At this point, the only recognized keyword for this - * service is "collation". - * @return an array of valid collation keywords. - * @see #getKeywordValues - * @stable ICU 3.0 - */ - public static final String[] getKeywords() { - return new String[0]; - } - - /** - * Given a keyword, return an array of all values for - * that keyword that are currently in use. - * @param keyword one of the keywords returned by getKeywords. - * @see #getKeywords - * @stable ICU 3.0 - */ - public static final String[] getKeywordValues(String keyword) { - return new String[0]; - } - - /** - *

Returns this Collator's strength property. The strength property - * determines the minimum level of difference considered significant. - *

- *

- * See the Collator class description for more details. - *

- * @return this Collator's current strength property. - * @see #setStrength - * @see #PRIMARY - * @see #SECONDARY - * @see #TERTIARY - * @see #QUATERNARY - * @see #IDENTICAL - * @stable ICU 2.8 - */ - public int getStrength() { - return collator.getStrength(); - } - - /** - *

- * Get the decomposition mode of this Collator. Decomposition mode - * determines how Unicode composed characters are handled. - *

- *

- * See the Collator class description for more details. - *

- * @return the decomposition mode - * @see #setDecomposition - * @see #NO_DECOMPOSITION - * @see #CANONICAL_DECOMPOSITION - * @stable ICU 2.8 - */ - public int getDecomposition() { - return collator.getDecomposition(); - } - - /** - *

- * Compares the source text String to the target text String according to - * this Collator's rules, strength and decomposition mode. - * Returns an integer less than, - * equal to or greater than zero depending on whether the source String is - * less than, equal to or greater than the target String. See the Collator - * class description for an example of use. - *

- * @param source the source String. - * @param target the target String. - * @return Returns an integer value. Value is less than zero if source is - * less than target, value is zero if source and target are equal, - * value is greater than zero if source is greater than target. - * @see CollationKey - * @see #getCollationKey - * @exception NullPointerException thrown if either arguments is null. - * IllegalArgumentException thrown if either source or target is - * not of the class String. - * @stable ICU 2.8 - */ - public int compare(Object source, Object target) { - return collator.compare(source, target); - } - - // public other methods ------------------------------------------------- - - /** - * Convenience method for comparing the equality of two text Strings using - * this Collator's rules, strength and decomposition mode. - * @param source the source string to be compared. - * @param target the target string to be compared. - * @return true if the strings are equal according to the collation - * rules, otherwise false. - * @see #compare - * @exception NullPointerException thrown if either arguments is null. - * @stable ICU 2.8 - */ - public boolean equals(String source, String target) { - return (compare(source, target) == 0); - } - - /** - *

- * Compares the source text String to the target text String according to - * this Collator's rules, strength and decomposition mode. - * Returns an integer less than, - * equal to or greater than zero depending on whether the source String is - * less than, equal to or greater than the target String. See the Collator - * class description for an example of use. - *

- * @param source the source String. - * @param target the target String. - * @return Returns an integer value. Value is less than zero if source is - * less than target, value is zero if source and target are equal, - * value is greater than zero if source is greater than target. - * @see CollationKey - * @see #getCollationKey - * @exception NullPointerException thrown if either arguments is null. - * @stable ICU 2.8 - */ - public int compare(String source, String target) { - return collator.compare(source, target); - } - - /** - *

- * Transforms the String into a CollationKey suitable for efficient - * repeated comparison. The resulting key depends on the collator's - * rules, strength and decomposition mode. - *

- *

See the CollationKey class documentation for more information.

- * @param source the string to be transformed into a CollationKey. - * @return the CollationKey for the given String based on this Collator's - * collation rules. If the source String is null, a null - * CollationKey is returned. - * @see CollationKey - * @see #compare(String, String) - * @stable ICU 2.8 - */ - public CollationKey getCollationKey(String source) { - return new CollationKey(collator.getCollationKey(source)); - } - - /** - * Return a string suitable for debugging. - * @return a string suitable for debugging - * @stable ICU 3.4.3 - */ - public String toString() { - return collator.toString(); - } - - /** - * Clone the collator. - * @return a clone of this collator. - * @stable ICU 2.6 - */ - public Object clone() throws CloneNotSupportedException { - return new Collator((java.text.Collator)collator.clone()); - } - - /** - * Return true if rhs is a Collator and compares the same as this. - * @return true if rhs equals this - * @stable ICU 3.4.3 - */ - public boolean equals(Object rhs) { - try { - return collator.equals(((Collator)rhs).collator); - } - catch (Exception e) { - return false; - } - } - - /** - * Return a hashCode. - * @return a hashCode - * @stable ICU 3.4.3 - */ - public int hashCode() { - return collator.hashCode(); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormat.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormat.java deleted file mode 100644 index dce51f10950..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormat.java +++ /dev/null @@ -1,983 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - -import java.text.FieldPosition; -import java.text.Format; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.TimeZone; -import com.ibm.icu.util.ULocale; - -/** - * DateFormat is an abstract class for date/time formatting subclasses which - * formats and parses dates or time in a language-independent manner. - * The date/time formatting subclass, such as SimpleDateFormat, allows for - * formatting (i.e., date -> text), parsing (text -> date), and - * normalization. The date is represented as a Date object or - * as the milliseconds since January 1, 1970, 00:00:00 GMT. - * - *

DateFormat provides many class methods for obtaining default date/time - * formatters based on the default or a given loacle and a number of formatting - * styles. The formatting styles include FULL, LONG, MEDIUM, and SHORT. More - * detail and examples of using these styles are provided in the method - * descriptions. - * - *

DateFormat helps you to format and parse dates for any locale. - * Your code can be completely independent of the locale conventions for - * months, days of the week, or even the calendar format: lunar vs. solar. - * - *

To format a date for the current Locale, use one of the - * static factory methods: - *

- *  myString = DateFormat.getDateInstance().format(myDate);
- * 
- *

If you are formatting multiple numbers, it is - * more efficient to get the format and use it multiple times so that - * the system doesn't have to fetch the information about the local - * language and country conventions multiple times. - *

- *  DateFormat df = DateFormat.getDateInstance();
- *  for (int i = 0; i < a.length; ++i) {
- *    output.println(df.format(myDate[i]) + "; ");
- *  }
- * 
- *

To format a number for a different Locale, specify it in the - * call to getDateInstance(). - *

- *  DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
- * 
- *

You can use a DateFormat to parse also. - *

- *  myDate = df.parse(myString);
- * 
- *

Use getDateInstance to get the normal date format for that country. - * There are other static factory methods available. - * Use getTimeInstance to get the time format for that country. - * Use getDateTimeInstance to get a date and time format. You can pass in - * different options to these factory methods to control the length of the - * result; from SHORT to MEDIUM to LONG to FULL. The exact result depends - * on the locale, but generally: - *

  • SHORT is completely numeric, such as 12.13.52 or 3:30pm - *
  • MEDIUM is longer, such as Jan 12, 1952 - *
  • LONG is longer, such as January 12, 1952 or 3:30:32pm - *
  • FULL is pretty completely specified, such as - * Tuesday, April 12, 1952 AD or 3:30:42pm PST. - *
- * - *

You can also set the time zone on the format if you wish. - * If you want even more control over the format or parsing, - * (or want to give your users more control), - * you can try casting the DateFormat you get from the factory methods - * to a SimpleDateFormat. This will work for the majority - * of countries; just remember to put it in a try block in case you - * encounter an unusual one. - * - *

You can also use forms of the parse and format methods with - * ParsePosition and FieldPosition to - * allow you to - *

  • progressively parse through pieces of a string. - *
  • align any particular field, or find out where it is for selection - * on the screen. - *
- * - *

Synchronization

- * - * Date formats are not synchronized. It is recommended to create separate - * format instances for each thread. If multiple threads access a format - * concurrently, it must be synchronized externally. - * - * @see UFormat - * @see NumberFormat - * @see SimpleDateFormat - * @see com.ibm.icu.util.Calendar - * @see com.ibm.icu.util.GregorianCalendar - * @see com.ibm.icu.util.TimeZone - * @author Mark Davis, Chen-Lieh Huang, Alan Liu - * @stable ICU 2.0 - */ -public class DateFormat extends Format { - private static final long serialVersionUID = 1; - - /** - * @internal - */ - public final java.text.DateFormat dateFormat; - - /** - * @internal - * @param delegate the DateFormat to which to delegate - */ - public DateFormat(java.text.DateFormat delegate) { - this.dateFormat = delegate; - } - - /** - * For subclass use. Subclasses will generally not - * work correctly unless they manipulate the delegate. - */ - protected DateFormat() { - this.dateFormat = java.text.DateFormat.getInstance(); - } - - /** - * FieldPosition selector for 'G' field alignment, - * corresponding to the {@link Calendar#ERA} field. - * @stable ICU 2.0 - */ - public final static int ERA_FIELD = 0; - - /** - * FieldPosition selector for 'y' field alignment, - * corresponding to the {@link Calendar#YEAR} field. - * @stable ICU 2.0 - */ - public final static int YEAR_FIELD = 1; - - /** - * FieldPosition selector for 'M' field alignment, - * corresponding to the {@link Calendar#MONTH} field. - * @stable ICU 2.0 - */ - public final static int MONTH_FIELD = 2; - - /** - * FieldPosition selector for 'd' field alignment, - * corresponding to the {@link Calendar#DATE} field. - * @stable ICU 2.0 - */ - public final static int DATE_FIELD = 3; - - /** - * FieldPosition selector for 'k' field alignment, - * corresponding to the {@link Calendar#HOUR_OF_DAY} field. - * HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock. - * For example, 23:59 + 01:00 results in 24:59. - * @stable ICU 2.0 - */ - public final static int HOUR_OF_DAY1_FIELD = 4; - - /** - * FieldPosition selector for 'H' field alignment, - * corresponding to the {@link Calendar#HOUR_OF_DAY} field. - * HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock. - * For example, 23:59 + 01:00 results in 00:59. - * @stable ICU 2.0 - */ - public final static int HOUR_OF_DAY0_FIELD = 5; - - /** - * FieldPosition selector for 'm' field alignment, - * corresponding to the {@link Calendar#MINUTE} field. - * @stable ICU 2.0 - */ - public final static int MINUTE_FIELD = 6; - - /** - * FieldPosition selector for 's' field alignment, - * corresponding to the {@link Calendar#SECOND} field. - * @stable ICU 2.0 - */ - public final static int SECOND_FIELD = 7; - - /** - * FieldPosition selector for 'S' field alignment, - * corresponding to the {@link Calendar#MILLISECOND} field. - * @stable ICU 3.0 - */ - public final static int FRACTIONAL_SECOND_FIELD = 8; - - /** - * Alias for FRACTIONAL_SECOND_FIELD. - * @stable ICU 3.4.3 - */ - public final static int MILLISECOND_FIELD = FRACTIONAL_SECOND_FIELD; - - /** - * FieldPosition selector for 'E' field alignment, - * corresponding to the {@link Calendar#DAY_OF_WEEK} field. - * @stable ICU 2.0 - */ - public final static int DAY_OF_WEEK_FIELD = 9; - - /** - * FieldPosition selector for 'D' field alignment, - * corresponding to the {@link Calendar#DAY_OF_YEAR} field. - * @stable ICU 2.0 - */ - public final static int DAY_OF_YEAR_FIELD = 10; - - /** - * FieldPosition selector for 'F' field alignment, - * corresponding to the {@link Calendar#DAY_OF_WEEK_IN_MONTH} field. - * @stable ICU 2.0 - */ - public final static int DAY_OF_WEEK_IN_MONTH_FIELD = 11; - - /** - * FieldPosition selector for 'w' field alignment, - * corresponding to the {@link Calendar#WEEK_OF_YEAR} field. - * @stable ICU 2.0 - */ - public final static int WEEK_OF_YEAR_FIELD = 12; - - /** - * FieldPosition selector for 'W' field alignment, - * corresponding to the {@link Calendar#WEEK_OF_MONTH} field. - * @stable ICU 2.0 - */ - public final static int WEEK_OF_MONTH_FIELD = 13; - - /** - * FieldPosition selector for 'a' field alignment, - * corresponding to the {@link Calendar#AM_PM} field. - * @stable ICU 2.0 - */ - public final static int AM_PM_FIELD = 14; - - /** - * FieldPosition selector for 'h' field alignment, - * corresponding to the {@link Calendar#HOUR} field. - * HOUR1_FIELD is used for the one-based 12-hour clock. - * For example, 11:30 PM + 1 hour results in 12:30 AM. - * @stable ICU 2.0 - */ - public final static int HOUR1_FIELD = 15; - - /** - * FieldPosition selector for 'K' field alignment, - * corresponding to the {@link Calendar#HOUR} field. - * HOUR0_FIELD is used for the zero-based 12-hour clock. - * For example, 11:30 PM + 1 hour results in 00:30 AM. - * @stable ICU 2.0 - */ - public final static int HOUR0_FIELD = 16; - - /** - * FieldPosition selector for 'z' field alignment, - * corresponding to the {@link Calendar#ZONE_OFFSET} and - * {@link Calendar#DST_OFFSET} fields. - * @stable ICU 2.0 - */ - public final static int TIMEZONE_FIELD = 17; - - /** - * Overrides Format. - * Formats a time object into a time string. Examples of time objects - * are a time value expressed in milliseconds and a Date object. - * @param obj must be a Number or a Date or a Calendar. - * @param toAppendTo the string buffer for the returning time string. - * @return the formatted time string. - * @param fieldPosition keeps track of the position of the field - * within the returned string. - * On input: an alignment field, - * if desired. On output: the offsets of the alignment field. For - * example, given a time text "1996.07.10 AD at 15:08:56 PDT", - * if the given fieldPosition is DateFormat.YEAR_FIELD, the - * begin index and end index of fieldPosition will be set to - * 0 and 4, respectively. - * Notice that if the same time field appears - * more than once in a pattern, the fieldPosition will be set for the first - * occurence of that time field. For instance, formatting a Date to - * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern - * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, - * the begin index and end index of fieldPosition will be set to - * 5 and 8, respectively, for the first occurence of the timezone - * pattern character 'z'. - * @see java.text.Format - * @stable ICU 2.0 - */ - public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition fieldPosition) { - if (obj instanceof Calendar) { - return format((Calendar)obj, toAppendTo, fieldPosition); - } else if (obj instanceof Date) { - return format((Date)obj, toAppendTo, fieldPosition); - } else if (obj instanceof Number) { - return format(new Date(((Number)obj).longValue()), toAppendTo, fieldPosition ); - } else { - throw new IllegalArgumentException("Cannot format given Object as a Date"); - } - } - - /** - * Formats a date into a date/time string. - * @param cal a Calendar set to the date and time to be formatted - * into a date/time string. - * @param toAppendTo the string buffer for the returning date/time string. - * @param fieldPosition keeps track of the position of the field - * within the returned string. - * On input: an alignment field, - * if desired. On output: the offsets of the alignment field. For - * example, given a time text "1996.07.10 AD at 15:08:56 PDT", - * if the given fieldPosition is DateFormat.YEAR_FIELD, the - * begin index and end index of fieldPosition will be set to - * 0 and 4, respectively. - * Notice that if the same time field appears - * more than once in a pattern, the fieldPosition will be set for the first - * occurence of that time field. For instance, formatting a Date to - * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern - * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, - * the begin index and end index of fieldPosition will be set to - * 5 and 8, respectively, for the first occurence of the timezone - * pattern character 'z'. - * @return the formatted date/time string. - * @stable ICU 2.0 - */ - public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition fieldPosition) { - return format(cal.getTime(), toAppendTo, fieldPosition); - } - - - /** - * Formats a Date into a date/time string. - * @param date a Date to be formatted into a date/time string. - * @param toAppendTo the string buffer for the returning date/time string. - * @param fieldPosition keeps track of the position of the field - * within the returned string. - * On input: an alignment field, - * if desired. On output: the offsets of the alignment field. For - * example, given a time text "1996.07.10 AD at 15:08:56 PDT", - * if the given fieldPosition is DateFormat.YEAR_FIELD, the - * begin index and end index of fieldPosition will be set to - * 0 and 4, respectively. - * Notice that if the same time field appears - * more than once in a pattern, the fieldPosition will be set for the first - * occurence of that time field. For instance, formatting a Date to - * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern - * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, - * the begin index and end index of fieldPosition will be set to - * 5 and 8, respectively, for the first occurence of the timezone - * pattern character 'z'. - * @return the formatted date/time string. - * @stable ICU 2.0 - */ - public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { - return dateFormat.format(date, toAppendTo, fieldPosition); - } - - /** - * Formats a Date into a date/time string. - * @param date the time value to be formatted into a time string. - * @return the formatted time string. - * @stable ICU 2.0 - */ - public final String format(Date date) { - return dateFormat.format(date); - } - - /** - * Parse a date/time string. - * - * @param text The date/time string to be parsed - * - * @return A Date, or null if the input could not be parsed - * - * @exception ParseException If the given string cannot be parsed as a date. - * - * @see #parse(String, ParsePosition) - * @stable ICU 2.0 - */ - public Date parse(String text) throws ParseException { - return dateFormat.parse(text); - } - - /** - * Parse a date/time string according to the given parse position. - * For example, a time text "07/10/96 4:5 PM, PDT" will be parsed - * into a Calendar that is equivalent to Date(837039928046). The - * caller should clear the calendar before calling this method, - * unless existing field information is to be kept. - * - *

By default, parsing is lenient: If the input is not in the form used - * by this object's format method but can still be parsed as a date, then - * the parse succeeds. Clients may insist on strict adherence to the - * format by calling setLenient(false). - * - * @see #setLenient(boolean) - * - * @param text The date/time string to be parsed - * - * @param cal The calendar into which parsed data will be stored. - * In general, this should be cleared before calling this - * method. If this parse fails, the calendar may still - * have been modified. - * - * @param pos On input, the position at which to start parsing; on - * output, the position at which parsing terminated, or the - * start position if the parse failed. - * @stable ICU 2.0 - */ - public void parse(String text, Calendar cal, ParsePosition pos) { - Date result = dateFormat.parse(text, pos); - cal.setTime(result); - } - - /** - * Parse a date/time string according to the given parse position. For - * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date - * that is equivalent to Date(837039928046). - * - *

By default, parsing is lenient: If the input is not in the form used - * by this object's format method but can still be parsed as a date, then - * the parse succeeds. Clients may insist on strict adherence to the - * format by calling setLenient(false). - * - * @see #setLenient(boolean) - * - * @param text The date/time string to be parsed - * - * @param pos On input, the position at which to start parsing; on - * output, the position at which parsing terminated, or the - * start position if the parse failed. - * - * @return A Date, or null if the input could not be parsed - * @stable ICU 2.0 - */ - public Date parse(String text, ParsePosition pos) { - return dateFormat.parse(text, pos); - } - - /** - * Parse a date/time string into an Object. This convenience method simply - * calls parse(String, ParsePosition). - * - * @see #parse(String, ParsePosition) - * @stable ICU 2.0 - */ - public Object parseObject(String source, ParsePosition pos) { - return parse(source, pos); - } - - /** - * Constant for full style pattern. - * @stable ICU 2.0 - */ - public static final int FULL = 0; - - /** - * Constant for long style pattern. - * @stable ICU 2.0 - */ - public static final int LONG = 1; - - /** - * Constant for medium style pattern. - * @stable ICU 2.0 - */ - public static final int MEDIUM = 2; - - /** - * Constant for short style pattern. - * @stable ICU 2.0 - */ - public static final int SHORT = 3; - - /** - * Constant for default style pattern. Its value is MEDIUM. - * @stable ICU 2.0 - */ - public static final int DEFAULT = MEDIUM; - - /** - * Gets the time formatter with the default formatting style - * for the default locale. - * @return a time formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getTimeInstance() { - return new DateFormat(java.text.DateFormat.getTimeInstance()); - } - - /** - * Gets the time formatter with the given formatting style - * for the default locale. - * @param style the given formatting style. For example, - * SHORT for "h:mm a" in the US locale. - * @return a time formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getTimeInstance(int style) { - return new DateFormat(java.text.DateFormat.getTimeInstance(style)); - } - - /** - * Gets the time formatter with the given formatting style - * for the given locale. - * @param style the given formatting style. For example, - * SHORT for "h:mm a" in the US locale. - * @param aLocale the given locale. - * @return a time formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getTimeInstance(int style, Locale aLocale) { - return new DateFormat(java.text.DateFormat.getTimeInstance(style, aLocale)); - } - - /** - * Gets the time formatter with the given formatting style - * for the given locale. - * @param style the given formatting style. For example, - * SHORT for "h:mm a" in the US locale. - * @param aLocale the given locale. - * @return a time formatter. - * @stable ICU 3.2 - */ - public final static DateFormat getTimeInstance(int style, ULocale aLocale) { - return new DateFormat(java.text.DateFormat.getTimeInstance(style, aLocale.toLocale())); - } - - /** - * Gets the date formatter with the default formatting style - * for the default locale. - * @return a date formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getDateInstance() { - return new DateFormat(java.text.DateFormat.getDateInstance()); - } - - /** - * Gets the date formatter with the given formatting style - * for the default locale. - * @param style the given formatting style. For example, - * SHORT for "M/d/yy" in the US locale. - * @return a date formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getDateInstance(int style) { - return new DateFormat(java.text.DateFormat.getDateInstance(style)); - } - - /** - * Gets the date formatter with the given formatting style - * for the given locale. - * @param style the given formatting style. For example, - * SHORT for "M/d/yy" in the US locale. - * @param aLocale the given locale. - * @return a date formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getDateInstance(int style, Locale aLocale) { - return new DateFormat(java.text.DateFormat.getDateInstance(style, aLocale)); - } - - /** - * Gets the date formatter with the given formatting style - * for the given locale. - * @param style the given formatting style. For example, - * SHORT for "M/d/yy" in the US locale. - * @param aLocale the given locale. - * @return a date formatter. - * @stable ICU 3.4.3 - */ - public final static DateFormat getDateInstance(int style, ULocale aLocale) { - return new DateFormat(java.text.DateFormat.getDateInstance(style, aLocale.toLocale())); - } - - /** - * Gets the date/time formatter with the default formatting style - * for the default locale. - * @return a date/time formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getDateTimeInstance() { - return new DateFormat(java.text.DateFormat.getDateTimeInstance()); - } - - /** - * Gets the date/time formatter with the given date and time - * formatting styles for the default locale. - * @param dateStyle the given date formatting style. For example, - * SHORT for "M/d/yy" in the US locale. - * @param timeStyle the given time formatting style. For example, - * SHORT for "h:mm a" in the US locale. - * @return a date/time formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle) { - return new DateFormat(java.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle)); - } - - /** - * Gets the date/time formatter with the given formatting styles - * for the given locale. - * @param dateStyle the given date formatting style. - * @param timeStyle the given time formatting style. - * @param aLocale the given locale. - * @return a date/time formatter. - * @stable ICU 2.0 - */ - public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale) { - return new DateFormat(java.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle, aLocale)); - } - - /** - * Gets the date/time formatter with the given formatting styles - * for the given locale. - * @param dateStyle the given date formatting style. - * @param timeStyle the given time formatting style. - * @param aLocale the given locale. - * @return a date/time formatter. - * @stable ICU 3.4.3 - */ - public final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, ULocale aLocale) { - return new DateFormat(java.text.DateFormat.getDateTimeInstance(dateStyle, timeStyle, aLocale.toLocale())); - } - - /** - * Get a default date/time formatter that uses the SHORT style for both the - * date and the time. - * @stable ICU 2.0 - */ - public final static DateFormat getInstance() { - return new DateFormat(java.text.DateFormat.getInstance()); - } - - /** - * Gets the set of locales for which DateFormats are installed. - * @return the set of locales for which DateFormats are installed. - * @stable ICU 2.0 - */ - public static Locale[] getAvailableLocales() { - return java.text.DateFormat.getAvailableLocales(); - } - - /** - * Gets the set of locales for which DateFormats are installed. - * @return the set of locales for which DateFormats are installed. - * @stable ICU 3.4.3 - */ - public static ULocale[] getAvailableULocales() { - Locale[] locales = java.text.DateFormat.getAvailableLocales(); - ULocale[] ulocales = new ULocale[locales.length]; - for (int i = 0; i < locales.length; ++i) { - ulocales[i] = ULocale.forLocale(locales[i]); - } - return ulocales; - } - - /** - * Set the calendar to be used by this date format. Initially, the default - * calendar for the specified or default locale is used. - * @param newCalendar the new Calendar to be used by the date format - * @stable ICU 2.0 - */ - public void setCalendar(Calendar newCalendar) { - dateFormat.setCalendar(newCalendar.calendar); - } - - /** - * Gets the calendar associated with this date/time formatter. - * @return the calendar associated with this date/time formatter. - * @stable ICU 2.0 - */ - public Calendar getCalendar() { - return new Calendar(dateFormat.getCalendar()); - } - - /** - * Allows you to set the number formatter. - * @param newNumberFormat the given new NumberFormat. - * @stable ICU 2.0 - */ - public void setNumberFormat(NumberFormat newNumberFormat) { - dateFormat.setNumberFormat(newNumberFormat.numberFormat); - } - - /** - * Gets the number formatter which this date/time formatter uses to - * format and parse a time. - * @return the number formatter which this date/time formatter uses. - * @stable ICU 2.0 - */ - public NumberFormat getNumberFormat() { - return new NumberFormat(dateFormat.getNumberFormat()); - } - - /** - * Sets the time zone for the calendar of this DateFormat object. - * @param zone the given new time zone. - * @stable ICU 2.0 - */ - public void setTimeZone(TimeZone zone) { - dateFormat.setTimeZone(zone.timeZone); - } - - /** - * Gets the time zone. - * @return the time zone associated with the calendar of DateFormat. - * @stable ICU 2.0 - */ - public TimeZone getTimeZone() { - return new TimeZone(dateFormat.getTimeZone()); - } - - /** - * Specify whether or not date/time parsing is to be lenient. With - * lenient parsing, the parser may use heuristics to interpret inputs that - * do not precisely match this object's format. With strict parsing, - * inputs must match this object's format. - * @param lenient when true, parsing is lenient - * @see com.ibm.icu.util.Calendar#setLenient - * @stable ICU 2.0 - */ - public void setLenient(boolean lenient) { - dateFormat.setLenient(lenient); - } - - /** - * Tell whether date/time parsing is to be lenient. - * @stable ICU 2.0 - */ - public boolean isLenient() { - return dateFormat.isLenient(); - } - - /** - * Create a {@link DateFormat} object that can be used to format dates in - * the calendar system specified by cal. - *

- * @param cal The calendar system for which a date format is desired. - * - * @param dateStyle The type of date format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param locale The locale for which the date format is desired. - * @stable ICU 2.0 - */ - static final public DateFormat getDateInstance(Calendar cal, int dateStyle, Locale locale) { - DateFormat df = getDateInstance(dateStyle, locale); - df.setCalendar(cal); - return df; - } - - /** - * Create a {@link DateFormat} object that can be used to format dates in - * the calendar system specified by cal. - *

- * @param cal The calendar system for which a date format is desired. - * - * @param dateStyle The type of date format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param locale The locale for which the date format is desired. - * @stable ICU 3.2 - */ - static final public DateFormat getDateInstance(Calendar cal, int dateStyle, ULocale locale) { - DateFormat df = getDateInstance(dateStyle, locale); - df.setCalendar(cal); - return df; - } - - /** - * Create a {@link DateFormat} object that can be used to format times in - * the calendar system specified by cal. - *

- * Note: When this functionality is moved into the core JDK, this method - * will probably be replaced by a new overload of {@link DateFormat#getInstance}. - *

- * @param cal The calendar system for which a time format is desired. - * - * @param timeStyle The type of time format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param locale The locale for which the time format is desired. - * - * @see DateFormat#getTimeInstance - * @stable ICU 2.0 - */ - static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, Locale locale) { - DateFormat df = getTimeInstance(timeStyle, locale); - df.setCalendar(cal); - return df; - } - - /** - * Create a {@link DateFormat} object that can be used to format times in - * the calendar system specified by cal. - *

- * Note: When this functionality is moved into the core JDK, this method - * will probably be replaced by a new overload of {@link DateFormat#getInstance}. - *

- * @param cal The calendar system for which a time format is desired. - * - * @param timeStyle The type of time format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param locale The locale for which the time format is desired. - * - * @see DateFormat#getTimeInstance - * @stable ICU 3.2 - */ - static final public DateFormat getTimeInstance(Calendar cal, int timeStyle, ULocale locale) { - DateFormat df = getTimeInstance(timeStyle, locale); - df.setCalendar(cal); - return df; - } - - /** - * Create a {@link DateFormat} object that can be used to format dates and times in - * the calendar system specified by cal. - *

- * Note: When this functionality is moved into the core JDK, this method - * will probably be replaced by a new overload of {@link DateFormat#getInstance}. - *

- * @param cal The calendar system for which a date/time format is desired. - * - * @param dateStyle The type of date format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param timeStyle The type of time format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param locale The locale for which the date/time format is desired. - * - * @see DateFormat#getDateTimeInstance - * @stable ICU 2.0 - */ - static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle, - int timeStyle, Locale locale) { - DateFormat df = getDateTimeInstance(dateStyle, timeStyle, locale); - df.setCalendar(cal); - return df; - } - - /** - * Create a {@link DateFormat} object that can be used to format dates and times in - * the calendar system specified by cal. - *

- * Note: When this functionality is moved into the core JDK, this method - * will probably be replaced by a new overload of {@link DateFormat#getInstance}. - *

- * @param cal The calendar system for which a date/time format is desired. - * - * @param dateStyle The type of date format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param timeStyle The type of time format desired. This can be - * {@link DateFormat#SHORT}, {@link DateFormat#MEDIUM}, - * etc. - * - * @param locale The locale for which the date/time format is desired. - * - * @see DateFormat#getDateTimeInstance - * @stable ICU 3.2 - */ - static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle, - int timeStyle, ULocale locale) { - DateFormat df = getDateTimeInstance(dateStyle, timeStyle, locale); - df.setCalendar(cal); - return df; - } - - /** - * Convenience overload - * @stable ICU 2.0 - */ - static final public DateFormat getInstance(Calendar cal, Locale locale) { - return getDateTimeInstance(cal, MEDIUM, SHORT, locale); - } - - /** - * Convenience overload - * @stable ICU 3.2 - */ - public static final DateFormat getInstance(Calendar cal, ULocale locale) { - return getDateTimeInstance(cal, MEDIUM, SHORT, locale); - } - - /** - * Convenience overload - * @stable ICU 2.0 - */ - public static final DateFormat getInstance(Calendar cal) { - return getDateTimeInstance(cal, MEDIUM, SHORT, ULocale.getDefault()); - } - - /** - * Convenience overload - * @stable ICU 2.0 - */ - public static final DateFormat getDateInstance(Calendar cal, int dateStyle) { - DateFormat df = getDateInstance(dateStyle); - df.setCalendar(cal); - return df; - } - - /** - * Convenience overload - * @stable ICU 2.0 - */ - static final public DateFormat getTimeInstance(Calendar cal, int timeStyle) { - DateFormat df = getTimeInstance(timeStyle); - df.setCalendar(cal); - return df; - } - - /** - * Convenience overload - * @stable ICU 2.0 - */ - static final public DateFormat getDateTimeInstance(Calendar cal, int dateStyle, int timeStyle) { - DateFormat df = getDateTimeInstance(dateStyle, timeStyle); - df.setCalendar(cal); - return df; - } - - /** - * Return a string suitable for debugging. - * @return a string suitable for debugging - * @stable ICU 3.4.3 - */ - public String toString() { - return dateFormat.toString(); - } - - /** - * Return a clone of this DateFormat. - * @return a clone of this DateFormat - * @stable ICU 3.4.3 - */ - public Object clone() { - return new DateFormat((java.text.DateFormat)dateFormat.clone()); - } - - /** - * Return true if rhs is a DateFormatSymbols and has the same symbols as this. - * @return true if rhs equals this - * @stable ICU 3.4.3 - */ - public boolean equals(Object arg0) { - try { - return dateFormat.equals(((DateFormat)arg0).dateFormat); - } - catch (Exception e) { - return false; - } - } - - /** - * Return a hashCode. - * @return a hashCode - * @stable ICU 3.4.3 - */ - public int hashCode() { - return dateFormat.hashCode(); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormatSymbols.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormatSymbols.java deleted file mode 100644 index 76319cd2899..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DateFormatSymbols.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - -import java.io.Serializable; -import java.util.Locale; - -import com.ibm.icu.util.ULocale; - -/** - * DateFormatSymbols is a public class for encapsulating - * localizable date-time formatting data, such as the names of the - * months, the names of the days of the week, and the time zone data. - * DateFormat and SimpleDateFormat both use - * DateFormatSymbols to encapsulate this information. - * - *

- * Typically you shouldn't use DateFormatSymbols directly. - * Rather, you are encouraged to create a date-time formatter with the - * DateFormat class's factory methods: getTimeInstance, - * getDateInstance, or getDateTimeInstance. - * These methods automatically create a DateFormatSymbols for - * the formatter so that you don't have to. After the - * formatter is created, you may modify its format pattern using the - * setPattern method. For more information about - * creating formatters using DateFormat's factory methods, - * see {@link DateFormat}. - * - *

- * If you decide to create a date-time formatter with a specific - * format pattern for a specific locale, you can do so with: - *

- *
- * new SimpleDateFormat(aPattern, new DateFormatSymbols(aLocale)).
- * 
- *
- * - *

- * DateFormatSymbols objects are clonable. When you obtain - * a DateFormatSymbols object, feel free to modify the - * date-time formatting data. For instance, you can replace the localized - * date-time format pattern characters with the ones that you feel easy - * to remember. Or you can change the representative cities - * to your favorite ones. - * - *

- * New DateFormatSymbols subclasses may be added to support - * SimpleDateFormat for date-time formatting for additional locales. - - * @see DateFormat - * @see SimpleDateFormat - * @see com.ibm.icu.util.SimpleTimeZone - * @author Chen-Lieh Huang - * @stable ICU 2.0 - */ -public class DateFormatSymbols implements Serializable, Cloneable { - private static final long serialVersionUID = 1; - - /** @internal */ - public java.text.DateFormatSymbols dfs; - - /** @internal */ - public DateFormatSymbols(java.text.DateFormatSymbols delegate) { - this.dfs = delegate; - } - - /** - * Construct a DateFormatSymbols object by loading format data from - * resources for the default locale. - * - * @throws java.util.MissingResourceException - * if the resources for the default locale cannot be - * found or cannot be loaded. - * @stable ICU 2.0 - */ - public DateFormatSymbols() { - this(new java.text.DateFormatSymbols()); - } - - /** - * Construct a DateFormatSymbols object by loading format data from - * resources for the given locale. - * - * @throws java.util.MissingResourceException - * if the resources for the specified locale cannot be - * found or cannot be loaded. - * @stable ICU 2.0 - */ - public DateFormatSymbols(Locale locale) { - this(new java.text.DateFormatSymbols(locale)); - } - - /** - * Construct a DateFormatSymbols object by loading format data from - * resources for the given ulocale. - * - * @throws java.util.MissingResourceException - * if the resources for the specified locale cannot be - * found or cannot be loaded. - * @stable ICU 3.2 - */ - public DateFormatSymbols(ULocale locale) { - this(new java.text.DateFormatSymbols(locale.toLocale())); - } - - /** - * Gets era strings. For example: "AD" and "BC". - * @return the era strings. - * @stable ICU 2.0 - */ - public String[] getEras() { - return dfs.getEras(); - } - - /** - * Sets era strings. For example: "AD" and "BC". - * @param newEras the new era strings. - * @stable ICU 2.0 - */ - public void setEras(String[] newEras) { - dfs.setEras(newEras); - } - - /** - * Gets month strings. For example: "January", "February", etc. - * @return the month strings. - * @stable ICU 2.0 - */ - public String[] getMonths() { - return dfs.getMonths(); - } - - /** - * Sets month strings. For example: "January", "February", etc. - * @param newMonths the new month strings. - * @stable ICU 2.0 - */ - public void setMonths(String[] newMonths) { - dfs.setMonths(newMonths); - } - - /** - * Gets short month strings. For example: "Jan", "Feb", etc. - * @return the short month strings. - * @stable ICU 2.0 - */ - public String[] getShortMonths() { - return dfs.getShortMonths(); - } - - /** - * Sets short month strings. For example: "Jan", "Feb", etc. - * @param newShortMonths the new short month strings. - * @stable ICU 2.0 - */ - public void setShortMonths(String[] newShortMonths) { - dfs.setShortMonths(newShortMonths); - } - - /** - * Gets weekday strings. For example: "Sunday", "Monday", etc. - * @return the weekday strings. Use Calendar.SUNDAY, - * Calendar.MONDAY, etc. to index the result array. - * @stable ICU 2.0 - */ - public String[] getWeekdays() { - return dfs.getWeekdays(); - } - - /** - * Sets weekday strings. For example: "Sunday", "Monday", etc. - * @param newWeekdays the new weekday strings. The array should - * be indexed by Calendar.SUNDAY, - * Calendar.MONDAY, etc. - * @stable ICU 2.0 - */ - public void setWeekdays(String[] newWeekdays) { - dfs.setWeekdays(newWeekdays); - } - - /** - * Gets short weekday strings. For example: "Sun", "Mon", etc. - * @return the short weekday strings. Use Calendar.SUNDAY, - * Calendar.MONDAY, etc. to index the result array. - * @stable ICU 2.0 - */ - public String[] getShortWeekdays() { - return dfs.getShortWeekdays(); - } - - /** - * Sets short weekday strings. For example: "Sun", "Mon", etc. - * @param newShortWeekdays the new short weekday strings. The array should - * be indexed by Calendar.SUNDAY, - * Calendar.MONDAY, etc. - * @stable ICU 2.0 - */ - public void setShortWeekdays(String[] newShortWeekdays) { - dfs.setShortWeekdays(newShortWeekdays); - } - - /** - * Gets ampm strings. For example: "AM" and "PM". - * @return the weekday strings. - * @stable ICU 2.0 - */ - public String[] getAmPmStrings() { - return dfs.getAmPmStrings(); - } - - /** - * Sets ampm strings. For example: "AM" and "PM". - * @param newAmpms the new ampm strings. - * @stable ICU 2.0 - */ - public void setAmPmStrings(String[] newAmpms) { - dfs.setAmPmStrings(newAmpms); - } - - /** - * Gets timezone strings. - * @return the timezone strings. - * @stable ICU 2.0 - */ - public String[][] getZoneStrings() { - return dfs.getZoneStrings(); - } - - /** - * Sets timezone strings. - * @param newZoneStrings the new timezone strings. - * @stable ICU 2.0 - */ - public void setZoneStrings(String[][] newZoneStrings) { - dfs.setZoneStrings(newZoneStrings); - } - - /** - * Gets localized date-time pattern characters. For example: 'u', 't', etc. - * @return the localized date-time pattern characters. - * @stable ICU 2.0 - */ - public String getLocalPatternChars() { - return dfs.getLocalPatternChars(); - } - - /** - * Sets localized date-time pattern characters. For example: 'u', 't', etc. - * @param newLocalPatternChars the new localized date-time - * pattern characters. - * @stable ICU 2.0 - */ - public void setLocalPatternChars(String newLocalPatternChars) { - dfs.setLocalPatternChars(newLocalPatternChars); - } - - /** - * Return a string suitable for debugging. - * @return a string suitable for debugging - * @stable ICU 3.4.2 - */ - public String toString() { - return dfs.toString(); - } - - /** - * Return a clone of this DateFormatSymbols. - * @return a clone of this DateFormatSymbols - * @stable ICU 3.4.2 - */ - public Object clone() { - return new DateFormatSymbols((java.text.DateFormatSymbols)dfs.clone()); - } - - /** - * Return true if rhs is a DateFormatSymbols and has the same symbols as this. - * @return true if rhs equals this - * @stable ICU 3.4.2 - */ - public boolean equals(Object rhs) { - try { - return dfs.equals(((DateFormatSymbols)rhs).dfs); - } - catch (Exception e) { - return false; - } - } - - /** - * Return a hashCode. - * @return a hashCode - * @stable ICU 3.4.2 - */ - public int hashCode() { - return dfs.hashCode(); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormat.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormat.java deleted file mode 100644 index 8a4494f5d24..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormat.java +++ /dev/null @@ -1,903 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2006, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - -/** - * DecimalFormat is a concrete subclass of - * {@link NumberFormat} that formats decimal numbers. - * - *

To obtain a {@link NumberFormat} for a specific locale (including the - * default locale) call one of NumberFormat's factory methods such - * as {@link NumberFormat#getInstance}. Do not call the DecimalFormat - * constructors directly, unless you know what you are doing, since the - * {@link NumberFormat} factory methods may return subclasses other than - * DecimalFormat. If you need to customize the format object, do - * something like this: - * - *

- * NumberFormat f = NumberFormat.getInstance(loc);
- * if (f instanceof DecimalFormat) {
- *     ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true);
- * }
- * - *

Example Usage - * - *

- * // Print out a number using the localized number, currency,
- * // and percent format for each locale
- * Locale[] locales = NumberFormat.getAvailableLocales();
- * double myNumber = -1234.56;
- * NumberFormat format;
- * for (int j=0; j<3; ++j) {
- *     System.out.println("FORMAT");
- *     for (int i = 0; i < locales.length; ++i) {
- *         if (locales[i].getCountry().length() == 0) {
- *            // Skip language-only locales
- *            continue;
- *         }
- *         System.out.print(locales[i].getDisplayName());
- *         switch (j) {
- *         case 0:
- *             format = NumberFormat.getInstance(locales[i]); break;
- *         case 1:
- *             format = NumberFormat.getCurrencyInstance(locales[i]); break;
- *         default:
- *             format = NumberFormat.getPercentInstance(locales[i]); break;
- *         }
- *         try {
- *             // Assume format is a DecimalFormat
- *             System.out.print(": " + ((DecimalFormat) format).toPattern()
- *                              + " -> " + form.format(myNumber));
- *         } catch (Exception e) {}
- *         try {
- *             System.out.println(" -> " + format.parse(form.format(myNumber)));
- *         } catch (ParseException e) {}
- *     }
- * }
- * - *

Patterns

- * - *

A DecimalFormat consists of a pattern and a set of - * symbols. The pattern may be set directly using - * {@link #applyPattern}, or indirectly using other API methods which - * manipulate aspects of the pattern, such as the minimum number of integer - * digits. The symbols are stored in a {@link DecimalFormatSymbols} - * object. When using the {@link NumberFormat} factory methods, the - * pattern and symbols are read from ICU's locale data. - * - *

Special Pattern Characters

- * - *

Many characters in a pattern are taken literally; they are matched during - * parsing and output unchanged during formatting. Special characters, on the - * other hand, stand for other characters, strings, or classes of characters. - * For example, the '#' character is replaced by a localized digit. Often the - * replacement character is the same as the pattern character; in the U.S. locale, - * the ',' grouping character is replaced by ','. However, the replacement is - * still happening, and if the symbols are modified, the grouping character - * changes. Some special characters affect the behavior of the formatter by - * their presence; for example, if the percent character is seen, then the - * value is multiplied by 100 before being displayed. - * - *

To insert a special character in a pattern as a literal, that is, without - * any special meaning, the character must be quoted. There are some exceptions to - * this which are noted below. - * - *

The characters listed here are used in non-localized patterns. Localized - * patterns use the corresponding characters taken from this formatter's - * {@link DecimalFormatSymbols} object instead, and these characters lose - * their special status. Two exceptions are the currency sign and quote, which - * are not localized. - * - *

- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Symbol - * Location - * Localized? - * Meaning - *
0 - * Number - * Yes - * Digit - *
1-9 - * Number - * Yes - * NEW - * '1' through '9' indicate rounding. - *
@ - * Number - * No - * NEW - * Significant digit - *
# - * Number - * Yes - * Digit, zero shows as absent - *
. - * Number - * Yes - * Decimal separator or monetary decimal separator - *
- - * Number - * Yes - * Minus sign - *
, - * Number - * Yes - * Grouping separator - *
E - * Number - * Yes - * Separates mantissa and exponent in scientific notation. - * Need not be quoted in prefix or suffix. - *
+ - * Exponent - * Yes - * NEW - * Prefix positive exponents with localized plus sign. - * Need not be quoted in prefix or suffix. - *
; - * Subpattern boundary - * Yes - * Separates positive and negative subpatterns - *
% - * Prefix or suffix - * Yes - * Multiply by 100 and show as percentage - *
\u2030 - * Prefix or suffix - * Yes - * Multiply by 1000 and show as per mille - *
¤ (\u00A4) - * Prefix or suffix - * No - * Currency sign, replaced by currency symbol. If - * doubled, replaced by international currency symbol. - * If present in a pattern, the monetary decimal separator - * is used instead of the decimal separator. - *
' - * Prefix or suffix - * No - * Used to quote special characters in a prefix or suffix, - * for example, "'#'#" formats 123 to - * "#123". To create a single quote - * itself, use two in a row: "# o''clock". - *
* - * Prefix or suffix boundary - * Yes - * NEW - * Pad escape, precedes pad character - *
- *
- * - *

A DecimalFormat pattern contains a postive and negative - * subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a - * prefix, a numeric part, and a suffix. If there is no explicit negative - * subpattern, the negative subpattern is the localized minus sign prefixed to the - * positive subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there - * is an explicit negative subpattern, it serves only to specify the negative - * prefix and suffix; the number of digits, minimal digits, and other - * characteristics are ignored in the negative subpattern. That means that - * "#,##0.0#;(#)" has precisely the same result as "#,##0.0#;(#,##0.0#)". - * - *

The prefixes, suffixes, and various symbols used for infinity, digits, - * thousands separators, decimal separators, etc. may be set to arbitrary - * values, and they will appear properly during formatting. However, care must - * be taken that the symbols and strings do not conflict, or parsing will be - * unreliable. For example, either the positive and negative prefixes or the - * suffixes must be distinct for {@link #parse} to be able - * to distinguish positive from negative values. Another example is that the - * decimal separator and thousands separator should be distinct characters, or - * parsing will be impossible. - * - *

The grouping separator is a character that separates clusters of - * integer digits to make large numbers more legible. It commonly used for - * thousands, but in some locales it separates ten-thousands. The grouping - * size is the number of digits between the grouping separators, such as 3 - * for "100,000,000" or 4 for "1 0000 0000". There are actually two different - * grouping sizes: One used for the least significant integer digits, the - * primary grouping size, and one used for all others, the - * secondary grouping size. In most locales these are the same, but - * sometimes they are different. For example, if the primary grouping interval - * is 3, and the secondary is 2, then this corresponds to the pattern - * "#,##,##0", and the number 123456789 is formatted as "12,34,56,789". If a - * pattern contains multiple grouping separators, the interval between the last - * one and the end of the integer defines the primary grouping size, and the - * interval between the last two defines the secondary grouping size. All others - * are ignored, so "#,##,###,####" == "###,###,####" == "##,#,###,####". - * - *

Illegal patterns, such as "#.#.#" or "#.###,###", will cause - * DecimalFormat to throw an {@link IllegalArgumentException} - * with a message that describes the problem. - * - *

Pattern BNF

- * - *
- * pattern    := subpattern (';' subpattern)?
- * subpattern := prefix? number exponent? suffix?
- * number     := (integer ('.' fraction)?) | sigDigits
- * prefix     := '\u0000'..'\uFFFD' - specialCharacters
- * suffix     := '\u0000'..'\uFFFD' - specialCharacters
- * integer    := '#'* '0'* '0'
- * fraction   := '0'* '#'*
- * sigDigits  := '#'* '@' '@'* '#'*
- * exponent   := 'E' '+'? '0'* '0'
- * padSpec    := '*' padChar
- * padChar    := '\u0000'..'\uFFFD' - quote
- *  
- * Notation:
- *   X*       0 or more instances of X
- *   X?       0 or 1 instances of X
- *   X|Y      either X or Y
- *   C..D     any character from C up to D, inclusive
- *   S-T      characters in S, except those in T
- * 
- * The first subpattern is for positive numbers. The second (optional) - * subpattern is for negative numbers. - * - *

Not indicated in the BNF syntax above: - * - *

  • The grouping separator ',' can occur inside the integer and - * sigDigits elements, between any two pattern characters of that - * element, as long as the integer or sigDigits element is not - * followed by the exponent element. - * - *
  • NEW - * Two grouping intervals are recognized: That between the - * decimal point and the first grouping symbol, and that - * between the first and second grouping symbols. These - * intervals are identical in most locales, but in some - * locales they differ. For example, the pattern - * "#,##,###" formats the number 123456789 as - * "12,34,56,789".
  • - * - *
  • - * NEW - * The pad specifier padSpec may appear before the prefix, - * after the prefix, before the suffix, after the suffix, or not at all. - * - *
  • - * NEW - * In place of '0', the digits '1' through '9' may be used to - * indicate a rounding increment. - *
- * - *

Parsing

- * - *

DecimalFormat parses all Unicode characters that represent - * decimal digits, as defined by {@link UCharacter#digit}. In addition, - * DecimalFormat also recognizes as digits the ten consecutive - * characters starting with the localized zero digit defined in the - * {@link DecimalFormatSymbols} object. During formatting, the - * {@link DecimalFormatSymbols}-based digits are output. - * - *

During parsing, grouping separators are ignored. - * - *

If {@link #parse(String, ParsePosition)} fails to parse - * a string, it returns null and leaves the parse position - * unchanged. The convenience method {@link #parse(String)} - * indicates parse failure by throwing a {@link java.text.ParseException}. - * - *

Formatting

- * - *

Formatting is guided by several parameters, all of which can be - * specified either using a pattern or using the API. The following - * description applies to formats that do not use scientific - * notation or significant digits. - * - *

  • If the number of actual integer digits exceeds the - * maximum integer digits, then only the least significant - * digits are shown. For example, 1997 is formatted as "97" if the - * maximum integer digits is set to 2. - * - *
  • If the number of actual integer digits is less than the - * minimum integer digits, then leading zeros are added. For - * example, 1997 is formatted as "01997" if the minimum integer digits - * is set to 5. - * - *
  • If the number of actual fraction digits exceeds the maximum - * fraction digits, then half-even rounding it performed to the - * maximum fraction digits. For example, 0.125 is formatted as "0.12" - * if the maximum fraction digits is 2. This behavior can be changed - * by specifying a rounding increment and a rounding mode. - * - *
  • If the number of actual fraction digits is less than the - * minimum fraction digits, then trailing zeros are added. - * For example, 0.125 is formatted as "0.1250" if the mimimum fraction - * digits is set to 4. - * - *
  • Trailing fractional zeros are not displayed if they occur - * j positions after the decimal, where j is less - * than the maximum fraction digits. For example, 0.10004 is - * formatted as "0.1" if the maximum fraction digits is four or less. - *
- * - *

Special Values - * - *

NaN is represented as a single character, typically - * \uFFFD. This character is determined by the - * {@link DecimalFormatSymbols} object. This is the only value for which - * the prefixes and suffixes are not used. - * - *

Infinity is represented as a single character, typically - * \u221E, with the positive or negative prefixes and suffixes - * applied. The infinity character is determined by the - * {@link DecimalFormatSymbols} object. - * - *

Scientific Notation

- * - *

Numbers in scientific notation are expressed as the product of a mantissa - * and a power of ten, for example, 1234 can be expressed as 1.234 x 103. The - * mantissa is typically in the half-open interval [1.0, 10.0) or sometimes [0.0, 1.0), - * but it need not be. DecimalFormat supports arbitrary mantissas. - * DecimalFormat can be instructed to use scientific - * notation through the API or through the pattern. In a pattern, the exponent - * character immediately followed by one or more digit characters indicates - * scientific notation. Example: "0.###E0" formats the number 1234 as - * "1.234E3". - * - *

    - *
  • The number of digit characters after the exponent character gives the - * minimum exponent digit count. There is no maximum. Negative exponents are - * formatted using the localized minus sign, not the prefix and suffix - * from the pattern. This allows patterns such as "0.###E0 m/s". To prefix - * positive exponents with a localized plus sign, specify '+' between the - * exponent and the digits: "0.###E+0" will produce formats "1E+1", "1E+0", - * "1E-1", etc. (In localized patterns, use the localized plus sign rather than - * '+'.) - * - *
  • The minimum number of integer digits is achieved by adjusting the - * exponent. Example: 0.00123 formatted with "00.###E0" yields "12.3E-4". This - * only happens if there is no maximum number of integer digits. If there is a - * maximum, then the minimum number of integer digits is fixed at one. - * - *
  • The maximum number of integer digits, if present, specifies the exponent - * grouping. The most common use of this is to generate engineering - * notation, in which the exponent is a multiple of three, e.g., - * "##0.###E0". The number 12345 is formatted using "##0.####E0" as "12.345E3". - * - *
  • When using scientific notation, the formatter controls the - * digit counts using significant digits logic. The maximum number of - * significant digits limits the total number of integer and fraction - * digits that will be shown in the mantissa; it does not affect - * parsing. For example, 12345 formatted with "##0.##E0" is "12.3E3". - * See the section on significant digits for more details. - * - *
  • The number of significant digits shown is determined as - * follows: If areSignificantDigitsUsed() returns false, then the - * minimum number of significant digits shown is one, and the maximum - * number of significant digits shown is the sum of the minimum - * integer and maximum fraction digits, and is - * unaffected by the maximum integer digits. If this sum is zero, - * then all significant digits are shown. If - * areSignificantDigitsUsed() returns true, then the significant digit - * counts are specified by getMinimumSignificantDigits() and - * getMaximumSignificantDigits(). In this case, the number of - * integer digits is fixed at one, and there is no exponent grouping. - * - *
  • Exponential patterns may not contain grouping separators. - *
- * - *

- * NEW - * Significant Digits

- * - * DecimalFormat has two ways of controlling how many - * digits are shows: (a) significant digits counts, or (b) integer and - * fraction digit counts. Integer and fraction digit counts are - * described above. When a formatter is using significant digits - * counts, the number of integer and fraction digits is not specified - * directly, and the formatter settings for these counts are ignored. - * Instead, the formatter uses however many integer and fraction - * digits are required to display the specified number of significant - * digits. Examples: - * - *
- * - * - * - * - * - * - *
Pattern - * Minimum significant digits - * Maximum significant digits - * Number - * Output of format() - *
@@@ - * 3 - * 3 - * 12345 - * 12300 - *
@@@ - * 3 - * 3 - * 0.12345 - * 0.123 - *
@@## - * 2 - * 4 - * 3.14159 - * 3.142 - *
@@## - * 2 - * 4 - * 1.23004 - * 1.23 - *
- *
- * - *
    - *
  • Significant digit counts may be expressed using patterns that - * specify a minimum and maximum number of significant digits. These - * are indicated by the '@' and '#' - * characters. The minimum number of significant digits is the number - * of '@' characters. The maximum number of significant - * digits is the number of '@' characters plus the number - * of '#' characters following on the right. For - * example, the pattern "@@@" indicates exactly 3 - * significant digits. The pattern "@##" indicates from - * 1 to 3 significant digits. Trailing zero digits to the right of - * the decimal separator are suppressed after the minimum number of - * significant digits have been shown. For example, the pattern - * "@##" formats the number 0.1203 as - * "0.12". - * - *
  • If a pattern uses significant digits, it may not contain a - * decimal separator, nor the '0' pattern character. - * Patterns such as "@00" or "@.###" are - * disallowed. - * - *
  • Any number of '#' characters may be prepended to - * the left of the leftmost '@' character. These have no - * effect on the minimum and maximum significant digits counts, but - * may be used to position grouping separators. For example, - * "#,#@#" indicates a minimum of one significant digits, - * a maximum of two significant digits, and a grouping size of three. - * - *
  • In order to enable significant digits formatting, use a pattern - * containing the '@' pattern character. Alternatively, - * call {@link #setSignificantDigitsUsed setSignificantDigitsUsed(true)}. - * - *
  • In order to disable significant digits formatting, use a - * pattern that does not contain the '@' pattern - * character. Alternatively, call {@link #setSignificantDigitsUsed - * setSignificantDigitsUsed(false)}. - * - *
  • The number of significant digits has no effect on parsing. - * - *
  • Significant digits may be used together with exponential notation. Such - * patterns are equivalent to a normal exponential pattern with a minimum and - * maximum integer digit count of one, a minimum fraction digit count of - * getMinimumSignificantDigits() - 1, and a maximum fraction digit - * count of getMaximumSignificantDigits() - 1. For example, the - * pattern "@@###E0" is equivalent to "0.0###E0". - * - *
  • If signficant digits are in use, then the integer and fraction - * digit counts, as set via the API, are ignored. If significant - * digits are not in use, then the signficant digit counts, as set via - * the API, are ignored. - * - *
- * - *

- * NEW - * Padding

- * - *

DecimalFormat supports padding the result of - * {@link #format} to a specific width. Padding may be specified either - * through the API or through the pattern syntax. In a pattern the pad escape - * character, followed by a single pad character, causes padding to be parsed - * and formatted. The pad escape character is '*' in unlocalized patterns, and - * can be localized using {@link DecimalFormatSymbols#setPadEscape}. For - * example, "$*x#,##0.00" formats 123 to "$xx123.00", - * and 1234 to "$1,234.00". - * - *

    - *
  • When padding is in effect, the width of the positive subpattern, - * including prefix and suffix, determines the format width. For example, in - * the pattern "* #0 o''clock", the format width is 10. - * - *
  • The width is counted in 16-bit code units (Java chars). - * - *
  • Some parameters which usually do not matter have meaning when padding is - * used, because the pattern width is significant with padding. In the pattern - * "* ##,##,#,##0.##", the format width is 14. The initial characters "##,##," - * do not affect the grouping size or maximum integer digits, but they do affect - * the format width. - * - *
  • Padding may be inserted at one of four locations: before the prefix, - * after the prefix, before the suffix, or after the suffix. If padding is - * specified in any other location, {@link #applyPattern} throws an {@link - * IllegalArgumentException}. If there is no prefix, before the - * prefix and after the prefix are equivalent, likewise for the suffix. - * - *
  • When specified in a pattern, the 16-bit char immediately - * following the pad escape is the pad character. This may be any character, - * including a special pattern character. That is, the pad escape - * escapes the following character. If there is no character after - * the pad escape, then the pattern is illegal. - * - *
- * - *

- * NEW - * Rounding - * - *

DecimalFormat supports rounding to a specific increment. For - * example, 1230 rounded to the nearest 50 is 1250. 1.234 rounded to the - * nearest 0.65 is 1.3. The rounding increment may be specified through the API - * or in a pattern. To specify a rounding increment in a pattern, include the - * increment in the pattern itself. "#,#50" specifies a rounding increment of - * 50. "#,##0.05" specifies a rounding increment of 0.05. - * - *

    - *
  • Rounding only affects the string produced by formatting. It does - * not affect parsing or change any numerical values. - * - *
  • A rounding mode determines how values are rounded; see the - * {@link com.ibm.icu.math.BigDecimal} documentation for a description of the - * modes. Rounding increments specified in patterns use the default mode, - * {@link com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN}. - * - *
  • Some locales use rounding in their currency formats to reflect the - * smallest currency denomination. - * - *
  • In a pattern, digits '1' through '9' specify rounding, but otherwise - * behave identically to digit '0'. - *
- * - *

Synchronization

- * - *

DecimalFormat objects are not synchronized. Multiple - * threads should not access one formatter concurrently. - * - * @see java.text.Format - * @see NumberFormat - * @author Mark Davis - * @author Alan Liu - * @stable ICU 2.0 - */ -public class DecimalFormat extends NumberFormat { - - private static final long serialVersionUID = 1L; - /** - * @internal - * @param delegate the NumberFormat to which to delegate - */ - public DecimalFormat(java.text.DecimalFormat delegate) { - super(delegate); - } - - /** - * Create a DecimalFormat using the default pattern and symbols - * for the default locale. This is a convenient way to obtain a - * DecimalFormat when internationalization is not the main concern. - *

- * To obtain standard formats for a given locale, use the factory methods - * on NumberFormat such as getNumberInstance. These factories will - * return the most appropriate sub-class of NumberFormat for a given - * locale. - * @see NumberFormat#getInstance - * @see NumberFormat#getNumberInstance - * @see NumberFormat#getCurrencyInstance - * @see NumberFormat#getPercentInstance - * @stable ICU 2.0 - */ - public DecimalFormat() { - this(new java.text.DecimalFormat()); - } - - /** - * Create a DecimalFormat from the given pattern and the symbols - * for the default locale. This is a convenient way to obtain a - * DecimalFormat when internationalization is not the main concern. - *

- * To obtain standard formats for a given locale, use the factory methods - * on NumberFormat such as getNumberInstance. These factories will - * return the most appropriate sub-class of NumberFormat for a given - * locale. - * @param pattern A non-localized pattern string. - * @exception IllegalArgumentException if the given pattern is invalid. - * @see NumberFormat#getInstance - * @see NumberFormat#getNumberInstance - * @see NumberFormat#getCurrencyInstance - * @see NumberFormat#getPercentInstance - * @stable ICU 2.0 - */ - public DecimalFormat(String pattern) { - this(new java.text.DecimalFormat(pattern)); - } - - - /** - * Create a DecimalFormat from the given pattern and symbols. - * Use this constructor when you need to completely customize the - * behavior of the format. - *

- * To obtain standard formats for a given - * locale, use the factory methods on NumberFormat such as - * getInstance or getCurrencyInstance. If you need only minor adjustments - * to a standard format, you can modify the format returned by - * a NumberFormat factory method. - * @param pattern a non-localized pattern string - * @param symbols the set of symbols to be used - * @exception IllegalArgumentException if the given pattern is invalid - * @see NumberFormat#getInstance - * @see NumberFormat#getNumberInstance - * @see NumberFormat#getCurrencyInstance - * @see NumberFormat#getPercentInstance - * @see DecimalFormatSymbols - * @stable ICU 2.0 - */ - public DecimalFormat(String pattern, DecimalFormatSymbols symbols) { - this(new java.text.DecimalFormat(pattern, symbols.dfs)); - } - - /** - * Returns a copy of the decimal format symbols used by this format. - * @return desired DecimalFormatSymbols - * @see DecimalFormatSymbols - * @stable ICU 2.0 - */ - public DecimalFormatSymbols getDecimalFormatSymbols() { - return new DecimalFormatSymbols(((java.text.DecimalFormat)numberFormat).getDecimalFormatSymbols()); - } - - /** - * Sets the decimal format symbols used by this format. The - * format uses a copy of the provided symbols. - * @param newSymbols desired DecimalFormatSymbols - * @see DecimalFormatSymbols - * @stable ICU 2.0 - */ - public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) { - ((java.text.DecimalFormat)numberFormat).setDecimalFormatSymbols(newSymbols.dfs); - } - - - /** - * Get the positive prefix. - *

Examples: +123, $123, sFr123 - * @stable ICU 2.0 - */ - public String getPositivePrefix() { - return ((java.text.DecimalFormat)numberFormat).getPositivePrefix(); - } - - /** - * Set the positive prefix. - *

Examples: +123, $123, sFr123 - * @stable ICU 2.0 - */ - public void setPositivePrefix(String newValue) { - ((java.text.DecimalFormat)numberFormat).setPositivePrefix(newValue); - } - - /** - * Get the negative prefix. - *

Examples: -123, ($123) (with negative suffix), sFr-123 - * @stable ICU 2.0 - */ - public String getNegativePrefix () { - return ((java.text.DecimalFormat)numberFormat).getNegativePrefix(); - } - - /** - * Set the negative prefix. - *

Examples: -123, ($123) (with negative suffix), sFr-123 - * @stable ICU 2.0 - */ - public void setNegativePrefix (String newValue) { - ((java.text.DecimalFormat)numberFormat).setNegativePrefix(newValue); - } - - /** - * Get the positive suffix. - *

Example: 123% - * @stable ICU 2.0 - */ - public String getPositiveSuffix () { - return ((java.text.DecimalFormat)numberFormat).getPositiveSuffix(); - } - - /** - * Set the positive suffix. - *

Example: 123% - * @stable ICU 2.0 - */ - public void setPositiveSuffix (String newValue) { - ((java.text.DecimalFormat)numberFormat).setPositiveSuffix(newValue); - } - - /** - * Get the negative suffix. - *

Examples: -123%, ($123) (with positive suffixes) - * @stable ICU 2.0 - */ - public String getNegativeSuffix () { - return ((java.text.DecimalFormat)numberFormat).getNegativeSuffix(); - } - - /** - * Set the positive suffix. - *

Examples: 123% - * @stable ICU 2.0 - */ - public void setNegativeSuffix (String newValue) { - ((java.text.DecimalFormat)numberFormat).setNegativeSuffix(newValue); - } - - /** - * Get the multiplier for use in percent, permill, etc. - * For a percentage, set the suffixes to have "%" and the multiplier to be 100. - * (For Arabic, use arabic percent symbol). - * For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000. - *

Examples: with 100, 1.23 -> "123", and "123" -> 1.23 - * @stable ICU 2.0 - */ - public int getMultiplier () { - return ((java.text.DecimalFormat)numberFormat).getMultiplier(); - } - - /** - * Set the multiplier for use in percent, permill, etc. - * For a percentage, set the suffixes to have "%" and the multiplier to be 100. - * (For Arabic, use arabic percent symbol). - * For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000. - *

Examples: with 100, 1.23 -> "123", and "123" -> 1.23 - * @stable ICU 2.0 - */ - public void setMultiplier (int newValue) { - ((java.text.DecimalFormat)numberFormat).setMultiplier(newValue); - } - - /** - * Return the grouping size. Grouping size is the number of digits between - * grouping separators in the integer portion of a number. For example, - * in the number "123,456.78", the grouping size is 3. - * @see #setGroupingSize - * @see NumberFormat#isGroupingUsed - * @see DecimalFormatSymbols#getGroupingSeparator - * @stable ICU 2.0 - */ - public int getGroupingSize () { - return ((java.text.DecimalFormat)numberFormat).getGroupingSize(); - } - - /** - * Set the grouping size. Grouping size is the number of digits between - * grouping separators in the integer portion of a number. For example, - * in the number "123,456.78", the grouping size is 3. - * @see #getGroupingSize - * @see NumberFormat#setGroupingUsed - * @see DecimalFormatSymbols#setGroupingSeparator - * @stable ICU 2.0 - */ - public void setGroupingSize (int newValue) { - ((java.text.DecimalFormat)numberFormat).setGroupingSize(newValue); - } - - /** - * Allows you to get the behavior of the decimal separator with integers. - * (The decimal separator will always appear with decimals.) - *

Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 - * @stable ICU 2.0 - */ - public boolean isDecimalSeparatorAlwaysShown() { - return ((java.text.DecimalFormat)numberFormat).isDecimalSeparatorAlwaysShown(); - } - - /** - * Allows you to set the behavior of the decimal separator with integers. - * (The decimal separator will always appear with decimals.) - * - *

This only affects formatting, and only where - * there might be no digits after the decimal point, e.g., - * if true, 3456.00 -> "3,456." - * if false, 3456.00 -> "3456" - * This is independent of parsing. If you want parsing to stop at the decimal - * point, use setParseIntegerOnly. - * - *

Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345 - * @stable ICU 2.0 - */ - public void setDecimalSeparatorAlwaysShown(boolean newValue) { - ((java.text.DecimalFormat)numberFormat).setDecimalSeparatorAlwaysShown(newValue); - } - - /** - * Standard override; no change in semantics. - * @stable ICU 2.0 - */ - public Object clone() { - return new DecimalFormatSymbols((java.text.DecimalFormatSymbols)numberFormat.clone()); - } - - /** - * Synthesizes a pattern string that represents the current state - * of this Format object. - * @see #applyPattern - * @stable ICU 2.0 - */ - public String toPattern() { - return ((java.text.DecimalFormat)numberFormat).toPattern(); - } - - /** - * Synthesizes a localized pattern string that represents the current - * state of this Format object. - * @see #applyPattern - * @stable ICU 2.0 - */ - public String toLocalizedPattern() { - return ((java.text.DecimalFormat)numberFormat).toLocalizedPattern(); - } - - - /** - * Apply the given pattern to this Format object. A pattern is a - * short-hand specification for the various formatting properties. - * These properties can also be changed individually through the - * various setter methods. - *

- * There is no limit to integer digits are set - * by this routine, since that is the typical end-user desire; - * use setMaximumInteger if you want to set a real value. - * For negative numbers, use a second pattern, separated by a semicolon - *

Example "#,#00.0#" -> 1,234.56 - *

This means a minimum of 2 integer digits, 1 fraction digit, and - * a maximum of 2 fraction digits. - *

Example: "#,#00.0#;(#,#00.0#)" for negatives in parentheses. - *

In negative patterns, the minimum and maximum counts are ignored; - * these are presumed to be set in the positive pattern. - * @stable ICU 2.0 - */ - public void applyPattern(String pattern) { - ((java.text.DecimalFormat)numberFormat).applyPattern(pattern); - } - - /** - * Apply the given pattern to this Format object. The pattern - * is assumed to be in a localized notation. A pattern is a - * short-hand specification for the various formatting properties. - * These properties can also be changed individually through the - * various setter methods. - *

- * There is no limit to integer digits are set - * by this routine, since that is the typical end-user desire; - * use setMaximumInteger if you want to set a real value. - * For negative numbers, use a second pattern, separated by a semicolon - *

Example "#,#00.0#" -> 1,234.56 - *

This means a minimum of 2 integer digits, 1 fraction digit, and - * a maximum of 2 fraction digits. - *

Example: "#,#00.0#;(#,#00.0#)" for negatives in parentheses. - *

In negative patterns, the minimum and maximum counts are ignored; - * these are presumed to be set in the positive pattern. - * @stable ICU 2.0 - */ - public void applyLocalizedPattern(String pattern) { - ((java.text.DecimalFormat)numberFormat).applyLocalizedPattern(pattern); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormatSymbols.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormatSymbols.java deleted file mode 100644 index 0ccbe3bbde0..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormatSymbols.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - - -import java.io.Serializable; -import java.util.Locale; - -import com.ibm.icu.util.ULocale; - -/** - * This class represents the set of symbols (such as the decimal separator, the - * grouping separator, and so on) needed by DecimalFormat to format - * numbers. DecimalFormat creates for itself an instance of - * DecimalFormatSymbols from its locale data. If you need to - * change any of these symbols, you can get the - * DecimalFormatSymbols object from your DecimalFormat - * and modify it. - * - *

This is an enhanced version of DecimalFormatSymbols that - * is based on the standard version in the JDK. New or changed functionality - * is labeled - * NEW. - * - * @see java.util.Locale - * @see DecimalFormat - * @author Mark Davis - * @author Alan Liu - * @stable ICU 2.0 - */ -final public class DecimalFormatSymbols implements Cloneable, Serializable { - private static final long serialVersionUID =1L; - - /** - * @internal - */ - public final java.text.DecimalFormatSymbols dfs; - - /** - * @internal - */ - public DecimalFormatSymbols(java.text.DecimalFormatSymbols delegate) { - this.dfs = delegate; - } - - /** - * Create a DecimalFormatSymbols object for the default locale. - * @stable ICU 2.0 - */ - public DecimalFormatSymbols() { - this(new java.text.DecimalFormatSymbols()); - } - - /** - * Create a DecimalFormatSymbols object for the given locale. - * @param locale the locale - * @stable ICU 2.0 - */ - public DecimalFormatSymbols(Locale locale) { - this(new java.text.DecimalFormatSymbols(locale)); - } - - /** - * Create a DecimalFormatSymbols object for the given locale. - * @param locale the locale - * @stable ICU 3.2 - */ - public DecimalFormatSymbols(ULocale locale) { - this(new java.text.DecimalFormatSymbols(locale.toLocale())); - } - - /** - * Return the character used for zero. Different for Arabic, etc. - * @return the character - * @stable ICU 2.0 - */ - public char getZeroDigit() { - return dfs.getZeroDigit(); - } - - /** - * Set the character used for zero. - * @param zeroDigit the zero character. - * @stable ICU 2.0 - */ - public void setZeroDigit(char zeroDigit) { - dfs.setZeroDigit(zeroDigit); - } - - /** - * Return the character used for thousands separator. Different for French, etc. - * @return the thousands character - * @stable ICU 2.0 - */ - public char getGroupingSeparator() { - return dfs.getGroupingSeparator(); - } - - /** - * Set the character used for thousands separator. Different for French, etc. - * @param groupingSeparator the thousands character - * @stable ICU 2.0 - */ - public void setGroupingSeparator(char groupingSeparator) { - dfs.setGroupingSeparator(groupingSeparator); - } - - /** - * Return the character used for decimal sign. Different for French, etc. - * @return the decimal character - * @stable ICU 2.0 - */ - public char getDecimalSeparator() { - return dfs.getDecimalSeparator(); - } - - /** - * Set the character used for decimal sign. Different for French, etc. - * @param decimalSeparator the decimal character - * @stable ICU 2.0 - */ - public void setDecimalSeparator(char decimalSeparator) { - dfs.setDecimalSeparator(decimalSeparator); - } - - /** - * Return the character used for mille percent sign. Different for Arabic, etc. - * @return the mille percent character - * @stable ICU 2.0 - */ - public char getPerMill() { - return dfs.getPerMill(); - } - - /** - * Set the character used for mille percent sign. Different for Arabic, etc. - * @param perMill the mille percent character - * @stable ICU 2.0 - */ - public void setPerMill(char perMill) { - dfs.setPerMill(perMill); - } - - /** - * Return the character used for percent sign. Different for Arabic, etc. - * @return the percent character - * @stable ICU 2.0 - */ - public char getPercent() { - return dfs.getPercent(); - } - - /** - * Set the character used for percent sign. Different for Arabic, etc. - * @param percent the percent character - * @stable ICU 2.0 - */ - public void setPercent(char percent) { - dfs.setPercent(percent); - } - - /** - * Return the character used for a digit in a pattern. - * @return the digit pattern character - * @stable ICU 2.0 - */ - public char getDigit() { - return dfs.getDigit(); - } - - /** - * Set the character used for a digit in a pattern. - * @param digit the digit pattern character - * @stable ICU 2.0 - */ - public void setDigit(char digit) { - dfs.setDigit(digit); - } - - /** - * Return the character used to separate positive and negative subpatterns - * in a pattern. - * @return the pattern separator character - * @stable ICU 2.0 - */ - public char getPatternSeparator() { - return dfs.getPatternSeparator(); - } - - /** - * Set the character used to separate positive and negative subpatterns - * in a pattern. - * @param patternSeparator the pattern separator character - * @stable ICU 2.0 - */ - public void setPatternSeparator(char patternSeparator) { - dfs.setPatternSeparator(patternSeparator); - } - - /** - * Return the String used to represent infinity. Almost always left - * unchanged. - * @return the Infinity string - * @stable ICU 2.0 - */ - public String getInfinity() { - return dfs.getInfinity(); - } - - /** - * Set the String used to represent infinity. Almost always left - * unchanged. - * @param infinity the Infinity String - * @stable ICU 2.0 - */ - public void setInfinity(String infinity) { - dfs.setInfinity(infinity); - } - - /** - * Return the String used to represent NaN. Almost always left - * unchanged. - * @return the NaN String - * @stable ICU 2.0 - */ - public String getNaN() { - return dfs.getNaN(); - } - - /** - * Set the String used to represent NaN. Almost always left - * unchanged. - * @param NaN the NaN String - * @stable ICU 2.0 - */ - public void setNaN(String NaN) { - dfs.setNaN(NaN); - } - - /** - * Return the character used to represent minus sign. If no explicit - * negative format is specified, one is formed by prefixing - * minusSign to the positive format. - * @return the minus sign character - * @stable ICU 2.0 - */ - public char getMinusSign() { - return dfs.getMinusSign(); - } - - /** - * Set the character used to represent minus sign. If no explicit - * negative format is specified, one is formed by prefixing - * minusSign to the positive format. - * @param minusSign the minus sign character - * @stable ICU 2.0 - */ - public void setMinusSign(char minusSign) { - dfs.setMinusSign(minusSign); - } - - /** - * Return the string denoting the local currency. - * @return the local currency String. - * @stable ICU 2.0 - */ - public String getCurrencySymbol() { - return dfs.getCurrencySymbol(); - } - - /** - * Set the string denoting the local currency. - * @param currency the local currency String. - * @stable ICU 2.0 - */ - public void setCurrencySymbol(String currency) { - dfs.setCurrencySymbol(currency); - } - - /** - * Return the international string denoting the local currency. - * @return the international string denoting the local currency - * @stable ICU 2.0 - */ - public String getInternationalCurrencySymbol() { - return dfs.getInternationalCurrencySymbol(); - } - - /** - * Set the international string denoting the local currency. - * @param currency the international string denoting the local currency. - * @stable ICU 2.0 - */ - public void setInternationalCurrencySymbol(String currency) { - dfs.setInternationalCurrencySymbol(currency); - } - - /** - * Return the monetary decimal separator. - * @return the monetary decimal separator character - * @stable ICU 2.0 - */ - public char getMonetaryDecimalSeparator() { - return dfs.getMonetaryDecimalSeparator(); - } - - /** - * Set the monetary decimal separator. - * @param sep the monetary decimal separator character - * @stable ICU 2.0 - */ - public void setMonetaryDecimalSeparator(char sep) { - dfs.setMonetaryDecimalSeparator(sep); - } - - /** - * Standard override. - * @stable ICU 2.0 - */ - public Object clone() { - return new DecimalFormatSymbols((java.text.DecimalFormatSymbols)dfs.clone()); - } - - /** - * Override equals. - * @stable ICU 2.0 - */ - public boolean equals(Object obj) { - try { - return dfs.equals(((DecimalFormatSymbols)obj).dfs); - } - catch (Exception e) { - return false; - } - } - - /** - * Override hashCode - * @stable ICU 2.0 - */ - public int hashCode() { - return dfs.hashCode(); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/MessageFormat.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/MessageFormat.java deleted file mode 100644 index 67e6300e8d4..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/MessageFormat.java +++ /dev/null @@ -1,1042 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2004-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ -package com.ibm.icu.text; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.text.FieldPosition; -import java.text.Format; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Locale; - -import com.ibm.icu.util.ULocale; - -/** - * MessageFormat provides a means to produce concatenated - * messages in language-neutral way. Use this to construct messages - * displayed for end users. - * - *

- * MessageFormat takes a set of objects, formats them, then - * inserts the formatted strings into the pattern at the appropriate places. - * - *

- * Note: - * MessageFormat differs from the other Format - * classes in that you create a MessageFormat object with one - * of its constructors (not with a getInstance style factory - * method). The factory methods aren't necessary because MessageFormat - * itself doesn't implement locale specific behavior. Any locale specific - * behavior is defined by the pattern that you provide as well as the - * subformats used for inserted arguments. - * - *

Patterns and Their Interpretation

- * - * MessageFormat uses patterns of the following form: - *
- * MessageFormatPattern:
- *         String
- *         MessageFormatPattern FormatElement String
- *
- * FormatElement:
- *         { ArgumentIndex }
- *         { ArgumentIndex , FormatType }
- *         { ArgumentIndex , FormatType , FormatStyle }
- *
- * FormatType: one of 
- *         number date time choice
- *
- * FormatStyle:
- *         short
- *         medium
- *         long
- *         full
- *         integer
- *         currency
- *         percent
- *         SubformatPattern
- *
- * String:
- *         StringPartopt
- *         String StringPart
- *
- * StringPart:
- *         ''
- *         ' QuotedString '
- *         UnquotedString
- *
- * SubformatPattern:
- *         SubformatPatternPartopt
- *         SubformatPattern SubformatPatternPart
- *
- * SubFormatPatternPart:
- *         ' QuotedPattern '
- *         UnquotedPattern
- * 
- * - *

- * Within a String, "''" represents a single - * quote. A QuotedString can contain arbitrary characters - * except single quotes; the surrounding single quotes are removed. - * An UnquotedString can contain arbitrary characters - * except single quotes and left curly brackets. Thus, a string that - * should result in the formatted message "'{0}'" can be written as - * "'''{'0}''" or "'''{0}'''". - *

- * Within a SubformatPattern, different rules apply. - * A QuotedPattern can contain arbitrary characters - * except single quotes; but the surrounding single quotes are - * not removed, so they may be interpreted by the - * subformat. For example, "{1,number,$'#',##}" will - * produce a number format with the pound-sign quoted, with a result - * such as: "$#31,45". - * An UnquotedPattern can contain arbitrary characters - * except single quotes, but curly braces within it must be balanced. - * For example, "ab {0} de" and "ab '}' de" - * are valid subformat patterns, but "ab {0'}' de" and - * "ab } de" are not. - *

- *

Warning:
The rules for using quotes within message - * format patterns unfortunately have shown to be somewhat confusing. - * In particular, it isn't always obvious to localizers whether single - * quotes need to be doubled or not. Make sure to inform localizers about - * the rules, and tell them (for example, by using comments in resource - * bundle source files) which strings will be processed by MessageFormat. - * Note that localizers may need to use single quotes in translated - * strings where the original version doesn't have them. - *
Note also that the simplest way to avoid the problem is to - * use the real apostrophe (single quote) character \u2019 (') for - * human-readable text, and to use the ASCII apostrophe (\u0027 ' ) - * only in program syntax, like quoting in MessageFormat. - * See the annotations for U+0027 Apostrophe in The Unicode Standard.

- *
- *

- * The ArgumentIndex value is a non-negative integer written - * using the digits '0' through '9', and represents an index into the - * arguments array passed to the format methods - * or the result array returned by the parse methods. - *

- * The FormatType and FormatStyle values are used to create - * a Format instance for the format element. The following - * table shows how the values map to Format instances. Combinations not - * shown in the table are illegal. A SubformatPattern must - * be a valid pattern string for the Format subclass used. - *

- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
Format Type - * Format Style - * Subformat Created - *
(none) - * null - *
number - * (none) - * NumberFormat.getInstance(getLocale()) - *
integer - * NumberFormat.getIntegerInstance(getLocale()) - *
currency - * NumberFormat.getCurrencyInstance(getLocale()) - *
percent - * NumberFormat.getPercentInstance(getLocale()) - *
SubformatPattern - * new DecimalFormat(subformatPattern, new DecimalFormatSymbols(getLocale())) - *
date - * (none) - * DateFormat.getDateInstance(DateFormat.DEFAULT, getLocale()) - *
short - * DateFormat.getDateInstance(DateFormat.SHORT, getLocale()) - *
medium - * DateFormat.getDateInstance(DateFormat.DEFAULT, getLocale()) - *
long - * DateFormat.getDateInstance(DateFormat.LONG, getLocale()) - *
full - * DateFormat.getDateInstance(DateFormat.FULL, getLocale()) - *
SubformatPattern - * new SimpleDateFormat(subformatPattern, getLocale()) - *
time - * (none) - * DateFormat.getTimeInstance(DateFormat.DEFAULT, getLocale()) - *
short - * DateFormat.getTimeInstance(DateFormat.SHORT, getLocale()) - *
medium - * DateFormat.getTimeInstance(DateFormat.DEFAULT, getLocale()) - *
long - * DateFormat.getTimeInstance(DateFormat.LONG, getLocale()) - *
full - * DateFormat.getTimeInstance(DateFormat.FULL, getLocale()) - *
SubformatPattern - * new SimpleDateFormat(subformatPattern, getLocale()) - *
choice - * SubformatPattern - * new ChoiceFormat(subformatPattern) - *
- *

- * - *

Usage Information

- * - *

- * Here are some examples of usage: - *

- *
- * Object[] arguments = {
- *     new Integer(7),
- *     new Date(System.currentTimeMillis()),
- *     "a disturbance in the Force"
- * };
- *
- * String result = MessageFormat.format(
- *     "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
- *     arguments);
- *
- * output: At 12:30 PM on Jul 3, 2053, there was a disturbance
- *           in the Force on planet 7.
- *
- * 
- *
- * Typically, the message format will come from resources, and the - * arguments will be dynamically set at runtime. - * - *

- * Example 2: - *

- *
- * Object[] testArgs = {new Long(3), "MyDisk"};
- *
- * MessageFormat form = new MessageFormat(
- *     "The disk \"{1}\" contains {0} file(s).");
- *
- * System.out.println(form.format(testArgs));
- *
- * // output, with different testArgs
- * output: The disk "MyDisk" contains 0 file(s).
- * output: The disk "MyDisk" contains 1 file(s).
- * output: The disk "MyDisk" contains 1,273 file(s).
- * 
- *
- * - *

- * For more sophisticated patterns, you can use a ChoiceFormat to get - * output such as: - *

- *
- * MessageFormat form = new MessageFormat("The disk \"{1}\" contains {0}.");
- * double[] filelimits = {0,1,2};
- * String[] filepart = {"no files","one file","{0,number} files"};
- * ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
- * form.setFormatByArgumentIndex(0, fileform);
- *
- * Object[] testArgs = {new Long(12373), "MyDisk"};
- *
- * System.out.println(form.format(testArgs));
- *
- * // output, with different testArgs
- * output: The disk "MyDisk" contains no files.
- * output: The disk "MyDisk" contains one file.
- * output: The disk "MyDisk" contains 1,273 files.
- * 
- *
- * You can either do this programmatically, as in the above example, - * or by using a pattern (see - * {@link ChoiceFormat} - * for more information) as in: - *
- *
- * form.applyPattern(
- *    "There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.");
- * 
- *
- *

- * Note: As we see above, the string produced - * by a ChoiceFormat in MessageFormat is treated specially; - * occurances of '{' are used to indicated subformats, and cause recursion. - * If you create both a MessageFormat and ChoiceFormat - * programmatically (instead of using the string patterns), then be careful not to - * produce a format that recurses on itself, which will cause an infinite loop. - *

- * When a single argument is parsed more than once in the string, the last match - * will be the final result of the parsing. For example, - *

- * MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}");
- * Object[] objs = {new Double(3.1415)};
- * String result = mf.format( objs );
- * // result now equals "3.14, 3.1"
- * objs = null;
- * objs = mf.parse(result, new ParsePosition(0));
- * // objs now equals {new Double(3.1)}
- * 
- *

- * Likewise, parsing with a MessageFormat object using patterns containing - * multiple occurances of the same argument would return the last match. For - * example, - *

- * MessageFormat mf = new MessageFormat("{0}, {0}, {0}");
- * String forParsing = "x, y, z";
- * Object[] objs = mf.parse(forParsing, new ParsePosition(0));
- * // result now equals {new String("z")}
- * 
- * - *

Synchronization

- * - *

- * Message formats are not synchronized. - * It is recommended to create separate format instances for each thread. - * If multiple threads access a format concurrently, it must be synchronized - * externally. - * - * @see java.util.Locale - * @see Format - * @see NumberFormat - * @see DecimalFormat - * @see ChoiceFormat - * @author Mark Davis - * @stable ICU 3.0 - */ -public class MessageFormat extends Format { - static final long serialVersionUID = 1L; - - /** - * @internal - */ - public final java.text.MessageFormat messageFormat; - - /** - * @internal - * @param delegate the DateFormat to which to delegate - */ - public MessageFormat(java.text.MessageFormat delegate) { - this.messageFormat = delegate; - } - - /** - * Constructs a MessageFormat for the default locale and the - * specified pattern. - * The constructor first sets the locale, then parses the pattern and - * creates a list of subformats for the format elements contained in it. - * Patterns and their interpretation are specified in the - * class description. - * - * @param pattern the pattern for this message format - * @exception IllegalArgumentException if the pattern is invalid - * @stable ICU 3.0 - */ - public MessageFormat(String pattern) { - this(new java.text.MessageFormat(pattern)); - } - - /** - * Constructs a MessageFormat for the specified locale and - * pattern. - * The constructor first sets the locale, then parses the pattern and - * creates a list of subformats for the format elements contained in it. - * Patterns and their interpretation are specified in the - * class description. - * - * @param pattern the pattern for this message format - * @param locale the locale for this message format - * @exception IllegalArgumentException if the pattern is invalid - * @stable ICU 3.0 - */ - public MessageFormat(String pattern, Locale locale) { - // locale is ignored - this(new java.text.MessageFormat(pattern)); - } - - /** - * Constructs a MessageFormat for the specified locale and - * pattern. - * The constructor first sets the locale, then parses the pattern and - * creates a list of subformats for the format elements contained in it. - * Patterns and their interpretation are specified in the - * class description. - * - * @param pattern the pattern for this message format - * @param locale the locale for this message format - * @exception IllegalArgumentException if the pattern is invalid - * @stable ICU 3.2 - */ - public MessageFormat(String pattern, ULocale locale) { - // locale is ignored - this(pattern); - } - - /** - * Sets the locale to be used when creating or comparing subformats. - * This affects subsequent calls to the {@link #applyPattern applyPattern} - * and {@link #toPattern toPattern} methods as well as to the - * format and - * {@link #formatToCharacterIterator formatToCharacterIterator} methods. - * - * @param locale the locale to be used when creating or comparing subformats - * @stable ICU 3.0 - */ - public void setLocale(Locale locale) { - messageFormat.setLocale(locale); - } - - /** - * Sets the locale to be used when creating or comparing subformats. - * This affects subsequent calls to the {@link #applyPattern applyPattern} - * and {@link #toPattern toPattern} methods as well as to the - * format and - * {@link #formatToCharacterIterator formatToCharacterIterator} methods. - * - * @param locale the locale to be used when creating or comparing subformats - * @stable ICU 3.2 - */ - public void setLocale(ULocale locale) { - messageFormat.setLocale(locale.toLocale()); - } - - /** - * Gets the locale that's used when creating or comparing subformats. - * - * @return the locale used when creating or comparing subformats - * @stable ICU 3.0 - */ - public Locale getLocale() { - return messageFormat.getLocale(); - } - - /** - * Gets the locale that's used when creating or comparing subformats. - * - * @return the locale used when creating or comparing subformats - * @stable ICU 3.2 - */ - public ULocale getULocale() { - return ULocale.forLocale(messageFormat.getLocale()); - } - - /** - * Sets the pattern used by this message format. - * The method parses the pattern and creates a list of subformats - * for the format elements contained in it. - * Patterns and their interpretation are specified in the - * class description. - * - * @param pattern the pattern for this message format - * @exception IllegalArgumentException if the pattern is invalid - * @stable ICU 3.0 - */ - public void applyPattern(String pattern) { - messageFormat.applyPattern(pattern); - } - - /** - * Returns a pattern representing the current state of the message format. - * The string is constructed from internal information and therefore - * does not necessarily equal the previously applied pattern. - * - * @return a pattern representing the current state of the message format - * @stable ICU 3.0 - */ - public String toPattern() { - return messageFormat.toPattern(); - } - - /** - * Sets the formats to use for the values passed into - * format methods or returned from parse - * methods. The indices of elements in newFormats - * correspond to the argument indices used in the previously set - * pattern string. - * The order of formats in newFormats thus corresponds to - * the order of elements in the arguments array passed - * to the format methods or the result array returned - * by the parse methods. - *

- * If an argument index is used for more than one format element - * in the pattern string, then the corresponding new format is used - * for all such format elements. If an argument index is not used - * for any format element in the pattern string, then the - * corresponding new format is ignored. If fewer formats are provided - * than needed, then only the formats for argument indices less - * than newFormats.length are replaced. - * - * @param newFormats the new formats to use - * @exception NullPointerException if newFormats is null - * @stable ICU 3.0 - * @throws UnsupportedOperationException if the underlying JVM does not - * support this method. - */ - public void setFormatsByArgumentIndex(Format[] newFormats) { - if (sfsbai == null) { - synchronized (missing) { - try { - Class[] params = { Format[].class }; - sfsbai = java.text.MessageFormat.class.getMethod("setFormatsByArgumentIndex", params); - } - catch (NoSuchMethodException e) { - sfsbai = missing; - } - } - } - if (sfsbai != missing) { - try { - Format[] unwrapped = new Format[newFormats.length]; - for (int i = 0; i < newFormats.length; ++i) { - unwrapped[i] = unwrap(newFormats[i]); - } - Object[] args = { unwrapped }; - ((Method)sfsbai).invoke(messageFormat, args); - return; - } - catch (IllegalAccessException e) { - // can't happen - } - catch (InvocationTargetException e) { - // can't happen - } - } - throw new UnsupportedOperationException(); - } - private static Object sfsbai; - - /** - * Sets the formats to use for the format elements in the - * previously set pattern string. - * The order of formats in newFormats corresponds to - * the order of format elements in the pattern string. - *

- * If more formats are provided than needed by the pattern string, - * the remaining ones are ignored. If fewer formats are provided - * than needed, then only the first newFormats.length - * formats are replaced. - *

- * Since the order of format elements in a pattern string often - * changes during localization, it is generally better to use the - * {@link #setFormatsByArgumentIndex setFormatsByArgumentIndex} - * method, which assumes an order of formats corresponding to the - * order of elements in the arguments array passed to - * the format methods or the result array returned by - * the parse methods. - * - * @param newFormats the new formats to use - * @exception NullPointerException if newFormats is null - * @stable ICU 3.0 - */ - public void setFormats(Format[] newFormats) { - messageFormat.setFormats(newFormats); - } - - /** - * Sets the format to use for the format elements within the - * previously set pattern string that use the given argument - * index. - * The argument index is part of the format element definition and - * represents an index into the arguments array passed - * to the format methods or the result array returned - * by the parse methods. - *

- * If the argument index is used for more than one format element - * in the pattern string, then the new format is used for all such - * format elements. If the argument index is not used for any format - * element in the pattern string, then the new format is ignored. - * - * @param argumentIndex the argument index for which to use the new format - * @param newFormat the new format to use - * @stable ICU 3.0 - * @throws UnsupportedOperationException if the underlying JVM does not - * support this method. - */ - public void setFormatByArgumentIndex(int argumentIndex, Format newFormat) { - if (sfbai == null) { - synchronized (missing) { - try { - Class[] params = { Integer.TYPE, Format.class }; - sfbai = java.text.MessageFormat.class.getMethod("setFormatByArgumentIndex", params); - } - catch (NoSuchMethodException e) { - sfbai = missing; - } - } - } - if (sfbai != missing) { - try { - Object[] args = { new Integer(argumentIndex), newFormat }; - ((Method)sfbai).invoke(messageFormat, args); - return; - } - catch (IllegalAccessException e) { - // can't happen - } - catch (InvocationTargetException e) { - // can't happen - } - } - throw new UnsupportedOperationException(); - } - private static Object sfbai; - - /** - * Sets the format to use for the format element with the given - * format element index within the previously set pattern string. - * The format element index is the zero-based number of the format - * element counting from the start of the pattern string. - *

- * Since the order of format elements in a pattern string often - * changes during localization, it is generally better to use the - * {@link #setFormatByArgumentIndex setFormatByArgumentIndex} - * method, which accesses format elements based on the argument - * index they specify. - * - * @param formatElementIndex the index of a format element within the pattern - * @param newFormat the format to use for the specified format element - * @exception ArrayIndexOutOfBoundsException if formatElementIndex is equal to or - * larger than the number of format elements in the pattern string - * @stable ICU 3.0 - */ - public void setFormat(int formatElementIndex, Format newFormat) { - messageFormat.setFormat(formatElementIndex, unwrap(newFormat)); - } - - /** - * Gets the formats used for the values passed into - * format methods or returned from parse - * methods. The indices of elements in the returned array - * correspond to the argument indices used in the previously set - * pattern string. - * The order of formats in the returned array thus corresponds to - * the order of elements in the arguments array passed - * to the format methods or the result array returned - * by the parse methods. - *

- * If an argument index is used for more than one format element - * in the pattern string, then the format used for the last such - * format element is returned in the array. If an argument index - * is not used for any format element in the pattern string, then - * null is returned in the array. - * - * @return the formats used for the arguments within the pattern - * @stable ICU 3.0 - * @throws UnsupportedOperationException if the underlying JVM does not - * support this method. - */ - public Format[] getFormatsByArgumentIndex() { - if (gfbai == null) { - synchronized (missing) { - try { - gfbai = java.text.MessageFormat.class.getMethod("getFormatsByArgumentIndex", null); - } - catch (NoSuchMethodException e) { - gfbai = missing; - } - } - } - if (gfbai != missing) { - try { - Format[] result = (Format[])((Method)gfbai).invoke(messageFormat, null); - for (int i = 0; i < result.length; ++i) { - result[i] = wrap(result[i]); - } - return result; - } - catch (IllegalAccessException e) { - // can't happen - } - catch (InvocationTargetException e) { - // can't happen - } - } - throw new UnsupportedOperationException(); - } - private static Object gfbai; - private static final Object missing = new Object(); - - /** - * Gets the formats used for the format elements in the - * previously set pattern string. - * The order of formats in the returned array corresponds to - * the order of format elements in the pattern string. - *

- * Since the order of format elements in a pattern string often - * changes during localization, it's generally better to use the - * {@link #getFormatsByArgumentIndex getFormatsByArgumentIndex} - * method, which assumes an order of formats corresponding to the - * order of elements in the arguments array passed to - * the format methods or the result array returned by - * the parse methods. - * - * @return the formats used for the format elements in the pattern - * @stable ICU 3.0 - */ - public Format[] getFormats() { - Format[] result = messageFormat.getFormats(); - for (int i = 0; i < result.length; ++i) { - result[i] = wrap(result[i]); - } - return result; - } - - /** - * Formats an array of objects and appends the MessageFormat's - * pattern, with format elements replaced by the formatted objects, to the - * provided StringBuffer. - *

- * The text substituted for the individual format elements is derived from - * the current subformat of the format element and the - * arguments element at the format element's argument index - * as indicated by the first matching line of the following table. An - * argument is unavailable if arguments is - * null or has fewer than argumentIndex+1 elements. - *

- * - * - * - * - * - * - * - * - * - * - *
Subformat - * Argument - * Formatted Text - *
any - * unavailable - * "{" + argumentIndex + "}" - *
any - * null - * "null" - *
instanceof ChoiceFormat - * any - * subformat.format(argument).indexOf('{') >= 0 ?
- * (new MessageFormat(subformat.format(argument), getLocale())).format(argument) : - * subformat.format(argument)
- *
!= null - * any - * subformat.format(argument) - *
null - * instanceof Number - * NumberFormat.getInstance(getLocale()).format(argument) - *
null - * instanceof Date - * DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()).format(argument) - *
null - * instanceof String - * argument - *
null - * any - * argument.toString() - *
- *

- * If pos is non-null, and refers to - * Field.ARGUMENT, the location of the first formatted - * string will be returned. - * - * @param arguments an array of objects to be formatted and substituted. - * @param result where text is appended. - * @param pos On input: an alignment field, if desired. - * On output: the offsets of the alignment field. - * @exception IllegalArgumentException if an argument in the - * arguments array is not of the type - * expected by the format element(s) that use it. - * @stable ICU 3.0 - */ - public final StringBuffer format(Object[] arguments, StringBuffer result, - FieldPosition pos) - { - return messageFormat.format(arguments, result, pos); - } - - /** - * Creates a MessageFormat with the given pattern and uses it - * to format the given arguments. This is equivalent to - *

- * (new {@link #MessageFormat(String) MessageFormat}(pattern)).{@link #format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) format}(arguments, new StringBuffer(), null).toString() - *
- * - * @exception IllegalArgumentException if the pattern is invalid, - * or if an argument in the arguments array - * is not of the type expected by the format element(s) - * that use it. - * @stable ICU 3.0 - */ - public static String format(String pattern, Object[] arguments) { - return java.text.MessageFormat.format(pattern, arguments); - } - - // Overrides - /** - * Formats an array of objects and appends the MessageFormat's - * pattern, with format elements replaced by the formatted objects, to the - * provided StringBuffer. - * This is equivalent to - *
- * {@link #format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) format}((Object[]) arguments, result, pos) - *
- * - * @param arguments an array of objects to be formatted and substituted. - * @param result where text is appended. - * @param pos On input: an alignment field, if desired. - * On output: the offsets of the alignment field. - * @exception IllegalArgumentException if an argument in the - * arguments array is not of the type - * expected by the format element(s) that use it. - * @stable ICU 3.0 - */ - public final StringBuffer format(Object arguments, StringBuffer result, - FieldPosition pos) - { - return messageFormat.format(arguments, result, pos); - } - - - /** - * Parses the string. - * - *

Caveats: The parse may fail in a number of circumstances. - * For example: - *

    - *
  • If one of the arguments does not occur in the pattern. - *
  • If the format of an argument loses information, such as - * with a choice format where a large number formats to "many". - *
  • Does not yet handle recursion (where - * the substituted strings contain {n} references.) - *
  • Will not always find a match (or the correct match) - * if some part of the parse is ambiguous. - * For example, if the pattern "{1},{2}" is used with the - * string arguments {"a,b", "c"}, it will format as "a,b,c". - * When the result is parsed, it will return {"a", "b,c"}. - *
  • If a single argument is parsed more than once in the string, - * then the later parse wins. - *
- * When the parse fails, use ParsePosition.getErrorIndex() to find out - * where in the string did the parsing failed. The returned error - * index is the starting offset of the sub-patterns that the string - * is comparing with. For example, if the parsing string "AAA {0} BBB" - * is comparing against the pattern "AAD {0} BBB", the error index is - * 0. When an error occurs, the call to this method will return null. - * If the source is null, return an empty array. - * @stable ICU 3.0 - */ - public Object[] parse(String source, ParsePosition pos) { - return messageFormat.parse(source, pos); - } - - /** - * Parses text from the beginning of the given string to produce an object - * array. - * The method may not use the entire text of the given string. - *

- * See the {@link #parse(String, ParsePosition)} method for more information - * on message parsing. - * - * @param source A String whose beginning should be parsed. - * @return An Object array parsed from the string. - * @exception ParseException if the beginning of the specified string - * cannot be parsed. - * @stable ICU 3.0 - */ - public Object[] parse(String source) throws ParseException { - return messageFormat.parse(source); - } - - /** - * Parses text from a string to produce an object array. - *

- * The method attempts to parse text starting at the index given by - * pos. - * If parsing succeeds, then the index of pos is updated - * to the index after the last character used (parsing does not necessarily - * use all characters up to the end of the string), and the parsed - * object array is returned. The updated pos can be used to - * indicate the starting point for the next call to this method. - * If an error occurs, then the index of pos is not - * changed, the error index of pos is set to the index of - * the character where the error occurred, and null is returned. - *

- * See the {@link #parse(String, ParsePosition)} method for more information - * on message parsing. - * - * @param source A String, part of which should be parsed. - * @param pos A ParsePosition object with index and error - * index information as described above. - * @return An Object array parsed from the string. In case of - * error, returns null. - * @exception NullPointerException if pos is null. - * @stable ICU 3.0 - */ - public Object parseObject(String source, ParsePosition pos) { - return messageFormat.parse(source, pos); - } - - /** - * Convert an 'apostrophe-friendly' pattern into a standard - * pattern. Standard patterns treat all apostrophes as - * quotes, which is problematic in some languages, e.g. - * French, where apostrophe is commonly used. This utility - * assumes that only an unpaired apostrophe immediately before - * a brace is a true quote. Other unpaired apostrophes are paired, - * and the resulting standard pattern string is returned. - * - *

Note it is not guaranteed that the returned pattern - * is indeed a valid pattern. The only effect is to convert - * between patterns having different quoting semantics. - * - * @param pattern the 'apostrophe-friendly' patttern to convert - * @return the standard equivalent of the original pattern - * @stable ICU 3.4 - */ - public static String autoQuoteApostrophe(String pattern) { - StringBuffer buf = new StringBuffer(pattern.length()*2); - int state = STATE_INITIAL; - int braceCount = 0; - for (int i = 0, j = pattern.length(); i < j; ++i) { - char c = pattern.charAt(i); - switch (state) { - case STATE_INITIAL: - switch (c) { - case SINGLE_QUOTE: - state = STATE_SINGLE_QUOTE; - break; - case CURLY_BRACE_LEFT: - state = STATE_MSG_ELEMENT; - ++braceCount; - break; - } - break; - case STATE_SINGLE_QUOTE: - switch (c) { - case SINGLE_QUOTE: - state = STATE_INITIAL; - break; - case CURLY_BRACE_LEFT: - case CURLY_BRACE_RIGHT: - state = STATE_IN_QUOTE; - break; - default: - buf.append(SINGLE_QUOTE); - state = STATE_INITIAL; - break; - } - break; - case STATE_IN_QUOTE: - switch (c) { - case SINGLE_QUOTE: - state = STATE_INITIAL; - break; - } - break; - case STATE_MSG_ELEMENT: - switch (c) { - case CURLY_BRACE_LEFT: - ++braceCount; - break; - case CURLY_BRACE_RIGHT: - if (--braceCount == 0) { - state = STATE_INITIAL; - } - break; - } - break; - default: // Never happens. - break; - } - buf.append(c); - } - // End of scan - if (state == STATE_SINGLE_QUOTE || state == STATE_IN_QUOTE) { - buf.append(SINGLE_QUOTE); - } - return new String(buf); - } - - /** - * Creates and returns a copy of this object. - * - * @return a clone of this instance. - * @stable ICU 3.0 - */ - public Object clone() { - return new MessageFormat((java.text.MessageFormat)messageFormat.clone()); - } - - /** - * Equality comparison between two message format objects - * @stable ICU 3.0 - */ - public boolean equals(Object obj) { - try { - return messageFormat.equals(((MessageFormat)obj).messageFormat); - } - catch (Exception e) { - return false; - } - } - - /** - * Generates a hash code for the message format object. - * @stable ICU 3.0 - */ - public int hashCode() { - return messageFormat.hashCode(); - } - - /** - * Return a string suitable for debugging. - * @return a string suitable for debugging - * @stable ICU 3.4.2 - */ - public String toString() { - return messageFormat.toPattern(); - } - - private static Format unwrap(Format f) { - if (f instanceof DateFormat) { - return ((DateFormat)f).dateFormat; - } else if (f instanceof NumberFormat) { - return ((NumberFormat)f).numberFormat; - } else if (f instanceof MessageFormat) { - return ((MessageFormat)f).messageFormat; - } else { - return f; - } - } - - private static Format wrap(Format f) { - if (f instanceof java.text.DateFormat) { - return new DateFormat((java.text.DateFormat)f); - } else if (f instanceof java.text.DecimalFormat) { - return new DecimalFormat((java.text.DecimalFormat)f); - } else if (f instanceof java.text.MessageFormat) { - return new MessageFormat((java.text.MessageFormat)f); - } else { - return f; - } - } - - private static final char SINGLE_QUOTE = '\''; - private static final char CURLY_BRACE_LEFT = '{'; - private static final char CURLY_BRACE_RIGHT = '}'; - - private static final int STATE_INITIAL = 0; - private static final int STATE_SINGLE_QUOTE = 1; - private static final int STATE_IN_QUOTE = 2; - private static final int STATE_MSG_ELEMENT = 3; -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/NumberFormat.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/NumberFormat.java deleted file mode 100644 index f825a943b76..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/NumberFormat.java +++ /dev/null @@ -1,778 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - - -package com.ibm.icu.text; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.math.BigInteger; -import java.text.DecimalFormatSymbols; -import java.text.FieldPosition; -import java.text.Format; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Locale; - -import com.ibm.icu.util.ULocale; - -/** - * NumberFormat is the abstract base class for all number - * formats. This class provides the interface for formatting and parsing - * numbers. NumberFormat also provides methods for determining - * which locales have number formats, and what their names are. - * - *

This is an enhanced version of NumberFormat that - * is based on the standard version in the JDK. New or changed functionality - * is labeled - * NEW or - * CHANGED. - * - *

- * NumberFormat helps you to format and parse numbers for any locale. - * Your code can be completely independent of the locale conventions for - * decimal points, thousands-separators, or even the particular decimal - * digits used, or whether the number format is even decimal. - * - *

- * To format a number for the current Locale, use one of the factory - * class methods: - *

- *
- *  myString = NumberFormat.getInstance().format(myNumber);
- * 
- *
- * If you are formatting multiple numbers, it is - * more efficient to get the format and use it multiple times so that - * the system doesn't have to fetch the information about the local - * language and country conventions multiple times. - *
- *
- * NumberFormat nf = NumberFormat.getInstance();
- * for (int i = 0; i < a.length; ++i) {
- *     output.println(nf.format(myNumber[i]) + "; ");
- * }
- * 
- *
- * To format a number for a different Locale, specify it in the - * call to getInstance. - *
- *
- * NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
- * 
- *
- * You can also use a NumberFormat to parse numbers: - *
- *
- * myNumber = nf.parse(myString);
- * 
- *
- * Use getInstance or getNumberInstance to get the - * normal number format. Use getIntegerInstance to get an - * integer number format. Use getCurrencyInstance to get the - * currency number format. And use getPercentInstance to get a - * format for displaying percentages. With this format, a fraction like - * 0.53 is displayed as 53%. - * - *

- * You can also control the display of numbers with such methods as - * setMinimumFractionDigits. - * If you want even more control over the format or parsing, - * or want to give your users more control, - * you can try casting the NumberFormat you get from the factory methods - * to a DecimalFormat. This will work for the vast majority - * of locales; just remember to put it in a try block in case you - * encounter an unusual one. - * - *

- * NumberFormat is designed such that some controls - * work for formatting and others work for parsing. The following is - * the detailed description for each these control methods, - *

- * setParseIntegerOnly : only affects parsing, e.g. - * if true, "3456.78" -> 3456 (and leaves the parse position just after '6') - * if false, "3456.78" -> 3456.78 (and leaves the parse position just after '8') - * This is independent of formatting. If you want to not show a decimal point - * where there might be no digits after the decimal point, use - * setDecimalSeparatorAlwaysShown on DecimalFormat. - *

- * You can also use forms of the parse and format - * methods with ParsePosition and FieldPosition to - * allow you to: - *

    - *
  • progressively parse through pieces of a string - *
  • align the decimal point and other areas - *
- * For example, you can align numbers in two ways: - *
    - *
  1. If you are using a monospaced font with spacing for alignment, - * you can pass the FieldPosition in your format call, with - * field = INTEGER_FIELD. On output, - * getEndIndex will be set to the offset between the - * last character of the integer and the decimal. Add - * (desiredSpaceCount - getEndIndex) spaces at the front of the string. - * - *
  2. If you are using proportional fonts, - * instead of padding with spaces, measure the width - * of the string in pixels from the start to getEndIndex. - * Then move the pen by - * (desiredPixelWidth - widthToAlignmentPoint) before drawing the text. - * It also works where there is no decimal, but possibly additional - * characters at the end, e.g., with parentheses in negative - * numbers: "(12)" for -12. - *
- * - *

Synchronization

- *

- * Number formats are generally not synchronized. It is recommended to create - * separate format instances for each thread. If multiple threads access a format - * concurrently, it must be synchronized externally. - *

- * - *

DecimalFormat

- *

DecimalFormat is the concrete implementation of NumberFormat, and the - * NumberFormat API is essentially an abstraction from DecimalFormat's API. - * Refer to DecimalFormat for more information about this API.

- * - * see DecimalFormat - * see java.text.ChoiceFormat - * @author Mark Davis - * @author Helena Shih - * @author Alan Liu - * @stable ICU 2.0 - */ -public class NumberFormat extends Format { - private static final long serialVersionUID = 1; - - /** - * @internal - */ - public final java.text.NumberFormat numberFormat; - - /** - * @internal - * @param delegate the NumberFormat to which to delegate - */ - public NumberFormat(java.text.NumberFormat delegate) { - this.numberFormat = delegate; - } - - /** - * Default constructor to mirror Java's default public - * constructor. Java's is not callable as a public API, since - * their NumberFormat is abstract, so this is only useful to - * subclasses. In general, subclasses will not work unless - * they manipulate the delegate. - */ - public NumberFormat() { - this.numberFormat = java.text.NumberFormat.getInstance(); - } - - /** - * Field constant used to construct a FieldPosition object. Signifies that - * the position of the integer part of a formatted number should be returned. - * @see java.text.FieldPosition - * @stable ICU 2.0 - */ - public static final int INTEGER_FIELD = 0; - - /** - * Field constant used to construct a FieldPosition object. Signifies that - * the position of the fraction part of a formatted number should be returned. - * @see java.text.FieldPosition - * @stable ICU 2.0 - */ - public static final int FRACTION_FIELD = 1; - - /** - * CHANGED - * Format an object. Change: recognizes BigInteger - * and BigDecimal objects. - * @stable ICU 2.0 - */ - public StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos) { - return numberFormat.format(number, toAppendTo, pos); - } - - /** - * @stable ICU 2.0 - */ - public final Object parseObject(String source, ParsePosition parsePosition) { - return numberFormat.parse(source, parsePosition); - } - - /** - * Specialization of format. - * @see java.text.Format#format(Object) - * @stable ICU 2.0 - */ - public final String format(double number) { - return numberFormat.format(number); - } - - /** - * Specialization of format. - * @see java.text.Format#format(Object) - * @stable ICU 2.0 - */ - public final String format(long number) { - return numberFormat.format(number); - } - - /** - * NEW - * Convenience method to format a BigInteger. - * @stable ICU 2.0 - */ - public final String format(BigInteger number) { - return numberFormat.format(number); - } - - /** - * Specialization of format. - * @see java.text.Format#format(Object, StringBuffer, FieldPosition) - * @stable ICU 2.0 - */ - public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { - return numberFormat.format(number, toAppendTo, pos); - } - - /** - * Specialization of format. - * @see java.text.Format#format(Object, StringBuffer, FieldPosition) - * @stable ICU 2.0 - */ - public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { - return numberFormat.format(number, toAppendTo, pos); - } - - /** - * NEW - * Format a BigInteger. - * @see java.text.Format#format(Object, StringBuffer, FieldPosition) - * @stable ICU 2.0 - */ - public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) { - return numberFormat.format(number, toAppendTo, pos); - } - /** - * Returns a Long if possible (e.g., within the range [Long.MIN_VALUE, - * Long.MAX_VALUE] and with no decimals), otherwise a Double. - * If IntegerOnly is set, will stop at a decimal - * point (or equivalent; e.g., for rational numbers "1 2/3", will stop - * after the 1). - * Does not throw an exception; if no object can be parsed, index is - * unchanged! - * @see #isParseIntegerOnly - * @see java.text.Format#parseObject(String, ParsePosition) - * @stable ICU 2.0 - */ - public Number parse(String text, ParsePosition parsePosition) { - return numberFormat.parse(text, parsePosition); - } - - /** - * Parses text from the beginning of the given string to produce a number. - * The method might not use the entire text of the given string. - * - * @param text A String whose beginning should be parsed. - * @return A Number parsed from the string. - * @exception ParseException if the beginning of the specified string - * cannot be parsed. - * @see #format - * @stable ICU 2.0 - */ - public Number parse(String text) throws ParseException { - return numberFormat.parse(text); - } - /** - * Returns true if this format will parse numbers as integers only. - * For example in the English locale, with ParseIntegerOnly true, the - * string "1234." would be parsed as the integer value 1234 and parsing - * would stop at the "." character. The decimal separator accepted - * by the parse operation is locale-dependent and determined by the - * subclass. - * @return true if this will parse integers only - * @stable ICU 2.0 - */ - public boolean isParseIntegerOnly() { - return numberFormat.isParseIntegerOnly(); - } - - /** - * Sets whether or not numbers should be parsed as integers only. - * @param value true if this should parse integers only - * @see #isParseIntegerOnly - * @stable ICU 2.0 - */ - public void setParseIntegerOnly(boolean value) { - numberFormat.setParseIntegerOnly(value); - } - - //============== Locale Stuff ===================== - - /** - * Returns the default number format for the current default locale. - * The default format is one of the styles provided by the other - * factory methods: getNumberInstance, getIntegerInstance, - * getCurrencyInstance or getPercentInstance. - * Exactly which one is locale-dependent. - * @stable ICU 2.0 - */ - public final static NumberFormat getInstance() { - return getInstance(ULocale.getDefault(), NUMBERSTYLE); - } - - /** - * Returns the default number format for the specified locale. - * The default format is one of the styles provided by the other - * factory methods: getNumberInstance, getCurrencyInstance or getPercentInstance. - * Exactly which one is locale-dependent. - * @stable ICU 2.0 - */ - public static NumberFormat getInstance(Locale inLocale) { - return getInstance(ULocale.forLocale(inLocale), NUMBERSTYLE); - } - - /** - * Returns the default number format for the specified locale. - * The default format is one of the styles provided by the other - * factory methods: getNumberInstance, getCurrencyInstance or getPercentInstance. - * Exactly which one is locale-dependent. - * @stable ICU 3.2 - */ - public static NumberFormat getInstance(ULocale inLocale) { - return getInstance(inLocale, NUMBERSTYLE); - } - - /** - * Returns a general-purpose number format for the current default locale. - * @stable ICU 2.0 - */ - public final static NumberFormat getNumberInstance() { - return getInstance(ULocale.getDefault(), NUMBERSTYLE); - } - - /** - * Returns a general-purpose number format for the specified locale. - * @stable ICU 2.0 - */ - public static NumberFormat getNumberInstance(Locale inLocale) { - return getInstance(ULocale.forLocale(inLocale), NUMBERSTYLE); - } - - /** - * Returns a general-purpose number format for the specified locale. - * @stable ICU 3.2 - */ - public static NumberFormat getNumberInstance(ULocale inLocale) { - return getInstance(inLocale, NUMBERSTYLE); - } - - /** - * Returns an integer number format for the current default locale. The - * returned number format is configured to round floating point numbers - * to the nearest integer using IEEE half-even rounding (see {@link - * com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN ROUND_HALF_EVEN}) for formatting, - * and to parse only the integer part of an input string (see {@link - * #isParseIntegerOnly isParseIntegerOnly}). - * - * @return a number format for integer values - * @stable ICU 2.0 - */ - public final static NumberFormat getIntegerInstance() { - return getInstance(ULocale.getDefault(), INTEGERSTYLE); - } - - /** - * Returns an integer number format for the specified locale. The - * returned number format is configured to round floating point numbers - * to the nearest integer using IEEE half-even rounding (see {@link - * com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN ROUND_HALF_EVEN}) for formatting, - * and to parse only the integer part of an input string (see {@link - * #isParseIntegerOnly isParseIntegerOnly}). - * - * @param inLocale the locale for which a number format is needed - * @return a number format for integer values - * @stable ICU 2.0 - */ - public static NumberFormat getIntegerInstance(Locale inLocale) { - return getInstance(ULocale.forLocale(inLocale), INTEGERSTYLE); - } - - /** - * Returns an integer number format for the specified locale. The - * returned number format is configured to round floating point numbers - * to the nearest integer using IEEE half-even rounding (see {@link - * com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN ROUND_HALF_EVEN}) for formatting, - * and to parse only the integer part of an input string (see {@link - * #isParseIntegerOnly isParseIntegerOnly}). - * - * @param inLocale the locale for which a number format is needed - * @return a number format for integer values - * @stable ICU 3.2 - */ - public static NumberFormat getIntegerInstance(ULocale inLocale) { - return getInstance(inLocale, INTEGERSTYLE); - } - - /** - * Returns a currency format for the current default locale. - * @return a number format for currency - * @stable ICU 2.0 - */ - public final static NumberFormat getCurrencyInstance() { - return getInstance(ULocale.getDefault(), CURRENCYSTYLE); - } - - /** - * Returns a currency format for the specified locale. - * @return a number format for currency - * @stable ICU 2.0 - */ - public static NumberFormat getCurrencyInstance(Locale inLocale) { - return getInstance(ULocale.forLocale(inLocale), CURRENCYSTYLE); - } - - /** - * Returns a currency format for the specified locale. - * @return a number format for currency - * @stable ICU 3.2 - */ - public static NumberFormat getCurrencyInstance(ULocale inLocale) { - return getInstance(inLocale, CURRENCYSTYLE); - } - - /** - * Returns a percentage format for the current default locale. - * @return a number format for percents - * @stable ICU 2.0 - */ - public final static NumberFormat getPercentInstance() { - return getInstance(ULocale.getDefault(), PERCENTSTYLE); - } - - /** - * Returns a percentage format for the specified locale. - * @return a number format for percents - * @stable ICU 2.0 - */ - public static NumberFormat getPercentInstance(Locale inLocale) { - return getInstance(ULocale.forLocale(inLocale), PERCENTSTYLE); - } - - /** - * Returns a percentage format for the specified locale. - * @return a number format for percents - * @stable ICU 3.2 - */ - public static NumberFormat getPercentInstance(ULocale inLocale) { - return getInstance(inLocale, PERCENTSTYLE); - } - - /** - * NEW - * Returns a scientific format for the current default locale. - * @return a scientific number format - * @stable ICU 2.0 - */ - public final static NumberFormat getScientificInstance() { - return getInstance(ULocale.getDefault(), SCIENTIFICSTYLE); - } - - /** - * NEW - * Returns a scientific format for the specified locale. - * @return a scientific number format - * @stable ICU 2.0 - */ - public static NumberFormat getScientificInstance(Locale inLocale) { - return getInstance(ULocale.forLocale(inLocale), SCIENTIFICSTYLE); - } - - /** - * NEW - * Returns a scientific format for the specified locale. - * @return a scientific number format - * @stable ICU 3.2 - */ - public static NumberFormat getScientificInstance(ULocale inLocale) { - return getInstance(inLocale, SCIENTIFICSTYLE); - } - - /** - * Get the list of Locales for which NumberFormats are available. - * @return the available locales - * @stable ICU 2.0 - */ - public static Locale[] getAvailableLocales() { - return java.text.NumberFormat.getAvailableLocales(); - } - - /** - * Get the list of Locales for which NumberFormats are available. - * @return the available locales - * @draft ICU 3.2 (retain) - */ - public static ULocale[] getAvailableULocales() { - if (availableULocales == null) { - Locale[] locales = java.text.NumberFormat.getAvailableLocales(); - ULocale[] ulocales = new ULocale[locales.length]; - for (int i = 0; i < locales.length; ++i) { - ulocales[i] = ULocale.forLocale(locales[i]); - } - availableULocales = ulocales; - } - return (ULocale[])availableULocales.clone(); - } - private static ULocale[] availableULocales; - - - /** - * Returns true if grouping is used in this format. For example, in the - * en_US locale, with grouping on, the number 1234567 will be formatted - * as "1,234,567". The grouping separator as well as the size of each group - * is locale-dependent and is determined by subclasses of NumberFormat. - * Grouping affects both parsing and formatting. - * @return true if grouping is used - * @see #setGroupingUsed - * @stable ICU 2.0 - */ - public boolean isGroupingUsed() { - return numberFormat.isGroupingUsed(); - } - - /** - * Sets whether or not grouping will be used in this format. Grouping - * affects both parsing and formatting. - * @see #isGroupingUsed - * @param newValue true to use grouping. - * @stable ICU 2.0 - */ - public void setGroupingUsed(boolean newValue) { - numberFormat.setGroupingUsed(newValue); - } - - /** - * Returns the maximum number of digits allowed in the integer portion of a - * number. The default value is 40, which subclasses can override. - * When formatting, the exact behavior when this value is exceeded is - * subclass-specific. When parsing, this has no effect. - * @return the maximum number of integer digits - * @see #setMaximumIntegerDigits - * @stable ICU 2.0 - */ - public int getMaximumIntegerDigits() { - return numberFormat.getMaximumIntegerDigits(); - } - - /** - * Sets the maximum number of digits allowed in the integer portion of a - * number. This must be >= minimumIntegerDigits. If the - * new value for maximumIntegerDigits is less than the current value - * of minimumIntegerDigits, then minimumIntegerDigits will also be set to - * the new value. - * @param newValue the maximum number of integer digits to be shown; if - * less than zero, then zero is used. Subclasses might enforce an - * upper limit to this value appropriate to the numeric type being formatted. - * @see #getMaximumIntegerDigits - * @stable ICU 2.0 - */ - public void setMaximumIntegerDigits(int newValue) { - numberFormat.setMaximumIntegerDigits(newValue); - } - - /** - * Returns the minimum number of digits allowed in the integer portion of a - * number. The default value is 1, which subclasses can override. - * When formatting, if this value is not reached, numbers are padded on the - * left with the locale-specific '0' character to ensure at least this - * number of integer digits. When parsing, this has no effect. - * @return the minimum number of integer digits - * @see #setMinimumIntegerDigits - * @stable ICU 2.0 - */ - public int getMinimumIntegerDigits() { - return numberFormat.getMinimumIntegerDigits(); - } - - /** - * Sets the minimum number of digits allowed in the integer portion of a - * number. This must be <= maximumIntegerDigits. If the - * new value for minimumIntegerDigits is more than the current value - * of maximumIntegerDigits, then maximumIntegerDigits will also be set to - * the new value. - * @param newValue the minimum number of integer digits to be shown; if - * less than zero, then zero is used. Subclasses might enforce an - * upper limit to this value appropriate to the numeric type being formatted. - * @see #getMinimumIntegerDigits - * @stable ICU 2.0 - */ - public void setMinimumIntegerDigits(int newValue) { - numberFormat.setMinimumIntegerDigits(newValue); - } - - /** - * Returns the maximum number of digits allowed in the fraction - * portion of a number. The default value is 3, which subclasses - * can override. When formatting, the exact behavior when this - * value is exceeded is subclass-specific. When parsing, this has - * no effect. - * @return the maximum number of fraction digits - * @see #setMaximumFractionDigits - * @stable ICU 2.0 - */ - public int getMaximumFractionDigits() { - return numberFormat.getMaximumFractionDigits(); - } - - /** - * Sets the maximum number of digits allowed in the fraction portion of a - * number. This must be >= minimumFractionDigits. If the - * new value for maximumFractionDigits is less than the current value - * of minimumFractionDigits, then minimumFractionDigits will also be set to - * the new value. - * @param newValue the maximum number of fraction digits to be shown; if - * less than zero, then zero is used. The concrete subclass may enforce an - * upper limit to this value appropriate to the numeric type being formatted. - * @see #getMaximumFractionDigits - * @stable ICU 2.0 - */ - public void setMaximumFractionDigits(int newValue) { - numberFormat.setMaximumFractionDigits(newValue); - } - - /** - * Returns the minimum number of digits allowed in the fraction portion of a - * number. The default value is 0, which subclasses can override. - * When formatting, if this value is not reached, numbers are padded on - * the right with the locale-specific '0' character to ensure at least - * this number of fraction digits. When parsing, this has no effect. - * @return the minimum number of fraction digits - * @see #setMinimumFractionDigits - * @stable ICU 2.0 - */ - public int getMinimumFractionDigits() { - return numberFormat.getMinimumFractionDigits(); - } - - /** - * Sets the minimum number of digits allowed in the fraction portion of a - * number. This must be <= maximumFractionDigits. If the - * new value for minimumFractionDigits exceeds the current value - * of maximumFractionDigits, then maximumFractionDigits will also be set to - * the new value. - * @param newValue the minimum number of fraction digits to be shown; if - * less than zero, then zero is used. Subclasses might enforce an - * upper limit to this value appropriate to the numeric type being formatted. - * @see #getMinimumFractionDigits - * @stable ICU 2.0 - */ - public void setMinimumFractionDigits(int newValue) { - numberFormat.setMinimumFractionDigits(newValue); - } - - /** - * Return a string suitable for debugging. - * @return a string suitable for debugging - * @stable ICU 3.4.2 - */ - public String toString() { - return numberFormat.toString(); - } - - /** - * Overrides Cloneable. - * @stable ICU 2.0 - */ - public Object clone() { - return new NumberFormat((java.text.NumberFormat)numberFormat.clone()); - } - - /** - * Overrides equals. Two NumberFormats are equal if they are of the same class - * and the settings (groupingUsed, parseIntegerOnly, maximumIntegerDigits, etc. - * are equal. - * @param obj the object to compare against - * @return true if the object is equal to this. - * @stable ICU 2.0 - */ - public boolean equals(Object obj) { - try { - return numberFormat.equals(((NumberFormat)obj).numberFormat); - } - catch (Exception e) { - return false; - } - } - - /** - * Overrides hashCode - * @stable ICU 2.0 - */ - public int hashCode() { - return numberFormat.hashCode(); - } - - // =======================privates=============================== - - private static NumberFormat getInstance(ULocale desiredLocale, int choice) { - Locale locale = desiredLocale.toLocale(); - java.text.NumberFormat nf = null; - switch (choice) { - case NUMBERSTYLE: nf = java.text.NumberFormat.getInstance(locale); break; - case CURRENCYSTYLE: nf = java.text.NumberFormat.getCurrencyInstance(locale); break; - case PERCENTSTYLE: nf = java.text.NumberFormat.getPercentInstance(locale); break; - case SCIENTIFICSTYLE: nf = new java.text.DecimalFormat("#E0", new DecimalFormatSymbols(locale)); - nf.setMaximumFractionDigits(10); - break; - case INTEGERSTYLE: - if (unchecked) { - unchecked = false; - try { - Class[] args = { java.util.Locale.class }; - integer14API = java.text.NumberFormat.class.getMethod("getIntegerInstance", args); - } - catch (Exception e) { - } - } - if (integer14API != null) { - try { - Object[] args = { locale }; - nf = (java.text.NumberFormat)integer14API.invoke(null, args); - } - catch (IllegalAccessException e) { - integer14API = null; - } - catch (InvocationTargetException e) { - integer14API = null; - } - catch (Exception e) { - // shouldn't happen, but locale might be null, for example - // and we don't want to throw away our method because someone - // called us with a bad parameter - } - } - if (nf == null) { - nf = java.text.NumberFormat.getNumberInstance(locale); - nf.setMaximumFractionDigits(0); - nf.setParseIntegerOnly(true); - } - break; - } - return new NumberFormat(nf); - } - - private static boolean unchecked = true; - private static Method integer14API; - - private static final int NUMBERSTYLE = 0; - private static final int CURRENCYSTYLE = 1; - private static final int PERCENTSTYLE = 2; - private static final int SCIENTIFICSTYLE = 3; - private static final int INTEGERSTYLE = 4; -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/SimpleDateFormat.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/SimpleDateFormat.java deleted file mode 100644 index ddf03001420..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/text/SimpleDateFormat.java +++ /dev/null @@ -1,382 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.text; - -import java.text.FieldPosition; -import java.text.ParsePosition; -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.ULocale; - -/** - * SimpleDateFormat is a concrete class for formatting and - * parsing dates in a locale-sensitive manner. It allows for formatting - * (date -> text), parsing (text -> date), and normalization. - * - *

- * SimpleDateFormat allows you to start by choosing - * any user-defined patterns for date-time formatting. However, you - * are encouraged to create a date-time formatter with either - * getTimeInstance, getDateInstance, or - * getDateTimeInstance in DateFormat. Each - * of these class methods can return a date/time formatter initialized - * with a default format pattern. You may modify the format pattern - * using the applyPattern methods as desired. - * For more information on using these methods, see - * {@link DateFormat}. - * - *

- * Time Format Syntax: - *

- * To specify the time format use a time pattern string. - * In this pattern, all ASCII letters are reserved as pattern letters, - * which are defined as the following: - *

- *
- * Symbol   Meaning                 Presentation        Example
- * ------   -------                 ------------        -------
- * G        era designator          (Text)              AD
- * y†       year                    (Number)            1996
- * Y*       year (week of year)     (Number)            1997
- * u*       extended year           (Number)            4601
- * M        month in year           (Text & Number)     July & 07
- * d        day in month            (Number)            10
- * h        hour in am/pm (1~12)    (Number)            12
- * H        hour in day (0~23)      (Number)            0
- * m        minute in hour          (Number)            30
- * s        second in minute        (Number)            55
- * S        fractional second       (Number)            978
- * E        day of week             (Text)              Tuesday
- * e*       day of week (local 1~7) (Number)            2
- * D        day in year             (Number)            189
- * F        day of week in month    (Number)            2 (2nd Wed in July)
- * w        week in year            (Number)            27
- * W        week in month           (Number)            2
- * a        am/pm marker            (Text)              PM
- * k        hour in day (1~24)      (Number)            24
- * K        hour in am/pm (0~11)    (Number)            0
- * z        time zone               (Text)              Pacific Standard Time
- * Z        time zone (RFC 822)     (Number)            -0800
- * v        time zone (generic)     (Text)              Pacific Time
- * g*       Julian day              (Number)            2451334
- * A*       milliseconds in day     (Number)            69540000
- * '        escape for text         (Delimiter)         'Date='
- * ''       single quote            (Literal)           'o''clock'
- * 
- *
- * * These items are not supported by Java's SimpleDateFormat.
- * ICU interprets a single 'y' differently than Java.

- *

- * The count of pattern letters determine the format. - *

- * (Text): 4 or more pattern letters--use full form, - * < 4--use short or abbreviated form if one exists. - *

- * (Number): the minimum number of digits. Shorter - * numbers are zero-padded to this amount. Year is handled specially; - * that is, if the count of 'y' is 2, the Year will be truncated to 2 digits. - * (e.g., if "yyyy" produces "1997", "yy" produces "97".) - * Unlike other fields, fractional seconds are padded on the right with zero. - *

- * (Text & Number): 3 or over, use text, otherwise use number. - *

- * Any characters in the pattern that are not in the ranges of ['a'..'z'] - * and ['A'..'Z'] will be treated as quoted text. For instance, characters - * like ':', '.', ' ', '#' and '@' will appear in the resulting time text - * even they are not embraced within single quotes. - *

- * A pattern containing any invalid pattern letter will result in a thrown - * exception during formatting or parsing. - * - *

- * Examples Using the US Locale: - *

- *
- * Format Pattern                         Result
- * --------------                         -------
- * "yyyy.MM.dd G 'at' HH:mm:ss vvvv" ->>  1996.07.10 AD at 15:08:56 Pacific Time
- * "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96
- * "h:mm a"                          ->>  12:08 PM
- * "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time
- * "K:mm a, vvv"                     ->>  0:00 PM, PT
- * "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  01996.July.10 AD 12:08 PM
- * 
- *
- * Code Sample: - *
- *
- * SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
- * pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2*60*60*1000);
- * pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*60*60*1000);
- * 
- * // Format the current time. - * SimpleDateFormat formatter - * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz"); - * Date currentTime_1 = new Date(); - * String dateString = formatter.format(currentTime_1); - *
- * // Parse the previous string back into a Date. - * ParsePosition pos = new ParsePosition(0); - * Date currentTime_2 = formatter.parse(dateString, pos); - *
- *
- * In the example, the time value currentTime_2 obtained from - * parsing will be equal to currentTime_1. However, they may not be - * equal if the am/pm marker 'a' is left out from the format pattern while - * the "hour in am/pm" pattern symbol is used. This information loss can - * happen when formatting the time in PM. - * - *

- * When parsing a date string using the abbreviated year pattern ("yy"), - * SimpleDateFormat must interpret the abbreviated year - * relative to some century. It does this by adjusting dates to be - * within 80 years before and 20 years after the time the SimpleDateFormat - * instance is created. For example, using a pattern of "MM/dd/yy" and a - * SimpleDateFormat instance created on Jan 1, 1997, the string - * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64" - * would be interpreted as May 4, 1964. - * During parsing, only strings consisting of exactly two digits, as defined by - * {@link java.lang.Character#isDigit(char)}, will be parsed into the default - * century. - * Any other numeric string, such as a one digit string, a three or more digit - * string, or a two digit string that isn't all digits (for example, "-1"), is - * interpreted literally. So "01/02/3" or "01/02/003" are parsed, using the - * same pattern, as Jan 2, 3 AD. Likewise, "01/02/-3" is parsed as Jan 2, 4 BC. - * - *

- * If the year pattern does not have exactly two 'y' characters, the year is - * interpreted literally, regardless of the number of digits. So using the - * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D. - * - *

- * When numeric fields abut one another directly, with no intervening delimiter - * characters, they constitute a run of abutting numeric fields. Such runs are - * parsed specially. For example, the format "HHmmss" parses the input text - * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to - * parse "1234". In other words, the leftmost field of the run is flexible, - * while the others keep a fixed width. If the parse fails anywhere in the run, - * then the leftmost field is shortened by one character, and the entire run is - * parsed again. This is repeated until either the parse succeeds or the - * leftmost field is one character in length. If the parse still fails at that - * point, the parse of the run fails. - * - *

- * For time zones that have no names, use strings GMT+hours:minutes or - * GMT-hours:minutes. - * - *

- * The calendar defines what is the first day of the week, the first week - * of the year, whether hours are zero based or not (0 vs 12 or 24), and the - * time zone. There is one common decimal format to handle all the numbers; - * the digit count is handled programmatically according to the pattern. - * - *

Synchronization

- * - * Date formats are not synchronized. It is recommended to create separate - * format instances for each thread. If multiple threads access a format - * concurrently, it must be synchronized externally. - * - * @see com.ibm.icu.util.Calendar - * @see com.ibm.icu.util.GregorianCalendar - * @see com.ibm.icu.util.TimeZone - * @see DateFormat - * @see DateFormatSymbols - * @see DecimalFormat - * @author Mark Davis, Chen-Lieh Huang, Alan Liu - * @stable ICU 2.0 - */ -public class SimpleDateFormat extends DateFormat { - private static final long serialVersionUID = 1; - - /** - * Construct a SimpleDateFormat using the default pattern for the default - * locale. Note: Not all locales support SimpleDateFormat; for full - * generality, use the factory methods in the DateFormat class. - * - * @see DateFormat - * @stable ICU 2.0 - */ - public SimpleDateFormat() { - super(new java.text.SimpleDateFormat()); - } - - /** - * Construct a SimpleDateFormat using the given pattern in the default - * locale. Note: Not all locales support SimpleDateFormat; for full - * generality, use the factory methods in the DateFormat class. - * @param pattern the pattern to use - * @stable ICU 2.0 - */ - public SimpleDateFormat(String pattern) { - super(new java.text.SimpleDateFormat(pattern)); - } - - /** - * Construct a SimpleDateFormat using the given pattern and locale. - * Note: Not all locales support SimpleDateFormat; for full - * generality, use the factory methods in the DateFormat class. - * @param pattern the pattern to use - * @param loc the locale to use for localization - * @stable ICU 2.0 - */ - public SimpleDateFormat(String pattern, Locale loc) { - super(new java.text.SimpleDateFormat(pattern, loc)); - } - - /** - * Construct a SimpleDateFormat using the given pattern and locale. - * Note: Not all locales support SimpleDateFormat; for full - * generality, use the factory methods in the DateFormat class. - * @param pattern the pattern to use - * @param loc the ulocale to use for localization - * @stable ICU 3.2 - */ - public SimpleDateFormat(String pattern, ULocale loc) { - this(pattern, loc.toLocale()); - } - - /** - * Construct a SimpleDateFormat using the given pattern and - * locale-specific symbol data. - * Warning: uses default locale for digits! - * @param pattern the pattern to use - * @param formatData the symbols to use for localization - * @stable ICU 2.0 - */ - public SimpleDateFormat(String pattern, DateFormatSymbols formatData) { - super(new java.text.SimpleDateFormat(pattern, formatData.dfs)); - } - - /** - * Sets the 100-year period 2-digit years will be interpreted as being in - * to begin on the date the user specifies. - * @param startDate During parsing, two digit years will be placed in the range - * startDate to startDate + 100 years. - * @stable ICU 2.0 - */ - public void set2DigitYearStart(Date startDate) { - ((java.text.SimpleDateFormat)dateFormat).set2DigitYearStart(startDate); - } - - /** - * Returns the beginning date of the 100-year period 2-digit years are interpreted - * as being within. - * @return the start of the 100-year period into which two digit years are - * parsed - * @stable ICU 2.0 - */ - public Date get2DigitYearStart() { - return ((java.text.SimpleDateFormat)dateFormat).get2DigitYearStart(); - } - - /** - * Overrides DateFormat. - *

Formats a date or time, which is the standard millis - * since January 1, 1970, 00:00:00 GMT. - *

Example: using the US locale: - * "yyyy.MM.dd G 'at' HH:mm:ss zzz" ->> 1996.07.10 AD at 15:08:56 PDT - * @param cal the calendar whose date-time value is to be formatted into a date-time string - * @param toAppendTo where the new date-time text is to be appended - * @param pos the formatting position. On input: an alignment field, - * if desired. On output: the offsets of the alignment field. - * @return the formatted date-time string. - * @see DateFormat - * @stable ICU 2.0 - */ - public StringBuffer format(Calendar cal, StringBuffer toAppendTo, FieldPosition pos) { - StringBuffer result; - synchronized(dateFormat) { - java.util.Calendar oldCal = dateFormat.getCalendar(); - dateFormat.setCalendar(cal.calendar); - result = dateFormat.format(cal.getTime(), toAppendTo, pos); - dateFormat.setCalendar(oldCal); - } - return result; - } - - /** - * Overrides DateFormat - * @see DateFormat - * @stable ICU 2.0 - */ - public void parse(String text, Calendar cal, ParsePosition parsePos) { - // TODO: cannot set the parsed timezone, document? - cal.setTime(dateFormat.parse(text, parsePos)); - } - - /** - * Return a pattern string describing this date format. - * @stable ICU 2.0 - */ - public String toPattern() { - return ((java.text.SimpleDateFormat)dateFormat).toPattern(); - } - - /** - * Return a localized pattern string describing this date format. - * @stable ICU 2.0 - */ - public String toLocalizedPattern() { - return ((java.text.SimpleDateFormat)dateFormat).toLocalizedPattern(); - } - - /** - * Apply the given unlocalized pattern string to this date format. - * @stable ICU 2.0 - */ - public void applyPattern(String pattern) { - ((java.text.SimpleDateFormat)dateFormat).applyPattern(pattern); - } - - /** - * Apply the given localized pattern string to this date format. - * @stable ICU 2.0 - */ - public void applyLocalizedPattern(String pattern) { - ((java.text.SimpleDateFormat)dateFormat).applyLocalizedPattern(pattern); - } - - /** - * Gets the date/time formatting data. - * @return a copy of the date-time formatting data associated - * with this date-time formatter. - * @stable ICU 2.0 - */ - public DateFormatSymbols getDateFormatSymbols() { - return new DateFormatSymbols(((java.text.SimpleDateFormat)dateFormat).getDateFormatSymbols()); - } - - /** - * Allows you to set the date/time formatting data. - * @param newFormatSymbols the new symbols - * @stable ICU 2.0 - */ - public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols) { - ((java.text.SimpleDateFormat)dateFormat).setDateFormatSymbols(newFormatSymbols.dfs); - } - - /** - * Overrides Cloneable - * @stable ICU 2.0 - */ - public Object clone() { - return new SimpleDateFormat((java.text.SimpleDateFormat)dateFormat.clone()); - } - - /** - * For clone to use - * @param sdf - */ - private SimpleDateFormat(java.text.SimpleDateFormat sdf) { - super(sdf); - } - - // hashCode, equals, clone use DateFormat implementation. -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/Calendar.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/Calendar.java deleted file mode 100644 index 18d4e02598a..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/Calendar.java +++ /dev/null @@ -1,2118 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - - -package com.ibm.icu.util; - -import java.io.Serializable; -import java.util.Date; -import java.util.Locale; - -import com.ibm.icu.text.DateFormat; - -/** - * Calendar is an abstract base class for converting between - * a Date object and a set of integer fields such as - * YEAR, MONTH, DAY, HOUR, - * and so on. (A Date object represents a specific instant in - * time with millisecond precision. See - * {@link Date} - * for information about the Date class.) - * - *

Note: This class is similar, but not identical, to the class - * java.util.Calendar. Changes are detailed below. - * - *

- * Subclasses of Calendar interpret a Date - * according to the rules of a specific calendar system. ICU4J contains - * several subclasses implementing different international calendar systems. - * - *

- * Like other locale-sensitive classes, Calendar provides a - * class method, getInstance, for getting a generally useful - * object of this type. Calendar's getInstance method - * returns a calendar of a type appropriate to the locale, whose - * time fields have been initialized with the current date and time: - *

- *
Calendar rightNow = Calendar.getInstance()
- *
- * - *

When a ULocale is used by getInstance, its - * 'calendar' tag and value are retrieved if present. If a recognized - * value is supplied, a calendar is provided and configured as appropriate. - * Currently recognized tags are "buddhist", "chinese", "coptic", "ethiopic", - * "gregorian", "hebrew", "islamic", "islamic-civil", and "japanese". For - * example:

- *
Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=japanese"));
- *
will return an instance of JapaneseCalendar (using en_US conventions for - * minimum days in first week, start day of week, et cetera). - * - *

A Calendar object can produce all the time field values - * needed to implement the date-time formatting for a particular language and - * calendar style (for example, Japanese-Gregorian, Japanese-Traditional). - * Calendar defines the range of values returned by certain fields, - * as well as their meaning. For example, the first month of the year has value - * MONTH == JANUARY for all calendars. Other values - * are defined by the concrete subclass, such as ERA and - * YEAR. See individual field documentation and subclass - * documentation for details. - * - *

When a Calendar is lenient, it accepts a wider range - * of field values than it produces. For example, a lenient - * GregorianCalendar interprets MONTH == - * JANUARY, DAY_OF_MONTH == 32 as February 1. A - * non-lenient GregorianCalendar throws an exception when given - * out-of-range field settings. When calendars recompute field values for - * return by get(), they normalize them. For example, a - * GregorianCalendar always produces DAY_OF_MONTH - * values between 1 and the length of the month. - * - *

Calendar defines a locale-specific seven day week using two - * parameters: the first day of the week and the minimal days in first week - * (from 1 to 7). These numbers are taken from the locale resource data when a - * Calendar is constructed. They may also be specified explicitly - * through the API. - * - *

When setting or getting the WEEK_OF_MONTH or - * WEEK_OF_YEAR fields, Calendar must determine the - * first week of the month or year as a reference point. The first week of a - * month or year is defined as the earliest seven day period beginning on - * getFirstDayOfWeek() and containing at least - * getMinimalDaysInFirstWeek() days of that month or year. Weeks - * numbered ..., -1, 0 precede the first week; weeks numbered 2, 3,... follow - * it. Note that the normalized numbering returned by get() may be - * different. For example, a specific Calendar subclass may - * designate the week before week 1 of a year as week n of the previous - * year. - * - *

When computing a Date from time fields, two special - * circumstances may arise: there may be insufficient information to compute the - * Date (such as only year and month but no day in the month), or - * there may be inconsistent information (such as "Tuesday, July 15, 1996" -- - * July 15, 1996 is actually a Monday). - * - *

- * Insufficient information. The calendar will use default - * information to specify the missing fields. This may vary by calendar; for - * the Gregorian calendar, the default for a field is the same as that of the - * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc. - * - *

- * Inconsistent information. If fields conflict, the calendar - * will give preference to fields set more recently. For example, when - * determining the day, the calendar will look for one of the following - * combinations of fields. The most recent combination, as determined by the - * most recently set single field, will be used. - * - *

- *
- * MONTH + DAY_OF_MONTH
- * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
- * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
- * DAY_OF_YEAR
- * DAY_OF_WEEK + WEEK_OF_YEAR
- *
- * - * For the time of day: - * - *
- *
- * HOUR_OF_DAY
- * AM_PM + HOUR
- *
- * - *

- * Note: for some non-Gregorian calendars, different - * fields may be necessary for complete disambiguation. For example, a full - * specification of the historial Arabic astronomical calendar requires year, - * month, day-of-month and day-of-week in some cases. - * - *

- * Note: There are certain possible ambiguities in - * interpretation of certain singular times, which are resolved in the - * following ways: - *

    - *
  1. 24:00:00 "belongs" to the following day. That is, - * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970 - * - *
  2. Although historically not precise, midnight also belongs to "am", - * and noon belongs to "pm", so on the same day, - * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm - *
- * - *

- * The date or time format strings are not part of the definition of a - * calendar, as those must be modifiable or overridable by the user at - * runtime. Use {@link DateFormat} - * to format dates. - * - *

Field manipulation methods

- * - *

Calendar fields can be changed using three methods: - * set(), add(), and roll().

- * - *

set(f, value) changes field - * f to value. In addition, it sets an - * internal member variable to indicate that field f has - * been changed. Although field f is changed immediately, - * the calendar's milliseconds is not recomputed until the next call to - * get(), getTime(), or - * getTimeInMillis() is made. Thus, multiple calls to - * set() do not trigger multiple, unnecessary - * computations. As a result of changing a field using - * set(), other fields may also change, depending on the - * field, the field value, and the calendar system. In addition, - * get(f) will not necessarily return value - * after the fields have been recomputed. The specifics are determined by - * the concrete calendar class.

- * - *

Example: Consider a GregorianCalendar - * originally set to August 31, 1999. Calling set(Calendar.MONTH, - * Calendar.SEPTEMBER) sets the calendar to September 31, - * 1999. This is a temporary internal representation that resolves to - * October 1, 1999 if getTime()is then called. However, a - * call to set(Calendar.DAY_OF_MONTH, 30) before the call to - * getTime() sets the calendar to September 30, 1999, since - * no recomputation occurs after set() itself.

- * - *

add(f, delta) adds delta - * to field f. This is equivalent to calling set(f, - * get(f) + delta) with two adjustments:

- * - *
- *

Add rule 1. The value of field f - * after the call minus the value of field f before the - * call is delta, modulo any overflow that has occurred in - * field f. Overflow occurs when a field value exceeds its - * range and, as a result, the next larger field is incremented or - * decremented and the field value is adjusted back into its range.

- * - *

Add rule 2. If a smaller field is expected to be - * invariant, but   it is impossible for it to be equal to its - * prior value because of changes in its minimum or maximum after field - * f is changed, then its value is adjusted to be as close - * as possible to its expected value. A smaller field represents a - * smaller unit of time. HOUR is a smaller field than - * DAY_OF_MONTH. No adjustment is made to smaller fields - * that are not expected to be invariant. The calendar system - * determines what fields are expected to be invariant.

- *
- * - *

In addition, unlike set(), add() forces - * an immediate recomputation of the calendar's milliseconds and all - * fields.

- * - *

Example: Consider a GregorianCalendar - * originally set to August 31, 1999. Calling add(Calendar.MONTH, - * 13) sets the calendar to September 30, 2000. Add rule - * 1 sets the MONTH field to September, since - * adding 13 months to August gives September of the next year. Since - * DAY_OF_MONTH cannot be 31 in September in a - * GregorianCalendar, add rule 2 sets the - * DAY_OF_MONTH to 30, the closest possible value. Although - * it is a smaller field, DAY_OF_WEEK is not adjusted by - * rule 2, since it is expected to change when the month changes in a - * GregorianCalendar.

- * - *

roll(f, delta) adds - * delta to field f without changing larger - * fields. This is equivalent to calling add(f, delta) with - * the following adjustment:

- * - *
- *

Roll rule. Larger fields are unchanged after the - * call. A larger field represents a larger unit of - * time. DAY_OF_MONTH is a larger field than - * HOUR.

- *
- * - *

Example: Consider a GregorianCalendar - * originally set to August 31, 1999. Calling roll(Calendar.MONTH, - * 8) sets the calendar to April 30, 1999. Add - * rule 1 sets the MONTH field to April. Using a - * GregorianCalendar, the DAY_OF_MONTH cannot - * be 31 in the month April. Add rule 2 sets it to the closest possible - * value, 30. Finally, the roll rule maintains the - * YEAR field value of 1999.

- * - *

Example: Consider a GregorianCalendar - * originally set to Sunday June 6, 1999. Calling - * roll(Calendar.WEEK_OF_MONTH, -1) sets the calendar to - * Tuesday June 1, 1999, whereas calling - * add(Calendar.WEEK_OF_MONTH, -1) sets the calendar to - * Sunday May 30, 1999. This is because the roll rule imposes an - * additional constraint: The MONTH must not change when the - * WEEK_OF_MONTH is rolled. Taken together with add rule 1, - * the resultant date must be between Tuesday June 1 and Saturday June - * 5. According to add rule 2, the DAY_OF_WEEK, an invariant - * when changing the WEEK_OF_MONTH, is set to Tuesday, the - * closest possible value to Sunday (where Sunday is the first day of the - * week).

- * - *

Usage model. To motivate the behavior of - * add() and roll(), consider a user interface - * component with increment and decrement buttons for the month, day, and - * year, and an underlying GregorianCalendar. If the - * interface reads January 31, 1999 and the user presses the month - * increment button, what should it read? If the underlying - * implementation uses set(), it might read March 3, 1999. A - * better result would be February 28, 1999. Furthermore, if the user - * presses the month increment button again, it should read March 31, - * 1999, not March 28, 1999. By saving the original date and using either - * add() or roll(), depending on whether larger - * fields should be affected, the user interface can behave as most users - * will intuitively expect.

- * - *

Note: You should always use {@link #roll roll} and {@link #add add} rather - * than attempting to perform arithmetic operations directly on the fields - * of a Calendar. It is quite possible for Calendar subclasses - * to have fields with non-linear behavior, for example missing months - * or days during non-leap years. The subclasses' add and roll - * methods will take this into account, while simple arithmetic manipulations - * may give invalid results. - * - *

Calendar Architecture in ICU4J

- * - *

Recently the implementation of Calendar has changed - * significantly in order to better support subclassing. The original - * Calendar class was designed to support subclassing, but - * it had only one implemented subclass, GregorianCalendar. - * With the implementation of several new calendar subclasses, including - * the BuddhistCalendar, ChineseCalendar, - * HebrewCalendar, IslamicCalendar, and - * JapaneseCalendar, the subclassing API has been reworked - * thoroughly. This section details the new subclassing API and other - * ways in which com.ibm.icu.util.Calendar differs from - * java.util.Calendar. - *

- * - *

Changes

- * - *

Overview of changes between the classic Calendar - * architecture and the new architecture. - * - *

    - * - *
  • The fields[] array is private now - * instead of protected. Subclasses must access it - * using the methods {@link #internalSet} and - * {@link #internalGet}. Motivation: Subclasses should - * not directly access data members.
  • - * - *
  • The time long word is private now - * instead of protected. Subclasses may access it using - * the method {@link #internalGetTimeInMillis}, which does not - * provoke an update. Motivation: Subclasses should not - * directly access data members.
  • - * - *
  • The scope of responsibility of subclasses has been drastically - * reduced. As much functionality as possible is implemented in the - * Calendar base class. As a result, it is much easier - * to subclass Calendar. Motivation: Subclasses - * should not have to reimplement common code. Certain behaviors are - * common across calendar systems: The definition and behavior of - * week-related fields and time fields, the arithmetic - * ({@link #add(int, int) add} and {@link #roll(int, int) roll}) behavior of many - * fields, and the field validation system.
  • - * - *
  • The subclassing API has been completely redesigned.
  • - * - *
  • The Calendar base class contains some Gregorian - * calendar algorithmic support that subclasses can use (specifically - * in {@link #handleComputeFields}). Subclasses can use the - * methods getGregorianXxx() to obtain precomputed - * values. Motivation: This is required by all - * Calendar subclasses in order to implement consistent - * time zone behavior, and Gregorian-derived systems can use the - * already computed data.
  • - * - *
  • The FIELD_COUNT constant has been removed. Use - * {@link #getFieldCount}. In addition, framework API has been - * added to allow subclasses to define additional fields. - * Motivation: The number of fields is not constant across - * calendar systems.
  • - * - *
  • The range of handled dates has been narrowed from +/- - * ~300,000,000 years to +/- ~5,000,000 years. In practical terms - * this should not affect clients. However, it does mean that client - * code cannot be guaranteed well-behaved results with dates such as - * Date(Long.MIN_VALUE) or - * Date(Long.MAX_VALUE). Instead, the - * Calendar constants {@link #MIN_DATE}, - * {@link #MAX_DATE}, {@link #MIN_MILLIS}, - * {@link #MAX_MILLIS}, {@link #MIN_JULIAN}, and - * {@link #MAX_JULIAN} should be used. Motivation: With - * the addition of the {@link #JULIAN_DAY} field, Julian day - * numbers must be restricted to a 32-bit int. This - * restricts the overall supported range. Furthermore, restricting - * the supported range simplifies the computations by removing - * special case code that was used to accomodate arithmetic overflow - * at millis near Long.MIN_VALUE and - * Long.MAX_VALUE.
  • - * - *
  • New fields are implemented: {@link #JULIAN_DAY} defines - * single-field specification of the - * date. {@link #MILLISECONDS_IN_DAY} defines a single-field - * specification of the wall time. {@link #DOW_LOCAL} and - * {@link #YEAR_WOY} implement localized day-of-week and - * week-of-year behavior.
  • - * - *
  • Subclasses can access millisecond constants - * {@link #ONE_SECOND}, {@link #ONE_MINUTE}, - * {@link #ONE_HOUR}, {@link #ONE_DAY}, and - * {@link #ONE_WEEK} defined in Calendar.
  • - * - *
  • New API has been added to suport calendar-specific subclasses - * of DateFormat.
  • - * - *
  • Several subclasses have been implemented, representing - * various international calendar systems.
  • - * - *
- * - *

Subclass API

- * - *

The original Calendar API was based on the experience - * of implementing a only a single subclass, - * GregorianCalendar. As a result, all of the subclassing - * kinks had not been worked out. The new subclassing API has been - * refined based on several implemented subclasses. This includes methods - * that must be overridden and methods for subclasses to call. Subclasses - * no longer have direct access to fields and - * stamp. Instead, they have new API to access - * these. Subclasses are able to allocate the fields array - * through a protected framework method; this allows subclasses to - * specify additional fields.

- * - *

More functionality has been moved into the base class. The base - * class now contains much of the computational machinery to support the - * Gregorian calendar. This is based on two things: (1) Many calendars - * are based on the Gregorian calendar (such as the Buddhist and Japanese - * imperial calendars). (2) All calendars require basic - * Gregorian support in order to handle timezone computations.

- * - *

Common computations have been moved into - * Calendar. Subclasses no longer compute the week related - * fields and the time related fields. These are commonly handled for all - * calendars by the base class.

- * - *

Subclass computation of time => fields - * - *

The {@link #ERA}, {@link #YEAR}, - * {@link #EXTENDED_YEAR}, {@link #MONTH}, - * {@link #DAY_OF_MONTH}, and {@link #DAY_OF_YEAR} fields are - * computed by the subclass, based on the Julian day. All other fields - * are computed by Calendar. - * - *

    - * - *
  • Subclasses should implement {@link #handleComputeFields} - * to compute the {@link #ERA}, {@link #YEAR}, - * {@link #EXTENDED_YEAR}, {@link #MONTH}, - * {@link #DAY_OF_MONTH}, and {@link #DAY_OF_YEAR} fields, - * based on the value of the {@link #JULIAN_DAY} field. If there - * are calendar-specific fields not defined by Calendar, - * they must also be computed. These are the only fields that the - * subclass should compute. All other fields are computed by the base - * class, so time and week fields behave in a consistent way across - * all calendars. The default version of this method in - * Calendar implements a proleptic Gregorian - * calendar. Within this method, subclasses may call - * getGregorianXxx() to obtain the Gregorian calendar - * month, day of month, and extended year for the given date.
  • - * - *
- * - *

Subclass computation of fields => time - * - *

The interpretation of most field values is handled entirely by - * Calendar. Calendar determines which fields - * are set, which are not, which are set more recently, and so on. In - * addition, Calendar handles the computation of the time - * from the time fields and handles the week-related fields. The only - * thing the subclass must do is determine the extended year, based on - * the year fields, and then, given an extended year and a month, it must - * return a Julian day number. - * - *

    - * - *
  • Subclasses should implement {@link #handleGetExtendedYear} - * to return the extended year for this calendar system, based on the - * {@link #YEAR}, {@link #EXTENDED_YEAR}, and any fields that - * the calendar system uses that are larger than a year, such as - * {@link #ERA}.
  • - * - *
  • Subclasses should implement {@link #handleComputeMonthStart} - * to return the Julian day number - * associated with a month and extended year. This is the Julian day - * number of the day before the first day of the month. The month - * number is zero-based. This computation should not depend on any - * field values.
  • - * - *
- * - *

Other methods - * - *

    - * - *
  • Subclasses should implement {@link #handleGetMonthLength} - * to return the number of days in a - * given month of a given extended year. The month number, as always, - * is zero-based.
  • - * - *
  • Subclasses should implement {@link #handleGetYearLength} - * to return the number of days in the given - * extended year. This method is used by - * computeWeekFields to compute the - * {@link #WEEK_OF_YEAR} and {@link #YEAR_WOY} fields.
  • - * - *
  • Subclasses should implement {@link #handleGetLimit} - * to return the {@link #MINIMUM}, - * {@link #GREATEST_MINIMUM}, {@link #LEAST_MAXIMUM}, or - * {@link #MAXIMUM} of a field, depending on the value of - * limitType. This method only needs to handle the - * fields {@link #ERA}, {@link #YEAR}, {@link #MONTH}, - * {@link #WEEK_OF_YEAR}, {@link #WEEK_OF_MONTH}, - * {@link #DAY_OF_MONTH}, {@link #DAY_OF_YEAR}, - * {@link #DAY_OF_WEEK_IN_MONTH}, {@link #YEAR_WOY}, and - * {@link #EXTENDED_YEAR}. Other fields are invariant (with - * respect to calendar system) and are handled by the base - * class.
  • - * - *
  • Optionally, subclasses may override {@link #validateField} - * to check any subclass-specific fields. If the - * field's value is out of range, the method should throw an - * IllegalArgumentException. The method may call - * super.validateField(field) to handle fields in a - * generic way, that is, to compare them to the range - * getMinimum(field)..getMaximum(field).
  • - * - *
  • Optionally, subclasses may override - * {@link #handleCreateFields} to create an int[] - * array large enough to hold the calendar's fields. This is only - * necessary if the calendar defines additional fields beyond those - * defined by Calendar. The length of the result must be - * at least {@link #BASE_FIELD_COUNT} and no more than - * {@link #MAX_FIELD_COUNT}.
  • - * - *
  • Optionally, subclasses may override - * {@link #handleGetDateFormat} to create a - * DateFormat appropriate to this calendar. This is only - * required if a calendar subclass redefines the use of a field (for - * example, changes the {@link #ERA} field from a symbolic field - * to a numeric one) or defines an additional field.
  • - * - *
  • Optionally, subclasses may override {@link #roll roll} and - * {@link #add add} to handle fields that are discontinuous. For - * example, in the Hebrew calendar the month "Adar I" only - * occurs in leap years; in other years the calendar jumps from - * Shevat (month #4) to Adar (month #6). The {@link - * HebrewCalendar#add HebrewCalendar.add} and {@link - * HebrewCalendar#roll HebrewCalendar.roll} methods take this into - * account, so that adding 1 month to Shevat gives the proper result - * (Adar) in a non-leap year. The protected utility method {@link - * #pinField pinField} is often useful when implementing these two - * methods.
  • - * - *
- * - *

Normalized behavior - * - *

The behavior of certain fields has been made consistent across all - * calendar systems and implemented in Calendar. - * - *

    - * - *
  • Time is normalized. Even though some calendar systems transition - * between days at sunset or at other times, all ICU4J calendars - * transition between days at local zone midnight. This - * allows ICU4J to centralize the time computations in - * Calendar and to maintain basic correpsondences - * between calendar systems. Affected fields: {@link #AM_PM}, - * {@link #HOUR}, {@link #HOUR_OF_DAY}, {@link #MINUTE}, - * {@link #SECOND}, {@link #MILLISECOND}, - * {@link #ZONE_OFFSET}, and {@link #DST_OFFSET}.
  • - * - *
  • DST behavior is normalized. Daylight savings time behavior is - * computed the same for all calendar systems, and depends on the - * value of several GregorianCalendar fields: the - * {@link #YEAR}, {@link #MONTH}, and - * {@link #DAY_OF_MONTH}. As a result, Calendar - * always computes these fields, even for non-Gregorian calendar - * systems. These fields are available to subclasses.
  • - * - *
  • Weeks are normalized. Although locales define the week - * differently, in terms of the day on which it starts, and the - * designation of week number one of a month or year, they all use a - * common mechanism. Furthermore, the day of the week has a simple - * and consistent definition throughout history. For example, - * although the Gregorian calendar introduced a discontinuity when - * first instituted, the day of week was not disrupted. For this - * reason, the fields {@link #DAY_OF_WEEK}, WEEK_OF_YEAR, - * WEEK_OF_MONTH, {@link #DAY_OF_WEEK_IN_MONTH}, - * {@link #DOW_LOCAL}, {@link #YEAR_WOY} are all computed in - * a consistent way in the base class, based on the - * {@link #EXTENDED_YEAR}, {@link #DAY_OF_YEAR}, - * {@link #MONTH}, and {@link #DAY_OF_MONTH}, which are - * computed by the subclass.
  • - * - *
- * - *

Supported range - * - *

The allowable range of Calendar has been - * narrowed. GregorianCalendar used to attempt to support - * the range of dates with millisecond values from - * Long.MIN_VALUE to Long.MAX_VALUE. This - * introduced awkward constructions (hacks) which slowed down - * performance. It also introduced non-uniform behavior at the - * boundaries. The new Calendar protocol specifies the - * maximum range of supportable dates as those having Julian day numbers - * of -0x7F000000 to +0x7F000000. This - * corresponds to years from ~5,000,000 BCE to ~5,000,000 CE. Programmers - * should use the constants {@link #MIN_DATE} (or - * {@link #MIN_MILLIS} or {@link #MIN_JULIAN}) and - * {@link #MAX_DATE} (or {@link #MAX_MILLIS} or - * {@link #MAX_JULIAN}) in Calendar to specify an - * extremely early or extremely late date.

- * - *

General notes - * - *

    - * - *
  • Calendars implementations are proleptic. For example, - * even though the Gregorian calendar was not instituted until the - * 16th century, the GregorianCalendar class supports - * dates before the historical onset of the calendar by extending the - * calendar system backward in time. Similarly, the - * HebrewCalendar extends backward before the start of - * its epoch into zero and negative years. Subclasses do not throw - * exceptions because a date precedes the historical start of a - * calendar system. Instead, they implement - * {@link #handleGetLimit} to return appropriate limits on - * {@link #YEAR}, {@link #ERA}, etc. fields. Then, if the - * calendar is set to not be lenient, out-of-range field values will - * trigger an exception.
  • - * - *
  • Calendar system subclasses compute a extended - * year. This differs from the {@link #YEAR} field in that - * it ranges over all integer values, including zero and negative - * values, and it encapsulates the information of the - * {@link #YEAR} field and all larger fields. Thus, for the - * Gregorian calendar, the {@link #EXTENDED_YEAR} is computed as - * ERA==AD ? YEAR : 1-YEAR. Another example is the Mayan - * long count, which has years (KUN) and nested cycles - * of years (KATUN and BAKTUN). The Mayan - * {@link #EXTENDED_YEAR} is computed as TUN + 20 * (KATUN - * + 20 * BAKTUN). The Calendar base class uses - * the {@link #EXTENDED_YEAR} field to compute the week-related - * fields.
  • - * - *
- * - * @see Date - * @see GregorianCalendar - * @see TimeZone - * @see DateFormat - * @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu, Laura Werner - * @stable ICU 2.0 - */ -public class Calendar implements Serializable, Cloneable, Comparable { - private static final long serialVersionUID = 1; - - /** - * @internal - */ - public final java.util.Calendar calendar; - - /** - * @internal - * @param delegate the Calendar to which to delegate - */ - public Calendar(java.util.Calendar delegate) { - this.calendar = delegate; - } - - - /** - * Field number for get and set indicating the - * era, e.g., AD or BC in the Julian calendar. This is a calendar-specific - * value; see subclass documentation. - * @see GregorianCalendar#AD - * @see GregorianCalendar#BC - * @stable ICU 2.0 - */ - public final static int ERA = 0; - - /** - * Field number for get and set indicating the - * year. This is a calendar-specific value; see subclass documentation. - * @stable ICU 2.0 - */ - public final static int YEAR = 1; - - /** - * Field number for get and set indicating the - * month. This is a calendar-specific value. The first month of the year is - * JANUARY; the last depends on the number of months in a year. - * @see #JANUARY - * @see #FEBRUARY - * @see #MARCH - * @see #APRIL - * @see #MAY - * @see #JUNE - * @see #JULY - * @see #AUGUST - * @see #SEPTEMBER - * @see #OCTOBER - * @see #NOVEMBER - * @see #DECEMBER - * @see #UNDECIMBER - * @stable ICU 2.0 - */ - public final static int MONTH = 2; - - /** - * Field number for get and set indicating the - * week number within the current year. The first week of the year, as - * defined by getFirstDayOfWeek() and - * getMinimalDaysInFirstWeek(), has value 1. Subclasses define - * the value of WEEK_OF_YEAR for days before the first week of - * the year. - * @see #getFirstDayOfWeek - * @see #getMinimalDaysInFirstWeek - * @stable ICU 2.0 - */ - public final static int WEEK_OF_YEAR = 3; - - /** - * Field number for get and set indicating the - * week number within the current month. The first week of the month, as - * defined by getFirstDayOfWeek() and - * getMinimalDaysInFirstWeek(), has value 1. Subclasses define - * the value of WEEK_OF_MONTH for days before the first week of - * the month. - * @see #getFirstDayOfWeek - * @see #getMinimalDaysInFirstWeek - * @stable ICU 2.0 - */ - public final static int WEEK_OF_MONTH = 4; - - /** - * Field number for get and set indicating the - * day of the month. This is a synonym for DAY_OF_MONTH. - * The first day of the month has value 1. - * @see #DAY_OF_MONTH - * @stable ICU 2.0 - */ - public final static int DATE = 5; - - /** - * Field number for get and set indicating the - * day of the month. This is a synonym for DATE. - * The first day of the month has value 1. - * @see #DATE - * @stable ICU 2.0 - */ - public final static int DAY_OF_MONTH = 5; - - /** - * Field number for get and set indicating the day - * number within the current year. The first day of the year has value 1. - * @stable ICU 2.0 - */ - public final static int DAY_OF_YEAR = 6; - - /** - * Field number for get and set indicating the day - * of the week. This field takes values SUNDAY, - * MONDAY, TUESDAY, WEDNESDAY, - * THURSDAY, FRIDAY, and SATURDAY. - * @see #SUNDAY - * @see #MONDAY - * @see #TUESDAY - * @see #WEDNESDAY - * @see #THURSDAY - * @see #FRIDAY - * @see #SATURDAY - * @stable ICU 2.0 - */ - public final static int DAY_OF_WEEK = 7; - - /** - * Field number for get and set indicating the - * ordinal number of the day of the week within the current month. Together - * with the DAY_OF_WEEK field, this uniquely specifies a day - * within a month. Unlike WEEK_OF_MONTH and - * WEEK_OF_YEAR, this field's value does not depend on - * getFirstDayOfWeek() or - * getMinimalDaysInFirstWeek(). DAY_OF_MONTH 1 - * through 7 always correspond to DAY_OF_WEEK_IN_MONTH - * 1; 8 through 15 correspond to - * DAY_OF_WEEK_IN_MONTH 2, and so on. - * DAY_OF_WEEK_IN_MONTH 0 indicates the week before - * DAY_OF_WEEK_IN_MONTH 1. Negative values count back from the - * end of the month, so the last Sunday of a month is specified as - * DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1. Because - * negative values count backward they will usually be aligned differently - * within the month than positive values. For example, if a month has 31 - * days, DAY_OF_WEEK_IN_MONTH -1 will overlap - * DAY_OF_WEEK_IN_MONTH 5 and the end of 4. - * @see #DAY_OF_WEEK - * @see #WEEK_OF_MONTH - * @stable ICU 2.0 - */ - public final static int DAY_OF_WEEK_IN_MONTH = 8; - - /** - * Field number for get and set indicating - * whether the HOUR is before or after noon. - * E.g., at 10:04:15.250 PM the AM_PM is PM. - * @see #AM - * @see #PM - * @see #HOUR - * @stable ICU 2.0 - */ - public final static int AM_PM = 9; - - /** - * Field number for get and set indicating the - * hour of the morning or afternoon. HOUR is used for the 12-hour - * clock. - * E.g., at 10:04:15.250 PM the HOUR is 10. - * @see #AM_PM - * @see #HOUR_OF_DAY - * @stable ICU 2.0 - */ - public final static int HOUR = 10; - - /** - * Field number for get and set indicating the - * hour of the day. HOUR_OF_DAY is used for the 24-hour clock. - * E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22. - * @see #HOUR - * @stable ICU 2.0 - */ - public final static int HOUR_OF_DAY = 11; - - /** - * Field number for get and set indicating the - * minute within the hour. - * E.g., at 10:04:15.250 PM the MINUTE is 4. - * @stable ICU 2.0 - */ - public final static int MINUTE = 12; - - /** - * Field number for get and set indicating the - * second within the minute. - * E.g., at 10:04:15.250 PM the SECOND is 15. - * @stable ICU 2.0 - */ - public final static int SECOND = 13; - - /** - * Field number for get and set indicating the - * millisecond within the second. - * E.g., at 10:04:15.250 PM the MILLISECOND is 250. - * @stable ICU 2.0 - */ - public final static int MILLISECOND = 14; - - /** - * Field number for get and set indicating the - * raw offset from GMT in milliseconds. - * @stable ICU 2.0 - */ - public final static int ZONE_OFFSET = 15; - - /** - * Field number for get and set indicating the - * daylight savings offset in milliseconds. - * @stable ICU 2.0 - */ - public final static int DST_OFFSET = 16; - - /** - * Field number for get() and set() - * indicating the extended year corresponding to the - * WEEK_OF_YEAR field. This may be one greater or less - * than the value of EXTENDED_YEAR. - * @stable ICU 2.0 - */ - public static final int YEAR_WOY = 17; - - /** - * Field number for get() and set() - * indicating the localized day of week. This will be a value from 1 - * to 7 inclusive, with 1 being the localized first day of the week. - * @stable ICU 2.0 - */ - public static final int DOW_LOCAL = 18; - - /** - * Field number for get() and set() - * indicating the extended year. This is a single number designating - * the year of this calendar system, encompassing all supra-year - * fields. For example, for the Julian calendar system, year numbers - * are positive, with an era of BCE or CE. An extended year value for - * the Julian calendar system assigns positive values to CE years and - * negative values to BCE years, with 1 BCE being year 0. - * @stable ICU 2.0 - */ - public static final int EXTENDED_YEAR = 19; - - /** - * Field number for get() and set() - * indicating the modified Julian day number. This is different from - * the conventional Julian day number in two regards. First, it - * demarcates days at local zone midnight, rather than noon GMT. - * Second, it is a local number; that is, it depends on the local time - * zone. It can be thought of as a single number that encompasses all - * the date-related fields. - * @stable ICU 2.0 - */ - public static final int JULIAN_DAY = 20; - - /** - * Field number for get() and set() - * indicating the milliseconds in the day. This ranges from 0 to - * 23:59:59.999 (regardless of DST). This field behaves - * exactly like a composite of all time-related fields, not - * including the zone fields. As such, it also reflects - * discontinuities of those fields on DST transition days. On a day of - * DST onset, it will jump forward. On a day of DST cessation, it will - * jump backward. This reflects the fact that is must be combined with - * the DST_OFFSET field to obtain a unique local time value. - * @stable ICU 2.0 - */ - public static final int MILLISECONDS_IN_DAY = 21; - - /** - * The number of fields defined by this class. Subclasses may define - * addition fields starting with this number. - * @stable ICU 2.0 - */ - protected static final int BASE_FIELD_COUNT = 22; - - /** - * The maximum number of fields possible. Subclasses must not define - * more total fields than this number. - * @stable ICU 2.0 - */ - protected static final int MAX_FIELD_COUNT = 32; - - /** - * Value of the DAY_OF_WEEK field indicating - * Sunday. - * @stable ICU 2.0 - */ - public final static int SUNDAY = 1; - - /** - * Value of the DAY_OF_WEEK field indicating - * Monday. - * @stable ICU 2.0 - */ - public final static int MONDAY = 2; - - /** - * Value of the DAY_OF_WEEK field indicating - * Tuesday. - * @stable ICU 2.0 - */ - public final static int TUESDAY = 3; - - /** - * Value of the DAY_OF_WEEK field indicating - * Wednesday. - * @stable ICU 2.0 - */ - public final static int WEDNESDAY = 4; - - /** - * Value of the DAY_OF_WEEK field indicating - * Thursday. - * @stable ICU 2.0 - */ - public final static int THURSDAY = 5; - - /** - * Value of the DAY_OF_WEEK field indicating - * Friday. - * @stable ICU 2.0 - */ - public final static int FRIDAY = 6; - - /** - * Value of the DAY_OF_WEEK field indicating - * Saturday. - * @stable ICU 2.0 - */ - public final static int SATURDAY = 7; - - /** - * Value of the MONTH field indicating the - * first month of the year. - * @stable ICU 2.0 - */ - public final static int JANUARY = 0; - - /** - * Value of the MONTH field indicating the - * second month of the year. - * @stable ICU 2.0 - */ - public final static int FEBRUARY = 1; - - /** - * Value of the MONTH field indicating the - * third month of the year. - * @stable ICU 2.0 - */ - public final static int MARCH = 2; - - /** - * Value of the MONTH field indicating the - * fourth month of the year. - * @stable ICU 2.0 - */ - public final static int APRIL = 3; - - /** - * Value of the MONTH field indicating the - * fifth month of the year. - * @stable ICU 2.0 - */ - public final static int MAY = 4; - - /** - * Value of the MONTH field indicating the - * sixth month of the year. - * @stable ICU 2.0 - */ - public final static int JUNE = 5; - - /** - * Value of the MONTH field indicating the - * seventh month of the year. - * @stable ICU 2.0 - */ - public final static int JULY = 6; - - /** - * Value of the MONTH field indicating the - * eighth month of the year. - * @stable ICU 2.0 - */ - public final static int AUGUST = 7; - - /** - * Value of the MONTH field indicating the - * ninth month of the year. - * @stable ICU 2.0 - */ - public final static int SEPTEMBER = 8; - - /** - * Value of the MONTH field indicating the - * tenth month of the year. - * @stable ICU 2.0 - */ - public final static int OCTOBER = 9; - - /** - * Value of the MONTH field indicating the - * eleventh month of the year. - * @stable ICU 2.0 - */ - public final static int NOVEMBER = 10; - - /** - * Value of the MONTH field indicating the - * twelfth month of the year. - * @stable ICU 2.0 - */ - public final static int DECEMBER = 11; - - /** - * Value of the MONTH field indicating the - * thirteenth month of the year. Although GregorianCalendar - * does not use this value, lunar calendars do. - * @stable ICU 2.0 - */ - public final static int UNDECIMBER = 12; - - /** - * Value of the AM_PM field indicating the - * period of the day from midnight to just before noon. - * @stable ICU 2.0 - */ - public final static int AM = 0; - - /** - * Value of the AM_PM field indicating the - * period of the day from noon to just before midnight. - * @stable ICU 2.0 - */ - public final static int PM = 1; - - /** - * Value returned by getDayOfWeekType(int dayOfWeek) to indicate a - * weekday. - * @see #WEEKEND - * @see #WEEKEND_ONSET - * @see #WEEKEND_CEASE - * @see #getDayOfWeekType - * @stable ICU 2.0 - */ - public static final int WEEKDAY = 0; - - /** - * Value returned by getDayOfWeekType(int dayOfWeek) to indicate a - * weekend day. - * @see #WEEKDAY - * @see #WEEKEND_ONSET - * @see #WEEKEND_CEASE - * @see #getDayOfWeekType - * @stable ICU 2.0 - */ - public static final int WEEKEND = 1; - - /** - * Value returned by getDayOfWeekType(int dayOfWeek) to indicate a - * day that starts as a weekday and transitions to the weekend. - * Call getWeekendTransition() to get the point of transition. - * @see #WEEKDAY - * @see #WEEKEND - * @see #WEEKEND_CEASE - * @see #getDayOfWeekType - * @stable ICU 2.0 - */ - public static final int WEEKEND_ONSET = 2; - - /** - * Value returned by getDayOfWeekType(int dayOfWeek) to indicate a - * day that starts as the weekend and transitions to a weekday. - * Call getWeekendTransition() to get the point of transition. - * @see #WEEKDAY - * @see #WEEKEND - * @see #WEEKEND_ONSET - * @see #getDayOfWeekType - * @stable ICU 2.0 - */ - public static final int WEEKEND_CEASE = 3; - /** - * Gets a calendar using the default time zone and locale. - * @return a Calendar. - * @stable ICU 2.0 - */ - public static synchronized Calendar getInstance() { - return new Calendar(java.util.Calendar.getInstance()); - } - - /** - * Gets a calendar using the specified time zone and default locale. - * @param zone the time zone to use - * @return a Calendar. - * @stable ICU 2.0 - */ - public static synchronized Calendar getInstance(TimeZone zone) { - return new Calendar(java.util.Calendar.getInstance(zone.timeZone)); - } - - /** - * Gets a calendar using the default time zone and specified locale. - * @param aLocale the locale for the week data - * @return a Calendar. - * @stable ICU 2.0 - */ - public static synchronized Calendar getInstance(Locale aLocale) { - return new Calendar(java.util.Calendar.getInstance(aLocale)); - } - - /** - * Gets a calendar using the default time zone and specified locale. - * @param locale the ulocale for the week data - * @return a Calendar. - * @stable ICU 3.2 - */ - public static synchronized Calendar getInstance(ULocale locale) { - return new Calendar(java.util.Calendar.getInstance(locale.toLocale())); - } - - /** - * Gets a calendar with the specified time zone and locale. - * @param zone the time zone to use - * @param aLocale the locale for the week data - * @return a Calendar. - * @stable ICU 2.0 - */ - public static synchronized Calendar getInstance(TimeZone zone, Locale aLocale) { - return new Calendar(java.util.Calendar.getInstance(zone.timeZone, aLocale)); - } - - /** - * Gets a calendar with the specified time zone and locale. - * @param zone the time zone to use - * @param locale the ulocale for the week data - * @return a Calendar. - * @stable ICU 3.2 - */ - public static synchronized Calendar getInstance(TimeZone zone, ULocale locale) { - return new Calendar(java.util.Calendar.getInstance(zone.timeZone, locale.toLocale())); - } - - /** - * Gets the list of locales for which Calendars are installed. - * @return the list of locales for which Calendars are installed. - * @stable ICU 2.0 - */ - public static Locale[] getAvailableLocales() { - return java.util.Calendar.getAvailableLocales(); - } - - /** - * Gets the list of locales for which Calendars are installed. - * @return the list of locales for which Calendars are installed. - * @draft ICU 3.2 (retain) - */ - public static ULocale[] getAvailableULocales() { - if (availableULocales == null) { - Locale[] locales = java.util.Calendar.getAvailableLocales(); - ULocale[] ulocales = new ULocale[locales.length]; - for (int i = 0; i < locales.length; ++i) { - ulocales[i] = ULocale.forLocale(locales[i]); - } - availableULocales = ulocales; - } - return (ULocale[])availableULocales.clone(); - } - private static ULocale[] availableULocales; - - /** - * Gets this Calendar's current time. - * @return the current time. - * @stable ICU 2.0 - */ - public final Date getTime() { - return calendar.getTime(); - } - - /** - * Sets this Calendar's current time with the given Date. - *

- * Note: Calling setTime() with - * Date(Long.MAX_VALUE) or Date(Long.MIN_VALUE) - * may yield incorrect field values from get(). - * @param date the given Date. - * @stable ICU 2.0 - */ - public final void setTime(Date date) { - calendar.setTime(date); - } - - /** - * Gets this Calendar's current time as a long. - * @return the current time as UTC milliseconds from the epoch. - * @stable ICU 2.0 - */ - public long getTimeInMillis() { - return calendar.getTime().getTime(); - } - - /** - * Sets this Calendar's current time from the given long value. - * @param millis the new time in UTC milliseconds from the epoch. - * @stable ICU 2.0 - */ - public void setTimeInMillis(long millis) { - calendar.setTime(new Date(millis)); - } - - /** - * Gets the value for a given time field. - * @param field the given time field. - * @return the value for the given time field. - * @stable ICU 2.0 - */ - public final int get(int field) { - return calendar.get(field); - } - - /** - * Sets the time field with the given value. - * @param field the given time field. - * @param value the value to be set for the given time field. - * @stable ICU 2.0 - */ - public final void set(int field, int value) { - calendar.set(field, value); - } - - /** - * Sets the values for the fields year, month, and date. - * Previous values of other fields are retained. If this is not desired, - * call clear first. - * @param year the value used to set the YEAR time field. - * @param month the value used to set the MONTH time field. - * Month value is 0-based. e.g., 0 for January. - * @param date the value used to set the DATE time field. - * @stable ICU 2.0 - */ - public final void set(int year, int month, int date) { - calendar.set(year, month, date); - } - - /** - * Sets the values for the fields year, month, date, hour, and minute. - * Previous values of other fields are retained. If this is not desired, - * call clear first. - * @param year the value used to set the YEAR time field. - * @param month the value used to set the MONTH time field. - * Month value is 0-based. e.g., 0 for January. - * @param date the value used to set the DATE time field. - * @param hour the value used to set the HOUR_OF_DAY time field. - * @param minute the value used to set the MINUTE time field. - * @stable ICU 2.0 - */ - public final void set(int year, int month, int date, int hour, int minute) { - calendar.set(year, month, date, hour, minute); - } - - /** - * Sets the values for the fields year, month, date, hour, minute, and second. - * Previous values of other fields are retained. If this is not desired, - * call clear first. - * @param year the value used to set the YEAR time field. - * @param month the value used to set the MONTH time field. - * Month value is 0-based. e.g., 0 for January. - * @param date the value used to set the DATE time field. - * @param hour the value used to set the HOUR_OF_DAY time field. - * @param minute the value used to set the MINUTE time field. - * @param second the value used to set the SECOND time field. - * @stable ICU 2.0 - */ - public final void set(int year, int month, int date, int hour, int minute, int second) { - calendar.set(year, month, date, hour, minute, second); - } - - /** - * Clears the values of all the time fields. - * @stable ICU 2.0 - */ - public final void clear() { - calendar.clear(); - } - - /** - * Clears the value in the given time field. - * @param field the time field to be cleared. - * @stable ICU 2.0 - */ - public final void clear(int field) { - calendar.clear(field); - } - - /** - * Determines if the given time field has a value set. - * @return true if the given time field has a value set; false otherwise. - * @stable ICU 2.0 - */ - public final boolean isSet(int field) { - return calendar.isSet(field); - } - - /** - * Compares this calendar to the specified object. - * The result is true if and only if the argument is - * not null and is a Calendar object that - * represents the same calendar as this object. - * @param obj the object to compare with. - * @return true if the objects are the same; - * false otherwise. - * @stable ICU 2.0 - */ - public boolean equals(Object obj) { - try { - return calendar.equals(((Calendar)obj).calendar); - } - catch (Exception e) { - return false; - } - } - - /** - * Returns true if the given Calendar object is equivalent to this - * one. An equivalent Calendar will behave exactly as this one - * does, but it may be set to a different time. By contrast, for - * the equals() method to return true, the other Calendar must - * be set to the same time. - * - * @param other the Calendar to be compared with this Calendar - * @stable ICU 2.4 - */ - public boolean isEquivalentTo(Calendar other) { - return this.getClass() == other.getClass() && - isLenient() == other.isLenient() && - getFirstDayOfWeek() == other.getFirstDayOfWeek() && - getMinimalDaysInFirstWeek() == other.getMinimalDaysInFirstWeek() && - getTimeZone().equals(other.getTimeZone()); - } - - /** - * Returns a hash code for this calendar. - * @return a hash code value for this object. - * @stable ICU 2.0 - */ - public int hashCode() { - return calendar.hashCode(); - } - - /** - * Return the difference in milliseconds between the moment this - * calendar is set to and the moment the given calendar or Date object - * is set to. - */ - private long compare(Object that) { - long thatMs; - if (that instanceof Calendar) { - thatMs = ((Calendar)that).getTimeInMillis(); - } else if (that instanceof Date) { - thatMs = ((Date)that).getTime(); - } else { - throw new IllegalArgumentException(that + "is not a Calendar or Date"); - } - return getTimeInMillis() - thatMs; - } - - /** - * Compares the time field records. - * Equivalent to comparing result of conversion to UTC. - * @param when the Calendar to be compared with this Calendar. - * @return true if the current time of this Calendar is before - * the time of Calendar when; false otherwise. - * @stable ICU 2.0 - */ - public boolean before(Object when) { - return compare(when) < 0; - } - - /** - * Compares the time field records. - * Equivalent to comparing result of conversion to UTC. - * @param when the Calendar to be compared with this Calendar. - * @return true if the current time of this Calendar is after - * the time of Calendar when; false otherwise. - * @stable ICU 2.0 - */ - public boolean after(Object when) { - return compare(when) > 0; - } - - /** - * Return the maximum value that this field could have, given the - * current date. For example, with the Gregorian date February 3, 1997 - * and the {@link #DAY_OF_MONTH DAY_OF_MONTH} field, the actual maximum - * is 28; for February 3, 1996 it is 29. - * - *

The actual maximum computation ignores smaller fields and the - * current value of like-sized fields. For example, the actual maximum - * of the DAY_OF_YEAR or MONTH depends only on the year and supra-year - * fields. The actual maximum of the DAY_OF_MONTH depends, in - * addition, on the MONTH field and any other fields at that - * granularity (such as ChineseCalendar.IS_LEAP_MONTH). The - * DAY_OF_WEEK_IN_MONTH field does not depend on the current - * DAY_OF_WEEK; it returns the maximum for any day of week in the - * current month. Likewise for the WEEK_OF_MONTH and WEEK_OF_YEAR - * fields. - * - * @param field the field whose maximum is desired - * @return the maximum of the given field for the current date of this calendar - * @see #getMaximum - * @see #getLeastMaximum - * @stable ICU 2.0 - */ - public int getActualMaximum(int field) { - return calendar.getActualMaximum(field); - } - - /** - * Return the minimum value that this field could have, given the current date. - * For most fields, this is the same as {@link #getMinimum getMinimum} - * and {@link #getGreatestMinimum getGreatestMinimum}. However, some fields, - * especially those related to week number, are more complicated. - *

- * For example, assume {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} - * returns 4 and {@link #getFirstDayOfWeek getFirstDayOfWeek} returns SUNDAY. - * If the first day of the month is Sunday, Monday, Tuesday, or Wednesday - * there will be four or more days in the first week, so it will be week number 1, - * and getActualMinimum(WEEK_OF_MONTH) will return 1. However, - * if the first of the month is a Thursday, Friday, or Saturday, there are - * not four days in that week, so it is week number 0, and - * getActualMinimum(WEEK_OF_MONTH) will return 0. - *

- * @param field the field whose actual minimum value is desired. - * @return the minimum of the given field for the current date of this calendar - * - * @see #getMinimum - * @see #getGreatestMinimum - * @stable ICU 2.0 - */ - public int getActualMinimum(int field) { - return calendar.getActualMinimum(field); - } - - - /** - * Rolls (up/down) a single unit of time on the given field. If the - * field is rolled past its maximum allowable value, it will "wrap" back - * to its minimum and continue rolling. For - * example, to roll the current date up by one day, you can call: - *

- * roll({@link #DATE}, true) - *

- * When rolling on the {@link #YEAR} field, it will roll the year - * value in the range between 1 and the value returned by calling - * {@link #getMaximum getMaximum}({@link #YEAR}). - *

- * When rolling on certain fields, the values of other fields may conflict and - * need to be changed. For example, when rolling the MONTH field - * for the Gregorian date 1/31/96 upward, the DAY_OF_MONTH field - * must be adjusted so that the result is 2/29/96 rather than the invalid - * 2/31/96. - *

- * Note: Calling roll(field, true) N times is not - * necessarily equivalent to calling roll(field, N). For example, - * imagine that you start with the date Gregorian date January 31, 1995. If you call - * roll(Calendar.MONTH, 2), the result will be March 31, 1995. - * But if you call roll(Calendar.MONTH, true), the result will be - * February 28, 1995. Calling it one more time will give March 28, 1995, which - * is usually not the desired result. - *

- * Note: You should always use roll and add rather - * than attempting to perform arithmetic operations directly on the fields - * of a Calendar. It is quite possible for Calendar subclasses - * to have fields with non-linear behavior, for example missing months - * or days during non-leap years. The subclasses' add and roll - * methods will take this into account, while simple arithmetic manipulations - * may give invalid results. - *

- * @param field the calendar field to roll. - * - * @param up indicates if the value of the specified time field is to be - * rolled up or rolled down. Use true if rolling up, - * false otherwise. - * - * @exception IllegalArgumentException if the field is invalid or refers - * to a field that cannot be handled by this method. - * @see #roll(int, int) - * @see #add - * @stable ICU 2.0 - */ - public final void roll(int field, boolean up) { - calendar.roll(field, up); - } - - /** - * Rolls (up/down) a specified amount time on the given field. For - * example, to roll the current date up by three days, you can call - * roll(Calendar.DATE, 3). If the - * field is rolled past its maximum allowable value, it will "wrap" back - * to its minimum and continue rolling. - * For example, calling roll(Calendar.DATE, 10) - * on a Gregorian calendar set to 4/25/96 will result in the date 4/5/96. - *

- * When rolling on certain fields, the values of other fields may conflict and - * need to be changed. For example, when rolling the {@link #MONTH MONTH} field - * for the Gregorian date 1/31/96 by +1, the {@link #DAY_OF_MONTH DAY_OF_MONTH} field - * must be adjusted so that the result is 2/29/96 rather than the invalid - * 2/31/96. - *

- * The com.ibm.icu.util.Calendar implementation of this method is able to roll - * all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET}, - * and {@link #ZONE_OFFSET ZONE_OFFSET}. Subclasses may, of course, add support for - * additional fields in their overrides of roll. - *

- * Note: You should always use roll and add rather - * than attempting to perform arithmetic operations directly on the fields - * of a Calendar. It is quite possible for Calendar subclasses - * to have fields with non-linear behavior, for example missing months - * or days during non-leap years. The subclasses' add and roll - * methods will take this into account, while simple arithmetic manipulations - * may give invalid results. - *

- * Subclassing:
- * This implementation of roll assumes that the behavior of the - * field is continuous between its minimum and maximum, which are found by - * calling {@link #getActualMinimum getActualMinimum} and {@link #getActualMaximum getActualMaximum}. - * For most such fields, simple addition, subtraction, and modulus operations - * are sufficient to perform the roll. For week-related fields, - * the results of {@link #getFirstDayOfWeek getFirstDayOfWeek} and - * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} are also necessary. - * Subclasses can override these two methods if their values differ from the defaults. - *

- * Subclasses that have fields for which the assumption of continuity breaks - * down must overide roll to handle those fields specially. - * For example, in the Hebrew calendar the month "Adar I" - * only occurs in leap years; in other years the calendar jumps from - * Shevat (month #4) to Adar (month #6). The - * {@link HebrewCalendar#roll HebrewCalendar.roll} method takes this into account, - * so that rolling the month of Shevat by one gives the proper result (Adar) in a - * non-leap year. - *

- * @param field the calendar field to roll. - * @param amount the amount by which the field should be rolled. - * - * @exception IllegalArgumentException if the field is invalid or refers - * to a field that cannot be handled by this method. - * @see #roll(int, boolean) - * @see #add - * @stable ICU 2.0 - */ - public void roll(int field, int amount) { - calendar.roll(field, amount); - } - - /** - * Add a signed amount to a specified field, using this calendar's rules. - * For example, to add three days to the current date, you can call - * add(Calendar.DATE, 3). - *

- * When adding to certain fields, the values of other fields may conflict and - * need to be changed. For example, when adding one to the {@link #MONTH MONTH} field - * for the Gregorian date 1/31/96, the {@link #DAY_OF_MONTH DAY_OF_MONTH} field - * must be adjusted so that the result is 2/29/96 rather than the invalid - * 2/31/96. - *

- * The com.ibm.icu.util.Calendar implementation of this method is able to add to - * all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET}, - * and {@link #ZONE_OFFSET ZONE_OFFSET}. Subclasses may, of course, add support for - * additional fields in their overrides of add. - *

- * Note: You should always use roll and add rather - * than attempting to perform arithmetic operations directly on the fields - * of a Calendar. It is quite possible for Calendar subclasses - * to have fields with non-linear behavior, for example missing months - * or days during non-leap years. The subclasses' add and roll - * methods will take this into account, while simple arithmetic manipulations - * may give invalid results. - *

- * Subclassing:
- * This implementation of add assumes that the behavior of the - * field is continuous between its minimum and maximum, which are found by - * calling {@link #getActualMinimum getActualMinimum} and - * {@link #getActualMaximum getActualMaximum}. - * For such fields, simple arithmetic operations are sufficient to - * perform the add. - *

- * Subclasses that have fields for which this assumption of continuity breaks - * down must overide add to handle those fields specially. - * For example, in the Hebrew calendar the month "Adar I" - * only occurs in leap years; in other years the calendar jumps from - * Shevat (month #4) to Adar (month #6). The - * {@link HebrewCalendar#add HebrewCalendar.add} method takes this into account, - * so that adding one month - * to a date in Shevat gives the proper result (Adar) in a non-leap year. - *

- * @param field the time field. - * @param amount the amount to add to the field. - * - * @exception IllegalArgumentException if the field is invalid or refers - * to a field that cannot be handled by this method. - * @see #roll(int, int) - * @stable ICU 2.0 - */ - public void add(int field, int amount) { - calendar.add(field, amount); - } - - /** - * Return the name of this calendar in the language of the given locale. - * @stable ICU 2.0 - */ - public String getDisplayName(Locale loc) { - return "Calendar"; - } - - /** - * Return the name of this calendar in the language of the given locale. - * @stable ICU 3.2 - */ - public String getDisplayName(ULocale loc) { - return "Calendar"; - } - - /** - * Compares the times (in millis) represented by two - * Calendar objects. - * - * @param that the Calendar to compare to this. - * @return 0 if the time represented by - * this Calendar is equal to the time represented - * by that Calendar, a value less than - * 0 if the time represented by this is before - * the time represented by that, and a value greater than - * 0 if the time represented by this - * is after the time represented by that. - * @throws NullPointerException if that - * Calendar is null. - * @throws IllegalArgumentException if the time of that - * Calendar can't be obtained because of invalid - * calendar values. - * @stable ICU 3.4 - */ - public int compareTo(Calendar that) { - long v = getTimeInMillis() - that.getTimeInMillis(); - return v < 0 ? -1 : (v > 0 ? 1 : 0); - } - - /** - * Implement comparable API as a convenience override of - * {@link #compareTo(Calendar)}. - * @stable ICU 3.4 - */ - public int compareTo(Object that) { - return compareTo((Calendar)that); - } - - //------------------------------------------------------------------------- - // Interface for creating custon DateFormats for different types of Calendars - //------------------------------------------------------------------------- - - /** - * Return a DateFormat appropriate to this calendar. - * @stable ICU 2.0 - */ - public DateFormat getDateTimeFormat(int dateStyle, int timeStyle, Locale loc) { - return formatHelper(this, loc, dateStyle, timeStyle); - } - - /** - * Return a DateFormat appropriate to this calendar. - * @stable ICU 3.2 - */ - public DateFormat getDateTimeFormat(int dateStyle, int timeStyle, ULocale loc) { - return formatHelper(this, loc.toLocale(), dateStyle, timeStyle); - } - - /* - * Utility for formatting. - */ - private static DateFormat formatHelper(Calendar cal, Locale loc, int dateStyle, int timeStyle) { - // Assume there is only one kind of calendar. In Java 6 there will also be Japanese - // calendars, but we'll worry about that when it happens. - DateFormat df = DateFormat.getDateTimeInstance(dateStyle, timeStyle, loc); - df.setCalendar(cal); - return df; - } - - //------------------------------------------------------------------------- - // Constants - //------------------------------------------------------------------------- - - /** - * [NEW] - * Return the difference between the given time and the time this - * calendar object is set to. If this calendar is set - * before the given time, the returned value will be - * positive. If this calendar is set after the given - * time, the returned value will be negative. The - * field parameter specifies the units of the return - * value. For example, if fieldDifference(when, - * Calendar.MONTH) returns 3, then this calendar is set to - * 3 months before when, and possibly some additional - * time less than one month. - * - *

As a side effect of this call, this calendar is advanced - * toward when by the given amount. That is, calling - * this method has the side effect of calling add(field, - * n), where n is the return value. - * - *

Usage: To use this method, call it first with the largest - * field of interest, then with progressively smaller fields. For - * example: - * - *

-     * int y = cal.fieldDifference(when, Calendar.YEAR);
-     * int m = cal.fieldDifference(when, Calendar.MONTH);
-     * int d = cal.fieldDifference(when, Calendar.DATE);
- * - * computes the difference between cal and - * when in years, months, and days. - * - *

Note: fieldDifference() is - * asymmetrical. That is, in the following code: - * - *

-     * cal.setTime(date1);
-     * int m1 = cal.fieldDifference(date2, Calendar.MONTH);
-     * int d1 = cal.fieldDifference(date2, Calendar.DATE);
-     * cal.setTime(date2);
-     * int m2 = cal.fieldDifference(date1, Calendar.MONTH);
-     * int d2 = cal.fieldDifference(date1, Calendar.DATE);
- * - * one might expect that m1 == -m2 && d1 == -d2. - * However, this is not generally the case, because of - * irregularities in the underlying calendar system (e.g., the - * Gregorian calendar has a varying number of days per month). - * - * @param when the date to compare this calendar's time to - * @param field the field in which to compute the result - * @return the difference, either positive or negative, between - * this calendar's time and when, in terms of - * field. - * @stable ICU 2.0 - */ - public int fieldDifference(Date when, int field) { - int min = 0; - long startMs = getTimeInMillis(); - long targetMs = when.getTime(); - // Always add from the start millis. This accomodates - // operations like adding years from February 29, 2000 up to - // February 29, 2004. If 1, 1, 1, 1 is added to the year - // field, the DOM gets pinned to 28 and stays there, giving an - // incorrect DOM difference of 1. We have to add 1, reset, 2, - // reset, 3, reset, 4. - if (startMs < targetMs) { - int max = 1; - // Find a value that is too large - for (;;) { - setTimeInMillis(startMs); - add(field, max); - long ms = getTimeInMillis(); - if (ms == targetMs) { - return max; - } else if (ms > targetMs) { - break; - } else { - max <<= 1; - if (max < 0) { - // Field difference too large to fit into int - throw new RuntimeException(); - } - } - } - // Do a binary search - while ((max - min) > 1) { - int t = (min + max) / 2; - setTimeInMillis(startMs); - add(field, t); - long ms = getTimeInMillis(); - if (ms == targetMs) { - return t; - } else if (ms > targetMs) { - max = t; - } else { - min = t; - } - } - } else if (startMs > targetMs) { - if (false) { - // This works, and makes the code smaller, but costs - // an extra object creation and an extra couple cycles - // of calendar computation. - setTimeInMillis(targetMs); - min = -fieldDifference(new Date(startMs), field); - } - int max = -1; - // Find a value that is too small - for (;;) { - setTimeInMillis(startMs); - add(field, max); - long ms = getTimeInMillis(); - if (ms == targetMs) { - return max; - } else if (ms < targetMs) { - break; - } else { - max <<= 1; - if (max == 0) { - // Field difference too large to fit into int - throw new RuntimeException(); - } - } - } - // Do a binary search - while ((min - max) > 1) { - int t = (min + max) / 2; - setTimeInMillis(startMs); - add(field, t); - long ms = getTimeInMillis(); - if (ms == targetMs) { - return t; - } else if (ms < targetMs) { - max = t; - } else { - min = t; - } - } - } - // Set calendar to end point - setTimeInMillis(startMs); - add(field, min); - return min; - } - - /** - * Sets the time zone with the given time zone value. - * @param value the given time zone. - * @stable ICU 2.0 - */ - public void setTimeZone(TimeZone value) { - calendar.setTimeZone(value.timeZone); - } - - /** - * Gets the time zone. - * @return the time zone object associated with this calendar. - * @stable ICU 2.0 - */ - public TimeZone getTimeZone() { - return new TimeZone(calendar.getTimeZone()); - } - - /** - * Specify whether or not date/time interpretation is to be lenient. With - * lenient interpretation, a date such as "February 942, 1996" will be - * treated as being equivalent to the 941st day after February 1, 1996. - * With strict interpretation, such dates will cause an exception to be - * thrown. - * - * @see DateFormat#setLenient - * @stable ICU 2.0 - */ - public void setLenient(boolean lenient) { - calendar.setLenient(lenient); - } - - /** - * Tell whether date/time interpretation is to be lenient. - * @stable ICU 2.0 - */ - public boolean isLenient() { - return calendar.isLenient(); - } - - /** - * Sets what the first day of the week is; e.g., Sunday in US, - * Monday in France. - * @param value the given first day of the week. - * @stable ICU 2.0 - */ - public void setFirstDayOfWeek(int value) { - calendar.setFirstDayOfWeek(value); - } - - /** - * Gets what the first day of the week is; e.g., Sunday in US, - * Monday in France. - * @return the first day of the week. - * @stable ICU 2.0 - */ - public int getFirstDayOfWeek() { - return calendar.getFirstDayOfWeek(); - } - - /** - * Sets what the minimal days required in the first week of the year are. - * For example, if the first week is defined as one that contains the first - * day of the first month of a year, call the method with value 1. If it - * must be a full week, use value 7. - * @param value the given minimal days required in the first week - * of the year. - * @stable ICU 2.0 - */ - public void setMinimalDaysInFirstWeek(int value) { - calendar.setMinimalDaysInFirstWeek(value); - } - - /** - * Gets what the minimal days required in the first week of the year are; - * e.g., if the first week is defined as one that contains the first day - * of the first month of a year, getMinimalDaysInFirstWeek returns 1. If - * the minimal days required must be a full week, getMinimalDaysInFirstWeek - * returns 7. - * @return the minimal days required in the first week of the year. - * @stable ICU 2.0 - */ - public int getMinimalDaysInFirstWeek() { - return calendar.getMinimalDaysInFirstWeek(); - } - - /** - * Gets the minimum value for the given time field. - * e.g., for Gregorian DAY_OF_MONTH, 1. - * @param field the given time field. - * @return the minimum value for the given time field. - * @stable ICU 2.0 - */ - public final int getMinimum(int field) { - return calendar.getMinimum(field); - } - - /** - * Gets the maximum value for the given time field. - * e.g. for Gregorian DAY_OF_MONTH, 31. - * @param field the given time field. - * @return the maximum value for the given time field. - * @stable ICU 2.0 - */ - public final int getMaximum(int field) { - return calendar.getMaximum(field); - } - - /** - * Gets the highest minimum value for the given field if varies. - * Otherwise same as getMinimum(). For Gregorian, no difference. - * @param field the given time field. - * @return the highest minimum value for the given time field. - * @stable ICU 2.0 - */ - public final int getGreatestMinimum(int field) { - return calendar.getGreatestMinimum(field); - } - - /** - * Gets the lowest maximum value for the given field if varies. - * Otherwise same as getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28. - * @param field the given time field. - * @return the lowest maximum value for the given time field. - * @stable ICU 2.0 - */ - public final int getLeastMaximum(int field) { - return calendar.getLeastMaximum(field); - } - - //------------------------------------------------------------------------- - // Weekend support -- determining which days of the week are the weekend - // in a given locale - //------------------------------------------------------------------------- - - /** - * Return whether the given day of the week is a weekday, a - * weekend day, or a day that transitions from one to the other, - * in this calendar system. If a transition occurs at midnight, - * then the days before and after the transition will have the - * type WEEKDAY or WEEKEND. If a transition occurs at a time - * other than midnight, then the day of the transition will have - * the type WEEKEND_ONSET or WEEKEND_CEASE. In this case, the - * method getWeekendTransition() will return the point of - * transition. - * @param dayOfWeek either SUNDAY, MONDAY, TUESDAY, WEDNESDAY, - * THURSDAY, FRIDAY, or SATURDAY - * @return either WEEKDAY, WEEKEND, WEEKEND_ONSET, or - * WEEKEND_CEASE - * @exception IllegalArgumentException if dayOfWeek is not - * between SUNDAY and SATURDAY, inclusive - * @see #WEEKDAY - * @see #WEEKEND - * @see #WEEKEND_ONSET - * @see #WEEKEND_CEASE - * @see #getWeekendTransition - * @see #isWeekend(Date) - * @see #isWeekend() - * @stable ICU 2.0 - */ - public int getDayOfWeekType(int dayOfWeek) { - // weekend always full saturday and sunday - if (dayOfWeek < 1 || dayOfWeek > 7) { - throw new IllegalArgumentException("illegal day of week: " + dayOfWeek); - } - return dayOfWeek >= SATURDAY ? WEEKEND : WEEKDAY; - } - - /** - * Return the time during the day at which the weekend begins or end in - * this calendar system. If getDayOfWeekType(dayOfWeek) == - * WEEKEND_ONSET return the time at which the weekend begins. If - * getDayOfWeekType(dayOfWeek) == WEEKEND_CEASE return the time at - * which the weekend ends. If getDayOfWeekType(dayOfWeek) has some - * other value, then throw an exception. - * @param dayOfWeek either SUNDAY, MONDAY, TUESDAY, WEDNESDAY, - * THURSDAY, FRIDAY, or SATURDAY - * @return the milliseconds after midnight at which the - * weekend begins or ends - * @exception IllegalArgumentException if dayOfWeek is not - * WEEKEND_ONSET or WEEKEND_CEASE - * @see #getDayOfWeekType - * @see #isWeekend(Date) - * @see #isWeekend() - * @stable ICU 2.0 - */ - public int getWeekendTransition(int dayOfWeek) { - throw new IllegalArgumentException("Not weekend transition day"); - } - - /** - * Return true if the given date and time is in the weekend in - * this calendar system. Equivalent to calling setTime() followed - * by isWeekend(). Note: This method changes the time this - * calendar is set to. - * @param date the date and time - * @return true if the given date and time is part of the - * weekend - * @see #getDayOfWeekType - * @see #getWeekendTransition - * @see #isWeekend() - * @stable ICU 2.0 - */ - public boolean isWeekend(Date date) { - calendar.setTime(date); - return isWeekend(); - } - - /** - * Return true if this Calendar's current date and time is in the - * weekend in this calendar system. - * @return true if the given date and time is part of the - * weekend - * @see #getDayOfWeekType - * @see #getWeekendTransition - * @see #isWeekend(Date) - * @stable ICU 2.0 - */ - public boolean isWeekend() { - return calendar.get(Calendar.DAY_OF_WEEK) >= SATURDAY; - } - - //------------------------------------------------------------------------- - // End of weekend support - //------------------------------------------------------------------------- - - /** - * Overrides Cloneable - * @stable ICU 2.0 - */ - public Object clone() { - return new Calendar((java.util.Calendar)calendar.clone()); - } - - /** - * Return a string representation of this calendar. This method - * is intended to be used only for debugging purposes, and the - * format of the returned string may vary between implementations. - * The returned string may be empty but may not be null. - * - * @return a string representation of this calendar. - * @stable ICU 2.0 - */ - public String toString() { - return calendar.toString(); - } - - /** - * Return the current Calendar type. - * Note, in 3.0 this function will return 'gregorian' in Calendar to emulate legacy behavior - * @return type of calendar (gregorian, etc) - * @internal ICU 3.0 - */ - public String getType() { - return "gregorian"; - } -} - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/TimeZone.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/TimeZone.java deleted file mode 100644 index 878afeb88a9..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/TimeZone.java +++ /dev/null @@ -1,432 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ - -package com.ibm.icu.util; - -import java.io.Serializable; -import java.util.Date; -import java.util.Locale; - -/** - * TimeZone represents a time zone offset, and also figures out daylight - * savings. - * - *

- * Typically, you get a TimeZone using getDefault - * which creates a TimeZone based on the time zone where the program - * is running. For example, for a program running in Japan, getDefault - * creates a TimeZone object based on Japanese Standard Time. - * - *

- * You can also get a TimeZone using getTimeZone - * along with a time zone ID. For instance, the time zone ID for the - * U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a - * U.S. Pacific Time TimeZone object with: - *

- *
- * TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
- * 
- *
- * You can use getAvailableIDs method to iterate through - * all the supported time zone IDs. You can then choose a - * supported ID to get a TimeZone. - * If the time zone you want is not represented by one of the - * supported IDs, then you can create a custom time zone ID with - * the following syntax: - * - *
- *
- * GMT[+|-]hh[[:]mm]
- * 
- *
- * - * For example, you might specify GMT+14:00 as a custom - * time zone ID. The TimeZone that is returned - * when you specify a custom time zone ID does not include - * daylight savings time. - *

- * For compatibility with JDK 1.1.x, some other three-letter time zone IDs - * (such as "PST", "CTT", "AST") are also supported. However, their - * use is deprecated because the same abbreviation is often used - * for multiple time zones (for example, "CST" could be U.S. "Central Standard - * Time" and "China Standard Time"), and the Java platform can then only - * recognize one of them. - * - * @see Calendar - * @see GregorianCalendar - * @see SimpleTimeZone - * @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu - * @stable ICU 2.0 - */ -public class TimeZone implements Serializable, Cloneable { - private static final long serialVersionUID = 1; - - /** - * @internal - */ - public final java.util.TimeZone timeZone; - - /** - * @internal - * @param delegate the TimeZone to which to delegate - */ - public TimeZone(java.util.TimeZone delegate) { - this.timeZone = delegate; - } - - /** - * Default constructor to mirror Java's public - * constructor. Java's is not callable as a public API, since - * their TimeZone is abstract, so this is only useful to - * subclasses. In general, subclasses will not work unless - * they manipulate the delegate. - */ - public TimeZone() { - this.timeZone = java.util.TimeZone.getDefault(); - } - - /** - * A style specifier for getDisplayName() indicating - * a short name, such as "PST." - * @see #LONG - * @stable ICU 2.0 - */ - public static final int SHORT = 0; - - /** - * A style specifier for getDisplayName() indicating - * a long name, such as "Pacific Standard Time." - * @see #SHORT - * @stable ICU 2.0 - */ - public static final int LONG = 1; - - /** - * Gets the time zone offset, for current date, modified in case of - * daylight savings. This is the offset to add *to* UTC to get local time. - * @param era the era of the given date. - * @param year the year in the given date. - * @param month the month in the given date. - * Month is 0-based. e.g., 0 for January. - * @param day the day-in-month of the given date. - * @param dayOfWeek the day-of-week of the given date. - * @param milliseconds the millis in day in standard local time. - * @return the offset to add *to* GMT to get local time. - * @stable ICU 2.0 - */ - public int getOffset(int era, int year, int month, int day, - int dayOfWeek, int milliseconds) { - return timeZone.getOffset(era, year, month, day, dayOfWeek, milliseconds); - } - - /** - * Returns the offset of this time zone from UTC at the specified - * date. If Daylight Saving Time is in effect at the specified - * date, the offset value is adjusted with the amount of daylight - * saving. - * - * @param date the date represented in milliseconds since January 1, 1970 00:00:00 GMT - * @return the amount of time in milliseconds to add to UTC to get local time. - * - * @see Calendar#ZONE_OFFSET - * @see Calendar#DST_OFFSET - * @see #getOffset(long, boolean, int[]) - * @stable ICU 2.8 - */ - public int getOffset(long date) { - if (inDaylightTime(new Date(date))) { - return getRawOffset() + getDSTSavings(); - } - return getRawOffset(); - } - - /** - * Sets the base time zone offset to GMT. - * This is the offset to add *to* UTC to get local time. - * @param offsetMillis the given base time zone offset to GMT. - * @stable ICU 2.0 - */ - public void setRawOffset(int offsetMillis) { - timeZone.setRawOffset(offsetMillis); - } - - /** - * Gets unmodified offset, NOT modified in case of daylight savings. - * This is the offset to add *to* UTC to get local time. - * @return the unmodified offset to add *to* UTC to get local time. - * @stable ICU 2.0 - */ - public int getRawOffset() { - return timeZone.getRawOffset(); - } - - /** - * Gets the ID of this time zone. - * @return the ID of this time zone. - * @stable ICU 2.0 - */ - public String getID() { - return timeZone.getID(); - } - - /** - * Sets the time zone ID. This does not change any other data in - * the time zone object. - * @param ID the new time zone ID. - * @stable ICU 2.0 - */ - public void setID(String ID) { - timeZone.setID(ID); - } - - /** - * Returns a name of this time zone suitable for presentation to the user - * in the default locale. - * This method returns the long generic name. - * If the display name is not available for the locale, - * a fallback based on the country, city, or time zone id will be used. - * @return the human-readable name of this time zone in the default locale. - * @stable ICU 2.0 - */ - public final String getDisplayName() { - return timeZone.getDisplayName(); - } - - /** - * Returns a name of this time zone suitable for presentation to the user - * in the specified locale. - * This method returns the long generic name. - * If the display name is not available for the locale, - * a fallback based on the country, city, or time zone id will be used. - * @param locale the locale in which to supply the display name. - * @return the human-readable name of this time zone in the given locale - * or in the default locale if the given locale is not recognized. - * @stable ICU 2.0 - */ - public final String getDisplayName(Locale locale) { - return timeZone.getDisplayName(locale); - } - - /** - * Returns a name of this time zone suitable for presentation to the user - * in the specified locale. - * This method returns the long name, not including daylight savings. - * If the display name is not available for the locale, - * a fallback based on the country, city, or time zone id will be used. - * @param locale the ulocale in which to supply the display name. - * @return the human-readable name of this time zone in the given locale - * or in the default ulocale if the given ulocale is not recognized. - * @stable ICU 3.2 - */ - public final String getDisplayName(ULocale locale) { - return timeZone.getDisplayName(locale.toLocale()); - } - - /** - * Returns a name of this time zone suitable for presentation to the user - * in the default locale. - * If the display name is not available for the locale, - * then this method returns a string in the format - * GMT[+-]hh:mm. - * @param daylight if true, return the daylight savings name. - * @param style either LONG or SHORT - * @return the human-readable name of this time zone in the default locale. - * @stable ICU 2.0 - */ - public final String getDisplayName(boolean daylight, int style) { - return timeZone.getDisplayName(daylight, style); - } - - /** - * Returns a name of this time zone suitable for presentation to the user - * in the specified locale. - * If the display name is not available for the locale, - * then this method returns a string in the format - * GMT[+-]hh:mm. - * @param daylight if true, return the daylight savings name. - * @param style either LONG or SHORT - * @param locale the locale in which to supply the display name. - * @return the human-readable name of this time zone in the given locale - * or in the default locale if the given locale is not recognized. - * @exception IllegalArgumentException style is invalid. - * @stable ICU 2.0 - */ - public String getDisplayName(boolean daylight, int style, Locale locale) { - return timeZone.getDisplayName(daylight, style, locale); - } - - /** - * Returns a name of this time zone suitable for presentation to the user - * in the specified locale. - * If the display name is not available for the locale, - * then this method returns a string in the format - * GMT[+-]hh:mm. - * @param daylight if true, return the daylight savings name. - * @param style either LONG or SHORT - * @param locale the locale in which to supply the display name. - * @return the human-readable name of this time zone in the given locale - * or in the default locale if the given locale is not recognized. - * @exception IllegalArgumentException style is invalid. - * @stable ICU 3.2 - */ - public String getDisplayName(boolean daylight, int style, ULocale locale) { - return timeZone.getDisplayName(daylight, style, locale.toLocale()); - } - - /** - * Returns the amount of time to be added to local standard time - * to get local wall clock time. - *

- * The default implementation always returns 3600000 milliseconds - * (i.e., one hour) if this time zone observes Daylight Saving - * Time. Otherwise, 0 (zero) is returned. - *

- * If an underlying TimeZone implementation subclass supports - * historical Daylight Saving Time changes, this method returns - * the known latest daylight saving value. - * - * @return the amount of saving time in milliseconds - * @stable ICU 2.8 - */ - public int getDSTSavings() { - if (useDaylightTime()) { - return 3600000; - } - return 0; - } - - /** - * Queries if this time zone uses daylight savings time. - * @return true if this time zone uses daylight savings time, - * false, otherwise. - * @stable ICU 2.0 - */ - public boolean useDaylightTime() { - return timeZone.useDaylightTime(); - } - - /** - * Queries if the given date is in daylight savings time in - * this time zone. - * @param date the given Date. - * @return true if the given date is in daylight savings time, - * false, otherwise. - * @stable ICU 2.0 - */ - public boolean inDaylightTime(Date date) { - return timeZone.inDaylightTime(date); - } - - /** - * Gets the TimeZone for the given ID. - * - * @param ID the ID for a TimeZone, either an abbreviation - * such as "PST", a full name such as "America/Los_Angeles", or a custom - * ID such as "GMT-8:00". Note that the support of abbreviations is - * for JDK 1.1.x compatibility only and full names should be used. - * - * @return the specified TimeZone, or the GMT zone if the given ID - * cannot be understood. - * @stable ICU 2.0 - */ - public static TimeZone getTimeZone(String ID) { - return new TimeZone(java.util.TimeZone.getTimeZone(ID)); - } - - /** - * Return a new String array containing all system TimeZone IDs - * with the given raw offset from GMT. These IDs may be passed to - * get() to construct the corresponding TimeZone - * object. - * @param rawOffset the offset in milliseconds from GMT - * @return an array of IDs for system TimeZones with the given - * raw offset. If there are none, return a zero-length array. - * @stable ICU 2.0 - */ - public static String[] getAvailableIDs(int rawOffset) { - return java.util.TimeZone.getAvailableIDs(rawOffset); - } - - /** - * Return a new String array containing all system TimeZone IDs. - * These IDs (and only these IDs) may be passed to - * get() to construct the corresponding TimeZone - * object. - * @return an array of all system TimeZone IDs - * @stable ICU 2.0 - */ - public static String[] getAvailableIDs() { - return java.util.TimeZone.getAvailableIDs(); - } - - /** - * Gets the default TimeZone for this host. - * The source of the default TimeZone - * may vary with implementation. - * @return a default TimeZone. - * @stable ICU 2.0 - */ - public static TimeZone getDefault() { - return new TimeZone(java.util.TimeZone.getDefault()); - } - - /** - * Sets the TimeZone that is - * returned by the getDefault method. If zone - * is null, reset the default to the value it had originally when the - * VM first started. - * @param tz the new default time zone - * @stable ICU 2.0 - */ - public static void setDefault(TimeZone tz) { - java.util.TimeZone.setDefault(tz.timeZone); - } - - /** - * Returns true if this zone has the same rule and offset as another zone. - * That is, if this zone differs only in ID, if at all. Returns false - * if the other zone is null. - * @param other the TimeZone object to be compared with - * @return true if the other zone is not null and is the same as this one, - * with the possible exception of the ID - * @stable ICU 2.0 - */ - public boolean hasSameRules(TimeZone other) { - return timeZone.hasSameRules(other.timeZone); - } - - /** - * Overrides Cloneable - * @stable ICU 2.0 - */ - public Object clone() { - return new TimeZone((java.util.TimeZone)timeZone.clone()); - } - - /** - * Return true if rhs is a TimeZone and has the same time rules as this. - * @return true if rhs equals this - * @stable ICU 3.4.2 - */ - public boolean equals(Object rhs){ - try { - return timeZone.equals(((TimeZone)rhs).timeZone); - } - catch (Exception e) { - return false; - } - } - - /** - * Return a hashCode. - * @return a hashCode - * @stable ICU 3.4.2 - */ - public int hashCode(){ - return timeZone.hashCode(); - } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/ULocale.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/ULocale.java deleted file mode 100644 index ea9a603ab3f..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.base/src/com/ibm/icu/util/ULocale.java +++ /dev/null @@ -1,3822 +0,0 @@ -/* -****************************************************************************** -* Copyright (C) 2003-2008, International Business Machines Corporation and * -* others. All Rights Reserved. * -****************************************************************************** -*/ - -package com.ibm.icu.util; - -import java.io.Serializable; -import java.lang.ref.SoftReference; -import java.text.ParseException; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.TreeMap; - -//import com.ibm.icu.impl.SimpleCache; -//import com.ibm.icu.impl.ICUResourceBundle; -//import com.ibm.icu.impl.LocaleUtility; - -/** - * A class analogous to {@link java.util.Locale} that provides additional - * support for ICU protocol. In ICU 3.0 this class is enhanced to support - * RFC 3066 language identifiers. - * - *

Many classes and services in ICU follow a factory idiom, in - * which a factory method or object responds to a client request with - * an object. The request includes a locale (the requested - * locale), and the returned object is constructed using data for that - * locale. The system may lack data for the requested locale, in - * which case the locale fallback mechanism will be invoked until a - * populated locale is found (the valid locale). Furthermore, - * even when a populated locale is found (the valid locale), - * further fallback may be required to reach a locale containing the - * specific data required by the service (the actual locale). - * - *

ULocale performs 'normalization' and 'canonicalization' of locale ids. - * Normalization 'cleans up' ICU locale ids as follows: - *

    - *
  • language, script, country, variant, and keywords are properly cased
    - * (lower, title, upper, upper, and lower case respectively)
  • - *
  • hyphens used as separators are converted to underscores
  • - *
  • three-letter language and country ids are converted to two-letter - * equivalents where available
  • - *
  • surrounding spaces are removed from keywords and values
  • - *
  • if there are multiple keywords, they are put in sorted order
  • - *
- * Canonicalization additionally performs the following: - *
    - *
  • POSIX ids are converted to ICU format IDs
  • - *
  • 'grandfathered' 3066 ids are converted to ICU standard form
  • - *
  • 'PREEURO' and 'EURO' variants are converted to currency keyword form, with the currency - * id appropriate to the country of the locale (for PREEURO) or EUR (for EURO). - *
- * All ULocale constructors automatically normalize the locale id. To handle - * POSIX ids, canonicalize can be called to convert the id - * to canonical form, or the canonicalInstance factory method - * can be called.

- * - *

This class provides selectors {@link #VALID_LOCALE} and {@link - * #ACTUAL_LOCALE} intended for use in methods named - * getLocale(). These methods exist in several ICU classes, - * including {@link com.ibm.icu.util.Calendar}, {@link - * com.ibm.icu.util.Currency}, {@link com.ibm.icu.text.UFormat}, - * {@link com.ibm.icu.text.BreakIterator}, {@link - * com.ibm.icu.text.Collator}, {@link - * com.ibm.icu.text.DateFormatSymbols}, and {@link - * com.ibm.icu.text.DecimalFormatSymbols} and their subclasses, if - * any. Once an object of one of these classes has been created, - * getLocale() may be called on it to determine the valid and - * actual locale arrived at during the object's construction. - * - *

Note: The getLocale() method will be implemented in ICU - * 3.0; ICU 2.8 contains a partial preview implementation. The - * actual locale is returned correctly, but the valid - * locale is not, in most cases. - * - * @see java.util.Locale - * @author weiv - * @author Alan Liu - * @author Ram Viswanadha - * @stable ICU 2.8 - */ -public final class ULocale implements Serializable { - // using serialver from jdk1.4.2_05 - private static final long serialVersionUID = 3715177670352309217L; - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale ENGLISH = new ULocale("en", Locale.ENGLISH); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale FRENCH = new ULocale("fr", Locale.FRENCH); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale GERMAN = new ULocale("de", Locale.GERMAN); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale ITALIAN = new ULocale("it", Locale.ITALIAN); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale JAPANESE = new ULocale("ja", Locale.JAPANESE); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale KOREAN = new ULocale("ko", Locale.KOREAN); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale CHINESE = new ULocale("zh", Locale.CHINESE); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale SIMPLIFIED_CHINESE = new ULocale("zh_Hans", Locale.CHINESE); - - /** - * Useful constant for language. - * @stable ICU 3.0 - */ - public static final ULocale TRADITIONAL_CHINESE = new ULocale("zh_Hant", Locale.CHINESE); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale FRANCE = new ULocale("fr_FR", Locale.FRANCE); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale GERMANY = new ULocale("de_DE", Locale.GERMANY); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale ITALY = new ULocale("it_IT", Locale.ITALY); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale JAPAN = new ULocale("ja_JP", Locale.JAPAN); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale KOREA = new ULocale("ko_KR", Locale.KOREA); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale CHINA = new ULocale("zh_Hans_CN", Locale.CHINA); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale PRC = CHINA; - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale TAIWAN = new ULocale("zh_Hant_TW", Locale.TAIWAN); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale UK = new ULocale("en_GB", Locale.UK); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale US = new ULocale("en_US", Locale.US); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale CANADA = new ULocale("en_CA", Locale.CANADA); - - /** - * Useful constant for country/region. - * @stable ICU 3.0 - */ - public static final ULocale CANADA_FRENCH = new ULocale("fr_CA", Locale.CANADA_FRENCH); - - /** - * Handy constant. - */ - private static final String EMPTY_STRING = ""; - - // Used in both ULocale and IDParser, so moved up here. - private static final char UNDERSCORE = '_'; - - // default empty locale - private static final Locale EMPTY_LOCALE = new Locale("", ""); - - /** - * The root ULocale. - * @stable ICU 2.8 - */ - public static final ULocale ROOT = new ULocale("root", EMPTY_LOCALE); - -// private static final SimpleCache CACHE = new SimpleCache(); - private static final HashMap CACHE = new HashMap(20); - - /** - * Cache the locale. - */ - private transient Locale locale; - - /** - * The raw localeID that we were passed in. - */ - private String localeID; - - /** - * Tables used in normalizing portions of the id. - */ - /* tables updated per http://lcweb.loc.gov/standards/iso639-2/ - to include the revisions up to 2001/7/27 *CWB*/ - /* The 3 character codes are the terminology codes like RFC 3066. - This is compatible with prior ICU codes */ - /* "in" "iw" "ji" "jw" & "sh" have been withdrawn but are still in - the table but now at the end of the table because - 3 character codes are duplicates. This avoids bad searches - going from 3 to 2 character codes.*/ - /* The range qaa-qtz is reserved for local use. */ - - private static String[] _languages; - private static String[] _replacementLanguages; - private static String[] _obsoleteLanguages; - private static String[] _languages3; - private static String[] _obsoleteLanguages3; - - // Avoid initializing languages tables unless we have to. - private static void initLanguageTables() { - if (_languages == null) { - - /* This list MUST be in sorted order, and MUST contain the two-letter codes - if one exists otherwise use the three letter code */ - String[] tempLanguages = { - "aa", "ab", "ace", "ach", "ada", "ady", "ae", "af", "afa", - "afh", "ak", "akk", "ale", "alg", "am", "an", "ang", "apa", - "ar", "arc", "arn", "arp", "art", "arw", "as", "ast", - "ath", "aus", "av", "awa", "ay", "az", "ba", "bad", - "bai", "bal", "ban", "bas", "bat", "be", "bej", - "bem", "ber", "bg", "bh", "bho", "bi", "bik", "bin", - "bla", "bm", "bn", "bnt", "bo", "br", "bra", "bs", - "btk", "bua", "bug", "byn", "ca", "cad", "cai", "car", "cau", - "ce", "ceb", "cel", "ch", "chb", "chg", "chk", "chm", - "chn", "cho", "chp", "chr", "chy", "cmc", "co", "cop", - "cpe", "cpf", "cpp", "cr", "crh", "crp", "cs", "csb", "cu", "cus", - "cv", "cy", "da", "dak", "dar", "day", "de", "del", "den", - "dgr", "din", "doi", "dra", "dsb", "dua", "dum", "dv", "dyu", - "dz", "ee", "efi", "egy", "eka", "el", "elx", "en", - "enm", "eo", "es", "et", "eu", "ewo", "fa", - "fan", "fat", "ff", "fi", "fiu", "fj", "fo", "fon", - "fr", "frm", "fro", "fur", "fy", "ga", "gaa", "gay", - "gba", "gd", "gem", "gez", "gil", "gl", "gmh", "gn", - "goh", "gon", "gor", "got", "grb", "grc", "gu", "gv", - "gwi", "ha", "hai", "haw", "he", "hi", "hil", "him", - "hit", "hmn", "ho", "hr", "hsb", "ht", "hu", "hup", "hy", "hz", - "ia", "iba", "id", "ie", "ig", "ii", "ijo", "ik", - "ilo", "inc", "ine", "inh", "io", "ira", "iro", "is", "it", - "iu", "ja", "jbo", "jpr", "jrb", "jv", "ka", "kaa", "kab", - "kac", "kam", "kar", "kaw", "kbd", "kg", "kha", "khi", - "kho", "ki", "kj", "kk", "kl", "km", "kmb", "kn", - "ko", "kok", "kos", "kpe", "kr", "krc", "kro", "kru", "ks", - "ku", "kum", "kut", "kv", "kw", "ky", "la", "lad", - "lah", "lam", "lb", "lez", "lg", "li", "ln", "lo", "lol", - "loz", "lt", "lu", "lua", "lui", "lun", "luo", "lus", - "lv", "mad", "mag", "mai", "mak", "man", "map", "mas", - "mdf", "mdr", "men", "mg", "mga", "mh", "mi", "mic", "min", - "mis", "mk", "mkh", "ml", "mn", "mnc", "mni", "mno", - "mo", "moh", "mos", "mr", "ms", "mt", "mul", "mun", - "mus", "mwr", "my", "myn", "myv", "na", "nah", "nai", "nap", - "nb", "nd", "nds", "ne", "new", "ng", "nia", "nic", - "niu", "nl", "nn", "no", "nog", "non", "nr", "nso", "nub", - "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", "oc", "oj", - "om", "or", "os", "osa", "ota", "oto", "pa", "paa", - "pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn", - "pi", "pl", "pon", "pra", "pro", "ps", "pt", "qu", - "raj", "rap", "rar", "rm", "rn", "ro", "roa", "rom", - "ru", "rup", "rw", "sa", "sad", "sah", "sai", "sal", "sam", - "sas", "sat", "sc", "sco", "sd", "se", "sel", "sem", - "sg", "sga", "sgn", "shn", "si", "sid", "sio", "sit", - "sk", "sl", "sla", "sm", "sma", "smi", "smj", "smn", - "sms", "sn", "snk", "so", "sog", "son", "sq", "sr", - "srr", "ss", "ssa", "st", "su", "suk", "sus", "sux", - "sv", "sw", "syr", "ta", "tai", "te", "tem", "ter", - "tet", "tg", "th", "ti", "tig", "tiv", "tk", "tkl", - "tl", "tlh", "tli", "tmh", "tn", "to", "tog", "tpi", "tr", - "ts", "tsi", "tt", "tum", "tup", "tut", "tvl", "tw", - "ty", "tyv", "udm", "ug", "uga", "uk", "umb", "und", "ur", - "uz", "vai", "ve", "vi", "vo", "vot", "wa", "wak", - "wal", "war", "was", "wen", "wo", "xal", "xh", "yao", "yap", - "yi", "yo", "ypk", "za", "zap", "zen", "zh", "znd", - "zu", "zun", - }; - - String[] tempReplacementLanguages = { - "id", "he", "yi", "jv", "sr", "nb",/* replacement language codes */ - }; - - String[] tempObsoleteLanguages = { - "in", "iw", "ji", "jw", "sh", "no", /* obsolete language codes */ - }; - - /* This list MUST contain a three-letter code for every two-letter code in the - list above, and they MUST ne in the same order (i.e., the same language must - be in the same place in both lists)! */ - String[] tempLanguages3 = { - /*"aa", "ab", "ace", "ach", "ada", "ady", "ae", "af", "afa", */ - "aar", "abk", "ace", "ach", "ada", "ady", "ave", "afr", "afa", - /*"afh", "ak", "akk", "ale", "alg", "am", "an", "ang", "apa", */ - "afh", "aka", "akk", "ale", "alg", "amh", "arg", "ang", "apa", - /*"ar", "arc", "arn", "arp", "art", "arw", "as", "ast", */ - "ara", "arc", "arn", "arp", "art", "arw", "asm", "ast", - /*"ath", "aus", "av", "awa", "ay", "az", "ba", "bad", */ - "ath", "aus", "ava", "awa", "aym", "aze", "bak", "bad", - /*"bai", "bal", "ban", "bas", "bat", "be", "bej", */ - "bai", "bal", "ban", "bas", "bat", "bel", "bej", - /*"bem", "ber", "bg", "bh", "bho", "bi", "bik", "bin", */ - "bem", "ber", "bul", "bih", "bho", "bis", "bik", "bin", - /*"bla", "bm", "bn", "bnt", "bo", "br", "bra", "bs", */ - "bla", "bam", "ben", "bnt", "bod", "bre", "bra", "bos", - /*"btk", "bua", "bug", "byn", "ca", "cad", "cai", "car", "cau", */ - "btk", "bua", "bug", "byn", "cat", "cad", "cai", "car", "cau", - /*"ce", "ceb", "cel", "ch", "chb", "chg", "chk", "chm", */ - "che", "ceb", "cel", "cha", "chb", "chg", "chk", "chm", - /*"chn", "cho", "chp", "chr", "chy", "cmc", "co", "cop", */ - "chn", "cho", "chp", "chr", "chy", "cmc", "cos", "cop", - /*"cpe", "cpf", "cpp", "cr", "crh", "crp", "cs", "csb", "cu", "cus", */ - "cpe", "cpf", "cpp", "cre", "crh", "crp", "ces", "csb", "chu", "cus", - /*"cv", "cy", "da", "dak", "dar", "day", "de", "del", "den", */ - "chv", "cym", "dan", "dak", "dar", "day", "deu", "del", "den", - /*"dgr", "din", "doi", "dra", "dsb", "dua", "dum", "dv", "dyu", */ - "dgr", "din", "doi", "dra", "dsb", "dua", "dum", "div", "dyu", - /*"dz", "ee", "efi", "egy", "eka", "el", "elx", "en", */ - "dzo", "ewe", "efi", "egy", "eka", "ell", "elx", "eng", - /*"enm", "eo", "es", "et", "eu", "ewo", "fa", */ - "enm", "epo", "spa", "est", "eus", "ewo", "fas", - /*"fan", "fat", "ff", "fi", "fiu", "fj", "fo", "fon", */ - "fan", "fat", "ful", "fin", "fiu", "fij", "fao", "fon", - /*"fr", "frm", "fro", "fur", "fy", "ga", "gaa", "gay", */ - "fra", "frm", "fro", "fur", "fry", "gle", "gaa", "gay", - /*"gba", "gd", "gem", "gez", "gil", "gl", "gmh", "gn", */ - "gba", "gla", "gem", "gez", "gil", "glg", "gmh", "grn", - /*"goh", "gon", "gor", "got", "grb", "grc", "gu", "gv", */ - "goh", "gon", "gor", "got", "grb", "grc", "guj", "glv", - /*"gwi", "ha", "hai", "haw", "he", "hi", "hil", "him", */ - "gwi", "hau", "hai", "haw", "heb", "hin", "hil", "him", - /*"hit", "hmn", "ho", "hr", "hsb", "ht", "hu", "hup", "hy", "hz", */ - "hit", "hmn", "hmo", "hrv", "hsb", "hat", "hun", "hup", "hye", "her", - /*"ia", "iba", "id", "ie", "ig", "ii", "ijo", "ik", */ - "ina", "iba", "ind", "ile", "ibo", "iii", "ijo", "ipk", - /*"ilo", "inc", "ine", "inh", "io", "ira", "iro", "is", "it", */ - "ilo", "inc", "ine", "inh", "ido", "ira", "iro", "isl", "ita", - /*"iu", "ja", "jbo", "jpr", "jrb", "jv", "ka", "kaa", "kab", */ - "iku", "jpn", "jbo", "jpr", "jrb", "jaw", "kat", "kaa", "kab", - /*"kac", "kam", "kar", "kaw", "kbd", "kg", "kha", "khi", */ - "kac", "kam", "kar", "kaw", "kbd", "kon", "kha", "khi", - /*"kho", "ki", "kj", "kk", "kl", "km", "kmb", "kn", */ - "kho", "kik", "kua", "kaz", "kal", "khm", "kmb", "kan", - /*"ko", "kok", "kos", "kpe", "kr", "krc", "kro", "kru", "ks", */ - "kor", "kok", "kos", "kpe", "kau", "krc", "kro", "kru", "kas", - /*"ku", "kum", "kut", "kv", "kw", "ky", "la", "lad", */ - "kur", "kum", "kut", "kom", "cor", "kir", "lat", "lad", - /*"lah", "lam", "lb", "lez", "lg", "li", "ln", "lo", "lol", */ - "lah", "lam", "ltz", "lez", "lug", "lim", "lin", "lao", "lol", - /*"loz", "lt", "lu", "lua", "lui", "lun", "luo", "lus", */ - "loz", "lit", "lub", "lua", "lui", "lun", "luo", "lus", - /*"lv", "mad", "mag", "mai", "mak", "man", "map", "mas", */ - "lav", "mad", "mag", "mai", "mak", "man", "map", "mas", - /*"mdf", "mdr", "men", "mg", "mga", "mh", "mi", "mic", "min", */ - "mdf", "mdr", "men", "mlg", "mga", "mah", "mri", "mic", "min", - /*"mis", "mk", "mkh", "ml", "mn", "mnc", "mni", "mno", */ - "mis", "mkd", "mkh", "mal", "mon", "mnc", "mni", "mno", - /*"mo", "moh", "mos", "mr", "ms", "mt", "mul", "mun", */ - "mol", "moh", "mos", "mar", "msa", "mlt", "mul", "mun", - /*"mus", "mwr", "my", "myn", "myv", "na", "nah", "nai", "nap", */ - "mus", "mwr", "mya", "myn", "myv", "nau", "nah", "nai", "nap", - /*"nb", "nd", "nds", "ne", "new", "ng", "nia", "nic", */ - "nob", "nde", "nds", "nep", "new", "ndo", "nia", "nic", - /*"niu", "nl", "nn", "no", "nog", "non", "nr", "nso", "nub", */ - "niu", "nld", "nno", "nor", "nog", "non", "nbl", "nso", "nub", - /*"nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", "oc", "oj", */ - "nav", "nwc", "nya", "nym", "nyn", "nyo", "nzi", "oci", "oji", - /*"om", "or", "os", "osa", "ota", "oto", "pa", "paa", */ - "orm", "ori", "oss", "osa", "ota", "oto", "pan", "paa", - /*"pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn", */ - "pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn", - /*"pi", "pl", "pon", "pra", "pro", "ps", "pt", "qu", */ - "pli", "pol", "pon", "pra", "pro", "pus", "por", "que", - /*"raj", "rap", "rar", "rm", "rn", "ro", "roa", "rom", */ - "raj", "rap", "rar", "roh", "run", "ron", "roa", "rom", - /*"ru", "rup", "rw", "sa", "sad", "sah", "sai", "sal", "sam", */ - "rus", "rup", "kin", "san", "sad", "sah", "sai", "sal", "sam", - /*"sas", "sat", "sc", "sco", "sd", "se", "sel", "sem", */ - "sas", "sat", "srd", "sco", "snd", "sme", "sel", "sem", - /*"sg", "sga", "sgn", "shn", "si", "sid", "sio", "sit", */ - "sag", "sga", "sgn", "shn", "sin", "sid", "sio", "sit", - /*"sk", "sl", "sla", "sm", "sma", "smi", "smj", "smn", */ - "slk", "slv", "sla", "smo", "sma", "smi", "smj", "smn", - /*"sms", "sn", "snk", "so", "sog", "son", "sq", "sr", */ - "sms", "sna", "snk", "som", "sog", "son", "sqi", "srp", - /*"srr", "ss", "ssa", "st", "su", "suk", "sus", "sux", */ - "srr", "ssw", "ssa", "sot", "sun", "suk", "sus", "sux", - /*"sv", "sw", "syr", "ta", "tai", "te", "tem", "ter", */ - "swe", "swa", "syr", "tam", "tai", "tel", "tem", "ter", - /*"tet", "tg", "th", "ti", "tig", "tiv", "tk", "tkl", */ - "tet", "tgk", "tha", "tir", "tig", "tiv", "tuk", "tkl", - /*"tl", "tlh", "tli", "tmh", "tn", "to", "tog", "tpi", "tr", */ - "tgl", "tlh", "tli", "tmh", "tsn", "ton", "tog", "tpi", "tur", - /*"ts", "tsi", "tt", "tum", "tup", "tut", "tvl", "tw", */ - "tso", "tsi", "tat", "tum", "tup", "tut", "tvl", "twi", - /*"ty", "tyv", "udm", "ug", "uga", "uk", "umb", "und", "ur", */ - "tah", "tyv", "udm", "uig", "uga", "ukr", "umb", "und", "urd", - /*"uz", "vai", "ve", "vi", "vo", "vot", "wa", "wak", */ - "uzb", "vai", "ven", "vie", "vol", "vot", "wln", "wak", - /*"wal", "war", "was", "wen", "wo", "xal", "xh", "yao", "yap", */ - "wal", "war", "was", "wen", "wol", "xal", "xho", "yao", "yap", - /*"yi", "yo", "ypk", "za", "zap", "zen", "zh", "znd", */ - "yid", "yor", "ypk", "zha", "zap", "zen", "zho", "znd", - /*"zu", "zun", */ - "zul", "zun", - }; - - String[] tempObsoleteLanguages3 = { - /* "in", "iw", "ji", "jw", "sh", */ - "ind", "heb", "yid", "jaw", "srp", - }; - - synchronized (ULocale.class) { - if (_languages == null) { - _languages = tempLanguages; - _replacementLanguages = tempReplacementLanguages; - _obsoleteLanguages = tempObsoleteLanguages; - _languages3 = tempLanguages3; - _obsoleteLanguages3 = tempObsoleteLanguages3; - } - } - } - } - - private static String[] _countries; - private static String[] _deprecatedCountries; - private static String[] _replacementCountries; - private static String[] _obsoleteCountries; - private static String[] _countries3; - private static String[] _obsoleteCountries3; - - // Avoid initializing country tables unless we have to. - private static void initCountryTables() { - if (_countries == null) { - /* ZR(ZAR) is now CD(COD) and FX(FXX) is PS(PSE) as per - http://www.evertype.com/standards/iso3166/iso3166-1-en.html - added new codes keeping the old ones for compatibility - updated to include 1999/12/03 revisions *CWB*/ - - /* RO(ROM) is now RO(ROU) according to - http://www.iso.org/iso/en/prods-services/iso3166ma/03updates-on-iso-3166/nlv3e-rou.html - */ - - /* This list MUST be in sorted order, and MUST contain only two-letter codes! */ - String[] tempCountries = { - "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", - "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", - "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", - "BJ", "BL", "BM", "BN", "BO", "BR", "BS", "BT", "BV", - "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", - "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", - "CU", "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", - "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", - "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", - "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", - "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", - "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", - "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", - "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", - "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", - "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", - "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", - "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", - "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", - "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", - "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", - "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", - "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", - "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", - "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", - "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", - "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", - "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", - "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", - "WS", "YE", "YT", "ZA", "ZM", "ZW", - }; - - /* this table is used for 3 letter codes */ - String[] tempObsoleteCountries = { - "FX", "CS", "RO", "TP", "YU", "ZR", /* obsolete country codes */ - }; - - String[] tempDeprecatedCountries = { - "BU", "CS", "DY", "FX", "HV", "NH", "RH", "TP", "YU", "ZR" /* deprecated country list */ - }; - String[] tempReplacementCountries = { - /* "BU", "CS", "DY", "FX", "HV", "NH", "RH", "TP", "YU", "ZR" */ - "MM", "RS", "BJ", "FR", "BF", "VU", "ZW", "TL", "RS", "CD", /* replacement country codes */ - }; - - /* This list MUST contain a three-letter code for every two-letter code in - the above list, and they MUST be listed in the same order! */ - String[] tempCountries3 = { - /* "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", */ - "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", "ANT", - /* "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", */ - "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", - /* "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", */ - "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", - /* "BJ", "BL", "BM", "BN", "BO", "BR", "BS", "BT", "BV", */ - "BEN", "BLM", "BMU", "BRN", "BOL", "BRA", "BHS", "BTN", "BVT", - /* "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", */ - "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", - /* "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", */ - "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", - /* "CU", "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", */ - "CUB", "CPV", "CXR", "CYP", "CZE", "DEU", "DJI", "DNK", - /* "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", */ - "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", "ERI", - /* "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", */ - "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", - /* "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", */ - "GAB", "GBR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", - /* "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", */ - "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", - /* "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", */ - "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", - /* "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS" */ - "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", - /* "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", */ - "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", - /* "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", */ - "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", - /* "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", */ - "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", - /* "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", */ - "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", - /* "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", */ - "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", - /* "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", */ - "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", - /* "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", */ - "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", - /* "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", */ - "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", - /* "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", */ - "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", - /* "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", */ - "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", - /* "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", */ - "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", - /* "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", */ - "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "STP", "SLV", - /* "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", */ - "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", - /* "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", */ - "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", - /* "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", */ - "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", - /* "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", */ - "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", - /* "WS", "YE", "YT", "ZA", "ZM", "ZW" */ - "WSM", "YEM", "MYT", "ZAF", "ZMB", "ZWE", - }; - - String[] tempObsoleteCountries3 = { - /*"FX", "CS", "RO", "TP", "YU", "ZR", */ - "FXX", "SCG", "ROM", "TMP", "YUG", "ZAR", - }; - - synchronized (ULocale.class) { - if (_countries == null) { - _countries = tempCountries; - _deprecatedCountries = tempDeprecatedCountries; - _replacementCountries = tempReplacementCountries; - _obsoleteCountries = tempObsoleteCountries; - _countries3 = tempCountries3; - _obsoleteCountries3 = tempObsoleteCountries3; - } - } - } - } - - private static String[][] CANONICALIZE_MAP; - private static String[][] variantsToKeywords; - - private static void initCANONICALIZE_MAP() { - if (CANONICALIZE_MAP == null) { - /** - * This table lists pairs of locale ids for canonicalization. The - * The 1st item is the normalized id. The 2nd item is the - * canonicalized id. The 3rd is the keyword. The 4th is the keyword value. - */ - String[][] tempCANONICALIZE_MAP = { -// { EMPTY_STRING, "en_US_POSIX", null, null }, /* .NET name */ - { "C", "en_US_POSIX", null, null }, /* POSIX name */ - { "art_LOJBAN", "jbo", null, null }, /* registered name */ - { "az_AZ_CYRL", "az_Cyrl_AZ", null, null }, /* .NET name */ - { "az_AZ_LATN", "az_Latn_AZ", null, null }, /* .NET name */ - { "ca_ES_PREEURO", "ca_ES", "currency", "ESP" }, - { "cel_GAULISH", "cel__GAULISH", null, null }, /* registered name */ - { "de_1901", "de__1901", null, null }, /* registered name */ - { "de_1906", "de__1906", null, null }, /* registered name */ - { "de__PHONEBOOK", "de", "collation", "phonebook" }, /* Old ICU name */ - { "de_AT_PREEURO", "de_AT", "currency", "ATS" }, - { "de_DE_PREEURO", "de_DE", "currency", "DEM" }, - { "de_LU_PREEURO", "de_LU", "currency", "EUR" }, - { "el_GR_PREEURO", "el_GR", "currency", "GRD" }, - { "en_BOONT", "en__BOONT", null, null }, /* registered name */ - { "en_SCOUSE", "en__SCOUSE", null, null }, /* registered name */ - { "en_BE_PREEURO", "en_BE", "currency", "BEF" }, - { "en_IE_PREEURO", "en_IE", "currency", "IEP" }, - { "es__TRADITIONAL", "es", "collation", "traditional" }, /* Old ICU name */ - { "es_ES_PREEURO", "es_ES", "currency", "ESP" }, - { "eu_ES_PREEURO", "eu_ES", "currency", "ESP" }, - { "fi_FI_PREEURO", "fi_FI", "currency", "FIM" }, - { "fr_BE_PREEURO", "fr_BE", "currency", "BEF" }, - { "fr_FR_PREEURO", "fr_FR", "currency", "FRF" }, - { "fr_LU_PREEURO", "fr_LU", "currency", "LUF" }, - { "ga_IE_PREEURO", "ga_IE", "currency", "IEP" }, - { "gl_ES_PREEURO", "gl_ES", "currency", "ESP" }, - { "hi__DIRECT", "hi", "collation", "direct" }, /* Old ICU name */ - { "it_IT_PREEURO", "it_IT", "currency", "ITL" }, - { "ja_JP_TRADITIONAL", "ja_JP", "calendar", "japanese" }, -// { "nb_NO_NY", "nn_NO", null, null }, - { "nl_BE_PREEURO", "nl_BE", "currency", "BEF" }, - { "nl_NL_PREEURO", "nl_NL", "currency", "NLG" }, - { "pt_PT_PREEURO", "pt_PT", "currency", "PTE" }, - { "sl_ROZAJ", "sl__ROZAJ", null, null }, /* registered name */ - { "sr_SP_CYRL", "sr_Cyrl_RS", null, null }, /* .NET name */ - { "sr_SP_LATN", "sr_Latn_RS", null, null }, /* .NET name */ - { "sr_YU_CYRILLIC", "sr_Cyrl_RS", null, null }, /* Linux name */ - { "th_TH_TRADITIONAL", "th_TH", "calendar", "buddhist" }, /* Old ICU name */ - { "uz_UZ_CYRILLIC", "uz_Cyrl_UZ", null, null }, /* Linux name */ - { "uz_UZ_CYRL", "uz_Cyrl_UZ", null, null }, /* .NET name */ - { "uz_UZ_LATN", "uz_Latn_UZ", null, null }, /* .NET name */ - { "zh_CHS", "zh_Hans", null, null }, /* .NET name */ - { "zh_CHT", "zh_Hant", null, null }, /* .NET name */ - { "zh_GAN", "zh__GAN", null, null }, /* registered name */ - { "zh_GUOYU", "zh", null, null }, /* registered name */ - { "zh_HAKKA", "zh__HAKKA", null, null }, /* registered name */ - { "zh_MIN", "zh__MIN", null, null }, /* registered name */ - { "zh_MIN_NAN", "zh__MINNAN", null, null }, /* registered name */ - { "zh_WUU", "zh__WUU", null, null }, /* registered name */ - { "zh_XIANG", "zh__XIANG", null, null }, /* registered name */ - { "zh_YUE", "zh__YUE", null, null } /* registered name */ - }; - - synchronized (ULocale.class) { - if (CANONICALIZE_MAP == null) { - CANONICALIZE_MAP = tempCANONICALIZE_MAP; - } - } - } - if (variantsToKeywords == null) { - /** - * This table lists pairs of locale ids for canonicalization. The - * The first item is the normalized variant id. - */ - String[][] tempVariantsToKeywords = { - { "EURO", "currency", "EUR" }, - { "PINYIN", "collation", "pinyin" }, /* Solaris variant */ - { "STROKE", "collation", "stroke" } /* Solaris variant */ - }; - - synchronized (ULocale.class) { - if (variantsToKeywords == null) { - variantsToKeywords = tempVariantsToKeywords; - } - } - } - } - - /* - * This table is used for mapping between ICU and special Java - * locales. When an ICU locale matches with - * /, the ICU locale is mapped to locale. - * For example, both ja_JP@calendar=japanese and ja@calendar=japanese - * are mapped to Java locale "ja_JP_JP". ICU locale "nn" is mapped - * to Java locale "no_NO_NY". - */ - private static final String[][] _javaLocaleMap = { - // { , , , , - { "ja_JP_JP", "ja_JP", "calendar", "japanese", "ja"}, - { "no_NO_NY", "nn_NO", null, null, "nn"}, - // { "th_TH_TH", "th_TH", ??, ??, "th"} //TODO - }; - - /** - * Private constructor used by static initializers. - */ - private ULocale(String localeID, Locale locale) { - this.localeID = localeID; - this.locale = locale; - } - - /** - * Construct a ULocale object from a {@link java.util.Locale}. - * @param loc a JDK locale - * @stable ICU 2.8 - * @internal - */ - private ULocale(Locale loc) { - this.localeID = getName(forLocale(loc).toString()); - this.locale = loc; - } - - /** - * Return a ULocale object for a {@link java.util.Locale}. - * The ULocale is canonicalized. - * @param loc a JDK locale - * @stable ICU 3.2 - */ - public static ULocale forLocale(Locale loc) { - if (loc == null) { - return null; - } - ULocale result = (ULocale)CACHE.get(loc); - if (result == null) { - if (defaultULocale != null && loc == defaultULocale.locale) { - result = defaultULocale; - } else { - String locStr = loc.toString(); - if (locStr.length() == 0) { - result = ROOT; - } else { - for (int i = 0; i < _javaLocaleMap.length; i++) { - if (_javaLocaleMap[i][0].equals(locStr)) { - IDParser p = new IDParser(_javaLocaleMap[i][1]); - p.setKeywordValue(_javaLocaleMap[i][2], _javaLocaleMap[i][3]); - locStr = p.getName(); - break; - } - } - result = new ULocale(locStr, loc); - } - } - CACHE.put(loc, result); - } - return result; - } - - /** - * Construct a ULocale from a RFC 3066 locale ID. The locale ID consists - * of optional language, script, country, and variant fields in that order, - * separated by underscores, followed by an optional keyword list. The - * script, if present, is four characters long-- this distinguishes it - * from a country code, which is two characters long. Other fields - * are distinguished by position as indicated by the underscores. The - * start of the keyword list is indicated by '@', and consists of two - * or more keyword/value pairs separated by semicolons(';'). - *

- * This constructor does not canonicalize the localeID. So, for - * example, "zh__pinyin" remains unchanged instead of converting - * to "zh@collation=pinyin". By default ICU only recognizes the - * latter as specifying pinyin collation. Use {@link #createCanonical} - * or {@link #canonicalize} if you need to canonicalize the localeID. - * - * @param localeID string representation of the locale, e.g: - * "en_US", "sy_Cyrl_YU", "zh__pinyin", "es_ES@currency=EUR;collation=traditional" - * @stable ICU 2.8 - */ - public ULocale(String localeID) { - this.localeID = getName(localeID); - } - - /** - * Convenience overload of ULocale(String, String, String) for - * compatibility with java.util.Locale. - * @see #ULocale(String, String, String) - * @stable ICU 3.4 - */ - public ULocale(String a, String b) { - this(a, b, null); - } - - /** - * Construct a ULocale from a localeID constructed from the three 'fields' a, b, and c. These - * fields are concatenated using underscores to form a localeID of - * the form a_b_c, which is then handled like the localeID passed - * to ULocale(String localeID). - * - *

Java locale strings consisting of language, country, and - * variant will be handled by this form, since the country code - * (being shorter than four letters long) will not be interpreted - * as a script code. If a script code is present, the final - * argument ('c') will be interpreted as the country code. It is - * recommended that this constructor only be used to ease porting, - * and that clients instead use the single-argument constructor - * when constructing a ULocale from a localeID. - * @param a first component of the locale id - * @param b second component of the locale id - * @param c third component of the locale id - * @see #ULocale(String) - * @stable ICU 3.0 - */ - public ULocale(String a, String b, String c) { - localeID = getName(lscvToID(a, b, c, EMPTY_STRING)); - } - - /** - * Create a ULocale from the id by first canonicalizing the id. - * @param nonCanonicalID the locale id to canonicalize - * @return the locale created from the canonical version of the ID. - * @stable ICU 3.0 - */ - public static ULocale createCanonical(String nonCanonicalID) { - return new ULocale(canonicalize(nonCanonicalID), (Locale)null); - } - - private static String lscvToID(String lang, String script, String country, String variant) { - StringBuffer buf = new StringBuffer(); - - if (lang != null && lang.length() > 0) { - buf.append(lang); - } - if (script != null && script.length() > 0) { - buf.append(UNDERSCORE); - buf.append(script); - } - if (country != null && country.length() > 0) { - buf.append(UNDERSCORE); - buf.append(country); - } - if (variant != null && variant.length() > 0) { - if (country == null || country.length() == 0) { - buf.append(UNDERSCORE); - } - buf.append(UNDERSCORE); - buf.append(variant); - } - return buf.toString(); - } - - /** - * Convert this ULocale object to a {@link java.util.Locale}. - * @return a JDK locale that either exactly represents this object - * or is the closest approximation. - * @stable ICU 2.8 - */ - public Locale toLocale() { - if (locale == null) { - IDParser p = new IDParser(localeID); - String base = p.getBaseName(); - for (int i = 0; i < _javaLocaleMap.length; i++) { - if (base.equals(_javaLocaleMap[i][1]) || base.equals(_javaLocaleMap[i][4])) { - if (_javaLocaleMap[i][2] != null) { - String val = p.getKeywordValue(_javaLocaleMap[i][2]); - if (val != null && val.equals(_javaLocaleMap[i][3])) { - p = new IDParser(_javaLocaleMap[i][0]); - break; - } - } else { - p = new IDParser(_javaLocaleMap[i][0]); - break; - } - } - } - String[] names = p.getLanguageScriptCountryVariant(); - locale = new Locale(names[0], names[2], names[3]); - } - return locale; - } - - private static Locale toLocale(String localeID) { - IDParser p = new IDParser(localeID); - String base = p.getBaseName(); - for (int i = 0; i < _javaLocaleMap.length; i++) { - if (base.equals(_javaLocaleMap[i][1]) || base.equals(_javaLocaleMap[i][4])) { - if (_javaLocaleMap[i][2] != null) { - String val = p.getKeywordValue(_javaLocaleMap[i][2]); - if (val != null && val.equals(_javaLocaleMap[i][3])) { - p = new IDParser(_javaLocaleMap[i][0]); - break; - } - } else { - p = new IDParser(_javaLocaleMap[i][0]); - break; - } - } - } - String[] names = p.getLanguageScriptCountryVariant(); - return new Locale(names[0], names[2], names[3]); - } - - - private static SoftReference nameCacheRef = new SoftReference(Collections.synchronizedMap(new HashMap())); - /** - * Keep our own default ULocale. - */ - private static Locale defaultLocale = Locale.getDefault(); - private static ULocale defaultULocale = new ULocale(defaultLocale); - - /** - * Returns the current default ULocale. - * @stable ICU 2.8 - */ - public static ULocale getDefault() { - synchronized (ULocale.class) { - Locale currentDefault = Locale.getDefault(); - if (defaultLocale != currentDefault) { - defaultLocale = currentDefault; - defaultULocale = new ULocale(defaultLocale); - } - return defaultULocale; - } - } - - /** - * Sets the default ULocale. This also sets the default Locale. - * If the caller does not have write permission to the - * user.language property, a security exception will be thrown, - * and the default ULocale will remain unchanged. - * @param newLocale the new default locale - * @throws SecurityException - * if a security manager exists and its - * checkPermission method doesn't allow the operation. - * @throws NullPointerException if newLocale is null - * @see SecurityManager#checkPermission(java.security.Permission) - * @see java.util.PropertyPermission - * @stable ICU 3.0 - */ - public static synchronized void setDefault(ULocale newLocale){ - Locale.setDefault(newLocale.toLocale()); - defaultULocale = newLocale; - } - - /** - * This is for compatibility with Locale-- in actuality, since ULocale is - * immutable, there is no reason to clone it, so this API returns 'this'. - * @stable ICU 3.0 - */ - public Object clone() { - return this; - } - - /** - * Returns the hashCode. - * @stable ICU 3.0 - */ - public int hashCode() { - return localeID.hashCode(); - } - - /** - * Returns true if the other object is another ULocale with the - * same full name, or is a String localeID that matches the full name. - * Note that since names are not canonicalized, two ULocales that - * function identically might not compare equal. - * - * @return true if this Locale is equal to the specified object. - * @stable ICU 3.0 - */ - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof String) { - return localeID.equals((String)obj); - } - if (obj instanceof ULocale) { - return localeID.equals(((ULocale)obj).localeID); - } - return false; - } - - private static ULocale[] ulocales; - - /** - * Returns a list of all installed locales. - * @stable ICU 3.0 - */ - public static ULocale[] getAvailableLocales() { -// return ICUResourceBundle.getAvailableULocales(); - if (ulocales == null) { - Locale[] locales = Locale.getAvailableLocales(); - ULocale[] ul = new ULocale[locales.length]; - for (int i = 0; i < locales.length; ++i) { - ul[i] = ULocale.forLocale(locales[i]); - } - ulocales = ul; - } - return (ULocale[])ulocales.clone(); - } - - /** - * Returns a list of all 2-letter country codes defined in ISO 3166. - * Can be used to create Locales. - * @stable ICU 3.0 - */ - public static String[] getISOCountries() { - initCountryTables(); - return (String[])_countries.clone(); - } - - /** - * Returns a list of all 2-letter language codes defined in ISO 639. - * Can be used to create Locales. - * [NOTE: ISO 639 is not a stable standard-- some languages' codes have changed. - * The list this function returns includes both the new and the old codes for the - * languages whose codes have changed.] - * @stable ICU 3.0 - */ - public static String[] getISOLanguages() { - initLanguageTables(); - return (String[])_languages.clone(); - } - - /** - * Returns the language code for this locale, which will either be the empty string - * or a lowercase ISO 639 code. - * @see #getDisplayLanguage() - * @see #getDisplayLanguage(ULocale) - * @stable ICU 3.0 - */ - public String getLanguage() { - return getLanguage(localeID); - } - - /** - * Returns the language code for the locale ID, - * which will either be the empty string - * or a lowercase ISO 639 code. - * @see #getDisplayLanguage() - * @see #getDisplayLanguage(ULocale) - * @stable ICU 3.0 - */ - public static String getLanguage(String localeID) { - return new IDParser(localeID).getLanguage(); - } - - /** - * Returns the script code for this locale, which might be the empty string. - * @see #getDisplayScript() - * @see #getDisplayScript(ULocale) - * @stable ICU 3.0 - */ - public String getScript() { - return getScript(localeID); - } - - /** - * Returns the script code for the specified locale, which might be the empty string. - * @see #getDisplayScript() - * @see #getDisplayScript(ULocale) - * @stable ICU 3.0 - */ - public static String getScript(String localeID) { - return new IDParser(localeID).getScript(); - } - - /** - * Returns the country/region code for this locale, which will either be the empty string - * or an uppercase ISO 3166 2-letter code. - * @see #getDisplayCountry() - * @see #getDisplayCountry(ULocale) - * @stable ICU 3.0 - */ - public String getCountry() { - return getCountry(localeID); - } - - /** - * Returns the country/region code for this locale, which will either be the empty string - * or an uppercase ISO 3166 2-letter code. - * @param localeID - * @see #getDisplayCountry() - * @see #getDisplayCountry(ULocale) - * @stable ICU 3.0 - */ - public static String getCountry(String localeID) { - return new IDParser(localeID).getCountry(); - } - - /** - * Returns the variant code for this locale, which might be the empty string. - * @see #getDisplayVariant() - * @see #getDisplayVariant(ULocale) - * @stable ICU 3.0 - */ - public String getVariant() { - return getVariant(localeID); - } - - /** - * Returns the variant code for the specified locale, which might be the empty string. - * @see #getDisplayVariant() - * @see #getDisplayVariant(ULocale) - * @stable ICU 3.0 - */ - public static String getVariant(String localeID) { - return new IDParser(localeID).getVariant(); - } - - /** - * Returns the fallback locale for the specified locale, which might be the empty string. - * @stable ICU 3.2 - */ - public static String getFallback(String localeID) { - return getFallbackString(getName(localeID)); - } - - /** - * Returns the fallback locale for this locale. If this locale is root, returns null. - * @stable ICU 3.2 - */ - public ULocale getFallback() { - if (localeID.length() == 0 || localeID.charAt(0) == '@') { - return null; - } - return new ULocale(getFallbackString(localeID), (Locale)null); - } - - /** - * Return the given (canonical) locale id minus the last part before the tags. - */ - private static String getFallbackString(String fallback) { - int limit = fallback.indexOf('@'); - if (limit == -1) { - limit = fallback.length(); - } - int start = fallback.lastIndexOf('_', limit); - if (start == -1) { - start = 0; - } - return fallback.substring(0, start) + fallback.substring(limit); - } - - /** - * Returns the (normalized) base name for this locale. - * @return the base name as a String. - * @stable ICU 3.0 - */ - public String getBaseName() { - return getBaseName(localeID); - } - - /** - * Returns the (normalized) base name for the specified locale. - * @param localeID the locale ID as a string - * @return the base name as a String. - * @stable ICU 3.0 - */ - public static String getBaseName(String localeID){ - if (localeID.indexOf('@') == -1) { - return localeID; - } - return new IDParser(localeID).getBaseName(); - } - - /** - * Returns the (normalized) full name for this locale. - * - * @return String the full name of the localeID - * @stable ICU 3.0 - */ - public String getName() { - return localeID; // always normalized - } - - /** - * Returns the (normalized) full name for the specified locale. - * - * @param localeID the localeID as a string - * @return String the full name of the localeID - * @stable ICU 3.0 - */ - public static String getName(String localeID){ - Map cache = (Map)nameCacheRef.get(); - if (cache == null) { - cache = Collections.synchronizedMap(new HashMap()); - nameCacheRef = new SoftReference(cache); - } - String name = (String)cache.get(localeID); - if (name == null) { - name = new IDParser(localeID).getName(); - cache.put(localeID, name); - } - return name; - } - - /** - * Returns a string representation of this object. - * @stable ICU 3.0 - */ - public String toString() { - return localeID; - } - - /** - * Returns an iterator over keywords for this locale. If there - * are no keywords, returns null. - * @return iterator over keywords, or null if there are no keywords. - * @stable ICU 3.0 - */ - public Iterator getKeywords() { - return getKeywords(localeID); - } - - /** - * Returns an iterator over keywords for the specified locale. If there - * are no keywords, returns null. - * @return an iterator over the keywords in the specified locale, or null - * if there are no keywords. - * @stable ICU 3.0 - */ - public static Iterator getKeywords(String localeID){ - return new IDParser(localeID).getKeywords(); - } - - /** - * Returns the value for a keyword in this locale. If the keyword is not defined, returns null. - * @param keywordName name of the keyword whose value is desired. Case insensitive. - * @return the value of the keyword, or null. - * @stable ICU 3.0 - */ - public String getKeywordValue(String keywordName){ - return getKeywordValue(localeID, keywordName); - } - - /** - * Returns the value for a keyword in the specified locale. If the keyword is not defined, returns null. - * The locale name does not need to be normalized. - * @param keywordName name of the keyword whose value is desired. Case insensitive. - * @return String the value of the keyword as a string - * @stable ICU 3.0 - */ - public static String getKeywordValue(String localeID, String keywordName) { - return new IDParser(localeID).getKeywordValue(keywordName); - } - - /** - * Utility class to parse and normalize locale ids (including POSIX style) - */ - private static final class IDParser { - private char[] id; - private int index; - private char[] buffer; - private int blen; - // um, don't handle POSIX ids unless we request it. why not? well... because. - private boolean canonicalize; - private boolean hadCountry; - - // used when canonicalizing - Map keywords; - String baseName; - - /** - * Parsing constants. - */ - private static final char KEYWORD_SEPARATOR = '@'; - private static final char HYPHEN = '-'; - private static final char KEYWORD_ASSIGN = '='; - private static final char COMMA = ','; - private static final char ITEM_SEPARATOR = ';'; - private static final char DOT = '.'; - - private IDParser(String localeID) { - this(localeID, false); - } - - private IDParser(String localeID, boolean canonicalize) { - id = localeID.toCharArray(); - index = 0; - buffer = new char[id.length + 5]; - blen = 0; - this.canonicalize = canonicalize; - } - - private void reset() { - index = blen = 0; - } - - // utilities for working on text in the buffer - - /** - * Append c to the buffer. - */ - private void append(char c) { - try { - buffer[blen] = c; - } - catch (IndexOutOfBoundsException e) { - if (buffer.length > 512) { - // something is seriously wrong, let this go - throw e; - } - char[] nbuffer = new char[buffer.length * 2]; - System.arraycopy(buffer, 0, nbuffer, 0, buffer.length); - nbuffer[blen] = c; - buffer = nbuffer; - } - ++blen; - } - - private void addSeparator() { - append(UNDERSCORE); - } - - /** - * Returns the text in the buffer from start to blen as a String. - */ - private String getString(int start) { - if (start == blen) { - return EMPTY_STRING; - } - return new String(buffer, start, blen-start); - } - - /** - * Set the length of the buffer to pos, then append the string. - */ - private void set(int pos, String s) { - this.blen = pos; // no safety - append(s); - } - - /** - * Append the string to the buffer. - */ - private void append(String s) { - for (int i = 0; i < s.length(); ++i) { - append(s.charAt(i)); - } - } - - // utilities for parsing text out of the id - - /** - * Character to indicate no more text is available in the id. - */ - private static final char DONE = '\uffff'; - - /** - * Returns the character at index in the id, and advance index. The returned character - * is DONE if index was at the limit of the buffer. The index is advanced regardless - * so that decrementing the index will always 'unget' the last character returned. - */ - private char next() { - if (index == id.length) { - index++; - return DONE; - } - - return id[index++]; - } - - /** - * Advance index until the next terminator or id separator, and leave it there. - */ - private void skipUntilTerminatorOrIDSeparator() { - while (!isTerminatorOrIDSeparator(next())) { - } - --index; - } - - /** - * Returns true if the character at index in the id is a terminator. - */ - private boolean atTerminator() { - return index >= id.length || isTerminator(id[index]); - } - - /* - * Returns true if the character is an id separator (underscore or hyphen). - */ -/* private boolean isIDSeparator(char c) { - return c == UNDERSCORE || c == HYPHEN; - }*/ - - /** - * Returns true if the character is a terminator (keyword separator, dot, or DONE). - * Dot is a terminator because of the POSIX form, where dot precedes the codepage. - */ - private boolean isTerminator(char c) { - // always terminate at DOT, even if not handling POSIX. It's an error... - return c == KEYWORD_SEPARATOR || c == DONE || c == DOT; - } - - /** - * Returns true if the character is a terminator or id separator. - */ - private boolean isTerminatorOrIDSeparator(char c) { - return c == KEYWORD_SEPARATOR || c == UNDERSCORE || c == HYPHEN || - c == DONE || c == DOT; - } - - /** - * Returns true if the start of the buffer has an experimental or private language - * prefix, the pattern '[ixIX][-_].' shows the syntax checked. - */ - private boolean haveExperimentalLanguagePrefix() { - if (id.length > 2) { - char c = id[1]; - if (c == HYPHEN || c == UNDERSCORE) { - c = id[0]; - return c == 'x' || c == 'X' || c == 'i' || c == 'I'; - } - } - return false; - } - - /** - * Returns true if a value separator occurs at or after index. - */ - private boolean haveKeywordAssign() { - // assume it is safe to start from index - for (int i = index; i < id.length; ++i) { - if (id[i] == KEYWORD_ASSIGN) { - return true; - } - } - return false; - } - - /** - * Advance index past language, and accumulate normalized language code in buffer. - * Index must be at 0 when this is called. Index is left at a terminator or id - * separator. Returns the start of the language code in the buffer. - */ - private int parseLanguage() { - if (haveExperimentalLanguagePrefix()) { - append(Character.toLowerCase(id[0])); - append(HYPHEN); - index = 2; - } - - char c; - while(!isTerminatorOrIDSeparator(c = next())) { - append(Character.toLowerCase(c)); - } - --index; // unget - - if (blen == 3) { - initLanguageTables(); - - /* convert 3 character code to 2 character code if possible *CWB*/ - String lang = getString(0); - int offset = findIndex(_languages3, lang); - if (offset >= 0) { - set(0, _languages[offset]); - } else { - offset = findIndex(_obsoleteLanguages3, lang); - if (offset >= 0) { - set(0, _obsoleteLanguages[offset]); - } - } - } - - return 0; - } - - /** - * Advance index past language. Index must be at 0 when this is called. Index - * is left at a terminator or id separator. - */ - private void skipLanguage() { - if (haveExperimentalLanguagePrefix()) { - index = 2; - } - skipUntilTerminatorOrIDSeparator(); - } - - /** - * Advance index past script, and accumulate normalized script in buffer. - * Index must be immediately after the language. - * If the item at this position is not a script (is not four characters - * long) leave index and buffer unchanged. Otherwise index is left at - * a terminator or id separator. Returns the start of the script code - * in the buffer (this may be equal to the buffer length, if there is no - * script). - */ - private int parseScript() { - if (!atTerminator()) { - int oldIndex = index; // save original index - ++index; - - int oldBlen = blen; // get before append hyphen, if we truncate everything is undone - char c; - while(!isTerminatorOrIDSeparator(c = next())) { - if (blen == oldBlen) { // first pass - addSeparator(); - append(Character.toUpperCase(c)); - } else { - append(Character.toLowerCase(c)); - } - } - --index; // unget - - /* If it's not exactly 4 characters long, then it's not a script. */ - if (index - oldIndex != 5) { // +1 to account for separator - index = oldIndex; - blen = oldBlen; - } else { - oldBlen++; // index past hyphen, for clients who want to extract just the script - } - - return oldBlen; - } - return blen; - } - - /** - * Advance index past script. - * Index must be immediately after the language and IDSeparator. - * If the item at this position is not a script (is not four characters - * long) leave index. Otherwise index is left at a terminator or - * id separator. - */ - private void skipScript() { - if (!atTerminator()) { - int oldIndex = index; - ++index; - - skipUntilTerminatorOrIDSeparator(); - if (index - oldIndex != 5) { // +1 to account for separator - index = oldIndex; - } - } - } - - /** - * Advance index past country, and accumulate normalized country in buffer. - * Index must be immediately after the script (if there is one, else language) - * and IDSeparator. Return the start of the country code in the buffer. - */ - private int parseCountry() { - if (!atTerminator()) { - int oldIndex = index; - ++index; - - int oldBlen = blen; - char c; - while (!isTerminatorOrIDSeparator(c = next())) { - if (oldBlen == blen) { // first, add hyphen - hadCountry = true; // we have a country, let variant parsing know - addSeparator(); - ++oldBlen; // increment past hyphen - } - append(Character.toUpperCase(c)); - } - --index; // unget - - int charsAppended = blen - oldBlen; - - if (charsAppended == 0) { - // Do nothing. - } - else if (charsAppended < 2 || charsAppended > 3) { - // It's not a country, so return index and blen to - // their previous values. - index = oldIndex; - --oldBlen; - blen = oldBlen; - hadCountry = false; - } - else if (charsAppended == 3) { - initCountryTables(); - - /* convert 3 character code to 2 character code if possible *CWB*/ - int offset = findIndex(_countries3, getString(oldBlen)); - if (offset >= 0) { - set(oldBlen, _countries[offset]); - } else { - offset = findIndex(_obsoleteCountries3, getString(oldBlen)); - if (offset >= 0) { - set(oldBlen, _obsoleteCountries[offset]); - } - } - } - - return oldBlen; - } - - return blen; - } - - /** - * Advance index past country. - * Index must be immediately after the script (if there is one, else language) - * and IDSeparator. - */ - private void skipCountry() { - if (!atTerminator()) { - ++index; - /* - * Save the index point after the separator, since the format - * requires two separators if the country is not present. - */ - int oldIndex = index; - - skipUntilTerminatorOrIDSeparator(); - int charsSkipped = index - oldIndex; - if (charsSkipped < 2 || charsSkipped > 3) { - index = oldIndex; - } - } - } - - /** - * Advance index past variant, and accumulate normalized variant in buffer. This ignores - * the codepage information from POSIX ids. Index must be immediately after the country - * or script. Index is left at the keyword separator or at the end of the text. Return - * the start of the variant code in the buffer. - * - * In standard form, we can have the following forms: - * ll__VVVV - * ll_CC_VVVV - * ll_Ssss_VVVV - * ll_Ssss_CC_VVVV - * - * This also handles POSIX ids, which can have the following forms (pppp is code page id): - * ll_CC.pppp --> ll_CC - * ll_CC.pppp@VVVV --> ll_CC_VVVV - * ll_CC@VVVV --> ll_CC_VVVV - * - * We identify this use of '@' in POSIX ids by looking for an '=' following - * the '@'. If there is one, we consider '@' to start a keyword list, instead of - * being part of a POSIX id. - * - * Note: since it was decided that we want an option to not handle POSIX ids, this - * becomes a bit more complex. - */ - private int parseVariant() { - int oldBlen = blen; - - boolean start = true; - boolean needSeparator = true; - boolean skipping = false; - char c; - while ((c = next()) != DONE) { - if (c == DOT) { - start = false; - skipping = true; - } else if (c == KEYWORD_SEPARATOR) { - if (haveKeywordAssign()) { - break; - } - skipping = false; - start = false; - needSeparator = true; // add another underscore if we have more text - } else if (start) { - start = false; - } else if (!skipping) { - if (needSeparator) { - boolean incOldBlen = blen == oldBlen; // need to skip separators - needSeparator = false; - if (incOldBlen && !hadCountry) { // no country, we'll need two - addSeparator(); - ++oldBlen; // for sure - } - addSeparator(); - if (incOldBlen) { // only for the first separator - ++oldBlen; - } - } - c = Character.toUpperCase(c); - if (c == HYPHEN || c == COMMA) { - c = UNDERSCORE; - } - append(c); - } - } - --index; // unget - - return oldBlen; - } - - // no need for skipvariant, to get the keywords we'll just scan directly for - // the keyword separator - - /** - * Returns the normalized language id, or the empty string. - */ - public String getLanguage() { - reset(); - return getString(parseLanguage()); - } - - /** - * Returns the normalized script id, or the empty string. - */ - public String getScript() { - reset(); - skipLanguage(); - return getString(parseScript()); - } - - /** - * return the normalized country id, or the empty string. - */ - public String getCountry() { - reset(); - skipLanguage(); - skipScript(); - return getString(parseCountry()); - } - - /** - * Returns the normalized variant id, or the empty string. - */ - public String getVariant() { - reset(); - skipLanguage(); - skipScript(); - skipCountry(); - return getString(parseVariant()); - } - - /** - * Returns the language, script, country, and variant as separate strings. - */ - public String[] getLanguageScriptCountryVariant() { - reset(); - return new String[] { - getString(parseLanguage()), - getString(parseScript()), - getString(parseCountry()), - getString(parseVariant()) - }; - } - - public void setBaseName(String baseName) { - this.baseName = baseName; - } - - public void parseBaseName() { - if (baseName != null) { - set(0, baseName); - } else { - reset(); - parseLanguage(); - parseScript(); - parseCountry(); - parseVariant(); - - // catch unwanted trailing underscore after country if there was no variant - if (blen > 1 && buffer[blen-1] == UNDERSCORE) { - --blen; - } - } - } - - /** - * Returns the normalized base form of the locale id. The base - * form does not include keywords. - */ - public String getBaseName() { - if (baseName != null) { - return baseName; - } - parseBaseName(); - return getString(0); - } - - /** - * Returns the normalized full form of the locale id. The full - * form includes keywords if they are present. - */ - public String getName() { - parseBaseName(); - parseKeywords(); - return getString(0); - } - - // keyword utilities - - /** - * If we have keywords, advance index to the start of the keywords and return true, - * otherwise return false. - */ - private boolean setToKeywordStart() { - for (int i = index; i < id.length; ++i) { - if (id[i] == KEYWORD_SEPARATOR) { - if (canonicalize) { - for (int j = ++i; j < id.length; ++j) { // increment i past separator for return - if (id[j] == KEYWORD_ASSIGN) { - index = i; - return true; - } - } - } else { - if (++i < id.length) { - index = i; - return true; - } - } - break; - } - } - return false; - } - - private static boolean isDoneOrKeywordAssign(char c) { - return c == DONE || c == KEYWORD_ASSIGN; - } - - private static boolean isDoneOrItemSeparator(char c) { - return c == DONE || c == ITEM_SEPARATOR; - } - - private String getKeyword() { - int start = index; - while (!isDoneOrKeywordAssign(next())) { - } - --index; - return new String(id, start, index-start).trim().toLowerCase(); - } - - private String getValue() { - int start = index; - while (!isDoneOrItemSeparator(next())) { - } - --index; - return new String(id, start, index-start).trim(); // leave case alone - } - - private Comparator getKeyComparator() { - final Comparator comp = new Comparator() { - public int compare(Object lhs, Object rhs) { - return ((String)lhs).compareTo((String)rhs); - } - }; - return comp; - } - - /** - * Returns a map of the keywords and values, or null if there are none. - */ - private Map getKeywordMap() { - if (keywords == null) { - TreeMap m = null; - if (setToKeywordStart()) { - // trim spaces and convert to lower case, both keywords and values. - do { - String key = getKeyword(); - if (key.length() == 0) { - break; - } - char c = next(); - if (c != KEYWORD_ASSIGN) { - // throw new IllegalArgumentException("key '" + key + "' missing a value."); - if (c == DONE) { - break; - } else { - continue; - } - } - String value = getValue(); - if (value.length() == 0) { - // throw new IllegalArgumentException("key '" + key + "' missing a value."); - continue; - } - if (m == null) { - m = new TreeMap(getKeyComparator()); - } else if (m.containsKey(key)) { - // throw new IllegalArgumentException("key '" + key + "' already has a value."); - continue; - } - m.put(key, value); - } while (next() == ITEM_SEPARATOR); - } - keywords = m != null ? m : Collections.EMPTY_MAP; - } - - return keywords; - } - - /** - * Parse the keywords and return start of the string in the buffer. - */ - private int parseKeywords() { - int oldBlen = blen; - Map m = getKeywordMap(); - if (!m.isEmpty()) { - Iterator iter = m.entrySet().iterator(); - boolean first = true; - while (iter.hasNext()) { - append(first ? KEYWORD_SEPARATOR : ITEM_SEPARATOR); - first = false; - Map.Entry e = (Map.Entry)iter.next(); - append((String)e.getKey()); - append(KEYWORD_ASSIGN); - append((String)e.getValue()); - } - if (blen != oldBlen) { - ++oldBlen; - } - } - return oldBlen; - } - - /** - * Returns an iterator over the keywords, or null if we have an empty map. - */ - public Iterator getKeywords() { - Map m = getKeywordMap(); - return m.isEmpty() ? null : m.keySet().iterator(); - } - - /** - * Returns the value for the named keyword, or null if the keyword is not - * present. - */ - public String getKeywordValue(String keywordName) { - Map m = getKeywordMap(); - return m.isEmpty() ? null : (String)m.get(keywordName.trim().toLowerCase()); - } - - /** - * Set the keyword value only if it is not already set to something else. - */ - public void defaultKeywordValue(String keywordName, String value) { - setKeywordValue(keywordName, value, false); - } - - /** - * Set the value for the named keyword, or unset it if value is null. If - * keywordName itself is null, unset all keywords. If keywordName is not null, - * value must not be null. - */ - public void setKeywordValue(String keywordName, String value) { - setKeywordValue(keywordName, value, true); - } - - /** - * Set the value for the named keyword, or unset it if value is null. If - * keywordName itself is null, unset all keywords. If keywordName is not null, - * value must not be null. If reset is true, ignore any previous value for - * the keyword, otherwise do not change the keyword (including removal of - * one or all keywords). - */ - private void setKeywordValue(String keywordName, String value, boolean reset) { - if (keywordName == null) { - if (reset) { - // force new map, ignore value - keywords = Collections.EMPTY_MAP; - } - } else { - keywordName = keywordName.trim().toLowerCase(); - if (keywordName.length() == 0) { - throw new IllegalArgumentException("keyword must not be empty"); - } - if (value != null) { - value = value.trim(); - if (value.length() == 0) { - throw new IllegalArgumentException("value must not be empty"); - } - } - Map m = getKeywordMap(); - if (m.isEmpty()) { // it is EMPTY_MAP - if (value != null) { - // force new map - keywords = new TreeMap(getKeyComparator()); - keywords.put(keywordName, value.trim()); - } - } else { - if (reset || !m.containsKey(keywordName)) { - if (value != null) { - m.put(keywordName, value); - } else { - m.remove(keywordName); - if (m.isEmpty()) { - // force new map - keywords = Collections.EMPTY_MAP; - } - } - } - } - } - } - } - - /** - * linear search of the string array. the arrays are unfortunately ordered by the - * two-letter target code, not the three-letter search code, which seems backwards. - */ - private static int findIndex(String[] array, String target){ - for (int i = 0; i < array.length; i++) { - if (target.equals(array[i])) { - return i; - } - } - return -1; - } - - /** - * Returns the canonical name for the specified locale ID. This is used to convert POSIX - * and other grandfathered IDs to standard ICU form. - * @param localeID the locale id - * @return the canonicalized id - * @stable ICU 3.0 - */ - public static String canonicalize(String localeID){ - IDParser parser = new IDParser(localeID, true); - String baseName = parser.getBaseName(); - boolean foundVariant = false; - - // formerly, we always set to en_US_POSIX if the basename was empty, but - // now we require that the entire id be empty, so that "@foo=bar" - // will pass through unchanged. - // {dlf} I'd rather keep "" unchanged. - if (localeID.equals("")) { - return ""; -// return "en_US_POSIX"; - } - - // we have an ID in the form xx_Yyyy_ZZ_KKKKK - - initCANONICALIZE_MAP(); - - /* convert the variants to appropriate ID */ - for (int i = 0; i < variantsToKeywords.length; i++) { - String[] vals = variantsToKeywords[i]; - int idx = baseName.lastIndexOf("_" + vals[0]); - if (idx > -1) { - foundVariant = true; - - baseName = baseName.substring(0, idx); - if (baseName.endsWith("_")) { - baseName = baseName.substring(0, --idx); - } - parser.setBaseName(baseName); - parser.defaultKeywordValue(vals[1], vals[2]); - break; - } - } - - /* See if this is an already known locale */ - for (int i = 0; i < CANONICALIZE_MAP.length; i++) { - if (CANONICALIZE_MAP[i][0].equals(baseName)) { - foundVariant = true; - - String[] vals = CANONICALIZE_MAP[i]; - parser.setBaseName(vals[1]); - if (vals[2] != null) { - parser.defaultKeywordValue(vals[2], vals[3]); - } - break; - } - } - - /* total mondo hack for Norwegian, fortunately the main NY case is handled earlier */ - if (!foundVariant) { - if (parser.getLanguage().equals("nb") && parser.getVariant().equals("NY")) { - parser.setBaseName(lscvToID("nn", parser.getScript(), parser.getCountry(), null)); - } - } - - return parser.getName(); - } - - /** - * Given a keyword and a value, return a new locale with an updated - * keyword and value. If keyword is null, this removes all keywords from the locale id. - * Otherwise, if the value is null, this removes the value for this keyword from the - * locale id. Otherwise, this adds/replaces the value for this keyword in the locale id. - * The keyword and value must not be empty. - * @param keyword the keyword to add/remove, or null to remove all keywords. - * @param value the value to add/set, or null to remove this particular keyword. - * @return the updated locale - * @stable ICU 3.2 - */ - public ULocale setKeywordValue(String keyword, String value) { - return new ULocale(setKeywordValue(localeID, keyword, value), (Locale)null); - } - - /** - * Given a locale id, a keyword, and a value, return a new locale id with an updated - * keyword and value. If keyword is null, this removes all keywords from the locale id. - * Otherwise, if the value is null, this removes the value for this keyword from the - * locale id. Otherwise, this adds/replaces the value for this keyword in the locale id. - * The keyword and value must not be empty. - * @param localeID the locale id to modify - * @param keyword the keyword to add/remove, or null to remove all keywords. - * @param value the value to add/set, or null to remove this particular keyword. - * @return the updated locale id - * @stable ICU 3.2 - */ - public static String setKeywordValue(String localeID, String keyword, String value) { - IDParser parser = new IDParser(localeID); - parser.setKeywordValue(keyword, value); - return parser.getName(); - } - - /* - * Given a locale id, a keyword, and a value, return a new locale id with an updated - * keyword and value, if the keyword does not already have a value. The keyword and - * value must not be null or empty. - * @param localeID the locale id to modify - * @param keyword the keyword to add, if not already present - * @param value the value to add, if not already present - * @return the updated locale id - * @internal - */ -/* private static String defaultKeywordValue(String localeID, String keyword, String value) { - IDParser parser = new IDParser(localeID); - parser.defaultKeywordValue(keyword, value); - return parser.getName(); - }*/ - - /** - * Returns a three-letter abbreviation for this locale's language. If the locale - * doesn't specify a language, returns the empty string. Otherwise, returns - * a lowercase ISO 639-2/T language code. - * The ISO 639-2 language codes can be found on-line at - * ftp://dkuug.dk/i18n/iso-639-2.txt - * @exception MissingResourceException Throws MissingResourceException if the - * three-letter language abbreviation is not available for this locale. - * @stable ICU 3.0 - */ - public String getISO3Language(){ - return getISO3Language(localeID); - } - - /** - * Returns a three-letter abbreviation for this locale's language. If the locale - * doesn't specify a language, returns the empty string. Otherwise, returns - * a lowercase ISO 639-2/T language code. - * The ISO 639-2 language codes can be found on-line at - * ftp://dkuug.dk/i18n/iso-639-2.txt - * @exception MissingResourceException Throws MissingResourceException if the - * three-letter language abbreviation is not available for this locale. - * @stable ICU 3.0 - */ - public static String getISO3Language(String localeID){ - initLanguageTables(); - - String language = getLanguage(localeID); - int offset = findIndex(_languages, language); - if(offset>=0){ - return _languages3[offset]; - } else { - offset = findIndex(_obsoleteLanguages, language); - if (offset >= 0) { - return _obsoleteLanguages3[offset]; - } - } - return EMPTY_STRING; - } - - /** - * Returns a three-letter abbreviation for this locale's country/region. If the locale - * doesn't specify a country, returns the empty string. Otherwise, returns - * an uppercase ISO 3166 3-letter country code. - * @exception MissingResourceException Throws MissingResourceException if the - * three-letter country abbreviation is not available for this locale. - * @stable ICU 3.0 - */ - public String getISO3Country(){ - return getISO3Country(localeID); - } - /** - * Returns a three-letter abbreviation for this locale's country/region. If the locale - * doesn't specify a country, returns the empty string. Otherwise, returns - * an uppercase ISO 3166 3-letter country code. - * @exception MissingResourceException Throws MissingResourceException if the - * three-letter country abbreviation is not available for this locale. - * @stable ICU 3.0 - */ - public static String getISO3Country(String localeID){ - initCountryTables(); - - String country = getCountry(localeID); - int offset = findIndex(_countries, country); - if(offset>=0){ - return _countries3[offset]; - }else{ - offset = findIndex(_obsoleteCountries, country); - if(offset>=0){ - return _obsoleteCountries3[offset]; - } - } - return EMPTY_STRING; - } - - // display names - -// /** -// * Utility to fetch locale display data from resource bundle tables. -// */ -// private static String getTableString(String tableName, String subtableName, String item, String displayLocaleID) { -// if (item.length() > 0) { -// try { -// ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle. -// getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, displayLocaleID); -// return getTableString(tableName, subtableName, item, bundle); -// } catch (Exception e) { -//// System.out.println("gtsu: " + e.getMessage()); -// } -// } -// return item; -// } -// -// /** -// * Utility to fetch locale display data from resource bundle tables. -// */ -// private static String getTableString(String tableName, String subtableName, String item, ICUResourceBundle bundle) { -//// System.out.println("gts table: " + tableName + -//// " subtable: " + subtableName + -//// " item: " + item + -//// " bundle: " + bundle.getULocale()); -// try { -// for (;;) { -// // special case currency -// if ("currency".equals(subtableName)) { -// ICUResourceBundle table = bundle.getWithFallback("Currencies"); -// table = table.getWithFallback(item); -// return table.getString(1); -// } else { -// ICUResourceBundle table = bundle.getWithFallback(tableName); -// try { -// if (subtableName != null) { -// table = table.getWithFallback(subtableName); -// } -// return table.getStringWithFallback(item); -// } -// catch (MissingResourceException e) { -// -// if(subtableName==null){ -// try{ -// // may be a deprecated code -// String currentName = null; -// if(tableName.equals("Countries")){ -// currentName = getCurrentCountryID(item); -// }else if(tableName.equals("Languages")){ -// currentName = getCurrentLanguageID(item); -// } -// return table.getStringWithFallback(currentName); -// }catch (MissingResourceException ex){/* fall through*/} -// } -// -// // still can't figure out ?.. try the fallback mechanism -// String fallbackLocale = table.getWithFallback("Fallback").getString(); -// if (fallbackLocale.length() == 0) { -// fallbackLocale = "root"; -// } -//// System.out.println("bundle: " + bundle.getULocale() + " fallback: " + fallbackLocale); -// if(fallbackLocale.equals(table.getULocale().localeID)){ -// return item; -// } -// bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, -// fallbackLocale); -//// System.out.println("fallback from " + table.getULocale() + " to " + fallbackLocale + -//// ", got bundle " + bundle.getULocale()); -// } -// } -// } -// } -// catch (Exception e) { -//// System.out.println("gtsi: " + e.getMessage()); -// } -// return item; -// } - - /** - * Returns this locale's language localized for display in the default locale. - * @return the localized language name. - * @stable ICU 3.0 - */ - public String getDisplayLanguage() { - return getDisplayLanguageInternal(localeID, getDefault().localeID); - } - - /** - * Returns this locale's language localized for display in the provided locale. - * @param displayLocale the locale in which to display the name. - * @return the localized language name. - * @stable ICU 3.0 - */ - public String getDisplayLanguage(ULocale displayLocale) { - return getDisplayLanguageInternal(localeID, displayLocale.localeID); - } - - /** - * Returns a locale's language localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose language will be displayed - * @param displayLocaleID the id of the locale in which to display the name. - * @return the localized language name. - * @stable ICU 3.0 - */ - public static String getDisplayLanguage(String localeID, String displayLocaleID) { - return getDisplayLanguageInternal(localeID, getName(displayLocaleID)); - } - - /** - * Returns a locale's language localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose language will be displayed. - * @param displayLocale the locale in which to display the name. - * @return the localized language name. - * @stable ICU 3.0 - */ - public static String getDisplayLanguage(String localeID, ULocale displayLocale) { - return getDisplayLanguageInternal(localeID, displayLocale.localeID); - } - - static String getCurrentCountryID(String oldID){ - initCountryTables(); - int offset = findIndex(_deprecatedCountries, oldID); - if (offset >= 0) { - return _replacementCountries[offset]; - } - return oldID; - } - static String getCurrentLanguageID(String oldID){ - initLanguageTables(); - int offset = findIndex(_obsoleteLanguages, oldID); - if (offset >= 0) { - return _replacementLanguages[offset]; - } - return oldID; - } - - - // displayLocaleID is canonical, localeID need not be since parsing will fix this. - private static String getDisplayLanguageInternal(String localeID, String displayLocaleID) { -// return getTableString("Languages", null, new IDParser(localeID).getLanguage(), displayLocaleID); - return toLocale(localeID).getDisplayLanguage(toLocale(displayLocaleID)); - } - - /** - * Returns this locale's script localized for display in the default locale. - * @return the localized script name. - * @stable ICU 3.0 - */ - public String getDisplayScript() { - return getDisplayScriptInternal(localeID, getDefault().localeID); - } - - /** - * Returns this locale's script localized for display in the provided locale. - * @param displayLocale the locale in which to display the name. - * @return the localized script name. - * @stable ICU 3.0 - */ - public String getDisplayScript(ULocale displayLocale) { - return getDisplayScriptInternal(localeID, displayLocale.localeID); - } - - /** - * Returns a locale's script localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose script will be displayed - * @param displayLocaleID the id of the locale in which to display the name. - * @return the localized script name. - * @stable ICU 3.0 - */ - public static String getDisplayScript(String localeID, String displayLocaleID) { - return getDisplayScriptInternal(localeID, getName(displayLocaleID)); - } - - /** - * Returns a locale's script localized for display in the provided locale. - * @param localeID the id of the locale whose script will be displayed. - * @param displayLocale the locale in which to display the name. - * @return the localized script name. - * @stable ICU 3.0 - */ - public static String getDisplayScript(String localeID, ULocale displayLocale) { - return getDisplayScriptInternal(localeID, displayLocale.localeID); - } - - // displayLocaleID is canonical, localeID need not be since parsing will fix this. - private static String getDisplayScriptInternal(String localeID, String displayLocaleID) { -// return getTableString("Scripts", null, new IDParser(localeID).getScript(), displayLocaleID); - return new IDParser(localeID).getScript(); - } - - /** - * Returns this locale's country localized for display in the default locale. - * @return the localized country name. - * @stable ICU 3.0 - */ - public String getDisplayCountry() { - return getDisplayCountryInternal(localeID, getDefault().localeID); - } - - /** - * Returns this locale's country localized for display in the provided locale. - * @param displayLocale the locale in which to display the name. - * @return the localized country name. - * @stable ICU 3.0 - */ - public String getDisplayCountry(ULocale displayLocale){ - return getDisplayCountryInternal(localeID, displayLocale.localeID); - } - - /** - * Returns a locale's country localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose country will be displayed - * @param displayLocaleID the id of the locale in which to display the name. - * @return the localized country name. - * @stable ICU 3.0 - */ - public static String getDisplayCountry(String localeID, String displayLocaleID) { - return getDisplayCountryInternal(localeID, getName(displayLocaleID)); - } - - /** - * Returns a locale's country localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose country will be displayed. - * @param displayLocale the locale in which to display the name. - * @return the localized country name. - * @stable ICU 3.0 - */ - public static String getDisplayCountry(String localeID, ULocale displayLocale) { - return getDisplayCountryInternal(localeID, displayLocale.localeID); - } - - // displayLocaleID is canonical, localeID need not be since parsing will fix this. - private static String getDisplayCountryInternal(String localeID, String displayLocaleID) { -// return getTableString("Countries", null, new IDParser(localeID).getCountry(), displayLocaleID); - return toLocale(localeID).getDisplayCountry(toLocale(displayLocaleID)); - } - - /** - * Returns this locale's variant localized for display in the default locale. - * @return the localized variant name. - * @stable ICU 3.0 - */ - public String getDisplayVariant() { - return getDisplayVariantInternal(localeID, getDefault().localeID); - } - - /** - * Returns this locale's variant localized for display in the provided locale. - * @param displayLocale the locale in which to display the name. - * @return the localized variant name. - * @stable ICU 3.0 - */ - public String getDisplayVariant(ULocale displayLocale) { - return getDisplayVariantInternal(localeID, displayLocale.localeID); - } - - /** - * Returns a locale's variant localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose variant will be displayed - * @param displayLocaleID the id of the locale in which to display the name. - * @return the localized variant name. - * @stable ICU 3.0 - */ - public static String getDisplayVariant(String localeID, String displayLocaleID){ - return getDisplayVariantInternal(localeID, getName(displayLocaleID)); - } - - /** - * Returns a locale's variant localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose variant will be displayed. - * @param displayLocale the locale in which to display the name. - * @return the localized variant name. - * @stable ICU 3.0 - */ - public static String getDisplayVariant(String localeID, ULocale displayLocale) { - return getDisplayVariantInternal(localeID, displayLocale.localeID); - } - - // displayLocaleID is canonical, localeID need not be since parsing will fix this. - private static String getDisplayVariantInternal(String localeID, String displayLocaleID) { -// return getTableString("Variants", null, new IDParser(localeID).getVariant(), displayLocaleID); - return toLocale(localeID).getDisplayVariant(toLocale(displayLocaleID)); - } - - /** - * Returns a keyword localized for display in the default locale. - * @param keyword the keyword to be displayed. - * @return the localized keyword name. - * @see #getKeywords() - * @stable ICU 3.0 - */ - public static String getDisplayKeyword(String keyword) { - return getDisplayKeywordInternal(keyword, getDefault().localeID); - } - - /** - * Returns a keyword localized for display in the specified locale. - * @param keyword the keyword to be displayed. - * @param displayLocaleID the id of the locale in which to display the keyword. - * @return the localized keyword name. - * @see #getKeywords(String) - * @stable ICU 3.0 - */ - public static String getDisplayKeyword(String keyword, String displayLocaleID) { - return getDisplayKeywordInternal(keyword, getName(displayLocaleID)); - } - - /** - * Returns a keyword localized for display in the specified locale. - * @param keyword the keyword to be displayed. - * @param displayLocale the locale in which to display the keyword. - * @return the localized keyword name. - * @see #getKeywords(String) - * @stable ICU 3.0 - */ - public static String getDisplayKeyword(String keyword, ULocale displayLocale) { - return getDisplayKeywordInternal(keyword, displayLocale.localeID); - } - - // displayLocaleID is canonical, localeID need not be since parsing will fix this. - private static String getDisplayKeywordInternal(String keyword, String displayLocaleID) { -// return getTableString("Keys", null, keyword.trim().toLowerCase(), displayLocaleID); - return keyword.trim().toLowerCase(); - } - - /** - * Returns a keyword value localized for display in the default locale. - * @param keyword the keyword whose value is to be displayed. - * @return the localized value name. - * @stable ICU 3.0 - */ - public String getDisplayKeywordValue(String keyword) { - return getDisplayKeywordValueInternal(localeID, keyword, getDefault().localeID); - } - - /** - * Returns a keyword value localized for display in the specified locale. - * @param keyword the keyword whose value is to be displayed. - * @param displayLocale the locale in which to display the value. - * @return the localized value name. - * @stable ICU 3.0 - */ - public String getDisplayKeywordValue(String keyword, ULocale displayLocale) { - return getDisplayKeywordValueInternal(localeID, keyword, displayLocale.localeID); - } - - /** - * Returns a keyword value localized for display in the specified locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose keyword value is to be displayed. - * @param keyword the keyword whose value is to be displayed. - * @param displayLocaleID the id of the locale in which to display the value. - * @return the localized value name. - * @stable ICU 3.0 - */ - public static String getDisplayKeywordValue(String localeID, String keyword, String displayLocaleID) { - return getDisplayKeywordValueInternal(localeID, keyword, getName(displayLocaleID)); - } - - /** - * Returns a keyword value localized for display in the specified locale. - * This is a cover for the ICU4C API. - * @param localeID the id of the locale whose keyword value is to be displayed. - * @param keyword the keyword whose value is to be displayed. - * @param displayLocale the id of the locale in which to display the value. - * @return the localized value name. - * @stable ICU 3.0 - */ - public static String getDisplayKeywordValue(String localeID, String keyword, ULocale displayLocale) { - return getDisplayKeywordValueInternal(localeID, keyword, displayLocale.localeID); - } - - // displayLocaleID is canonical, localeID need not be since parsing will fix this. - private static String getDisplayKeywordValueInternal(String localeID, String keyword, String displayLocaleID) { - keyword = keyword.trim().toLowerCase(); - String value = new IDParser(localeID).getKeywordValue(keyword); -// return getTableString("Types", keyword, value, displayLocaleID); - return value; - } - - /** - * Returns this locale name localized for display in the default locale. - * @return the localized locale name. - * @stable ICU 3.0 - */ - public String getDisplayName() { - return getDisplayNameInternal(localeID, getDefault().localeID); - } - - /** - * Returns this locale name localized for display in the provided locale. - * @param displayLocale the locale in which to display the locale name. - * @return the localized locale name. - * @stable ICU 3.0 - */ - public String getDisplayName(ULocale displayLocale) { - return getDisplayNameInternal(localeID, displayLocale.localeID); - } - - /** - * Returns the locale ID localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the locale whose name is to be displayed. - * @param displayLocaleID the id of the locale in which to display the locale name. - * @return the localized locale name. - * @stable ICU 3.0 - */ - public static String getDisplayName(String localeID, String displayLocaleID) { - return getDisplayNameInternal(localeID, getName(displayLocaleID)); - } - - /** - * Returns the locale ID localized for display in the provided locale. - * This is a cover for the ICU4C API. - * @param localeID the locale whose name is to be displayed. - * @param displayLocale the locale in which to display the locale name. - * @return the localized locale name. - * @stable ICU 3.0 - */ - public static String getDisplayName(String localeID, ULocale displayLocale) { - return getDisplayNameInternal(localeID, displayLocale.localeID); - } - - // displayLocaleID is canonical, localeID need not be since parsing will fix this. - private static String getDisplayNameInternal(String localeID, String displayLocaleID) { - // lang - // lang (script, country, variant, keyword=value, ...) - // script, country, variant, keyword=value, ... - -// final String[] tableNames = { "Languages", "Scripts", "Countries", "Variants" }; -// -// ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, displayLocaleID); - - StringBuffer buf = new StringBuffer(); - - IDParser parser = new IDParser(localeID); - String[] names = parser.getLanguageScriptCountryVariant(); - - Locale locale = toLocale(localeID); - Locale dispLocale = toLocale(displayLocaleID); - - boolean haveLanguage = names[0].length() > 0; - boolean openParen = false; - for (int i = 0; i < names.length; ++i) { - String name = names[i]; - if (name.length() > 0) { -// name = getTableString(tableNames[i], null, name, bundle); - - switch (i) { - case 0: name = locale.getDisplayLanguage(dispLocale); break; - case 1: break; - case 2: name = locale.getDisplayCountry(dispLocale); break; - case 3: name = locale.getDisplayVariant(dispLocale); break; - } - - if (buf.length() > 0) { // need a separator - if (haveLanguage & !openParen) { - buf.append(" ("); - openParen = true; - } else { - buf.append(", "); - } - } - buf.append(name); - } - } - - Map m = parser.getKeywordMap(); - if (!m.isEmpty()) { - Iterator keys = m.entrySet().iterator(); - while (keys.hasNext()) { - if (buf.length() > 0) { - if (haveLanguage & !openParen) { - buf.append(" ("); - openParen = true; - } else { - buf.append(", "); - } - } - Map.Entry e = (Map.Entry)keys.next(); - String key = (String)e.getKey(); - String val = (String)e.getValue(); -// buf.append(getTableString("Keys", null, key, bundle)); -// buf.append("="); -// buf.append(getTableString("Types", key, val, bundle)); - buf.append(key); - buf.append("="); - buf.append(val); - } - } - - if (openParen) { - buf.append(")"); - } - - return buf.toString(); - } - -// /** -// * Returns this locale's layout orientation for characters. The possible -// * values are "left-to-right", "right-to-left", "top-to-bottom" or -// * "bottom-to-top". -// * @return The locale's layout orientation for characters. -// * @draft ICU 4.0 -// * @provisional This API might change or be removed in a future release. -// */ -// public String getCharacterOrientation() { -// return getTableString("layout", null, "characters", getName()); -// } -// -// /** -// * Returns this locale's layout orientation for lines. The possible -// * values are "left-to-right", "right-to-left", "top-to-bottom" or -// * "bottom-to-top". -// * @return The locale's layout orientation for lines. -// * @draft ICU 4.0 -// * @provisional This API might change or be removed in a future release. -// */ -// public String getLineOrientation() { -// return getTableString("layout", null, "lines", getName()); -// } - - /** - * Selector for getLocale() indicating the locale of the - * resource containing the data. This is always at or above the - * valid locale. If the valid locale does not contain the - * specific data being requested, then the actual locale will be - * above the valid locale. If the object was not constructed from - * locale data, then the valid locale is null. - * - * @draft ICU 2.8 (retain) - * @provisional This API might change or be removed in a future release. - */ - public static Type ACTUAL_LOCALE = new Type(); - - /** - * Selector for getLocale() indicating the most specific - * locale for which any data exists. This is always at or above - * the requested locale, and at or below the actual locale. If - * the requested locale does not correspond to any resource data, - * then the valid locale will be above the requested locale. If - * the object was not constructed from locale data, then the - * actual locale is null. - * - *

Note: The valid locale will be returned correctly in ICU - * 3.0 or later. In ICU 2.8, it is not returned correctly. - * @draft ICU 2.8 (retain) - * @provisional This API might change or be removed in a future release. - */ - public static Type VALID_LOCALE = new Type(); - - /** - * Opaque selector enum for getLocale(). - * @see com.ibm.icu.util.ULocale - * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE - * @see com.ibm.icu.util.ULocale#VALID_LOCALE - * @draft ICU 2.8 (retainAll) - * @provisional This API might change or be removed in a future release. - */ - public static final class Type { - private Type() {} - } - - /** - * Based on a HTTP formatted list of acceptable locales, determine an available locale for the user. - * NullPointerException is thrown if acceptLanguageList or availableLocales is - * null. If fallback is non-null, it will contain true if a fallback locale (one - * not in the acceptLanguageList) was returned. The value on entry is ignored. - * ULocale will be one of the locales in availableLocales, or the ROOT ULocale if - * if a ROOT locale was used as a fallback (because nothing else in - * availableLocales matched). No ULocale array element should be null; behavior - * is undefined if this is the case. - * @param acceptLanguageList list in HTTP "Accept-Language:" format of acceptable locales - * @param availableLocales list of available locales. One of these will be returned. - * @param fallback if non-null, a 1-element array containing a boolean to be set with the fallback status - * @return one of the locales from the availableLocales list, or null if none match - * @stable ICU 3.4 - */ - - public static ULocale acceptLanguage(String acceptLanguageList, ULocale[] availableLocales, - boolean[] fallback) { - if (acceptLanguageList == null) { - throw new NullPointerException(); - } - ULocale acceptList[] = null; - try { - acceptList = parseAcceptLanguage(acceptLanguageList, true); - } catch (ParseException pe) { - acceptList = null; - } - if (acceptList == null) { - return null; - } - return acceptLanguage(acceptList, availableLocales, fallback); - } - - /** - * Based on a list of acceptable locales, determine an available locale for the user. - * NullPointerException is thrown if acceptLanguageList or availableLocales is - * null. If fallback is non-null, it will contain true if a fallback locale (one - * not in the acceptLanguageList) was returned. The value on entry is ignored. - * ULocale will be one of the locales in availableLocales, or the ROOT ULocale if - * if a ROOT locale was used as a fallback (because nothing else in - * availableLocales matched). No ULocale array element should be null; behavior - * is undefined if this is the case. - * @param acceptLanguageList list of acceptable locales - * @param availableLocales list of available locales. One of these will be returned. - * @param fallback if non-null, a 1-element array containing a boolean to be set with the fallback status - * @return one of the locales from the availableLocales list, or null if none match - * @stable ICU 3.4 - */ - - public static ULocale acceptLanguage(ULocale[] acceptLanguageList, ULocale[] - availableLocales, boolean[] fallback) { - // fallbacklist - int i,j; - if(fallback != null) { - fallback[0]=true; - } - for(i=0;i=0; --i) { - if (parts[i].length() != 0) { - parts[i] = ""; - break; - } - } - if (i<0) { - return null; // All parts were empty - } - return new Locale(parts[0], parts[1], parts[2]); - } - - /** - * Based on a HTTP formatted list of acceptable locales, determine an available locale for the user. - * NullPointerException is thrown if acceptLanguageList or availableLocales is - * null. If fallback is non-null, it will contain true if a fallback locale (one - * not in the acceptLanguageList) was returned. The value on entry is ignored. - * ULocale will be one of the locales in availableLocales, or the ROOT ULocale if - * if a ROOT locale was used as a fallback (because nothing else in - * availableLocales matched). No ULocale array element should be null; behavior - * is undefined if this is the case. - * This function will choose a locale from the ULocale.getAvailableLocales() list as available. - * @param acceptLanguageList list in HTTP "Accept-Language:" format of acceptable locales - * @param fallback if non-null, a 1-element array containing a boolean to be set with the fallback status - * @return one of the locales from the ULocale.getAvailableLocales() list, or null if none match - * @stable ICU 3.4 - */ - - public static ULocale acceptLanguage(String acceptLanguageList, boolean[] fallback) { - return acceptLanguage(acceptLanguageList, ULocale.getAvailableLocales(), - fallback); - } - - /** - * Based on an ordered array of acceptable locales, determine an available locale for the user. - * NullPointerException is thrown if acceptLanguageList or availableLocales is - * null. If fallback is non-null, it will contain true if a fallback locale (one - * not in the acceptLanguageList) was returned. The value on entry is ignored. - * ULocale will be one of the locales in availableLocales, or the ROOT ULocale if - * if a ROOT locale was used as a fallback (because nothing else in - * availableLocales matched). No ULocale array element should be null; behavior - * is undefined if this is the case. - * This function will choose a locale from the ULocale.getAvailableLocales() list as available. - * @param acceptLanguageList ordered array of acceptable locales (preferred are listed first) - * @param fallback if non-null, a 1-element array containing a boolean to be set with the fallback status - * @return one of the locales from the ULocale.getAvailableLocales() list, or null if none match - * @stable ICU 3.4 - */ - - public static ULocale acceptLanguage(ULocale[] acceptLanguageList, boolean[] - fallback) { - return acceptLanguage(acceptLanguageList, ULocale.getAvailableLocales(), - fallback); - } - - /** - * Package local method used for parsing Accept-Language string - * @internal ICU 3.8 - */ - static ULocale[] parseAcceptLanguage(String acceptLanguage, boolean isLenient) throws ParseException { - /** - * @internal ICU 3.4 - */ - class ULocaleAcceptLanguageQ implements Comparable { - private double q; - private double serial; - public ULocaleAcceptLanguageQ(double theq, int theserial) { - q = theq; - serial = theserial; - } - public int compareTo(Object o) { - ULocaleAcceptLanguageQ other = (ULocaleAcceptLanguageQ) o; - if (q > other.q) { // reverse - to sort in descending order - return -1; - } else if (q < other.q) { - return 1; - } - if (serial < other.serial) { - return -1; - } else if (serial > other.serial) { - return 1; - } else { - return 0; // same object - } - } - } - - // parse out the acceptLanguage into an array - TreeMap map = new TreeMap(); - StringBuffer languageRangeBuf = new StringBuffer(); - StringBuffer qvalBuf = new StringBuffer(); - int state = 0; - acceptLanguage += ","; // append comma to simplify the parsing code - int n; - boolean subTag = false; - boolean q1 = false; - for (n = 0; n < acceptLanguage.length(); n++) { - boolean gotLanguageQ = false; - char c = acceptLanguage.charAt(n); - switch (state) { - case 0: // before language-range start - if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) { - // in language-range - languageRangeBuf.append(c); - state = 1; - subTag = false; - } else if (c == '*') { - languageRangeBuf.append(c); - state = 2; - } else if (c != ' ' && c != '\t') { - // invalid character - state = -1; - } - break; - case 1: // in language-range - if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')) { - languageRangeBuf.append(c); - } else if (c == '-') { - subTag = true; - languageRangeBuf.append(c); - } else if (c == '_') { - if (isLenient) { - subTag = true; - languageRangeBuf.append(c); - } else { - state = -1; - } - } else if ('0' <= c && c <= '9') { - if (subTag) { - languageRangeBuf.append(c); - } else { - // DIGIT is allowed only in language sub tag - state = -1; - } - } else if (c == ',') { - // language-q end - gotLanguageQ = true; - } else if (c == ' ' || c == '\t') { - // language-range end - state = 3; - } else if (c == ';') { - // before q - state = 4; - } else { - // invalid character for language-range - state = -1; - } - break; - case 2: // saw wild card range - if (c == ',') { - // language-q end - gotLanguageQ = true; - } else if (c == ' ' || c == '\t') { - // language-range end - state = 3; - } else if (c == ';') { - // before q - state = 4; - } else { - // invalid - state = -1; - } - break; - case 3: // language-range end - if (c == ',') { - // language-q end - gotLanguageQ = true; - } else if (c == ';') { - // before q - state =4; - } else if (c != ' ' && c != '\t') { - // invalid - state = -1; - } - break; - case 4: // before q - if (c == 'q') { - // before equal - state = 5; - } else if (c != ' ' && c != '\t') { - // invalid - state = -1; - } - break; - case 5: // before equal - if (c == '=') { - // before q value - state = 6; - } else if (c != ' ' && c != '\t') { - // invalid - state = -1; - } - break; - case 6: // before q value - if (c == '0') { - // q value start with 0 - q1 = false; - qvalBuf.append(c); - state = 7; - } else if (c == '1') { - // q value start with 1 - qvalBuf.append(c); - state = 7; - } else if (c == '.') { - if (isLenient) { - qvalBuf.append(c); - state = 8; - } else { - state = -1; - } - } else if (c != ' ' && c != '\t') { - // invalid - state = -1; - } - break; - case 7: // q value start - if (c == '.') { - // before q value fraction part - qvalBuf.append(c); - state = 8; - } else if (c == ',') { - // language-q end - gotLanguageQ = true; - } else if (c == ' ' || c == '\t') { - // after q value - state = 10; - } else { - // invalid - state = -1; - } - break; - case 8: // before q value fraction part - if ('0' <= c || c <= '9') { - if (q1 && c != '0' && !isLenient) { - // if q value starts with 1, the fraction part must be 0 - state = -1; - } else { - // in q value fraction part - qvalBuf.append(c); - state = 9; - } - } else { - // invalid - state = -1; - } - break; - case 9: // in q value fraction part - if ('0' <= c && c <= '9') { - if (q1 && c != '0') { - // if q value starts with 1, the fraction part must be 0 - state = -1; - } else { - qvalBuf.append(c); - } - } else if (c == ',') { - // language-q end - gotLanguageQ = true; - } else if (c == ' ' || c == '\t') { - // after q value - state = 10; - } else { - // invalid - state = -1; - } - break; - case 10: // after q value - if (c == ',') { - // language-q end - gotLanguageQ = true; - } else if (c != ' ' && c != '\t') { - // invalid - state = -1; - } - break; - } - if (state == -1) { - // error state - throw new ParseException("Invalid Accept-Language", n); - } - if (gotLanguageQ) { - double q = 1.0; - if (qvalBuf.length() != 0) { - try { - q = Double.parseDouble(qvalBuf.toString()); - } catch (NumberFormatException nfe) { - // Already validated, so it should never happen - q = 1.0; - } - if (q > 1.0) { - q = 1.0; - } - } - if (languageRangeBuf.charAt(0) != '*') { - int serial = map.size(); - ULocaleAcceptLanguageQ entry = new ULocaleAcceptLanguageQ(q, serial); - map.put(entry, new ULocale(canonicalize(languageRangeBuf.toString()))); // sort in reverse order.. 1.0, 0.9, 0.8 .. etc - } - - // reset buffer and parse state - languageRangeBuf.setLength(0); - qvalBuf.setLength(0); - state = 0; - } - } - if (state != 0) { - // Well, the parser should handle all cases. So just in case. - throw new ParseException("Invalid AcceptlLanguage", n); - } - - // pull out the map - ULocale acceptList[] = (ULocale[])map.values().toArray(new ULocale[map.size()]); - return acceptList; - } - -// private static final String UNDEFINED_LANGUAGE = "und"; -// private static final String UNDEFINED_SCRIPT = "Zzzz"; -// private static final String UNDEFINED_REGION = "ZZ"; -// -// /** -// * Supply most likely subtags to the given locale -// * @param loc The input locale -// * @return A ULocale with most likely subtags filled in. -// * @internal -// * @deprecated This API is ICU internal only. -// */ -// public static ULocale addLikelySubtag(ULocale loc) { -// return addLikelySubtags(loc); -// } -// -// /** -// * Add the likely subtags for a provided locale ID, per the algorithm described -// * in the following CLDR technical report: -// * -// * http://www.unicode.org/reports/tr35/#Likely_Subtags -// * -// * If the provided ULocale instance is already in the maximal form, or there is no -// * data available available for maximization, it will be returned. For example, -// * "und-Zzzz" cannot be maximized, since there is no reasonable maximization. -// * Otherwise, a new ULocale instance with the maximal form is returned. -// * -// * Examples: -// * -// * "en" maximizes to "en_Latn_US" -// * -// * "de" maximizes to "de_Latn_US" -// * -// * "sr" maximizes to "sr_Cyrl_RS" -// * -// * "sh" maximizes to "sr_Latn_RS" (Note this will not reverse.) -// * -// * "zh_Hani" maximizes to "zh_Hans_CN" (Note this will not reverse.) -// * -// * @param loc The ULocale to maximize -// * @return The maximized ULocale instance. -// * @draft ICU 4.0 -// * @provisional This API might change or be removed in a future release. -// */ -// public static ULocale -// addLikelySubtags(ULocale loc) -// { -// String[] tags = new String[3]; -// String trailing = null; -// -// int trailingIndex = parseTagString( -// loc.localeID, -// tags); -// -// if (trailingIndex < loc.localeID.length()) { -// trailing = loc.localeID.substring(trailingIndex); -// } -// -// String newLocaleID = -// createLikelySubtagsString( -// (String)tags[0], -// (String)tags[1], -// (String)tags[2], -// trailing); -// -// return newLocaleID == null ? loc : new ULocale(newLocaleID); -// } -// -// /** -// * Minimize the subtags for a provided locale ID, per the algorithm described -// * in the following CLDR technical report: -// * -// * http://www.unicode.org/reports/tr35/#Likely_Subtags -// * -// * If the provided ULocale instance is already in the minimal form, or there -// * is no data available for minimization, it will be returned. Since the -// * minimization algorithm relies on proper maximization, see the comments -// * for addLikelySubtags for reasons why there might not be any data. -// * -// * Examples: -// * -// * "en_Latn_US" minimizes to "en" -// * -// * "de_Latn_US" minimizes to "de" -// * -// * "sr_Cyrl_RS" minimizes to "sr" -// * -// * "zh_Hant_TW" minimizes to "zh_TW" (The region is preferred to the -// * script, and minimizing to "zh" would imply "zh_Hans_CN".) -// * -// * @param loc The ULocale to minimize -// * @return The minimized ULocale instance. -// * @draft ICU 4.0 -// * @provisional This API might change or be removed in a future release. -// */ -// public static ULocale -// minimizeSubtags(ULocale loc) -// { -// String[] tags = new String[3]; -// -// int trailingIndex = parseTagString( -// loc.localeID, -// tags); -// -// String originalLang = (String)tags[0]; -// String originalScript = (String)tags[1]; -// String originalRegion = (String)tags[2]; -// String originalTrailing = null; -// -// if (trailingIndex < loc.localeID.length()) { -// /* -// * Create a String that contains everything -// * after the language, script, and region. -// */ -// originalTrailing = loc.localeID.substring(trailingIndex); -// } -// -// /** -// * First, we need to first get the maximization -// * by adding any likely subtags. -// **/ -// String maximizedLocaleID = -// createLikelySubtagsString( -// originalLang, -// originalScript, -// originalRegion, -// null); -// -// /** -// * If maximization fails, there's nothing -// * we can do. -// **/ -// if (isEmptyString(maximizedLocaleID)) { -// return loc; -// } -// else { -// /** -// * Start first with just the language. -// **/ -// String tag = -// createLikelySubtagsString( -// originalLang, -// null, -// null, -// null); -// -// if (tag.equals(maximizedLocaleID)) { -// String newLocaleID = -// createTagString( -// originalLang, -// null, -// null, -// originalTrailing); -// -// return new ULocale(newLocaleID); -// } -// } -// -// /** -// * Next, try the language and region. -// **/ -// if (originalRegion.length() != 0) { -// -// String tag = -// createLikelySubtagsString( -// originalLang, -// null, -// originalRegion, -// null); -// -// if (tag.equals(maximizedLocaleID)) { -// String newLocaleID = -// createTagString( -// originalLang, -// null, -// originalRegion, -// originalTrailing); -// -// return new ULocale(newLocaleID); -// } -// } -// -// /** -// * Finally, try the language and script. This is our last chance, -// * since trying with all three subtags would only yield the -// * maximal version that we already have. -// **/ -// if (originalRegion.length() != 0 && -// originalScript.length() != 0) { -// -// String tag = -// createLikelySubtagsString( -// originalLang, -// originalScript, -// null, -// null); -// -// if (tag.equals(maximizedLocaleID)) { -// String newLocaleID = -// createTagString( -// originalLang, -// originalScript, -// null, -// originalTrailing); -// -// return new ULocale(newLocaleID); -// } -// } -// -// return loc; -// } -// -// /** -// * A trivial utility function that checks for a null -// * reference or checks the length of the supplied String. -// * -// * @param string The string to check -// * -// * @return true if the String is empty, or if the reference is null. -// */ -// private static boolean isEmptyString(String string) { -// return string == null || string.length() == 0; -// } -// -// /** -// * Append a tag to a StringBuffer, adding the separator if necessary.The tag must -// * not be a zero-length string. -// * -// * @param tag The tag to add. -// * @param buffer The output buffer. -// **/ -// private static void -// appendTag( -// String tag, -// StringBuffer buffer) { -// -// if (buffer.length() != 0) { -// buffer.append(UNDERSCORE); -// } -// -// buffer.append(tag); -// } -// -// /** -// * Create a tag string from the supplied parameters. The lang, script and region -// * parameters may be null references. -// * -// * If any of the language, script or region parameters are empty, and the alternateTags -// * parameter is not null, it will be parsed for potential language, script and region tags -// * to be used when constructing the new tag. If the alternateTags parameter is null, or -// * it contains no language tag, the default tag for the unknown language is used. -// * -// * @param lang The language tag to use. -// * @param script The script tag to use. -// * @param region The region tag to use. -// * @param trailing Any trailing data to append to the new tag. -// * @param alternateTags A string containing any alternate tags. -// * @return The new tag string. -// **/ -// private static String -// createTagString( -// String lang, -// String script, -// String region, -// String trailing, -// String alternateTags) { -// -// IDParser parser = null; -// boolean regionAppended = false; -// -// StringBuffer tag = new StringBuffer(); -// -// if (!isEmptyString(lang)) { -// appendTag( -// lang, -// tag); -// } -// else if (isEmptyString(alternateTags)) { -// /* -// * Append the value for an unknown language, if -// * we found no language. -// */ -// appendTag( -// UNDEFINED_LANGUAGE, -// tag); -// } -// else { -// parser = new IDParser(alternateTags); -// -// String alternateLang = parser.getLanguage(); -// -// /* -// * Append the value for an unknown language, if -// * we found no language. -// */ -// appendTag( -// !isEmptyString(alternateLang) ? alternateLang : UNDEFINED_LANGUAGE, -// tag); -// } -// -// if (!isEmptyString(script)) { -// appendTag( -// script, -// tag); -// } -// else if (!isEmptyString(alternateTags)) { -// /* -// * Parse the alternateTags string for the script. -// */ -// if (parser == null) { -// parser = new IDParser(alternateTags); -// } -// -// String alternateScript = parser.getScript(); -// -// if (!isEmptyString(alternateScript)) { -// appendTag( -// alternateScript, -// tag); -// } -// } -// -// if (!isEmptyString(region)) { -// appendTag( -// region, -// tag); -// -// regionAppended = true; -// } -// else if (!isEmptyString(alternateTags)) { -// /* -// * Parse the alternateTags string for the region. -// */ -// if (parser == null) { -// parser = new IDParser(alternateTags); -// } -// -// String alternateRegion = parser.getCountry(); -// -// if (!isEmptyString(alternateRegion)) { -// appendTag( -// alternateRegion, -// tag); -// -// regionAppended = true; -// } -// } -// -// if (trailing != null && trailing.length() > 1) { -// /* -// * The current ICU format expects two underscores -// * will separate the variant from the preceeding -// * parts of the tag, if there is no region. -// */ -// int separators = 0; -// -// if (trailing.charAt(0) == UNDERSCORE) { -// if (trailing.charAt(1) == UNDERSCORE) { -// separators = 2; -// } -// } -// else { -// separators = 1; -// } -// -// if (regionAppended) { -// /* -// * If we appended a region, we may need to strip -// * the extra separator from the variant portion. -// */ -// if (separators == 2) { -// tag.append(trailing.substring(1)); -// } -// else { -// tag.append(trailing); -// } -// } -// else { -// /* -// * If we did not append a region, we may need to add -// * an extra separator to the variant portion. -// */ -// if (separators == 1) { -// tag.append(UNDERSCORE); -// } -// tag.append(trailing); -// } -// } -// -// return tag.toString(); -// } -// -// /** -// * Create a tag string from the supplied parameters. The lang, script and region -// * parameters may be null references.If the lang parameter is an empty string, the -// * default value for an unknown language is written to the output buffer. -// * -// * @param lang The language tag to use. -// * @param script The script tag to use. -// * @param region The region tag to use. -// * @param trailing Any trailing data to append to the new tag. -// * @return The new String. -// **/ -// static String -// createTagString( -// String lang, -// String script, -// String region, -// String trailing) { -// -// return createTagString( -// lang, -// script, -// region, -// trailing, -// null); -// } -// -// /** -// * Parse the language, script, and region subtags from a tag string, and return the results. -// * -// * This function does not return the canonical strings for the unknown script and region. -// * -// * @param localeID The locale ID to parse. -// * @param tags An array of three String references to return the subtag strings. -// * @return The number of chars of the localeID parameter consumed. -// **/ -// private static int -// parseTagString( -// String localeID, -// String tags[]) -// { -// IDParser parser = new IDParser(localeID); -// -// String lang = parser.getLanguage(); -// String script = parser.getScript(); -// String region = parser.getCountry(); -// -// if (isEmptyString(lang)) { -// tags[0] = UNDEFINED_LANGUAGE; -// } -// else { -// tags[0] = lang; -// } -// -// if (script.equals(UNDEFINED_SCRIPT)) { -// tags[1] = ""; -// } -// else { -// tags[1] = script; -// } -// -// if (region.equals(UNDEFINED_REGION)) { -// tags[2] = ""; -// } -// else { -// tags[2] = region; -// } -// -// /* -// * Search for the variant. If there is one, then return the index of -// * the preceeding separator. -// * If there's no variant, search for the keyword delimiter, -// * and return its index. Otherwise, return the length of the -// * string. -// * -// * $TOTO(dbertoni) we need to take into account that we might -// * find a part of the language as the variant, since it can -// * can have a variant portion that is long enough to contain -// * the same characters as the variant. -// */ -// String variant = parser.getVariant(); -// -// if (!isEmptyString(variant)){ -// int index = localeID.indexOf(variant); -// -// -// return index > 0 ? index - 1 : index; -// } -// else -// { -// int index = localeID.indexOf('@'); -// -// return index == -1 ? localeID.length() : index; -// } -// } -// -// private static String -// lookupLikelySubtags(String localeId) { -// UResourceBundle bundle = -// UResourceBundle.getBundleInstance( -// ICUResourceBundle.ICU_BASE_NAME, "likelySubtags"); -// try { -// return bundle.getString(localeId); -// } -// catch(MissingResourceException e) { -// return null; -// } -// } -// -// private static String -// createLikelySubtagsString( -// String lang, -// String script, -// String region, -// String variants) { -// -// /** -// * Try the language with the script and region first. -// **/ -// if (!isEmptyString(script) && !isEmptyString(region)) { -// -// String searchTag = -// createTagString( -// lang, -// script, -// region, -// null); -// -// String likelySubtags = lookupLikelySubtags(searchTag); -// -// /* -// if (likelySubtags == null) { -// if (likelySubtags2 != null) { -// System.err.println("Tag mismatch: \"(null)\" \"" + likelySubtags2 + "\""); -// } -// } -// else if (likelySubtags2 == null) { -// System.err.println("Tag mismatch: \"" + likelySubtags + "\" \"(null)\""); -// } -// else if (!likelySubtags.equals(likelySubtags2)) { -// System.err.println("Tag mismatch: \"" + likelySubtags + "\" \"" + likelySubtags2 + "\""); -// } -// */ -// if (likelySubtags != null) { -// // Always use the language tag from the -// // maximal string, since it may be more -// // specific than the one provided. -// return createTagString( -// null, -// null, -// null, -// variants, -// likelySubtags); -// } -// } -// -// /** -// * Try the language with just the script. -// **/ -// if (!isEmptyString(script)) { -// -// String searchTag = -// createTagString( -// lang, -// script, -// null, -// null); -// -// String likelySubtags = lookupLikelySubtags(searchTag); -// if (likelySubtags != null) { -// // Always use the language tag from the -// // maximal string, since it may be more -// // specific than the one provided. -// return createTagString( -// null, -// null, -// region, -// variants, -// likelySubtags); -// } -// } -// -// /** -// * Try the language with just the region. -// **/ -// if (!isEmptyString(region)) { -// -// String searchTag = -// createTagString( -// lang, -// null, -// region, -// null); -// -// String likelySubtags = lookupLikelySubtags(searchTag); -// -// if (likelySubtags != null) { -// // Always use the language tag from the -// // maximal string, since it may be more -// // specific than the one provided. -// return createTagString( -// null, -// script, -// null, -// variants, -// likelySubtags); -// } -// } -// -// /** -// * Finally, try just the language. -// **/ -// { -// String searchTag = -// createTagString( -// lang, -// null, -// null, -// null); -// -// String likelySubtags = lookupLikelySubtags(searchTag); -// -// if (likelySubtags != null) { -// // Always use the language tag from the -// // maximal string, since it may be more -// // specific than the one provided. -// return createTagString( -// null, -// script, -// region, -// variants, -// likelySubtags); -// } -// } -// -// return null; -// } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.classpath b/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.classpath deleted file mode 100644 index 751c8f2e504..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.project b/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.project deleted file mode 100644 index 4a1190f90be..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - com.ibm.icu.jse4 - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.core.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 3c5b9590f61..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Dec 14 11:50:53 EST 2006 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.ui.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index fb606529765..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Dec 14 11:50:53 EST 2006 -eclipse.preferences.version=1 -internal.default.compliance=default diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/META-INF/MANIFEST.MF b/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/META-INF/MANIFEST.MF deleted file mode 100644 index 4b08f74431a..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/META-INF/MANIFEST.MF +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %fragmentName -Bundle-SymbolicName: com.ibm.icu.jse4 -Bundle-Version: @BUILD_VERSION@ -Bundle-Vendor: %providerName -Fragment-Host: com.ibm.icu;bundle-version="[4.2.0,4.4.0)" -Bundle-Copyright: @COPYRIGHT@ -Bundle-RequiredExecutionEnvironment: J2SE-1.4 -Bundle-Localization: fragment-icu-jse4 -Bundle-Classpath: icu-jse4.jar -Eclipse-PatchFragment: true diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/build.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/build.properties deleted file mode 100644 index a321eae9801..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/build.properties +++ /dev/null @@ -1,19 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -source.icu-jse4.jar = src/ -src.includes = about.html,\ - about_files/ -bin.includes = META-INF/,\ - icu-jse4.jar,\ - about.html,\ - about_files/,\ - fragment-icu-jse4.properties,\ - fragment.xml diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/fragment-icu-jse4.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/fragment-icu-jse4.properties deleted file mode 100644 index 427917feba5..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.jse4/fragment-icu-jse4.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2006-2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -fragmentName = International Components for Unicode for Java (ICU4J), Foundation Fragment -providerName = IBM Corporation diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.classpath b/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.classpath deleted file mode 100644 index 751c8f2e504..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.project b/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.project deleted file mode 100644 index b406f25e57d..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - com.ibm.icu.tests - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.core.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 93763f6170f..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Dec 14 11:51:01 EST 2006 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.ui.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 1c69cb6a3c0..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Dec 14 11:51:01 EST 2006 -eclipse.preferences.version=1 -internal.default.compliance=default diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/META-INF/MANIFEST.MF b/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/META-INF/MANIFEST.MF deleted file mode 100644 index 7582e35e1ba..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,11 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: ICU Test Fragment -Bundle-SymbolicName: com.ibm.icu.tests -Bundle-Version: 1.0.0 -Bundle-Vendor: IBM -Fragment-Host: com.ibm.icu -Bundle-Copyright: @COPYRIGHT@ -Require-Bundle: org.junit -Bundle-RequiredExecutionEnvironment: J2SE-1.3, - CDC-1.0/Foundation-1.0 diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/build.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/build.properties deleted file mode 100644 index 2d0d402649a..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/build.properties +++ /dev/null @@ -1,14 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - .,\ - ./icu4jtests.jar,\ - .classpath,\ - bin/,\ - build.properties,\ - .project -src.includes = src/,\ - build.properties,\ - .classpath,\ - .project,\ - META-INF/ diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/src/com/ibm/icu/tests/UnitTest.java b/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/src/com/ibm/icu/tests/UnitTest.java deleted file mode 100644 index cc2871ab870..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu.tests/src/com/ibm/icu/tests/UnitTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - ****************************************************************************** - * Copyright (C) 2005-2008, International Business Machines Corporation and * - * others. All Rights Reserved. * - ****************************************************************************** - */ -package com.ibm.icu.tests; - -import junit.framework.TestCase; -import com.ibm.icu.dev.test.TestAll; -import com.ibm.icu.dev.test.TestFmwk; -import com.ibm.icu.dev.test.TestFmwk.TestParams; - -//import com.ibm.icu.text.DateFormat; -//import com.ibm.icu.util.Calendar; -//import com.ibm.icu.util.GregorianCalendar; -//import com.ibm.icu.util.TimeZone; -//import com.ibm.icu.util.ULocale; - -public class UnitTest extends TestCase { - - public void testBidi() throws Exception { - runUtility("Bidi"); - } - - public void testCalendar() throws Exception { - runUtility("Calendar"); - } - - public void testCollator() throws Exception { - runUtility("Collator"); - } - - public void testCompression() throws Exception { - runUtility("Compression"); - } - - public void testDuration() throws Exception { - runUtility("Duration"); - } - - public void testDiagBigDecimal() throws Exception { - runUtility("DiagBigDecimal"); - } - - public void testFormat() throws Exception { - runUtility("Format"); - } - - public void testImpl() throws Exception { - runUtility("Impl"); - } - - public void testNormalizer() throws Exception { - runUtility("Normalizer"); - } - - public void testProperty() throws Exception { - runUtility("Property"); - } - - public void testRBBI() throws Exception { - runUtility("RBBI"); - } - - public void testSearchTest() throws Exception { - runUtility("SearchTest"); - } - - public void testStringPrep() throws Exception { - runUtility("StringPrep"); - } - - public void testTestCharsetDetector() throws Exception { - runUtility("TestCharsetDetector"); - } - - public void testTestUCharacterIterator() throws Exception { - runUtility("TestUCharacterIterator"); - } - - public void testTimeScale() throws Exception { - runUtility("TimeScale"); - } - - public void testTimeZone() throws Exception { - runUtility("TimeZone"); - } - - public void testTranslit() throws Exception { - runUtility("Translit"); - } - - public void testUtil() throws Exception { - runUtility("Util"); - } - - public void runUtility(String testname) throws Exception { - TestParams params = TestParams.create("-n", null); - TestFmwk test = new TestAll(); - test.resolveTarget(params, testname).run(); - if (params.errorCount > 0) { - fail(params.errorSummary.toString()); - } - } - - // sample tests from ICU4J test suite - - // Calendar -// public void testCalendarSimple() throws Exception { -// TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); -// GregorianCalendar gc = new GregorianCalendar(tz); -// gc.set(2005,9,17,14,15,33); -// Date time = gc.getTime(); -// -// final String[] calendars = { -// "buddhist", "chinese", "coptic", "ethiopic", "gregorian", -// "hebrew", "islamic", "islamic-civil", "japanese" -// }; -// final String[] ustimes = { -// "Monday, October 17, 2548 BE 2:15:33 PM PDT", -// "Monday 22x78-9-15 2:15:33 PM PDT", -// "Monday, Baba 7, 1722 2:15:33 PM PDT", -// "Monday, Tekemt 7, 1998 2:15:33 PM PDT", -// "Monday, October 17, 2005 2:15:33 PM PDT", -// "Monday, Tishri 14, 5766 2:15:33 PM PDT", -// "Monday, Ramadan 14, 1426 2:15:33 PM PDT", -// "Monday, Ramadan 14, 1426 2:15:33 PM PDT", -// "Monday, October 17, 17 Heisei 2:15:33 PM PDT", -// }; -// final String[] detimes = { -// "Montag, Oktober 17, 2548 BE 2:15:33 nachm. GMT-07:00", -// "Montag 22x78-9-15 2:15:33 nachm. GMT-07:00", -// "Montag, 7. Baba 1722 14:15 Uhr GMT-07:00", -// "Montag, 7. Tekemt 1998 14:15 Uhr GMT-07:00", -// "Montag, 17. Oktober 2005 14:15 Uhr GMT-07:00", -// "Montag, 14. Tishri 5766 14:15 Uhr GMT-07:00", -// "Montag, 14. Ramadan 1426 14:15 Uhr GMT-07:00", -// "Montag, 14. Ramadan 1426 14:15 Uhr GMT-07:00", -// "Montag, Oktober 17, 17 Heisei 2:15:33 nachm. GMT-07:00", -// }; -// -// ULocale[] locales = {ULocale.US, ULocale.GERMANY }; -// String[][] times = { ustimes, detimes }; -// for (int j = 0; j < locales.length; ++j) { -// ULocale ul = new ULocale("en_US"); -// for (int i = 0; i < calendars.length; ++i) { -// ul = ul.setKeywordValue("calendar", calendars[i]); -// Calendar cal = Calendar.getInstance(ul); -// DateFormat fmt = cal.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, locales[j]); -// String result = fmt.format(time); -// System.out.println(calendars[i] + ": " + result); -// if (!result.equals(times[j][i])) { -// fail("calendar: " + calendars[i]); -// } -// } -// } -// } -} diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu/.classpath b/icu4j/icu-eclipse/plugins/com.ibm.icu/.classpath deleted file mode 100644 index 751c8f2e504..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu/.project b/icu4j/icu-eclipse/plugins/com.ibm.icu/.project deleted file mode 100644 index e73714f9be5..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - com.ibm.icu - - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.pde.PluginNature - - diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.core.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 6b3fe56a618..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Dec 14 11:50:17 EST 2006 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.ui.prefs b/icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 5693f2fd40d..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Dec 14 11:50:17 EST 2006 -eclipse.preferences.version=1 -internal.default.compliance=default diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu/META-INF/MANIFEST.MF b/icu4j/icu-eclipse/plugins/com.ibm.icu/META-INF/MANIFEST.MF deleted file mode 100644 index 2f1e2786346..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu/META-INF/MANIFEST.MF +++ /dev/null @@ -1,24 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-SymbolicName: com.ibm.icu; singleton:=true -Bundle-Version: @BUILD_VERSION@ -Bundle-Vendor: %providerName -Bundle-Localization: plugin -Bundle-Copyright: @COPYRIGHT@ -Export-Package: com.ibm.icu.lang;base=true;full=true;version="@IMPL_VERSION@", - com.ibm.icu.math;base=true;full=true;version="@IMPL_VERSION@", - com.ibm.icu.text;base=true;full=true;version="@IMPL_VERSION@", - com.ibm.icu.util;base=true;full=true;version="@IMPL_VERSION@", - com.ibm.icu.impl;x-internal:=true, - com.ibm.icu.impl.data;x-internal:=true, - com.ibm.icu.impl.data.icudt@DATA_VERSION_NUMBER@b;x-internal:=true, - com.ibm.icu.impl.data.icudt@DATA_VERSION_NUMBER@b.brkitr;x-internal:=true, - com.ibm.icu.impl.data.icudt@DATA_VERSION_NUMBER@b.coll;x-internal:=true, - com.ibm.icu.impl.data.icudt@DATA_VERSION_NUMBER@b.rbnf;x-internal:=true, - com.ibm.icu.impl.data.icudt@DATA_VERSION_NUMBER@b.translit;x-internal:=true -Eclipse-LazyStart: true -Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0, - J2SE-1.3 -Bundle-ClassPath: icu-jse4.jar,icu-data.jar,. -Eclipse-ExtensibleAPI: true diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu/build.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu/build.properties deleted file mode 100644 index 8c108f29641..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu/build.properties +++ /dev/null @@ -1,19 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -source.. = src/ -output.. = bin/ -src.includes = about.html,\ - about_files/ -bin.includes = .,\ - about.html,\ - about_files/,\ - plugin.properties,\ - META-INF/ diff --git a/icu4j/icu-eclipse/plugins/com.ibm.icu/plugin.properties b/icu4j/icu-eclipse/plugins/com.ibm.icu/plugin.properties deleted file mode 100644 index 9fe7037be7f..00000000000 --- a/icu4j/icu-eclipse/plugins/com.ibm.icu/plugin.properties +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -pluginName = International Components for Unicode for Java (ICU4J) -providerName = IBM Corporation \ No newline at end of file