ICU-7919 Synchronized eclipse37 with maint-4-4 r30603 for Java 7 category locale support in com.ibm.icu.base plug-in. Set the plug-in version to v20110831.

X-SVN-Rev: 30607
This commit is contained in:
Yoshito Umaoka 2011-08-31 09:39:27 +00:00
parent e2c81707f7
commit 701bff1db3
87 changed files with 34506 additions and 30076 deletions

67
.gitattributes vendored
View file

@ -49,12 +49,10 @@ README text !eol
*.tri2 -text
/build.properties -text
demos/.settings/org.eclipse.core.resources.prefs -text
demos/manifest.stub -text
eclipse-build/eclipse_mod_classes.txt -text
eclipse-build/eclipse_mod_test_classes.txt -text
eclipse-build/features.template/com.ibm.icu.base/.project -text
eclipse-build/features.template/com.ibm.icu.base/build.properties -text
eclipse-build/features.template/com.ibm.icu.base/feature.xml -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/.classpath -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/.project -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.core.prefs -text
@ -62,20 +60,6 @@ eclipse-build/plugins.template/com.ibm.icu.base.tests/.settings/org.eclipse.jdt.
eclipse-build/plugins.template/com.ibm.icu.base.tests/META-INF/MANIFEST.MF -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/build.properties -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/plugin.properties -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/BreakIteratorTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CalendarTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollationKeyTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/CollatorTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatSymbolsTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DateFormatTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatSymbolsTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/DecimalFormatTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ICUTestCase.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/MessageFormatTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/NumberFormatTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/SimpleDateFormatTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/TimeZoneTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base.tests/src/com/ibm/icu/tests/ULocaleTest.java -text
eclipse-build/plugins.template/com.ibm.icu.base/.classpath -text
eclipse-build/plugins.template/com.ibm.icu.base/.project -text
eclipse-build/plugins.template/com.ibm.icu.base/.settings/org.eclipse.jdt.core.prefs -text
@ -83,63 +67,38 @@ eclipse-build/plugins.template/com.ibm.icu.base/.settings/org.eclipse.jdt.ui.pre
eclipse-build/plugins.template/com.ibm.icu.base/META-INF/MANIFEST.MF -text
eclipse-build/plugins.template/com.ibm.icu.base/build.properties -text
eclipse-build/plugins.template/com.ibm.icu.base/plugin.properties -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/impl/ICUCache.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/impl/LocaleIDParser.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/impl/LocaleIDs.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/impl/LocaleUtility.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/impl/SimpleCache.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/impl/locale/AsciiUtil.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/math/BigDecimal.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/math/MathContext.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/Bidi.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/BidiClassifier.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/BidiRun.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/BreakIterator.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/CollationKey.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/Collator.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/CurrencyPluralInfo.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/DateFormat.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/DateFormatSymbols.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormat.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/DecimalFormatSymbols.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/MessageFormat.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/NumberFormat.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/RawCollationKey.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/SimpleDateFormat.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/UFormat.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/text/UnicodeSet.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/util/Calendar.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/util/Currency.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/util/CurrencyAmount.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/util/TimeZone.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/util/ULocale.java -text
eclipse-build/plugins.template/com.ibm.icu.base/src/com/ibm/icu/util/VersionInfo.java -text
eclipse-build/plugins.template/com.ibm.icu.tests/META-INF/MANIFEST.MF -text
eclipse-build/plugins.template/com.ibm.icu.tests/plugin.properties -text
eclipse-build/plugins.template/com.ibm.icu/META-INF/MANIFEST.MF -text
main/classes/charset/.classpath -text
main/classes/charset/.project -text
main/classes/charset/.settings/org.eclipse.core.resources.prefs -text
main/classes/charset/.settings/org.eclipse.jdt.core.prefs -text
main/classes/charset/manifest.stub -text
main/classes/collate/.classpath -text
main/classes/collate/.project -text
main/classes/collate/.settings/org.eclipse.core.resources.prefs -text
main/classes/collate/.settings/org.eclipse.jdt.core.prefs -text
main/classes/collate/.settings/org.eclipse.jdt.ui.prefs -text
main/classes/collate/collate-build.launch -text
main/classes/core/.classpath -text
main/classes/core/.project -text
main/classes/core/.settings/org.eclipse.core.resources.prefs -text
main/classes/core/.settings/org.eclipse.jdt.core.prefs -text
main/classes/core/manifest.stub -text
main/classes/currdata/.externalToolBuilders/copy-data-currdata.launch -text
main/classes/currdata/.settings/org.eclipse.core.resources.prefs -text
main/classes/currdata/.settings/org.eclipse.jdt.core.prefs -text
main/classes/currdata/.settings/org.eclipse.jdt.ui.prefs -text
main/classes/currdata/currdata-build.launch -text
main/classes/langdata/.externalToolBuilders/copy-data-langdata.launch -text
main/classes/langdata/.settings/org.eclipse.core.resources.prefs -text
main/classes/langdata/.settings/org.eclipse.jdt.core.prefs -text
main/classes/langdata/.settings/org.eclipse.jdt.ui.prefs -text
main/classes/langdata/langdata-build.launch -text
main/classes/localespi/.classpath -text
main/classes/localespi/.project -text
main/classes/localespi/.settings/org.eclipse.core.resources.prefs -text
main/classes/localespi/.settings/org.eclipse.jdt.core.prefs -text
main/classes/localespi/manifest.stub -text
main/classes/localespi/src/META-INF/services/java.text.spi.BreakIteratorProvider -text
@ -153,27 +112,33 @@ main/classes/localespi/src/META-INF/services/java.util.spi.LocaleNameProvider -t
main/classes/localespi/src/META-INF/services/java.util.spi.TimeZoneNameProvider -text
main/classes/localespi/src/com/ibm/icu/impl/javaspi/ICULocaleServiceProviderConfig.properties -text
main/classes/regiondata/.externalToolBuilders/copy-data-regiondata.launch -text
main/classes/regiondata/.settings/org.eclipse.core.resources.prefs -text
main/classes/regiondata/.settings/org.eclipse.jdt.core.prefs -text
main/classes/regiondata/.settings/org.eclipse.jdt.ui.prefs -text
main/classes/regiondata/regiondata-build.launch -text
main/classes/translit/.externalToolBuilders/copy-data-translit.launch -text
main/classes/translit/.settings/org.eclipse.core.resources.prefs -text
main/classes/translit/.settings/org.eclipse.jdt.core.prefs -text
main/classes/translit/.settings/org.eclipse.jdt.ui.prefs -text
main/classes/translit/translit-build.launch -text
main/shared/.project -text
main/shared/.settings/org.eclipse.core.resources.prefs -text
main/shared/data/icudata.jar -text
main/shared/data/testdata.jar -text
main/tests/charset/.classpath -text
main/tests/charset/.project -text
main/tests/charset/.settings/org.eclipse.core.resources.prefs -text
main/tests/charset/.settings/org.eclipse.jdt.core.prefs -text
main/tests/charset/manifest.stub -text
main/tests/collate/.classpath -text
main/tests/collate/.project -text
main/tests/collate/.settings/org.eclipse.core.resources.prefs -text
main/tests/collate/.settings/org.eclipse.jdt.core.prefs -text
main/tests/collate/.settings/org.eclipse.jdt.ui.prefs -text
main/tests/collate/collate-tests-build.launch -text
main/tests/core/.classpath -text
main/tests/core/.project -text
main/tests/core/.settings/org.eclipse.core.resources.prefs -text
main/tests/core/.settings/org.eclipse.jdt.core.prefs -text
main/tests/core/manifest.stub -text
main/tests/core/src/com/ibm/icu/dev/data/rbbi/english.dict -text
@ -381,19 +346,24 @@ main/tests/core/src/com/ibm/icu/dev/test/util/Trie2Test.setRangesSingleValue.16.
main/tests/core/src/com/ibm/icu/dev/test/util/Trie2Test.setRangesSingleValue.32.tri2 -text
main/tests/framework/.classpath -text
main/tests/framework/.project -text
main/tests/framework/.settings/org.eclipse.core.resources.prefs -text
main/tests/framework/.settings/org.eclipse.jdt.core.prefs -text
main/tests/framework/manifest.stub -text
main/tests/localespi/.classpath -text
main/tests/localespi/.project -text
main/tests/localespi/.settings/org.eclipse.core.resources.prefs -text
main/tests/localespi/manifest.stub -text
main/tests/packaging/.externalToolBuilders/copy-test-data.launch -text
main/tests/packaging/.settings/org.eclipse.core.resources.prefs -text
main/tests/packaging/.settings/org.eclipse.jdt.core.prefs -text
main/tests/packaging/.settings/org.eclipse.jdt.ui.prefs -text
main/tests/packaging/packaging-tests-build.launch -text
main/tests/translit/.externalToolBuilders/copy-translit-test-data.launch -text
main/tests/translit/.settings/org.eclipse.core.resources.prefs -text
main/tests/translit/.settings/org.eclipse.jdt.core.prefs -text
main/tests/translit/.settings/org.eclipse.jdt.ui.prefs -text
main/tests/translit/translit-tests-build.launch -text
tools/build/.settings/org.eclipse.core.resources.prefs -text
tools/build/icu4j28.api.gz -text
tools/build/icu4j30.api.gz -text
tools/build/icu4j32.api.gz -text
@ -410,6 +380,7 @@ tools/build/icu4j42.api.gz -text
tools/build/icu4j421.api.gz -text
tools/build/icu4j44.api2.gz -text
tools/build/manifest.stub -text
tools/misc/.settings/org.eclipse.core.resources.prefs -text
tools/misc/manifest.stub -text
# The following file types are stored in Git-LFS.

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
/.project
demos/out
/doc
eclipse-build/out
main/classes/charset/out
main/classes/collate/out
main/classes/core/out

View file

@ -1,6 +1,6 @@
<!--
*******************************************************************************
* Copyright (C) 1997-2010, International Business Machines Corporation and *
* Copyright (C) 1997-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
-->
@ -444,8 +444,8 @@
nodeprecatedlist="true"
windowtitle="icu4j"
doctitle="icu4j"
encoding="iso-8859-1"
docencoding="iso-8859-1"
encoding="${java.src.encoding}"
docencoding="UTF-8"
bottom="&lt;font size=-1&gt;Copyright (c) ${current.year} IBM Corporation and others.&lt;/font&gt;"
additionalparam="-breakiterator -use -tagletpath ${icu4j.build-tools.jar} -taglet com.ibm.icu.dev.tool.docs.ICUTaglet"
link="http://java.sun.com/javase/6/docs/api/"
@ -547,7 +547,8 @@
<!-- Release management targets -->
<target name="checktags" depends="info, build-tools" description="Check API tags before release">
<javadoc source="1.5">
<javadoc source="1.5"
encoding="${java.src.encoding}">
<packageset dir="${icu4j.core.dir}/src">
<include name="com/ibm/icu/lang/**"/>
<include name="com/ibm/icu/math/**"/>
@ -566,7 +567,8 @@
<target name="gatherapi" depends="info, build-tools" description="Run API database generator tool">
<mkdir dir="${out.dir}"/>
<javadoc source="1.5">
<javadoc source="1.5"
encoding="${java.src.encoding}">
<packageset dir="${icu4j.core.dir}/src">
<include name="com/ibm/icu/lang/**"/>
<include name="com/ibm/icu/math/**"/>
@ -609,7 +611,8 @@
<target name="gatherapiOld" depends="info, build-tools" description="Run API database generator tool (Pre Java 5 style)">
<mkdir dir="${out.dir}"/>
<javadoc source="1.5">
<javadoc source="1.5"
encoding="${java.src.encoding}">
<packageset dir="${icu4j.core.dir}/src">
<include name="com/ibm/icu/lang/**"/>
<include name="com/ibm/icu/math/**"/>
@ -696,6 +699,7 @@
<javac destdir="${translit.ime.out.dir}/bin"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
<src path="${icu4j.translit.dir}/src"/>
@ -723,6 +727,7 @@
<javac destdir="${indic.ime.out.dir}/bin"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
<src path="${icu4j.tools.dir}/src"/>
@ -749,6 +754,7 @@
<javac destdir="${cldr.util.out.dir}/bin"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -782,6 +788,7 @@
<javac destdir="${xliff.out.dir}/bin"
source="1.3"
target="1.3"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<src path="${icu4j.tools.dir}/src"/>
<include name="com/ibm/icu/dev/tool/localeconverter/CalculateCRC32.java"/>
@ -863,6 +870,7 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<include name="com/ibm/icu/impl/UCharacterName.java"/>
<include name="com/ibm/icu/impl/data/*Break*.java"/>
@ -877,6 +885,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -898,6 +907,7 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<include name="com/ibm/icu/impl/data/*Holiday*.java"/>
<include name="com/ibm/icu/lang/UCharacter.java"/>
@ -926,6 +936,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -950,6 +961,7 @@
<javac destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
<src path="${icu4j.collate.dir}/src"/>
@ -981,6 +993,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -1015,6 +1028,7 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<include name="com/ibm/icu/text/SCSU.java"/>
<include name="com/ibm/icu/text/UnicodeCompressor.java"/>
@ -1027,6 +1041,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -1045,6 +1060,7 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<include name="com/ibm/icu/lang/UCharacter.java"/>
<include name="com/ibm/icu/text/*Collator*.java"/>
@ -1057,12 +1073,14 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off"/>
<javac srcdir="${icu4j.currdata.dir}/src"
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off"/>
<!-- Format does not require BreakIterator data -->
@ -1080,6 +1098,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -1109,6 +1128,7 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<include name="com/ibm/icu/lang/**/*"/>
<include name="com/ibm/icu/text/CanonicalIterator.java"/>
@ -1139,6 +1159,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -1208,6 +1229,7 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<include name="com/ibm/icu/impl/data/*Break*.java"/>
<include name="com/ibm/icu/lang/**/*"/>
@ -1222,6 +1244,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -1256,6 +1279,7 @@
<javac destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
<src path="${icu4j.translit.dir}/src"/>
@ -1291,6 +1315,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>
@ -1314,6 +1339,7 @@
destdir="${module.bin.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="on" deprecation="off">
<include name="com/ibm/icu/impl/*StringPrep*.java"/>
<include name="com/ibm/icu/text/*IDNA*.java"/>
@ -1338,6 +1364,7 @@
<javac destdir="${module.tests.dir}"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
classpath="${module.bin.dir}"
debug="on" deprecation="off">
<src path="${icu4j.core.dir}/src"/>

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:50:12 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -5,4 +5,4 @@
icu4j.plugin.impl.version.string=4.4.2
copyright.eclipse=Licensed Materials - Property of IBM \n (C) Copyright IBM Corp. 2000, 2011. All Rights Reserved. \n IBM is a registered trademark of IBM Corp.
icu4j.data.version.number=44
icu4j.eclipse.build.version.string=4.4.2.v20110823
icu4j.eclipse.build.version.string=4.4.2.v20110831

View file

@ -1,5 +1,5 @@
# Copyright (C) 2011, International Business Machines Corporation and
# others. All Rights Reserved.
com/ibm/icu/lang/UCharacter.java
com/ibm/icu/text/DecimalFormat.java
# Copyright (C) 2011, International Business Machines Corporation and
# others. All Rights Reserved.
com/ibm/icu/lang/UCharacter.java
com/ibm/icu/text/DecimalFormat.java

View file

@ -1,7 +1,7 @@
# Copyright (C) 2011, International Business Machines Corporation and
# others. All Rights Reserved.
com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPI.java
com/ibm/icu/dev/test/format/NumberFormatTest.java
com/ibm/icu/dev/test/serializable/CompatibilityTest.java
com/ibm/icu/dev/test/serializable/CoverageTest.java
# Copyright (C) 2011, International Business Machines Corporation and
# others. All Rights Reserved.
com/ibm/icu/dev/test/format/IntlTestDecimalFormatAPI.java
com/ibm/icu/dev/test/format/NumberFormatTest.java
com/ibm/icu/dev/test/serializable/CompatibilityTest.java
com/ibm/icu/dev/test/serializable/CoverageTest.java

View file

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="com.ibm.icu.base"
label="com.ibm.icu.base"
version="@BUILD_VERSION@">
<description url="http://www.example.com/description">
[Enter Feature Description here.]
</description>
<copyright url="http://www.example.com/copyright">
[Enter Copyright Description here.]
</copyright>
<license url="http://www.example.com/license">
[Enter License Description here.]
</license>
<plugin
id="com.ibm.icu.base"
download-size="0"
install-size="0"
version="@BUILD_VERSION@"
unpack="false"/>
<plugin
id="com.ibm.icu.base.source"
download-size="0"
install-size="0"
version="@BUILD_VERSION@"
unpack="false"/>
</feature>
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="com.ibm.icu.base"
label="com.ibm.icu.base"
version="@BUILD_VERSION@">
<description url="http://www.example.com/description">
[Enter Feature Description here.]
</description>
<copyright url="http://www.example.com/copyright">
[Enter Copyright Description here.]
</copyright>
<license url="http://www.example.com/license">
[Enter License Description here.]
</license>
<plugin
id="com.ibm.icu.base"
download-size="0"
install-size="0"
version="@BUILD_VERSION@"
unpack="false"/>
<plugin
id="com.ibm.icu.base.source"
download-size="0"
install-size="0"
version="@BUILD_VERSION@"
unpack="false"/>
</feature>

View file

@ -1,359 +1,359 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}

View file

@ -1,102 +1,102 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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(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);
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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(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);
}
}

View file

@ -1,205 +1,205 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}

View file

@ -1,257 +1,257 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}

View file

@ -1,454 +1,454 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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;
private FieldPosition anFPField;
private static int YEAR_POS_START = 8;
private static int YEAR_POS_END = 12;
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(DateFormat.YEAR_FIELD);
anFPField = new FieldPosition(DateFormat.Field.YEAR);
}
/*
* 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));
assertEquals(YEAR_POS_START, anFP.getBeginIndex());
assertEquals(YEAR_POS_END, anFP.getEndIndex());
}
/*
* Test method for 'com.ibm.icu.text.DateFormat.format(Calendar, StringBuffer, FieldPosition)'
*/
public final void testFormatCalendarStringBufferFieldPosition() {
assertEqualDateString(aDF.format(aCal, aBuf, anFP));
assertEquals(YEAR_POS_START, anFP.getBeginIndex());
assertEquals(YEAR_POS_END, anFP.getEndIndex());
}
/*
* Test method for 'com.ibm.icu.text.DateFormat.format(Date, StringBuffer, FieldPosition)'
*/
public final void testFormatDateStringBufferFieldPosition() {
assertEqualDateString(aDF.format(aDate, aBuf, anFPField));
assertEquals(YEAR_POS_START, anFPField.getBeginIndex());
assertEquals(YEAR_POS_END, anFPField.getEndIndex());
}
/*
* 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
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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;
private FieldPosition anFPField;
private static int YEAR_POS_START = 8;
private static int YEAR_POS_END = 12;
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(DateFormat.YEAR_FIELD);
anFPField = new FieldPosition(DateFormat.Field.YEAR);
}
/*
* 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));
assertEquals(YEAR_POS_START, anFP.getBeginIndex());
assertEquals(YEAR_POS_END, anFP.getEndIndex());
}
/*
* Test method for 'com.ibm.icu.text.DateFormat.format(Calendar, StringBuffer, FieldPosition)'
*/
public final void testFormatCalendarStringBufferFieldPosition() {
assertEqualDateString(aDF.format(aCal, aBuf, anFP));
assertEquals(YEAR_POS_START, anFP.getBeginIndex());
assertEquals(YEAR_POS_END, anFP.getEndIndex());
}
/*
* Test method for 'com.ibm.icu.text.DateFormat.format(Date, StringBuffer, FieldPosition)'
*/
public final void testFormatDateStringBufferFieldPosition() {
assertEqualDateString(aDF.format(aDate, aBuf, anFPField));
assertEquals(YEAR_POS_START, anFPField.getBeginIndex());
assertEquals(YEAR_POS_END, anFPField.getEndIndex());
}
/*
* 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
}
}

View file

@ -1,344 +1,344 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}

View file

@ -1,242 +1,242 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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));
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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));
}
}

View file

@ -1,286 +1,286 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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<? extends Object> 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<? extends Object> lcls = lhs.getClass();
Class<? extends Object> 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<? extends Object> lcls = lhs.getClass();
Class<? extends Object> 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<? extends Object> 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", EMPTY_CLASSES);
result = cloneM.invoke(obj, EMPTY_ARGS);
}
catch (NoSuchMethodException e) {
}
catch (IllegalAccessException e) {
}
catch (InvocationTargetException e) {
}
}
}
return result;
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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<? extends Object> 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<? extends Object> lcls = lhs.getClass();
Class<? extends Object> 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<? extends Object> lcls = lhs.getClass();
Class<? extends Object> 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<? extends Object> 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", EMPTY_CLASSES);
result = cloneM.invoke(obj, EMPTY_ARGS);
}
catch (NoSuchMethodException e) {
}
catch (IllegalAccessException e) {
}
catch (InvocationTargetException e) {
}
}
}
return result;
}
}

View file

@ -1,307 +1,307 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}

View file

@ -1,447 +1,447 @@
/*
*******************************************************************************
* Copyright (C) 2007-2011, 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(NumberFormat.INTEGER_FIELD);
NumberFormat.getInstance().format(num, buf, fp);
assertEquals("1,234", buf.toString());
assertEquals(0, fp.getBeginIndex());
assertEquals(5, fp.getEndIndex());
}
/*
* 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(NumberFormat.FRACTION_FIELD);
assertEquals("123,456.789", NumberFormat.getInstance().format(123456.789, buf, fp).toString());
assertEquals(8, fp.getBeginIndex());
assertEquals(11, fp.getEndIndex());
}
/*
* Test method for 'com.ibm.icu.x.text.NumberFormat.format(long, StringBuffer, FieldPosition)'
*/
public void testFormatLongStringBufferFieldPosition() {
StringBuffer buf = new StringBuffer();
FieldPosition fp = new FieldPosition(NumberFormat.Field.GROUPING_SEPARATOR);
assertEquals("123,456", NumberFormat.getInstance().format(123456L, buf, fp).toString());
assertEquals(3, fp.getBeginIndex());
assertEquals(4, fp.getEndIndex());
}
/*
* 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
}
}
/*
*******************************************************************************
* Copyright (C) 2007-2011, 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(NumberFormat.INTEGER_FIELD);
NumberFormat.getInstance().format(num, buf, fp);
assertEquals("1,234", buf.toString());
assertEquals(0, fp.getBeginIndex());
assertEquals(5, fp.getEndIndex());
}
/*
* 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(NumberFormat.FRACTION_FIELD);
assertEquals("123,456.789", NumberFormat.getInstance().format(123456.789, buf, fp).toString());
assertEquals(8, fp.getBeginIndex());
assertEquals(11, fp.getEndIndex());
}
/*
* Test method for 'com.ibm.icu.x.text.NumberFormat.format(long, StringBuffer, FieldPosition)'
*/
public void testFormatLongStringBufferFieldPosition() {
StringBuffer buf = new StringBuffer();
FieldPosition fp = new FieldPosition(NumberFormat.Field.GROUPING_SEPARATOR);
assertEquals("123,456", NumberFormat.getInstance().format(123456L, buf, fp).toString());
assertEquals(3, fp.getBeginIndex());
assertEquals(4, fp.getEndIndex());
}
/*
* 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
}
}

View file

@ -1,202 +1,202 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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"));
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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"));
}
}

View file

@ -1,235 +1,235 @@
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}
/*
*******************************************************************************
* Copyright (C) 2006-2011, 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
}
}

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -1,21 +1,21 @@
/*
***************************************************************************
* Copyright (c) 2007-2011 International Business Machines Corporation and *
* others. All rights reserved. *
***************************************************************************
*/
package com.ibm.icu.impl;
public interface ICUCache<K, V> {
// Type of reference holding the Map instance
public static final int SOFT = 0;
public static final int WEAK = 1;
// NULL object, which may be used for a cache key
public static final Object NULL = new Object();
public void clear();
public void put(K key, V value);
public V get(Object key);
}
/*
***************************************************************************
* Copyright (c) 2007-2011 International Business Machines Corporation and *
* others. All rights reserved. *
***************************************************************************
*/
package com.ibm.icu.impl;
public interface ICUCache<K, V> {
// Type of reference holding the Map instance
public static final int SOFT = 0;
public static final int WEAK = 1;
// NULL object, which may be used for a cache key
public static final Object NULL = new Object();
public void clear();
public void put(K key, V value);
public V get(Object key);
}

View file

@ -1,132 +1,132 @@
/*
******************************************************************************
* Copyright (C) 1996-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
******************************************************************************
*
******************************************************************************
*/
package com.ibm.icu.impl;
import java.util.Locale;
/**
* A class to hold utility functions missing from java.util.Locale.
*/
public class LocaleUtility {
/**
* A helper function to convert a string of the form
* aa_BB_CC to a locale object. Why isn't this in Locale?
*/
public static Locale getLocaleFromName(String name) {
String language = "";
String country = "";
String variant = "";
int i1 = name.indexOf('_');
if (i1 < 0) {
language = name;
} else {
language = name.substring(0, i1);
++i1;
int i2 = name.indexOf('_', i1);
if (i2 < 0) {
country = name.substring(i1);
} else {
country = name.substring(i1, i2);
variant = name.substring(i2+1);
}
}
return new Locale(language, country, variant);
}
/**
* Compare two locale strings of the form aa_BB_CC, and
* return true if parent is a 'strict' fallback of child, that is,
* if child =~ "^parent(_.+)*" (roughly).
*/
public static boolean isFallbackOf(String parent, String child) {
if (!child.startsWith(parent)) {
return false;
}
int i = parent.length();
return (i == child.length() ||
child.charAt(i) == '_');
}
/**
* Compare two locales, and return true if the parent is a
* 'strict' fallback of the child (parent string is a fallback
* of child string).
*/
public static boolean isFallbackOf(Locale parent, Locale child) {
return isFallbackOf(parent.toString(), child.toString());
}
/*
* Convenience method that calls canonicalLocaleString(String) with
* locale.toString();
*/
/*public static String canonicalLocaleString(Locale locale) {
return canonicalLocaleString(locale.toString());
}*/
/*
* You'd think that Locale canonicalizes, since it munges the
* renamed languages, but it doesn't quite. It forces the region
* to be upper case but doesn't do anything about the language or
* variant. Our canonical form is 'lower_UPPER_UPPER'.
*/
/*public static String canonicalLocaleString(String id) {
if (id != null) {
int x = id.indexOf("_");
if (x == -1) {
id = id.toLowerCase(Locale.ENGLISH);
} else {
StringBuffer buf = new StringBuffer();
buf.append(id.substring(0, x).toLowerCase(Locale.ENGLISH));
buf.append(id.substring(x).toUpperCase(Locale.ENGLISH));
int len = buf.length();
int n = len;
while (--n >= 0 && buf.charAt(n) == '_') {
}
if (++n != len) {
buf.delete(n, len);
}
id = buf.toString();
}
}
return id;
}*/
/**
* Fallback from the given locale name by removing the rightmost _-delimited
* element. If there is none, return the root locale ("", "", ""). If this
* is the root locale, return null. NOTE: The string "root" is not
* recognized; do not use it.
*
* @return a new Locale that is a fallback from the given locale, or null.
*/
public static Locale fallback(Locale loc) {
// Split the locale into parts and remove the rightmost part
String[] parts = new String[]
{ loc.getLanguage(), loc.getCountry(), loc.getVariant() };
int i;
for (i=2; 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]);
}
}
/*
******************************************************************************
* Copyright (C) 1996-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
******************************************************************************
*
******************************************************************************
*/
package com.ibm.icu.impl;
import java.util.Locale;
/**
* A class to hold utility functions missing from java.util.Locale.
*/
public class LocaleUtility {
/**
* A helper function to convert a string of the form
* aa_BB_CC to a locale object. Why isn't this in Locale?
*/
public static Locale getLocaleFromName(String name) {
String language = "";
String country = "";
String variant = "";
int i1 = name.indexOf('_');
if (i1 < 0) {
language = name;
} else {
language = name.substring(0, i1);
++i1;
int i2 = name.indexOf('_', i1);
if (i2 < 0) {
country = name.substring(i1);
} else {
country = name.substring(i1, i2);
variant = name.substring(i2+1);
}
}
return new Locale(language, country, variant);
}
/**
* Compare two locale strings of the form aa_BB_CC, and
* return true if parent is a 'strict' fallback of child, that is,
* if child =~ "^parent(_.+)*" (roughly).
*/
public static boolean isFallbackOf(String parent, String child) {
if (!child.startsWith(parent)) {
return false;
}
int i = parent.length();
return (i == child.length() ||
child.charAt(i) == '_');
}
/**
* Compare two locales, and return true if the parent is a
* 'strict' fallback of the child (parent string is a fallback
* of child string).
*/
public static boolean isFallbackOf(Locale parent, Locale child) {
return isFallbackOf(parent.toString(), child.toString());
}
/*
* Convenience method that calls canonicalLocaleString(String) with
* locale.toString();
*/
/*public static String canonicalLocaleString(Locale locale) {
return canonicalLocaleString(locale.toString());
}*/
/*
* You'd think that Locale canonicalizes, since it munges the
* renamed languages, but it doesn't quite. It forces the region
* to be upper case but doesn't do anything about the language or
* variant. Our canonical form is 'lower_UPPER_UPPER'.
*/
/*public static String canonicalLocaleString(String id) {
if (id != null) {
int x = id.indexOf("_");
if (x == -1) {
id = id.toLowerCase(Locale.ENGLISH);
} else {
StringBuffer buf = new StringBuffer();
buf.append(id.substring(0, x).toLowerCase(Locale.ENGLISH));
buf.append(id.substring(x).toUpperCase(Locale.ENGLISH));
int len = buf.length();
int n = len;
while (--n >= 0 && buf.charAt(n) == '_') {
}
if (++n != len) {
buf.delete(n, len);
}
id = buf.toString();
}
}
return id;
}*/
/**
* Fallback from the given locale name by removing the rightmost _-delimited
* element. If there is none, return the root locale ("", "", ""). If this
* is the root locale, return null. NOTE: The string "root" is not
* recognized; do not use it.
*
* @return a new Locale that is a fallback from the given locale, or null.
*/
public static Locale fallback(Locale loc) {
// Split the locale into parts and remove the rightmost part
String[] parts = new String[]
{ loc.getLanguage(), loc.getCountry(), loc.getVariant() };
int i;
for (i=2; 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]);
}
}

View file

@ -1,73 +1,73 @@
/*
****************************************************************************
* Copyright (c) 2007-2011 International Business Machines Corporation and *
* others. All rights reserved. *
****************************************************************************
*/
package com.ibm.icu.impl;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class SimpleCache<K, V> implements ICUCache<K, V> {
private static final int DEFAULT_CAPACITY = 16;
private Reference<Map<K, V>> cacheRef = null;
private int type = ICUCache.SOFT;
private int capacity = DEFAULT_CAPACITY;
public SimpleCache() {
}
public SimpleCache(int cacheType) {
this(cacheType, DEFAULT_CAPACITY);
}
public SimpleCache(int cacheType, int initialCapacity) {
if (cacheType == ICUCache.WEAK) {
type = cacheType;
}
if (initialCapacity > 0) {
capacity = initialCapacity;
}
}
public V get(Object key) {
Reference<Map<K, V>> ref = cacheRef;
if (ref != null) {
Map<K, V> map = ref.get();
if (map != null) {
return map.get(key);
}
}
return null;
}
public void put(K key, V value) {
Reference<Map<K, V>> ref = cacheRef;
Map<K, V> map = null;
if (ref != null) {
map = ref.get();
}
if (map == null) {
map = Collections.synchronizedMap(new HashMap<K, V>(capacity));
if (type == ICUCache.WEAK) {
ref = new WeakReference<Map<K, V>>(map);
} else {
ref = new SoftReference<Map<K, V>>(map);
}
cacheRef = ref;
}
map.put(key, value);
}
public void clear() {
cacheRef = null;
}
}
/*
****************************************************************************
* Copyright (c) 2007-2011 International Business Machines Corporation and *
* others. All rights reserved. *
****************************************************************************
*/
package com.ibm.icu.impl;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class SimpleCache<K, V> implements ICUCache<K, V> {
private static final int DEFAULT_CAPACITY = 16;
private Reference<Map<K, V>> cacheRef = null;
private int type = ICUCache.SOFT;
private int capacity = DEFAULT_CAPACITY;
public SimpleCache() {
}
public SimpleCache(int cacheType) {
this(cacheType, DEFAULT_CAPACITY);
}
public SimpleCache(int cacheType, int initialCapacity) {
if (cacheType == ICUCache.WEAK) {
type = cacheType;
}
if (initialCapacity > 0) {
capacity = initialCapacity;
}
}
public V get(Object key) {
Reference<Map<K, V>> ref = cacheRef;
if (ref != null) {
Map<K, V> map = ref.get();
if (map != null) {
return map.get(key);
}
}
return null;
}
public void put(K key, V value) {
Reference<Map<K, V>> ref = cacheRef;
Map<K, V> map = null;
if (ref != null) {
map = ref.get();
}
if (map == null) {
map = Collections.synchronizedMap(new HashMap<K, V>(capacity));
if (type == ICUCache.WEAK) {
ref = new WeakReference<Map<K, V>>(map);
} else {
ref = new SoftReference<Map<K, V>>(map);
}
cacheRef = ref;
}
map.put(key, value);
}
public void clear() {
cacheRef = null;
}
}

View file

@ -1,180 +1,183 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
public final class AsciiUtil {
public static boolean caseIgnoreMatch(String s1, String s2) {
if (s1 == s2) {
return true;
}
int len = s1.length();
if (len != s2.length()) {
return false;
}
int i = 0;
while (i < len) {
char c1 = s1.charAt(i);
char c2 = s2.charAt(i);
if (c1 != c2 && toLower(c1) != toLower(c2)) {
break;
}
i++;
}
return (i == len);
}
public static int caseIgnoreCompare(String s1, String s2) {
if (s1 == s2) {
return 0;
}
return AsciiUtil.toLowerString(s1).compareTo(AsciiUtil.toLowerString(s2));
}
public static char toUpper(char c) {
if (c >= 'a' && c <= 'z') {
c -= 0x20;
}
return c;
}
public static char toLower(char c) {
if (c >= 'A' && c <= 'Z') {
c += 0x20;
}
return c;
}
public static String toLowerString(String s) {
int idx = 0;
for (; idx < s.length(); idx++) {
char c = s.charAt(idx);
if (c >= 'A' && c <= 'Z') {
break;
}
}
if (idx == s.length()) {
return s;
}
StringBuilder buf = new StringBuilder(s.substring(0, idx));
for (; idx < s.length(); idx++) {
buf.append(toLower(s.charAt(idx)));
}
return buf.toString();
}
public static String toUpperString(String s) {
int idx = 0;
for (; idx < s.length(); idx++) {
char c = s.charAt(idx);
if (c >= 'a' && c <= 'z') {
break;
}
}
if (idx == s.length()) {
return s;
}
StringBuilder buf = new StringBuilder(s.substring(0, idx));
for (; idx < s.length(); idx++) {
buf.append(toUpper(s.charAt(idx)));
}
return buf.toString();
}
public static String toTitleString(String s) {
if (s.length() == 0) {
return s;
}
int idx = 0;
char c = s.charAt(idx);
if (!(c >= 'a' && c <= 'z')) {
for (idx = 1; idx < s.length(); idx++) {
if (c >= 'A' && c <= 'Z') {
break;
}
}
}
if (idx == s.length()) {
return s;
}
StringBuilder buf = new StringBuilder(s.substring(0, idx));
if (idx == 0) {
buf.append(toUpper(s.charAt(idx)));
idx++;
}
for (; idx < s.length(); idx++) {
buf.append(toLower(s.charAt(idx)));
}
return buf.toString();
}
public static boolean isAlpha(char c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
public static boolean isAlphaString(String s) {
boolean b = true;
for (int i = 0; i < s.length(); i++) {
if (!isAlpha(s.charAt(i))) {
b = false;
break;
}
}
return b;
}
public static boolean isNumeric(char c) {
return (c >= '0' && c <= '9');
}
public static boolean isNumericString(String s) {
boolean b = true;
for (int i = 0; i < s.length(); i++) {
if (!isNumeric(s.charAt(i))) {
b = false;
break;
}
}
return b;
}
public static boolean isAlphaNumeric(char c) {
return isAlpha(c) || isNumeric(c);
}
public static boolean isAlphaNumericString(String s) {
boolean b = true;
for (int i = 0; i < s.length(); i++) {
if (!isAlphaNumeric(s.charAt(i))) {
b = false;
break;
}
}
return b;
}
public static class CaseInsensitiveKey {
private String _key;
private int _hash;
public CaseInsensitiveKey(String key) {
_key = key;
_hash = AsciiUtil.toLowerString(key).hashCode();
}
public boolean equals(Object o) {
if (o instanceof CaseInsensitiveKey) {
return AsciiUtil.caseIgnoreMatch(_key, ((CaseInsensitiveKey)o)._key);
}
return false;
}
public int hashCode() {
return _hash;
}
}
}
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
public final class AsciiUtil {
public static boolean caseIgnoreMatch(String s1, String s2) {
if (s1 == s2) {
return true;
}
int len = s1.length();
if (len != s2.length()) {
return false;
}
int i = 0;
while (i < len) {
char c1 = s1.charAt(i);
char c2 = s2.charAt(i);
if (c1 != c2 && toLower(c1) != toLower(c2)) {
break;
}
i++;
}
return (i == len);
}
public static int caseIgnoreCompare(String s1, String s2) {
if (s1 == s2) {
return 0;
}
return AsciiUtil.toLowerString(s1).compareTo(AsciiUtil.toLowerString(s2));
}
public static char toUpper(char c) {
if (c >= 'a' && c <= 'z') {
c -= 0x20;
}
return c;
}
public static char toLower(char c) {
if (c >= 'A' && c <= 'Z') {
c += 0x20;
}
return c;
}
public static String toLowerString(String s) {
int idx = 0;
for (; idx < s.length(); idx++) {
char c = s.charAt(idx);
if (c >= 'A' && c <= 'Z') {
break;
}
}
if (idx == s.length()) {
return s;
}
StringBuilder buf = new StringBuilder(s.substring(0, idx));
for (; idx < s.length(); idx++) {
buf.append(toLower(s.charAt(idx)));
}
return buf.toString();
}
public static String toUpperString(String s) {
int idx = 0;
for (; idx < s.length(); idx++) {
char c = s.charAt(idx);
if (c >= 'a' && c <= 'z') {
break;
}
}
if (idx == s.length()) {
return s;
}
StringBuilder buf = new StringBuilder(s.substring(0, idx));
for (; idx < s.length(); idx++) {
buf.append(toUpper(s.charAt(idx)));
}
return buf.toString();
}
public static String toTitleString(String s) {
if (s.length() == 0) {
return s;
}
int idx = 0;
char c = s.charAt(idx);
if (!(c >= 'a' && c <= 'z')) {
for (idx = 1; idx < s.length(); idx++) {
if (c >= 'A' && c <= 'Z') {
break;
}
}
}
if (idx == s.length()) {
return s;
}
StringBuilder buf = new StringBuilder(s.substring(0, idx));
if (idx == 0) {
buf.append(toUpper(s.charAt(idx)));
idx++;
}
for (; idx < s.length(); idx++) {
buf.append(toLower(s.charAt(idx)));
}
return buf.toString();
}
public static boolean isAlpha(char c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
public static boolean isAlphaString(String s) {
boolean b = true;
for (int i = 0; i < s.length(); i++) {
if (!isAlpha(s.charAt(i))) {
b = false;
break;
}
}
return b;
}
public static boolean isNumeric(char c) {
return (c >= '0' && c <= '9');
}
public static boolean isNumericString(String s) {
boolean b = true;
for (int i = 0; i < s.length(); i++) {
if (!isNumeric(s.charAt(i))) {
b = false;
break;
}
}
return b;
}
public static boolean isAlphaNumeric(char c) {
return isAlpha(c) || isNumeric(c);
}
public static boolean isAlphaNumericString(String s) {
boolean b = true;
for (int i = 0; i < s.length(); i++) {
if (!isAlphaNumeric(s.charAt(i))) {
b = false;
break;
}
}
return b;
}
public static class CaseInsensitiveKey {
private String _key;
private int _hash;
public CaseInsensitiveKey(String key) {
_key = key;
_hash = AsciiUtil.toLowerString(key).hashCode();
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o instanceof CaseInsensitiveKey) {
return AsciiUtil.caseIgnoreMatch(_key, ((CaseInsensitiveKey)o)._key);
}
return false;
}
public int hashCode() {
return _hash;
}
}
}

View file

@ -0,0 +1,257 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
public final class BaseLocale {
private static final boolean JDKIMPL = false;
public static final String SEP = "_";
private static final Cache CACHE = new Cache();
public static final BaseLocale ROOT = BaseLocale.getInstance("", "", "", "");
private String _language = "";
private String _script = "";
private String _region = "";
private String _variant = "";
private transient volatile int _hash = 0;
private BaseLocale(String language, String script, String region, String variant) {
if (language != null) {
_language = AsciiUtil.toLowerString(language).intern();
}
if (script != null) {
_script = AsciiUtil.toTitleString(script).intern();
}
if (region != null) {
_region = AsciiUtil.toUpperString(region).intern();
}
if (variant != null) {
if (JDKIMPL) {
// preserve upper/lower cases
_variant = variant.intern();
} else {
_variant = AsciiUtil.toUpperString(variant).intern();
}
}
}
public static BaseLocale getInstance(String language, String script, String region, String variant) {
if (JDKIMPL) {
// JDK uses deprecated ISO639.1 language codes for he, yi and id
if (AsciiUtil.caseIgnoreMatch(language, "he")) {
language = "iw";
} else if (AsciiUtil.caseIgnoreMatch(language, "yi")) {
language = "ji";
} else if (AsciiUtil.caseIgnoreMatch(language, "id")) {
language = "in";
}
}
Key key = new Key(language, script, region, variant);
BaseLocale baseLocale = CACHE.get(key);
return baseLocale;
}
public String getLanguage() {
return _language;
}
public String getScript() {
return _script;
}
public String getRegion() {
return _region;
}
public String getVariant() {
return _variant;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof BaseLocale)) {
return false;
}
BaseLocale other = (BaseLocale)obj;
return hashCode() == other.hashCode()
&& _language.equals(other._language)
&& _script.equals(other._script)
&& _region.equals(other._region)
&& _variant.equals(other._variant);
}
public String toString() {
StringBuilder buf = new StringBuilder();
if (_language.length() > 0) {
buf.append("language=");
buf.append(_language);
}
if (_script.length() > 0) {
if (buf.length() > 0) {
buf.append(", ");
}
buf.append("script=");
buf.append(_script);
}
if (_region.length() > 0) {
if (buf.length() > 0) {
buf.append(", ");
}
buf.append("region=");
buf.append(_region);
}
if (_variant.length() > 0) {
if (buf.length() > 0) {
buf.append(", ");
}
buf.append("variant=");
buf.append(_variant);
}
return buf.toString();
}
public int hashCode() {
int h = _hash;
if (h == 0) {
// Generating a hash value from language, script, region and variant
for (int i = 0; i < _language.length(); i++) {
h = 31*h + _language.charAt(i);
}
for (int i = 0; i < _script.length(); i++) {
h = 31*h + _script.charAt(i);
}
for (int i = 0; i < _region.length(); i++) {
h = 31*h + _region.charAt(i);
}
for (int i = 0; i < _variant.length(); i++) {
h = 31*h + _variant.charAt(i);
}
_hash = h;
}
return h;
}
private static class Key implements Comparable<Key> {
private String _lang = "";
private String _scrt = "";
private String _regn = "";
private String _vart = "";
private volatile int _hash; // Default to 0
public Key(String language, String script, String region, String variant) {
if (language != null) {
_lang = language;
}
if (script != null) {
_scrt = script;
}
if (region != null) {
_regn = region;
}
if (variant != null) {
_vart = variant;
}
}
public boolean equals(Object obj) {
if (JDKIMPL) {
return (this == obj) ||
(obj instanceof Key)
&& AsciiUtil.caseIgnoreMatch(((Key)obj)._lang, this._lang)
&& AsciiUtil.caseIgnoreMatch(((Key)obj)._scrt, this._scrt)
&& AsciiUtil.caseIgnoreMatch(((Key)obj)._regn, this._regn)
&& ((Key)obj)._vart.equals(_vart); // variant is case sensitive in JDK!
}
return (this == obj) ||
(obj instanceof Key)
&& AsciiUtil.caseIgnoreMatch(((Key)obj)._lang, this._lang)
&& AsciiUtil.caseIgnoreMatch(((Key)obj)._scrt, this._scrt)
&& AsciiUtil.caseIgnoreMatch(((Key)obj)._regn, this._regn)
&& AsciiUtil.caseIgnoreMatch(((Key)obj)._vart, this._vart);
}
public int compareTo(Key other) {
int res = AsciiUtil.caseIgnoreCompare(this._lang, other._lang);
if (res == 0) {
res = AsciiUtil.caseIgnoreCompare(this._scrt, other._scrt);
if (res == 0) {
res = AsciiUtil.caseIgnoreCompare(this._regn, other._regn);
if (res == 0) {
if (JDKIMPL) {
res = this._vart.compareTo(other._vart);
} else {
res = AsciiUtil.caseIgnoreCompare(this._vart, other._vart);
}
}
}
}
return res;
}
public int hashCode() {
int h = _hash;
if (h == 0) {
// Generating a hash value from language, script, region and variant
for (int i = 0; i < _lang.length(); i++) {
h = 31*h + AsciiUtil.toLower(_lang.charAt(i));
}
for (int i = 0; i < _scrt.length(); i++) {
h = 31*h + AsciiUtil.toLower(_scrt.charAt(i));
}
for (int i = 0; i < _regn.length(); i++) {
h = 31*h + AsciiUtil.toLower(_regn.charAt(i));
}
for (int i = 0; i < _vart.length(); i++) {
if (JDKIMPL) {
h = 31*h + _vart.charAt(i);
} else {
h = 31*h + AsciiUtil.toLower(_vart.charAt(i));
}
}
_hash = h;
}
return h;
}
public static Key normalize(Key key) {
String lang = AsciiUtil.toLowerString(key._lang).intern();
String scrt = AsciiUtil.toTitleString(key._scrt).intern();
String regn = AsciiUtil.toUpperString(key._regn).intern();
String vart;
if (JDKIMPL) {
// preserve upper/lower cases
vart = key._vart.intern();
} else {
vart = AsciiUtil.toUpperString(key._vart).intern();
}
return new Key(lang, scrt, regn, vart);
}
}
private static class Cache extends LocaleObjectCache<Key, BaseLocale> {
public Cache() {
}
protected Key normalizeKey(Key key) {
return Key.normalize(key);
}
protected BaseLocale createObject(Key key) {
return new BaseLocale(key._lang, key._scrt, key._regn, key._vart);
}
}
}

View file

@ -0,0 +1,38 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
public class Extension {
private char _key;
protected String _value;
protected Extension(char key) {
_key = key;
}
Extension(char key, String value) {
_key = key;
_value = value;
}
public char getKey() {
return _key;
}
public String getValue() {
return _value;
}
public String getID() {
return _key + LanguageTag.SEP + _value;
}
public String toString() {
return getID();
}
}

View file

@ -0,0 +1,684 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public final class InternalLocaleBuilder {
private static final boolean JDKIMPL = false;
private String _language = "";
private String _script = "";
private String _region = "";
private String _variant = "";
private static final CaseInsensitiveChar PRIVUSE_KEY = new CaseInsensitiveChar(LanguageTag.PRIVATEUSE.charAt(0));
private HashMap<CaseInsensitiveChar, String> _extensions;
private HashSet<CaseInsensitiveString> _uattributes;
private HashMap<CaseInsensitiveString, String> _ukeywords;
public InternalLocaleBuilder() {
}
public InternalLocaleBuilder setLanguage(String language) throws LocaleSyntaxException {
if (language == null || language.length() == 0) {
_language = "";
} else {
if (!LanguageTag.isLanguage(language)) {
throw new LocaleSyntaxException("Ill-formed language: " + language, 0);
}
_language = language;
}
return this;
}
public InternalLocaleBuilder setScript(String script) throws LocaleSyntaxException {
if (script == null || script.length() == 0) {
_script = "";
} else {
if (!LanguageTag.isScript(script)) {
throw new LocaleSyntaxException("Ill-formed script: " + script, 0);
}
_script = script;
}
return this;
}
public InternalLocaleBuilder setRegion(String region) throws LocaleSyntaxException {
if (region == null || region.length() == 0) {
_region = "";
} else {
if (!LanguageTag.isRegion(region)) {
throw new LocaleSyntaxException("Ill-formed region: " + region, 0);
}
_region = region;
}
return this;
}
public InternalLocaleBuilder setVariant(String variant) throws LocaleSyntaxException {
if (variant == null || variant.length() == 0) {
_variant = "";
} else {
// normalize separators to "_"
String var = variant.replaceAll(LanguageTag.SEP, BaseLocale.SEP);
int errIdx = checkVariants(var, BaseLocale.SEP);
if (errIdx != -1) {
throw new LocaleSyntaxException("Ill-formed variant: " + variant, errIdx);
}
_variant = var;
}
return this;
}
public InternalLocaleBuilder addUnicodeLocaleAttribute(String attribute) throws LocaleSyntaxException {
if (attribute == null || !UnicodeLocaleExtension.isAttribute(attribute)) {
throw new LocaleSyntaxException("Ill-formed Unicode locale attribute: " + attribute);
}
// Use case insensitive string to prevent duplication
if (_uattributes == null) {
_uattributes = new HashSet<CaseInsensitiveString>(4);
}
_uattributes.add(new CaseInsensitiveString(attribute));
return this;
}
public InternalLocaleBuilder removeUnicodeLocaleAttribute(String attribute) throws LocaleSyntaxException {
if (attribute == null || !UnicodeLocaleExtension.isAttribute(attribute)) {
throw new LocaleSyntaxException("Ill-formed Unicode locale attribute: " + attribute);
}
if (_uattributes != null) {
_uattributes.remove(new CaseInsensitiveString(attribute));
}
return this;
}
public InternalLocaleBuilder setUnicodeLocaleKeyword(String key, String type) throws LocaleSyntaxException {
if (!UnicodeLocaleExtension.isKey(key)) {
throw new LocaleSyntaxException("Ill-formed Unicode locale keyword key: " + key);
}
CaseInsensitiveString cikey = new CaseInsensitiveString(key);
if (type == null) {
if (_ukeywords != null) {
// null type is used for remove the key
_ukeywords.remove(cikey);
}
} else {
if (type.length() != 0) {
// normalize separator to "-"
String tp = type.replaceAll(BaseLocale.SEP, LanguageTag.SEP);
// validate
StringTokenIterator itr = new StringTokenIterator(tp, LanguageTag.SEP);
while (!itr.isDone()) {
String s = itr.current();
if (!UnicodeLocaleExtension.isTypeSubtag(s)) {
throw new LocaleSyntaxException("Ill-formed Unicode locale keyword type: " + type, itr.currentStart());
}
itr.next();
}
}
if (_ukeywords == null) {
_ukeywords = new HashMap<CaseInsensitiveString, String>(4);
}
_ukeywords.put(cikey, type);
}
return this;
}
public InternalLocaleBuilder setExtension(char singleton, String value) throws LocaleSyntaxException {
// validate key
boolean isBcpPrivateuse = LanguageTag.isPrivateusePrefixChar(singleton);
if (!isBcpPrivateuse && !LanguageTag.isExtensionSingletonChar(singleton)) {
throw new LocaleSyntaxException("Ill-formed extension key: " + singleton);
}
boolean remove = (value == null || value.length() == 0);
CaseInsensitiveChar key = new CaseInsensitiveChar(singleton);
if (remove) {
if (UnicodeLocaleExtension.isSingletonChar(key.value())) {
// clear entire Unicode locale extension
if (_uattributes != null) {
_uattributes.clear();
}
if (_ukeywords != null) {
_ukeywords.clear();
}
} else {
if (_extensions != null && _extensions.containsKey(key)) {
_extensions.remove(key);
}
}
} else {
// validate value
String val = value.replaceAll(BaseLocale.SEP, LanguageTag.SEP);
StringTokenIterator itr = new StringTokenIterator(val, LanguageTag.SEP);
while (!itr.isDone()) {
String s = itr.current();
boolean validSubtag;
if (isBcpPrivateuse) {
validSubtag = LanguageTag.isPrivateuseSubtag(s);
} else {
validSubtag = LanguageTag.isExtensionSubtag(s);
}
if (!validSubtag) {
throw new LocaleSyntaxException("Ill-formed extension value: " + s, itr.currentStart());
}
itr.next();
}
if (UnicodeLocaleExtension.isSingletonChar(key.value())) {
setUnicodeLocaleExtension(val);
} else {
if (_extensions == null) {
_extensions = new HashMap<CaseInsensitiveChar, String>(4);
}
_extensions.put(key, val);
}
}
return this;
}
/*
* Set extension/private subtags in a single string representation
*/
public InternalLocaleBuilder setExtensions(String subtags) throws LocaleSyntaxException {
if (subtags == null || subtags.length() == 0) {
clearExtensions();
return this;
}
subtags = subtags.replaceAll(BaseLocale.SEP, LanguageTag.SEP);
StringTokenIterator itr = new StringTokenIterator(subtags, LanguageTag.SEP);
List<String> extensions = null;
String privateuse = null;
int parsed = 0;
int start;
// Make a list of extension subtags
while (!itr.isDone()) {
String s = itr.current();
if (LanguageTag.isExtensionSingleton(s)) {
start = itr.currentStart();
String singleton = s;
StringBuilder sb = new StringBuilder(singleton);
itr.next();
while (!itr.isDone()) {
s = itr.current();
if (LanguageTag.isExtensionSubtag(s)) {
sb.append(LanguageTag.SEP).append(s);
parsed = itr.currentEnd();
} else {
break;
}
itr.next();
}
if (parsed < start) {
throw new LocaleSyntaxException("Incomplete extension '" + singleton + "'", start);
}
if (extensions == null) {
extensions = new ArrayList<String>(4);
}
extensions.add(sb.toString());
} else {
break;
}
}
if (!itr.isDone()) {
String s = itr.current();
if (LanguageTag.isPrivateusePrefix(s)) {
start = itr.currentStart();
StringBuilder sb = new StringBuilder(s);
itr.next();
while (!itr.isDone()) {
s = itr.current();
if (!LanguageTag.isPrivateuseSubtag(s)) {
break;
}
sb.append(LanguageTag.SEP).append(s);
parsed = itr.currentEnd();
itr.next();
}
if (parsed <= start) {
throw new LocaleSyntaxException("Incomplete privateuse:" + subtags.substring(start), start);
} else {
privateuse = sb.toString();
}
}
}
if (!itr.isDone()) {
throw new LocaleSyntaxException("Ill-formed extension subtags:" + subtags.substring(itr.currentStart()), itr.currentStart());
}
return setExtensions(extensions, privateuse);
}
/*
* Set a list of BCP47 extensions and private use subtags
* BCP47 extensions are already validated and well-formed, but may contain duplicates
*/
private InternalLocaleBuilder setExtensions(List<String> bcpExtensions, String privateuse) {
clearExtensions();
if (bcpExtensions != null && bcpExtensions.size() > 0) {
HashSet<CaseInsensitiveChar> processedExtensions = new HashSet<CaseInsensitiveChar>(bcpExtensions.size());
for (String bcpExt : bcpExtensions) {
CaseInsensitiveChar key = new CaseInsensitiveChar(bcpExt.charAt(0));
// ignore duplicates
if (!processedExtensions.contains(key)) {
// each extension string contains singleton, e.g. "a-abc-def"
if (UnicodeLocaleExtension.isSingletonChar(key.value())) {
setUnicodeLocaleExtension(bcpExt.substring(2));
} else {
if (_extensions == null) {
_extensions = new HashMap<CaseInsensitiveChar, String>(4);
}
_extensions.put(key, bcpExt.substring(2));
}
}
}
}
if (privateuse != null && privateuse.length() > 0) {
// privateuse string contains prefix, e.g. "x-abc-def"
if (_extensions == null) {
_extensions = new HashMap<CaseInsensitiveChar, String>(1);
}
_extensions.put(new CaseInsensitiveChar(privateuse.charAt(0)), privateuse.substring(2));
}
return this;
}
/*
* Reset Builder's internal state with the given language tag
*/
public InternalLocaleBuilder setLanguageTag(LanguageTag langtag) {
clear();
if (langtag.getExtlangs().size() > 0) {
_language = langtag.getExtlangs().get(0);
} else {
String language = langtag.getLanguage();
if (!language.equals(LanguageTag.UNDETERMINED)) {
_language = language;
}
}
_script = langtag.getScript();
_region = langtag.getRegion();
List<String> bcpVariants = langtag.getVariants();
if (bcpVariants.size() > 0) {
StringBuilder var = new StringBuilder(bcpVariants.get(0));
for (int i = 1; i < bcpVariants.size(); i++) {
var.append(BaseLocale.SEP).append(bcpVariants.get(i));
}
_variant = var.toString();
}
setExtensions(langtag.getExtensions(), langtag.getPrivateuse());
return this;
}
public InternalLocaleBuilder setLocale(BaseLocale base, LocaleExtensions extensions) throws LocaleSyntaxException {
String language = base.getLanguage();
String script = base.getScript();
String region = base.getRegion();
String variant = base.getVariant();
if (JDKIMPL) {
// Special backward compatibility support
// Exception 1 - ja_JP_JP
if (language.equals("ja") && region.equals("JP") && variant.equals("JP")) {
// When locale ja_JP_JP is created, ca-japanese is always there.
// The builder ignores the variant "JP"
assert("japanese".equals(extensions.getUnicodeLocaleType("ca")));
variant = "";
}
// Exception 2 - th_TH_TH
else if (language.equals("th") && region.equals("TH") && variant.equals("TH")) {
// When locale th_TH_TH is created, nu-thai is always there.
// The builder ignores the variant "TH"
assert("thai".equals(extensions.getUnicodeLocaleType("nu")));
variant = "";
}
// Exception 3 - no_NO_NY
else if (language.equals("no") && region.equals("NO") && variant.equals("NY")) {
// no_NO_NY is a valid locale and used by Java 6 or older versions.
// The build ignores the variant "NY" and change the language to "nn".
language = "nn";
variant = "";
}
}
// Validate base locale fields before updating internal state.
// LocaleExtensions always store validated/canonicalized values,
// so no checks are necessary.
if (language.length() > 0 && !LanguageTag.isLanguage(language)) {
throw new LocaleSyntaxException("Ill-formed language: " + language);
}
if (script.length() > 0 && !LanguageTag.isScript(script)) {
throw new LocaleSyntaxException("Ill-formed script: " + script);
}
if (region.length() > 0 && !LanguageTag.isRegion(region)) {
throw new LocaleSyntaxException("Ill-formed region: " + region);
}
if (variant.length() > 0) {
int errIdx = checkVariants(variant, BaseLocale.SEP);
if (errIdx != -1) {
throw new LocaleSyntaxException("Ill-formed variant: " + variant, errIdx);
}
}
// The input locale is validated at this point.
// Now, updating builder's internal fields.
_language = language;
_script = script;
_region = region;
_variant = variant;
clearExtensions();
Set<Character> extKeys = (extensions == null) ? null : extensions.getKeys();
if (extKeys != null) {
// map extensions back to builder's internal format
for (Character key : extKeys) {
Extension e = extensions.getExtension(key);
if (e instanceof UnicodeLocaleExtension) {
UnicodeLocaleExtension ue = (UnicodeLocaleExtension)e;
for (String uatr : ue.getUnicodeLocaleAttributes()) {
if (_uattributes == null) {
_uattributes = new HashSet<CaseInsensitiveString>(4);
}
_uattributes.add(new CaseInsensitiveString(uatr));
}
for (String ukey : ue.getUnicodeLocaleKeys()) {
if (_ukeywords == null) {
_ukeywords = new HashMap<CaseInsensitiveString, String>(4);
}
_ukeywords.put(new CaseInsensitiveString(ukey), ue.getUnicodeLocaleType(ukey));
}
} else {
if (_extensions == null) {
_extensions = new HashMap<CaseInsensitiveChar, String>(4);
}
_extensions.put(new CaseInsensitiveChar(key.charValue()), e.getValue());
}
}
}
return this;
}
public InternalLocaleBuilder clear() {
_language = "";
_script = "";
_region = "";
_variant = "";
clearExtensions();
return this;
}
public InternalLocaleBuilder clearExtensions() {
if (_extensions != null) {
_extensions.clear();
}
if (_uattributes != null) {
_uattributes.clear();
}
if (_ukeywords != null) {
_ukeywords.clear();
}
return this;
}
public BaseLocale getBaseLocale() {
String language = _language;
String script = _script;
String region = _region;
String variant = _variant;
// Special private use subtag sequence identified by "lvariant" will be
// interpreted as Java variant.
if (_extensions != null) {
String privuse = _extensions.get(PRIVUSE_KEY);
if (privuse != null) {
StringTokenIterator itr = new StringTokenIterator(privuse, LanguageTag.SEP);
boolean sawPrefix = false;
int privVarStart = -1;
while (!itr.isDone()) {
if (sawPrefix) {
privVarStart = itr.currentStart();
break;
}
if (AsciiUtil.caseIgnoreMatch(itr.current(), LanguageTag.PRIVUSE_VARIANT_PREFIX)) {
sawPrefix = true;
}
itr.next();
}
if (privVarStart != -1) {
StringBuilder sb = new StringBuilder(variant);
if (sb.length() != 0) {
sb.append(BaseLocale.SEP);
}
sb.append(privuse.substring(privVarStart).replaceAll(LanguageTag.SEP, BaseLocale.SEP));
variant = sb.toString();
}
}
}
return BaseLocale.getInstance(language, script, region, variant);
}
public LocaleExtensions getLocaleExtensions() {
if ((_extensions == null || _extensions.size() == 0)
&& (_uattributes == null || _uattributes.size() == 0)
&& (_ukeywords == null || _ukeywords.size() == 0)) {
return LocaleExtensions.EMPTY_EXTENSIONS;
}
return new LocaleExtensions(_extensions, _uattributes, _ukeywords);
}
/*
* Remove special private use subtag sequence identified by "lvariant"
* and return the rest. Only used by LocaleExtensions
*/
static String removePrivateuseVariant(String privuseVal) {
StringTokenIterator itr = new StringTokenIterator(privuseVal, LanguageTag.SEP);
// Note: privateuse value "abc-lvariant" is unchanged
// because no subtags after "lvariant".
int prefixStart = -1;
boolean sawPrivuseVar = false;
while (!itr.isDone()) {
if (prefixStart != -1) {
// Note: privateuse value "abc-lvariant" is unchanged
// because no subtags after "lvariant".
sawPrivuseVar = true;
break;
}
if (AsciiUtil.caseIgnoreMatch(itr.current(), LanguageTag.PRIVUSE_VARIANT_PREFIX)) {
prefixStart = itr.currentStart();
}
itr.next();
}
if (!sawPrivuseVar) {
return privuseVal;
}
assert(prefixStart == 0 || prefixStart > 1);
return (prefixStart == 0) ? null : privuseVal.substring(0, prefixStart -1);
}
/*
* Check if the given variant subtags separated by the given
* separator(s) are valid
*/
private int checkVariants(String variants, String sep) {
StringTokenIterator itr = new StringTokenIterator(variants, sep);
while (!itr.isDone()) {
String s = itr.current();
if (!LanguageTag.isVariant(s)) {
return itr.currentStart();
}
itr.next();
}
return -1;
}
/*
* Private methods parsing Unicode Locale Extension subtags.
* Duplicated attributes/keywords will be ignored.
* The input must be a valid extension subtags (excluding singleton).
*/
private void setUnicodeLocaleExtension(String subtags) {
// wipe out existing attributes/keywords
if (_uattributes != null) {
_uattributes.clear();
}
if (_ukeywords != null) {
_ukeywords.clear();
}
StringTokenIterator itr = new StringTokenIterator(subtags, LanguageTag.SEP);
// parse attributes
while (!itr.isDone()) {
if (!UnicodeLocaleExtension.isAttribute(itr.current())) {
break;
}
if (_uattributes == null) {
_uattributes = new HashSet<CaseInsensitiveString>(4);
}
_uattributes.add(new CaseInsensitiveString(itr.current()));
itr.next();
}
// parse keywords
CaseInsensitiveString key = null;
String type;
int typeStart = -1;
int typeEnd = -1;
while (!itr.isDone()) {
if (key != null) {
if (UnicodeLocaleExtension.isKey(itr.current())) {
// next keyword - emit previous one
assert(typeStart == -1 || typeEnd != -1);
type = (typeStart == -1) ? "" : subtags.substring(typeStart, typeEnd);
if (_ukeywords == null) {
_ukeywords = new HashMap<CaseInsensitiveString, String>(4);
}
_ukeywords.put(key, type);
// reset keyword info
CaseInsensitiveString tmpKey = new CaseInsensitiveString(itr.current());
key = _ukeywords.containsKey(tmpKey) ? null : tmpKey;
typeStart = typeEnd = -1;
} else {
if (typeStart == -1) {
typeStart = itr.currentStart();
}
typeEnd = itr.currentEnd();
}
} else if (UnicodeLocaleExtension.isKey(itr.current())) {
// 1. first keyword or
// 2. next keyword, but previous one was duplicate
key = new CaseInsensitiveString(itr.current());
if (_ukeywords != null && _ukeywords.containsKey(key)) {
// duplicate
key = null;
}
}
if (!itr.hasNext()) {
if (key != null) {
// last keyword
assert(typeStart == -1 || typeEnd != -1);
type = (typeStart == -1) ? "" : subtags.substring(typeStart, typeEnd);
if (_ukeywords == null) {
_ukeywords = new HashMap<CaseInsensitiveString, String>(4);
}
_ukeywords.put(key, type);
}
break;
}
itr.next();
}
}
static class CaseInsensitiveString {
private String _s;
CaseInsensitiveString(String s) {
_s = s;
}
public String value() {
return _s;
}
public int hashCode() {
return AsciiUtil.toLowerString(_s).hashCode();
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof CaseInsensitiveString)) {
return false;
}
return AsciiUtil.caseIgnoreMatch(_s, ((CaseInsensitiveString)obj).value());
}
}
static class CaseInsensitiveChar {
private char _c;
CaseInsensitiveChar(char c) {
_c = c;
}
public char value() {
return _c;
}
public int hashCode() {
return AsciiUtil.toLower(_c);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof CaseInsensitiveChar)) {
return false;
}
return _c == AsciiUtil.toLower(((CaseInsensitiveChar)obj).value());
}
}
}

View file

@ -0,0 +1,720 @@
/*
*******************************************************************************
* Copyright (C) 2010-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class LanguageTag {
private static final boolean JDKIMPL = false;
//
// static fields
//
public static final String SEP = "-";
public static final String PRIVATEUSE = "x";
public static String UNDETERMINED = "und";
public static final String PRIVUSE_VARIANT_PREFIX = "lvariant";
//
// Language subtag fields
//
private String _language = ""; // language subtag
private String _script = ""; // script subtag
private String _region = ""; // region subtag
private String _privateuse = ""; // privateuse
private List<String> _extlangs = Collections.emptyList(); // extlang subtags
private List<String> _variants = Collections.emptyList(); // variant subtags
private List<String> _extensions = Collections.emptyList(); // extensions
// Map contains grandfathered tags and its preferred mappings from
// http://www.ietf.org/rfc/rfc5646.txt
private static final Map<AsciiUtil.CaseInsensitiveKey, String[]> GRANDFATHERED =
new HashMap<AsciiUtil.CaseInsensitiveKey, String[]>();
static {
// grandfathered = irregular ; non-redundant tags registered
// / regular ; during the RFC 3066 era
//
// irregular = "en-GB-oed" ; irregular tags do not match
// / "i-ami" ; the 'langtag' production and
// / "i-bnn" ; would not otherwise be
// / "i-default" ; considered 'well-formed'
// / "i-enochian" ; These tags are all valid,
// / "i-hak" ; but most are deprecated
// / "i-klingon" ; in favor of more modern
// / "i-lux" ; subtags or subtag
// / "i-mingo" ; combination
// / "i-navajo"
// / "i-pwn"
// / "i-tao"
// / "i-tay"
// / "i-tsu"
// / "sgn-BE-FR"
// / "sgn-BE-NL"
// / "sgn-CH-DE"
//
// regular = "art-lojban" ; these tags match the 'langtag'
// / "cel-gaulish" ; production, but their subtags
// / "no-bok" ; are not extended language
// / "no-nyn" ; or variant subtags: their meaning
// / "zh-guoyu" ; is defined by their registration
// / "zh-hakka" ; and all of these are deprecated
// / "zh-min" ; in favor of a more modern
// / "zh-min-nan" ; subtag or sequence of subtags
// / "zh-xiang"
final String[][] entries = {
//{"tag", "preferred"},
{"art-lojban", "jbo"},
{"cel-gaulish", "xtg-x-cel-gaulish"}, // fallback
{"en-GB-oed", "en-GB-x-oed"}, // fallback
{"i-ami", "ami"},
{"i-bnn", "bnn"},
{"i-default", "en-x-i-default"}, // fallback
{"i-enochian", "und-x-i-enochian"}, // fallback
{"i-hak", "hak"},
{"i-klingon", "tlh"},
{"i-lux", "lb"},
{"i-mingo", "see-x-i-mingo"}, // fallback
{"i-navajo", "nv"},
{"i-pwn", "pwn"},
{"i-tao", "tao"},
{"i-tay", "tay"},
{"i-tsu", "tsu"},
{"no-bok", "nb"},
{"no-nyn", "nn"},
{"sgn-BE-FR", "sfb"},
{"sgn-BE-NL", "vgt"},
{"sgn-CH-DE", "sgg"},
{"zh-guoyu", "cmn"},
{"zh-hakka", "hak"},
{"zh-min", "nan-x-zh-min"}, // fallback
{"zh-min-nan", "nan"},
{"zh-xiang", "hsn"},
};
for (String[] e : entries) {
GRANDFATHERED.put(new AsciiUtil.CaseInsensitiveKey(e[0]), e);
}
}
private LanguageTag() {
}
/*
* BNF in RFC5464
*
* Language-Tag = langtag ; normal language tags
* / privateuse ; private use tag
* / grandfathered ; grandfathered tags
*
*
* langtag = language
* ["-" script]
* ["-" region]
* *("-" variant)
* *("-" extension)
* ["-" privateuse]
*
* language = 2*3ALPHA ; shortest ISO 639 code
* ["-" extlang] ; sometimes followed by
* ; extended language subtags
* / 4ALPHA ; or reserved for future use
* / 5*8ALPHA ; or registered language subtag
*
* extlang = 3ALPHA ; selected ISO 639 codes
* *2("-" 3ALPHA) ; permanently reserved
*
* script = 4ALPHA ; ISO 15924 code
*
* region = 2ALPHA ; ISO 3166-1 code
* / 3DIGIT ; UN M.49 code
*
* variant = 5*8alphanum ; registered variants
* / (DIGIT 3alphanum)
*
* extension = singleton 1*("-" (2*8alphanum))
*
* ; Single alphanumerics
* ; "x" reserved for private use
* singleton = DIGIT ; 0 - 9
* / %x41-57 ; A - W
* / %x59-5A ; Y - Z
* / %x61-77 ; a - w
* / %x79-7A ; y - z
*
* privateuse = "x" 1*("-" (1*8alphanum))
*
*/
public static LanguageTag parse(String languageTag, ParseStatus sts) {
if (sts == null) {
sts = new ParseStatus();
} else {
sts.reset();
}
StringTokenIterator itr;
// Check if the tag is grandfathered
String[] gfmap = GRANDFATHERED.get(new AsciiUtil.CaseInsensitiveKey(languageTag));
if (gfmap != null) {
// use preferred mapping
itr = new StringTokenIterator(gfmap[1], SEP);
} else {
itr = new StringTokenIterator(languageTag, SEP);
}
LanguageTag tag = new LanguageTag();
// langtag must start with either language or privateuse
if (tag.parseLanguage(itr, sts)) {
tag.parseExtlangs(itr, sts);
tag.parseScript(itr, sts);
tag.parseRegion(itr, sts);
tag.parseVariants(itr, sts);
tag.parseExtensions(itr, sts);
}
tag.parsePrivateuse(itr, sts);
if (!itr.isDone() && !sts.isError()) {
String s = itr.current();
sts._errorIndex = itr.currentStart();
if (s.length() == 0) {
sts._errorMsg = "Empty subtag";
} else {
sts._errorMsg = "Invalid subtag: " + s;
}
}
return tag;
}
//
// Language subtag parsers
//
private boolean parseLanguage(StringTokenIterator itr, ParseStatus sts) {
if (itr.isDone() || sts.isError()) {
return false;
}
boolean found = false;
String s = itr.current();
if (isLanguage(s)) {
found = true;
_language = s;
sts._parseLength = itr.currentEnd();
itr.next();
}
return found;
}
private boolean parseExtlangs(StringTokenIterator itr, ParseStatus sts) {
if (itr.isDone() || sts.isError()) {
return false;
}
boolean found = false;
while (!itr.isDone()) {
String s = itr.current();
if (!isExtlang(s)) {
break;
}
found = true;
if (_extlangs.isEmpty()) {
_extlangs = new ArrayList<String>(3);
}
_extlangs.add(s);
sts._parseLength = itr.currentEnd();
itr.next();
if (_extlangs.size() == 3) {
// Maximum 3 extlangs
break;
}
}
return found;
}
private boolean parseScript(StringTokenIterator itr, ParseStatus sts) {
if (itr.isDone() || sts.isError()) {
return false;
}
boolean found = false;
String s = itr.current();
if (isScript(s)) {
found = true;
_script = s;
sts._parseLength = itr.currentEnd();
itr.next();
}
return found;
}
private boolean parseRegion(StringTokenIterator itr, ParseStatus sts) {
if (itr.isDone() || sts.isError()) {
return false;
}
boolean found = false;
String s = itr.current();
if (isRegion(s)) {
found = true;
_region = s;
sts._parseLength = itr.currentEnd();
itr.next();
}
return found;
}
private boolean parseVariants(StringTokenIterator itr, ParseStatus sts) {
if (itr.isDone() || sts.isError()) {
return false;
}
boolean found = false;
while (!itr.isDone()) {
String s = itr.current();
if (!isVariant(s)) {
break;
}
found = true;
if (_variants.isEmpty()) {
_variants = new ArrayList<String>(3);
}
_variants.add(s);
sts._parseLength = itr.currentEnd();
itr.next();
}
return found;
}
private boolean parseExtensions(StringTokenIterator itr, ParseStatus sts) {
if (itr.isDone() || sts.isError()) {
return false;
}
boolean found = false;
while (!itr.isDone()) {
String s = itr.current();
if (isExtensionSingleton(s)) {
int start = itr.currentStart();
String singleton = s;
StringBuilder sb = new StringBuilder(singleton);
itr.next();
while (!itr.isDone()) {
s = itr.current();
if (isExtensionSubtag(s)) {
sb.append(SEP).append(s);
sts._parseLength = itr.currentEnd();
} else {
break;
}
itr.next();
}
if (sts._parseLength <= start) {
sts._errorIndex = start;
sts._errorMsg = "Incomplete extension '" + singleton + "'";
break;
}
if (_extensions.size() == 0) {
_extensions = new ArrayList<String>(4);
}
_extensions.add(sb.toString());
found = true;
} else {
break;
}
}
return found;
}
private boolean parsePrivateuse(StringTokenIterator itr, ParseStatus sts) {
if (itr.isDone() || sts.isError()) {
return false;
}
boolean found = false;
String s = itr.current();
if (isPrivateusePrefix(s)) {
int start = itr.currentStart();
StringBuilder sb = new StringBuilder(s);
itr.next();
while (!itr.isDone()) {
s = itr.current();
if (!isPrivateuseSubtag(s)) {
break;
}
sb.append(SEP).append(s);
sts._parseLength = itr.currentEnd();
itr.next();
}
if (sts._parseLength <= start) {
// need at least 1 private subtag
sts._errorIndex = start;
sts._errorMsg = "Incomplete privateuse";
} else {
_privateuse = sb.toString();
found = true;
}
}
return found;
}
public static LanguageTag parseLocale(BaseLocale baseLocale, LocaleExtensions localeExtensions) {
LanguageTag tag = new LanguageTag();
String language = baseLocale.getLanguage();
String script = baseLocale.getScript();
String region = baseLocale.getRegion();
String variant = baseLocale.getVariant();
boolean hasSubtag = false;
String privuseVar = null; // store ill-formed variant subtags
if (language.length() > 0 && isLanguage(language)) {
// Convert a deprecated language code used by Java to
// a new code
if (language.equals("iw")) {
language = "he";
} else if (language.equals("ji")) {
language = "yi";
} else if (language.equals("in")) {
language = "id";
}
tag._language = language;
}
if (script.length() > 0 && isScript(script)) {
tag._script = canonicalizeScript(script);
hasSubtag = true;
}
if (region.length() > 0 && isRegion(region)) {
tag._region = canonicalizeRegion(region);
hasSubtag = true;
}
if (JDKIMPL) {
// Special handling for no_NO_NY - use nn_NO for language tag
if (tag._language.equals("no") && tag._region.equals("NO") && variant.equals("NY")) {
tag._language = "nn";
variant = "";
}
}
if (variant.length() > 0) {
List<String> variants = null;
StringTokenIterator varitr = new StringTokenIterator(variant, BaseLocale.SEP);
while (!varitr.isDone()) {
String var = varitr.current();
if (!isVariant(var)) {
break;
}
if (variants == null) {
variants = new ArrayList<String>();
}
if (JDKIMPL) {
variants.add(var); // Do not canonicalize!
} else {
variants.add(canonicalizeVariant(var));
}
varitr.next();
}
if (variants != null) {
tag._variants = variants;
hasSubtag = true;
}
if (!varitr.isDone()) {
// ill-formed variant subtags
StringBuilder buf = new StringBuilder();
while (!varitr.isDone()) {
String prvv = varitr.current();
if (!isPrivateuseSubtag(prvv)) {
// cannot use private use subtag - truncated
break;
}
if (buf.length() > 0) {
buf.append(SEP);
}
if (!JDKIMPL) {
prvv = AsciiUtil.toLowerString(prvv);
}
buf.append(prvv);
varitr.next();
}
if (buf.length() > 0) {
privuseVar = buf.toString();
}
}
}
List<String> extensions = null;
String privateuse = null;
Set<Character> locextKeys = localeExtensions.getKeys();
for (Character locextKey : locextKeys) {
Extension ext = localeExtensions.getExtension(locextKey);
if (isPrivateusePrefixChar(locextKey.charValue())) {
privateuse = ext.getValue();
} else {
if (extensions == null) {
extensions = new ArrayList<String>();
}
extensions.add(locextKey.toString() + SEP + ext.getValue());
}
}
if (extensions != null) {
tag._extensions = extensions;
hasSubtag = true;
}
// append ill-formed variant subtags to private use
if (privuseVar != null) {
if (privateuse == null) {
privateuse = PRIVUSE_VARIANT_PREFIX + SEP + privuseVar;
} else {
privateuse = privateuse + SEP + PRIVUSE_VARIANT_PREFIX + SEP + privuseVar.replace(BaseLocale.SEP, SEP);
}
}
if (privateuse != null) {
tag._privateuse = privateuse;
}
if (tag._language.length() == 0 && (hasSubtag || privateuse == null)) {
// use lang "und" when 1) no language is available AND
// 2) any of other subtags other than private use are available or
// no private use tag is available
tag._language = UNDETERMINED;
}
return tag;
}
//
// Getter methods for language subtag fields
//
public String getLanguage() {
return _language;
}
public List<String> getExtlangs() {
return Collections.unmodifiableList(_extlangs);
}
public String getScript() {
return _script;
}
public String getRegion() {
return _region;
}
public List<String> getVariants() {
return Collections.unmodifiableList(_variants);
}
public List<String> getExtensions() {
return Collections.unmodifiableList(_extensions);
}
public String getPrivateuse() {
return _privateuse;
}
//
// Language subtag syntax checking methods
//
public static boolean isLanguage(String s) {
// language = 2*3ALPHA ; shortest ISO 639 code
// ["-" extlang] ; sometimes followed by
// ; extended language subtags
// / 4ALPHA ; or reserved for future use
// / 5*8ALPHA ; or registered language subtag
return (s.length() >= 2) && (s.length() <= 8) && AsciiUtil.isAlphaString(s);
}
public static boolean isExtlang(String s) {
// extlang = 3ALPHA ; selected ISO 639 codes
// *2("-" 3ALPHA) ; permanently reserved
return (s.length() == 3) && AsciiUtil.isAlphaString(s);
}
public static boolean isScript(String s) {
// script = 4ALPHA ; ISO 15924 code
return (s.length() == 4) && AsciiUtil.isAlphaString(s);
}
public static boolean isRegion(String s) {
// region = 2ALPHA ; ISO 3166-1 code
// / 3DIGIT ; UN M.49 code
return ((s.length() == 2) && AsciiUtil.isAlphaString(s))
|| ((s.length() == 3) && AsciiUtil.isNumericString(s));
}
public static boolean isVariant(String s) {
// variant = 5*8alphanum ; registered variants
// / (DIGIT 3alphanum)
int len = s.length();
if (len >= 5 && len <= 8) {
return AsciiUtil.isAlphaNumericString(s);
}
if (len == 4) {
return AsciiUtil.isNumeric(s.charAt(0))
&& AsciiUtil.isAlphaNumeric(s.charAt(1))
&& AsciiUtil.isAlphaNumeric(s.charAt(2))
&& AsciiUtil.isAlphaNumeric(s.charAt(3));
}
return false;
}
public static boolean isExtensionSingleton(String s) {
// singleton = DIGIT ; 0 - 9
// / %x41-57 ; A - W
// / %x59-5A ; Y - Z
// / %x61-77 ; a - w
// / %x79-7A ; y - z
return (s.length() == 1)
&& AsciiUtil.isAlphaString(s)
&& !AsciiUtil.caseIgnoreMatch(PRIVATEUSE, s);
}
public static boolean isExtensionSingletonChar(char c) {
return isExtensionSingleton(String.valueOf(c));
}
public static boolean isExtensionSubtag(String s) {
// extension = singleton 1*("-" (2*8alphanum))
return (s.length() >= 2) && (s.length() <= 8) && AsciiUtil.isAlphaNumericString(s);
}
public static boolean isPrivateusePrefix(String s) {
// privateuse = "x" 1*("-" (1*8alphanum))
return (s.length() == 1)
&& AsciiUtil.caseIgnoreMatch(PRIVATEUSE, s);
}
public static boolean isPrivateusePrefixChar(char c) {
return (AsciiUtil.caseIgnoreMatch(PRIVATEUSE, String.valueOf(c)));
}
public static boolean isPrivateuseSubtag(String s) {
// privateuse = "x" 1*("-" (1*8alphanum))
return (s.length() >= 1) && (s.length() <= 8) && AsciiUtil.isAlphaNumericString(s);
}
//
// Language subtag canonicalization methods
//
public static String canonicalizeLanguage(String s) {
return AsciiUtil.toLowerString(s);
}
public static String canonicalizeExtlang(String s) {
return AsciiUtil.toLowerString(s);
}
public static String canonicalizeScript(String s) {
return AsciiUtil.toTitleString(s);
}
public static String canonicalizeRegion(String s) {
return AsciiUtil.toUpperString(s);
}
public static String canonicalizeVariant(String s) {
return AsciiUtil.toLowerString(s);
}
public static String canonicalizeExtension(String s) {
return AsciiUtil.toLowerString(s);
}
public static String canonicalizeExtensionSingleton(String s) {
return AsciiUtil.toLowerString(s);
}
public static String canonicalizeExtensionSubtag(String s) {
return AsciiUtil.toLowerString(s);
}
public static String canonicalizePrivateuse(String s) {
return AsciiUtil.toLowerString(s);
}
public static String canonicalizePrivateuseSubtag(String s) {
return AsciiUtil.toLowerString(s);
}
public String toString() {
StringBuilder sb = new StringBuilder();
if (_language.length() > 0) {
sb.append(_language);
for (String extlang : _extlangs) {
sb.append(SEP).append(extlang);
}
if (_script.length() > 0) {
sb.append(SEP).append(_script);
}
if (_region.length() > 0) {
sb.append(SEP).append(_region);
}
for (String variant : _extlangs) {
sb.append(SEP).append(variant);
}
for (String extension : _extensions) {
sb.append(SEP).append(extension);
}
}
if (_privateuse.length() > 0) {
if (sb.length() > 0) {
sb.append(SEP);
}
sb.append(_privateuse);
}
return sb.toString();
}
}

View file

@ -0,0 +1,221 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
import com.ibm.icu.impl.locale.InternalLocaleBuilder.CaseInsensitiveChar;
import com.ibm.icu.impl.locale.InternalLocaleBuilder.CaseInsensitiveString;
public class LocaleExtensions {
private SortedMap<Character, Extension> _map;
private String _id;
private static final SortedMap<Character, Extension> EMPTY_MAP =
Collections.unmodifiableSortedMap(new TreeMap<Character, Extension>());
public static final LocaleExtensions EMPTY_EXTENSIONS;
public static final LocaleExtensions CALENDAR_JAPANESE;
public static final LocaleExtensions NUMBER_THAI;
static {
EMPTY_EXTENSIONS = new LocaleExtensions();
EMPTY_EXTENSIONS._id = "";
EMPTY_EXTENSIONS._map = EMPTY_MAP;
CALENDAR_JAPANESE = new LocaleExtensions();
CALENDAR_JAPANESE._id = "u-ca-japanese";
CALENDAR_JAPANESE._map = new TreeMap<Character, Extension>();
CALENDAR_JAPANESE._map.put(Character.valueOf(UnicodeLocaleExtension.SINGLETON), UnicodeLocaleExtension.CA_JAPANESE);
NUMBER_THAI = new LocaleExtensions();
NUMBER_THAI._id = "u-nu-thai";
NUMBER_THAI._map = new TreeMap<Character, Extension>();
NUMBER_THAI._map.put(Character.valueOf(UnicodeLocaleExtension.SINGLETON), UnicodeLocaleExtension.NU_THAI);
}
private LocaleExtensions() {
}
/*
* Package local constructor, only used by InternalLocaleBuilder.
*/
LocaleExtensions(Map<CaseInsensitiveChar, String> extensions,
Set<CaseInsensitiveString> uattributes, Map<CaseInsensitiveString, String> ukeywords) {
boolean hasExtension = (extensions != null && extensions.size() > 0);
boolean hasUAttributes = (uattributes != null && uattributes.size() > 0);
boolean hasUKeywords = (ukeywords != null && ukeywords.size() > 0);
if (!hasExtension && !hasUAttributes && !hasUKeywords) {
_map = EMPTY_MAP;
_id = "";
return;
}
// Build extension map
_map = new TreeMap<Character, Extension>();
if (hasExtension) {
for (Entry<CaseInsensitiveChar, String> ext : extensions.entrySet()) {
char key = AsciiUtil.toLower(ext.getKey().value());
String value = ext.getValue();
if (LanguageTag.isPrivateusePrefixChar(key)) {
// we need to exclude special variant in privuateuse, e.g. "x-abc-lvariant-DEF"
value = InternalLocaleBuilder.removePrivateuseVariant(value);
if (value == null) {
continue;
}
}
Extension e = new Extension(key, AsciiUtil.toLowerString(value));
_map.put(Character.valueOf(key), e);
}
}
if (hasUAttributes || hasUKeywords) {
TreeSet<String> uaset = null;
TreeMap<String, String> ukmap = null;
if (hasUAttributes) {
uaset = new TreeSet<String>();
for (CaseInsensitiveString cis : uattributes) {
uaset.add(AsciiUtil.toLowerString(cis.value()));
}
}
if (hasUKeywords) {
ukmap = new TreeMap<String, String>();
for (Entry<CaseInsensitiveString, String> kwd : ukeywords.entrySet()) {
String key = AsciiUtil.toLowerString(kwd.getKey().value());
String type = AsciiUtil.toLowerString(kwd.getValue());
ukmap.put(key, type);
}
}
UnicodeLocaleExtension ule = new UnicodeLocaleExtension(uaset, ukmap);
_map.put(Character.valueOf(UnicodeLocaleExtension.SINGLETON), ule);
}
if (_map.size() == 0) {
// this could happen when only privuateuse with special variant
_map = EMPTY_MAP;
_id = "";
} else {
_id = toID(_map);
}
}
public Set<Character> getKeys() {
return Collections.unmodifiableSet(_map.keySet());
}
public Extension getExtension(Character key) {
return _map.get(Character.valueOf(AsciiUtil.toLower(key.charValue())));
}
public String getExtensionValue(Character key) {
Extension ext = _map.get(Character.valueOf(AsciiUtil.toLower(key.charValue())));
if (ext == null) {
return null;
}
return ext.getValue();
}
public Set<String> getUnicodeLocaleAttributes() {
Extension ext = _map.get(Character.valueOf(UnicodeLocaleExtension.SINGLETON));
if (ext == null) {
return Collections.emptySet();
}
assert (ext instanceof UnicodeLocaleExtension);
return ((UnicodeLocaleExtension)ext).getUnicodeLocaleAttributes();
}
public Set<String> getUnicodeLocaleKeys() {
Extension ext = _map.get(Character.valueOf(UnicodeLocaleExtension.SINGLETON));
if (ext == null) {
return Collections.emptySet();
}
assert (ext instanceof UnicodeLocaleExtension);
return ((UnicodeLocaleExtension)ext).getUnicodeLocaleKeys();
}
public String getUnicodeLocaleType(String unicodeLocaleKey) {
Extension ext = _map.get(Character.valueOf(UnicodeLocaleExtension.SINGLETON));
if (ext == null) {
return null;
}
assert (ext instanceof UnicodeLocaleExtension);
return ((UnicodeLocaleExtension)ext).getUnicodeLocaleType(AsciiUtil.toLowerString(unicodeLocaleKey));
}
public boolean isEmpty() {
return _map.isEmpty();
}
public static boolean isValidKey(char c) {
return LanguageTag.isExtensionSingletonChar(c) || LanguageTag.isPrivateusePrefixChar(c);
}
public static boolean isValidUnicodeLocaleKey(String ukey) {
return UnicodeLocaleExtension.isKey(ukey);
}
private static String toID(SortedMap<Character, Extension> map) {
StringBuilder buf = new StringBuilder();
Extension privuse = null;
for (Entry<Character, Extension> entry : map.entrySet()) {
char singleton = entry.getKey().charValue();
Extension extension = entry.getValue();
if (LanguageTag.isPrivateusePrefixChar(singleton)) {
privuse = extension;
} else {
if (buf.length() > 0) {
buf.append(LanguageTag.SEP);
}
buf.append(extension);
}
}
if (privuse != null) {
if (buf.length() > 0) {
buf.append(LanguageTag.SEP);
}
buf.append(privuse);
}
return buf.toString();
}
public String toString() {
return _id;
}
public String getID() {
return _id;
}
public int hashCode() {
return _id.hashCode();
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof LocaleExtensions)) {
return false;
}
return this._id.equals(((LocaleExtensions)other)._id);
}
}

View file

@ -0,0 +1,83 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.util.concurrent.ConcurrentHashMap;
public abstract class LocaleObjectCache<K, V> {
private ConcurrentHashMap<K, CacheEntry<K, V>> _map;
private ReferenceQueue<V> _queue = new ReferenceQueue<V>();
public LocaleObjectCache() {
this(16, 0.75f, 16);
}
public LocaleObjectCache(int initialCapacity, float loadFactor, int concurrencyLevel) {
_map = new ConcurrentHashMap<K, CacheEntry<K, V>>(initialCapacity, loadFactor, concurrencyLevel);
}
public V get(K key) {
V value = null;
cleanStaleEntries();
CacheEntry<K, V> entry = _map.get(key);
if (entry != null) {
value = entry.get();
}
if (value == null) {
key = normalizeKey(key);
V newVal = createObject(key);
if (key == null || newVal == null) {
// subclass must return non-null key/value object
return null;
}
CacheEntry<K, V> newEntry = new CacheEntry<K, V>(key, newVal, _queue);
while (value == null) {
cleanStaleEntries();
entry = _map.putIfAbsent(key, newEntry);
if (entry == null) {
value = newVal;
break;
} else {
value = entry.get();
}
}
}
return value;
}
@SuppressWarnings("unchecked")
private void cleanStaleEntries() {
CacheEntry<K, V> entry;
while ((entry = (CacheEntry<K, V>)_queue.poll()) != null) {
_map.remove(entry.getKey());
}
}
protected abstract V createObject(K key);
protected K normalizeKey(K key) {
return key;
}
private static class CacheEntry<K, V> extends SoftReference<V> {
private K _key;
CacheEntry(K key, V value, ReferenceQueue<V> queue) {
super(value, queue);
_key = key;
}
K getKey() {
return _key;
}
}
}

View file

@ -0,0 +1,27 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
public class LocaleSyntaxException extends Exception {
private static final long serialVersionUID = 1L;
private int _index = -1;
public LocaleSyntaxException(String msg) {
this(msg, 0);
}
public LocaleSyntaxException(String msg, int errorIndex) {
super(msg);
_index = errorIndex;
}
public int getErrorIndex() {
return _index;
}
}

View file

@ -0,0 +1,35 @@
/*
*******************************************************************************
* Copyright (C) 2010-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
public class ParseStatus {
int _parseLength = 0;
int _errorIndex = -1;
String _errorMsg = null;
public void reset() {
_parseLength = 0;
_errorIndex = -1;
_errorMsg = null;
}
public boolean isError() {
return (_errorIndex >= 0);
}
public int getErrorIndex() {
return _errorIndex;
}
public int getParseLength() {
return _parseLength;
}
public String getErrorMessage() {
return _errorMsg;
}
}

View file

@ -0,0 +1,93 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
public class StringTokenIterator {
private String _text;
private String _dlms;
private String _token;
private int _start;
private int _end;
private boolean _done;
public StringTokenIterator(String text, String dlms) {
_text = text;
_dlms = dlms;
setStart(0);
}
public String first() {
setStart(0);
return _token;
}
public String current() {
return _token;
}
public int currentStart() {
return _start;
}
public int currentEnd() {
return _end;
}
public boolean isDone() {
return _done;
}
public String next() {
if (hasNext()) {
_start = _end + 1;
_end = nextDelimiter(_start);
_token = _text.substring(_start, _end);
} else {
_start = _end;
_token = null;
_done = true;
}
return _token;
}
public boolean hasNext() {
return (_end < _text.length());
}
public StringTokenIterator setStart(int offset) {
if (offset > _text.length()) {
throw new IndexOutOfBoundsException();
}
_start = offset;
_end = nextDelimiter(_start);
_token = _text.substring(_start, _end);
_done = false;
return this;
}
public StringTokenIterator setText(String text) {
_text = text;
setStart(0);
return this;
}
private int nextDelimiter(int start) {
int idx = start;
outer: while (idx < _text.length()) {
char c = _text.charAt(idx);
for (int i = 0; i < _dlms.length(); i++) {
if (c == _dlms.charAt(i)) {
break outer;
}
}
idx++;
}
return idx;
}
}

View file

@ -0,0 +1,102 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.impl.locale;
import java.util.Collections;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
public class UnicodeLocaleExtension extends Extension {
public static final char SINGLETON = 'u';
private static final SortedSet<String> EMPTY_SORTED_SET = new TreeSet<String>();
private static final SortedMap<String, String> EMPTY_SORTED_MAP = new TreeMap<String, String>();
private SortedSet<String> _attributes = EMPTY_SORTED_SET;
private SortedMap<String, String> _keywords = EMPTY_SORTED_MAP;
public static final UnicodeLocaleExtension CA_JAPANESE;
public static final UnicodeLocaleExtension NU_THAI;
static {
CA_JAPANESE = new UnicodeLocaleExtension();
CA_JAPANESE._keywords = new TreeMap<String, String>();
CA_JAPANESE._keywords.put("ca", "japanese");
CA_JAPANESE._value = "ca-japanese";
NU_THAI = new UnicodeLocaleExtension();
NU_THAI._keywords = new TreeMap<String, String>();
NU_THAI._keywords.put("nu", "thai");
NU_THAI._value = "nu-thai";
}
private UnicodeLocaleExtension() {
super(SINGLETON);
}
UnicodeLocaleExtension(SortedSet<String> attributes, SortedMap<String, String> keywords) {
this();
if (attributes != null && attributes.size() > 0) {
_attributes = attributes;
}
if (keywords != null && keywords.size() > 0) {
_keywords = keywords;
}
if (_attributes.size() > 0 || _keywords.size() > 0) {
StringBuilder sb = new StringBuilder();
for (String attribute : _attributes) {
sb.append(LanguageTag.SEP).append(attribute);
}
for (Entry<String, String> keyword : _keywords.entrySet()) {
String key = keyword.getKey();
String value = keyword.getValue();
sb.append(LanguageTag.SEP).append(key);
if (value.length() > 0) {
sb.append(LanguageTag.SEP).append(value);
}
}
_value = sb.substring(1); // skip leading '-'
}
}
public Set<String> getUnicodeLocaleAttributes() {
return Collections.unmodifiableSet(_attributes);
}
public Set<String> getUnicodeLocaleKeys() {
return Collections.unmodifiableSet(_keywords.keySet());
}
public String getUnicodeLocaleType(String unicodeLocaleKey) {
return _keywords.get(unicodeLocaleKey);
}
public static boolean isSingletonChar(char c) {
return (SINGLETON == AsciiUtil.toLower(c));
}
public static boolean isAttribute(String s) {
// 3*8alphanum
return (s.length() >= 3) && (s.length() <= 8) && AsciiUtil.isAlphaNumericString(s);
}
public static boolean isKey(String s) {
// 2alphanum
return (s.length() == 2) && AsciiUtil.isAlphaNumericString(s);
}
public static boolean isTypeSubtag(String s) {
// 3*8alphanum
return (s.length() >= 3) && (s.length() <= 8) && AsciiUtil.isAlphaNumericString(s);
}
}

View file

@ -1,14 +1,14 @@
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class BidiClassifier {
private BidiClassifier() {}
}
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class BidiClassifier {
private BidiClassifier() {}
}

View file

@ -1,14 +1,14 @@
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class BidiRun {
private BidiRun() {}
}
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class BidiRun {
private BidiRun() {}
}

View file

@ -1,415 +1,415 @@
/**
*******************************************************************************
* Copyright (C) 1996-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/**
* <p>A <code>CollationKey</code> represents a <code>String</code>
* under the rules of a specific <code>Collator</code>
* object. Comparing two <code>CollationKey</code>s returns the
* relative order of the <code>String</code>s they represent.</p>
*
* <p>Since the rule set of <code>Collator</code>s can differ, the
* sort orders of the same string under two different
* <code>Collator</code>s might differ. Hence comparing
* <code>CollationKey</code>s generated from different
* <code>Collator</code>s can give incorrect results.</p>
* <p>Both the method
* <code>CollationKey.compareTo(CollationKey)</code> and the method
* <code>Collator.compare(String, String)</code> compare two strings
* and returns their relative order. The performance characterictics
* of these two approaches can differ.</p>
*
* <p>During the construction of a <code>CollationKey</code>, the
* entire source string is examined and processed into a series of
* bits terminated by a null, that are stored in the <code>CollationKey</code>.
* When <code>CollationKey.compareTo(CollationKey)</code> executes, it
* performs bitwise comparison on the bit sequences. This can incurs
* startup cost when creating the <code>CollationKey</code>, 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.</p>
*
* <p>On the other hand, implementations of
* <code>Collator.compare(String, String)</code> 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.</p>
*
* <p>More information about the composition of the bit sequence can
* be found in the
* <a href="http://www.icu-project.org/userguide/Collate_ServiceArchitecture.html">
* user guide</a>.</p>
*
* <p>The following example shows how <code>CollationKey</code>s can be used
* to sort a list of <code>String</code>s.</p>
* <blockquote>
* <pre>
* // 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 );
* <br>
* //...
* <br>
* // Inside body of sort routine, compare keys this way
* if( keys[i].compareTo( keys[j] ) > 0 )
* // swap keys[i] and keys[j]
* <br>
* //...
* <br>
* // 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() );
* </pre>
* </blockquote>
* </p>
* <p>
* This class is not subclassable
* </p>
* @see Collator
* @see RuleBasedCollator
* @author Syn Wee Quek
* @stable ICU 2.8
*/
public final class CollationKey implements Comparable<CollationKey>
{
/**
* @internal
*/
final java.text.CollationKey key;
/**
* @internal
*/
CollationKey(java.text.CollationKey delegate) {
this.key = delegate;
}
// public inner classes -------------------------------------------------
/**
* Options that used in the API CollationKey.getBound() for getting a
* CollationKey based on the bound mode requested.
* @stable ICU 2.6
*/
public static final class BoundMode
{
/*
* do not change the values assigned to the members of this enum.
* Underlying code depends on them having these numbers
*/
/**
* Lower bound
* @stable ICU 2.6
*/
public static final int LOWER = 0;
/**
* Upper bound that will match strings of exact size
* @stable ICU 2.6
*/
public static final int UPPER = 1;
/**
* Upper bound that will match all the strings that have the same
* initial substring as the given string
* @stable ICU 2.6
*/
public static final int UPPER_LONG = 2;
/**
* Number of bound mode
* @stable ICU 2.6
*/
public static final int COUNT = 3;
/**
* Private Constructor
*/
///CLOVER:OFF
private BoundMode(){}
///CLOVER:ON
}
// public constructor ---------------------------------------------------
/**
* CollationKey constructor.
* This constructor is given public access, unlike the JDK version, to
* allow access to users extending the Collator class. See
* {@link Collator#getCollationKey(String)}.
* @param source string this CollationKey is to represent
* @param key array of bytes that represent the collation order of argument
* source terminated by a null
* @see Collator
* @stable ICU 2.8
*/
public CollationKey(String source, byte key[])
{
throw new UnsupportedOperationException("Constructor not supported by com.ibm.icu.base");
}
/**
* CollationKey constructor that forces key to release its internal byte
* array for adoption. key will have a null byte array after this
* construction.
* @param source string this CollationKey is to represent
* @param key RawCollationKey object that represents the collation order of
* argument source.
* @see Collator
* @see RawCollationKey
* @stable ICU 2.8
*/
public CollationKey(String source, RawCollationKey key)
{
throw new UnsupportedOperationException("Constructor not supported by com.ibm.icu.base");
}
// public getters -------------------------------------------------------
/**
* 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();
}
/**
* <p>Duplicates and returns the value of this CollationKey as a sequence
* of big-endian bytes terminated by a null.</p>
*
* <p>If two CollationKeys can be legitimately compared, then one can
* compare the byte arrays of each to obtain the same result, e.g.
* <pre>
* 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 &lt; targetkey) {
* System.out.println("String 1 is less than string 2");
* return;
* }
* if (targetkey &lt; key) {
* System.out.println("String 1 is more than string 2");
* }
* i ++;
* } while (key != 0 && targetKey != 0);
*
* System.out.println("Strings are equal.");
* </pre>
* </p>
* @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();
}
// public other methods -------------------------------------------------
/**
* <p>Compare this CollationKey to another CollationKey. The
* collation rules of the Collator that created this key are
* applied.</p>
*
* <p><strong>Note:</strong> Comparison between CollationKeys
* created by different Collators might return incorrect
* results. See class documentation.</p>
*
* @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);
}
/**
* <p>Compare this CollationKey and the specified Object for
* equality. The collation rules of the Collator that created
* this key are applied.</p>
*
* <p>See note in compareTo(CollationKey) for warnings about
* possible incorrect results.</p>
*
* @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)
{
if (!(target instanceof CollationKey)) {
return false;
}
return equals((CollationKey)target);
}
/**
* <p>
* Compare this CollationKey and the argument target CollationKey for
* equality.
* The collation
* rules of the Collator object which created these objects are applied.
* </p>
* <p>
* See note in compareTo(CollationKey) for warnings of incorrect results
* </p>
* @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);
}
/**
* <p>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.
* </p>
* @return the hash value.
* @stable ICU 2.8
*/
public int hashCode()
{
return key.hashCode();
}
/**
* <p>
* Produce a bound for the sort order of a given collation key and a
* strength level. This API does not attempt to find a bound for the
* CollationKey String representation, hence null will be returned in its
* place.
* </p>
* <p>
* Resulting bounds can be used to produce a range of strings that are
* between upper and lower bounds. For example, if bounds are produced
* for a sortkey of string "smith", strings between upper and lower
* bounds with primary strength would include "Smith", "SMITH", "sMiTh".
* </p>
* <p>
* There are two upper bounds that can be produced. If BoundMode.UPPER
* is produced, strings matched would be as above. However, if a bound
* is produced using BoundMode.UPPER_LONG is used, the above example will
* also match "Smithsonian" and similar.
* </p>
* <p>
* For more on usage, see example in test procedure
* <a href="http://source.icu-project.org/repos/icu/icu4j/trunk/src/com/ibm/icu/dev/test/collator/CollationAPITest.java">
* src/com/ibm/icu/dev/test/collator/CollationAPITest/TestBounds.
* </a>
* </p>
* <p>
* Collation keys produced may be compared using the <TT>compare</TT> API.
* </p>
* @param boundType Mode of bound required. It can be BoundMode.LOWER, which
* produces a lower inclusive bound, BoundMode.UPPER, that
* produces upper bound that matches strings of the same
* length or BoundMode.UPPER_LONG that matches strings that
* have the same starting substring as the source string.
* @param noOfLevels Strength levels required in the resulting bound
* (for most uses, the recommended value is PRIMARY). This
* strength should be less than the maximum strength of
* this CollationKey.
* See users guide for explanation on the strength levels a
* collation key can have.
* @return the result bounded CollationKey with a valid sort order but
* a null String representation.
* @exception IllegalArgumentException thrown when the strength level
* requested is higher than or equal to the strength in this
* CollationKey.
* In the case of an Exception, information
* about the maximum strength to use will be returned in the
* Exception. The user can then call getBound() again with the
* appropriate strength.
* @see CollationKey
* @see CollationKey.BoundMode
* @see Collator#PRIMARY
* @see Collator#SECONDARY
* @see Collator#TERTIARY
* @see Collator#QUATERNARY
* @see Collator#IDENTICAL
* @stable ICU 2.6
*/
public CollationKey getBound(int boundType, int noOfLevels)
{
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* <p>
* Merges this CollationKey with another. Only the sorting order of the
* CollationKeys will be merged. This API does not attempt to merge the
* String representations of the CollationKeys, hence null will be returned
* as the String representation.
* </p>
* <p>
* The strength levels are merged with their corresponding counterparts
* (PRIMARIES with PRIMARIES, SECONDARIES with SECONDARIES etc.).
* </p>
* <p>
* The merged String representation of the result CollationKey will be a
* concatenation of the String representations of the 2 source
* CollationKeys.
* </p>
* <p>
* Between the values from the same level a separator is inserted.
* example (uncompressed):
* <pre>
* 191B1D 01 050505 01 910505 00 and 1F2123 01 050505 01 910505 00
* will be merged as
* 191B1D 02 1F212301 050505 02 050505 01 910505 02 910505 00
* </pre>
* </p>
* <p>
* This allows for concatenating of first and last names for sorting, among
* other things.
* </p>
* </p>
* @param source CollationKey to merge with
* @return a CollationKey that contains the valid merged sorting order
* with a null String representation,
* i.e. <tt>new CollationKey(null, merge_sort_order)</tt>
* @exception IllegalArgumentException thrown if source CollationKey
* argument is null or of 0 length.
* @stable ICU 2.6
*/
public CollationKey merge(CollationKey source)
{
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
}
/**
*******************************************************************************
* Copyright (C) 1996-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/**
* <p>A <code>CollationKey</code> represents a <code>String</code>
* under the rules of a specific <code>Collator</code>
* object. Comparing two <code>CollationKey</code>s returns the
* relative order of the <code>String</code>s they represent.</p>
*
* <p>Since the rule set of <code>Collator</code>s can differ, the
* sort orders of the same string under two different
* <code>Collator</code>s might differ. Hence comparing
* <code>CollationKey</code>s generated from different
* <code>Collator</code>s can give incorrect results.</p>
* <p>Both the method
* <code>CollationKey.compareTo(CollationKey)</code> and the method
* <code>Collator.compare(String, String)</code> compare two strings
* and returns their relative order. The performance characterictics
* of these two approaches can differ.</p>
*
* <p>During the construction of a <code>CollationKey</code>, the
* entire source string is examined and processed into a series of
* bits terminated by a null, that are stored in the <code>CollationKey</code>.
* When <code>CollationKey.compareTo(CollationKey)</code> executes, it
* performs bitwise comparison on the bit sequences. This can incurs
* startup cost when creating the <code>CollationKey</code>, 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.</p>
*
* <p>On the other hand, implementations of
* <code>Collator.compare(String, String)</code> 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.</p>
*
* <p>More information about the composition of the bit sequence can
* be found in the
* <a href="http://www.icu-project.org/userguide/Collate_ServiceArchitecture.html">
* user guide</a>.</p>
*
* <p>The following example shows how <code>CollationKey</code>s can be used
* to sort a list of <code>String</code>s.</p>
* <blockquote>
* <pre>
* // 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 );
* <br>
* //...
* <br>
* // Inside body of sort routine, compare keys this way
* if( keys[i].compareTo( keys[j] ) > 0 )
* // swap keys[i] and keys[j]
* <br>
* //...
* <br>
* // 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() );
* </pre>
* </blockquote>
* </p>
* <p>
* This class is not subclassable
* </p>
* @see Collator
* @see RuleBasedCollator
* @author Syn Wee Quek
* @stable ICU 2.8
*/
public final class CollationKey implements Comparable<CollationKey>
{
/**
* @internal
*/
final java.text.CollationKey key;
/**
* @internal
*/
CollationKey(java.text.CollationKey delegate) {
this.key = delegate;
}
// public inner classes -------------------------------------------------
/**
* Options that used in the API CollationKey.getBound() for getting a
* CollationKey based on the bound mode requested.
* @stable ICU 2.6
*/
public static final class BoundMode
{
/*
* do not change the values assigned to the members of this enum.
* Underlying code depends on them having these numbers
*/
/**
* Lower bound
* @stable ICU 2.6
*/
public static final int LOWER = 0;
/**
* Upper bound that will match strings of exact size
* @stable ICU 2.6
*/
public static final int UPPER = 1;
/**
* Upper bound that will match all the strings that have the same
* initial substring as the given string
* @stable ICU 2.6
*/
public static final int UPPER_LONG = 2;
/**
* Number of bound mode
* @stable ICU 2.6
*/
public static final int COUNT = 3;
/**
* Private Constructor
*/
///CLOVER:OFF
private BoundMode(){}
///CLOVER:ON
}
// public constructor ---------------------------------------------------
/**
* CollationKey constructor.
* This constructor is given public access, unlike the JDK version, to
* allow access to users extending the Collator class. See
* {@link Collator#getCollationKey(String)}.
* @param source string this CollationKey is to represent
* @param key array of bytes that represent the collation order of argument
* source terminated by a null
* @see Collator
* @stable ICU 2.8
*/
public CollationKey(String source, byte key[])
{
throw new UnsupportedOperationException("Constructor not supported by com.ibm.icu.base");
}
/**
* CollationKey constructor that forces key to release its internal byte
* array for adoption. key will have a null byte array after this
* construction.
* @param source string this CollationKey is to represent
* @param key RawCollationKey object that represents the collation order of
* argument source.
* @see Collator
* @see RawCollationKey
* @stable ICU 2.8
*/
public CollationKey(String source, RawCollationKey key)
{
throw new UnsupportedOperationException("Constructor not supported by com.ibm.icu.base");
}
// public getters -------------------------------------------------------
/**
* 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();
}
/**
* <p>Duplicates and returns the value of this CollationKey as a sequence
* of big-endian bytes terminated by a null.</p>
*
* <p>If two CollationKeys can be legitimately compared, then one can
* compare the byte arrays of each to obtain the same result, e.g.
* <pre>
* 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 &lt; targetkey) {
* System.out.println("String 1 is less than string 2");
* return;
* }
* if (targetkey &lt; key) {
* System.out.println("String 1 is more than string 2");
* }
* i ++;
* } while (key != 0 && targetKey != 0);
*
* System.out.println("Strings are equal.");
* </pre>
* </p>
* @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();
}
// public other methods -------------------------------------------------
/**
* <p>Compare this CollationKey to another CollationKey. The
* collation rules of the Collator that created this key are
* applied.</p>
*
* <p><strong>Note:</strong> Comparison between CollationKeys
* created by different Collators might return incorrect
* results. See class documentation.</p>
*
* @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);
}
/**
* <p>Compare this CollationKey and the specified Object for
* equality. The collation rules of the Collator that created
* this key are applied.</p>
*
* <p>See note in compareTo(CollationKey) for warnings about
* possible incorrect results.</p>
*
* @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)
{
if (!(target instanceof CollationKey)) {
return false;
}
return equals((CollationKey)target);
}
/**
* <p>
* Compare this CollationKey and the argument target CollationKey for
* equality.
* The collation
* rules of the Collator object which created these objects are applied.
* </p>
* <p>
* See note in compareTo(CollationKey) for warnings of incorrect results
* </p>
* @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);
}
/**
* <p>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.
* </p>
* @return the hash value.
* @stable ICU 2.8
*/
public int hashCode()
{
return key.hashCode();
}
/**
* <p>
* Produce a bound for the sort order of a given collation key and a
* strength level. This API does not attempt to find a bound for the
* CollationKey String representation, hence null will be returned in its
* place.
* </p>
* <p>
* Resulting bounds can be used to produce a range of strings that are
* between upper and lower bounds. For example, if bounds are produced
* for a sortkey of string "smith", strings between upper and lower
* bounds with primary strength would include "Smith", "SMITH", "sMiTh".
* </p>
* <p>
* There are two upper bounds that can be produced. If BoundMode.UPPER
* is produced, strings matched would be as above. However, if a bound
* is produced using BoundMode.UPPER_LONG is used, the above example will
* also match "Smithsonian" and similar.
* </p>
* <p>
* For more on usage, see example in test procedure
* <a href="http://source.icu-project.org/repos/icu/icu4j/trunk/src/com/ibm/icu/dev/test/collator/CollationAPITest.java">
* src/com/ibm/icu/dev/test/collator/CollationAPITest/TestBounds.
* </a>
* </p>
* <p>
* Collation keys produced may be compared using the <TT>compare</TT> API.
* </p>
* @param boundType Mode of bound required. It can be BoundMode.LOWER, which
* produces a lower inclusive bound, BoundMode.UPPER, that
* produces upper bound that matches strings of the same
* length or BoundMode.UPPER_LONG that matches strings that
* have the same starting substring as the source string.
* @param noOfLevels Strength levels required in the resulting bound
* (for most uses, the recommended value is PRIMARY). This
* strength should be less than the maximum strength of
* this CollationKey.
* See users guide for explanation on the strength levels a
* collation key can have.
* @return the result bounded CollationKey with a valid sort order but
* a null String representation.
* @exception IllegalArgumentException thrown when the strength level
* requested is higher than or equal to the strength in this
* CollationKey.
* In the case of an Exception, information
* about the maximum strength to use will be returned in the
* Exception. The user can then call getBound() again with the
* appropriate strength.
* @see CollationKey
* @see CollationKey.BoundMode
* @see Collator#PRIMARY
* @see Collator#SECONDARY
* @see Collator#TERTIARY
* @see Collator#QUATERNARY
* @see Collator#IDENTICAL
* @stable ICU 2.6
*/
public CollationKey getBound(int boundType, int noOfLevels)
{
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* <p>
* Merges this CollationKey with another. Only the sorting order of the
* CollationKeys will be merged. This API does not attempt to merge the
* String representations of the CollationKeys, hence null will be returned
* as the String representation.
* </p>
* <p>
* The strength levels are merged with their corresponding counterparts
* (PRIMARIES with PRIMARIES, SECONDARIES with SECONDARIES etc.).
* </p>
* <p>
* The merged String representation of the result CollationKey will be a
* concatenation of the String representations of the 2 source
* CollationKeys.
* </p>
* <p>
* Between the values from the same level a separator is inserted.
* example (uncompressed):
* <pre>
* 191B1D 01 050505 01 910505 00 and 1F2123 01 050505 01 910505 00
* will be merged as
* 191B1D 02 1F212301 050505 02 050505 01 910505 02 910505 00
* </pre>
* </p>
* <p>
* This allows for concatenating of first and last names for sorting, among
* other things.
* </p>
* </p>
* @param source CollationKey to merge with
* @return a CollationKey that contains the valid merged sorting order
* with a null String representation,
* i.e. <tt>new CollationKey(null, merge_sort_order)</tt>
* @exception IllegalArgumentException thrown if source CollationKey
* argument is null or of 0 length.
* @stable ICU 2.6
*/
public CollationKey merge(CollationKey source)
{
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
}

View file

@ -1,14 +1,14 @@
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class CurrencyPluralInfo {
private CurrencyPluralInfo() {}
}
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class CurrencyPluralInfo {
private CurrencyPluralInfo() {}
}

View file

@ -1,350 +1,350 @@
/*
*******************************************************************************
* Copyright (C) 1996-2011, 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 <code>DecimalFormat</code> to format
* numbers. <code>DecimalFormat</code> creates for itself an instance of
* <code>DecimalFormatSymbols</code> from its locale data. If you need to
* change any of these symbols, you can get the
* <code>DecimalFormatSymbols</code> object from your <code>DecimalFormat</code>
* and modify it.
*
* <p><strong>This is an enhanced version of <code>DecimalFormatSymbols</code> that
* is based on the standard version in the JDK. New or changed functionality
* is labeled
* <strong><font face=helvetica color=red>NEW</font></strong>.</strong>
*
* @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();
}
}
/*
*******************************************************************************
* Copyright (C) 1996-2011, 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 <code>DecimalFormat</code> to format
* numbers. <code>DecimalFormat</code> creates for itself an instance of
* <code>DecimalFormatSymbols</code> from its locale data. If you need to
* change any of these symbols, you can get the
* <code>DecimalFormatSymbols</code> object from your <code>DecimalFormat</code>
* and modify it.
*
* <p><strong>This is an enhanced version of <code>DecimalFormatSymbols</code> that
* is based on the standard version in the JDK. New or changed functionality
* is labeled
* <strong><font face=helvetica color=red>NEW</font></strong>.</strong>
*
* @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();
}
}

View file

@ -1,14 +1,14 @@
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class RawCollationKey {
private RawCollationKey() {}
}
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class RawCollationKey {
private RawCollationKey() {}
}

View file

@ -1,80 +1,80 @@
/*
*******************************************************************************
* Copyright (C) 2003-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
import java.text.Format;
import com.ibm.icu.util.ULocale;
/**
* An abstract class that extends {@link java.text.Format} to provide
* additional ICU protocol, specifically, the <tt>getLocale()</tt>
* API. All ICU format classes are subclasses of this class.
*
* @see com.ibm.icu.util.ULocale
* @author weiv
* @author Alan Liu
* @draft ICU 2.8 (retain)
* @provisional This API might change or be removed in a future release.
*/
public abstract class UFormat extends Format {
private static final long serialVersionUID = 1L;
/**
* @draft ICU 2.8 (retain)
* @provisional This API might change or be removed in a future release.
*/
public UFormat() {}
/**
* Return the locale that was used to create this object, or null.
* This may may differ from the locale requested at the time of
* this object's creation. For example, if an object is created
* for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
* drawn from <tt>en</tt> (the <i>actual</i> locale), and
* <tt>en_US</tt> may be the most specific locale that exists (the
* <i>valid</i> locale).
*
* <p>Note: This method will be implemented in ICU 3.0; ICU 2.8
* contains a partial preview implementation. The <i>actual</i>
* locale is returned correctly, but the <i>valid</i> locale is
* not, in most cases.
* @param type type of information requested, either {@link
* com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
* com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
* @return the information specified by <i>type</i>, or null if
* this object was not constructed from locale data.
* @see com.ibm.icu.util.ULocale
* @see com.ibm.icu.util.ULocale#VALID_LOCALE
* @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
* @draft ICU 2.8 (retain)
* @provisional This API might change or be removed in a future release.
*/
public final ULocale getLocale(ULocale.Type type) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Set information about the locales that were used to create this
* object. If the object was not constructed from locale data,
* both arguments should be set to null. Otherwise, neither
* should be null. The actual locale must be at the same level or
* less specific than the valid locale. This method is intended
* for use by factories or other entities that create objects of
* this class.
* @param valid the most specific locale containing any resource
* data, or null
* @param actual the locale containing data used to construct this
* object, or null
* @see com.ibm.icu.util.ULocale
* @see com.ibm.icu.util.ULocale#VALID_LOCALE
* @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
*/
final void setLocale(ULocale valid, ULocale actual) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
}
/*
*******************************************************************************
* Copyright (C) 2003-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
import java.text.Format;
import com.ibm.icu.util.ULocale;
/**
* An abstract class that extends {@link java.text.Format} to provide
* additional ICU protocol, specifically, the <tt>getLocale()</tt>
* API. All ICU format classes are subclasses of this class.
*
* @see com.ibm.icu.util.ULocale
* @author weiv
* @author Alan Liu
* @draft ICU 2.8 (retain)
* @provisional This API might change or be removed in a future release.
*/
public abstract class UFormat extends Format {
private static final long serialVersionUID = 1L;
/**
* @draft ICU 2.8 (retain)
* @provisional This API might change or be removed in a future release.
*/
public UFormat() {}
/**
* Return the locale that was used to create this object, or null.
* This may may differ from the locale requested at the time of
* this object's creation. For example, if an object is created
* for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
* drawn from <tt>en</tt> (the <i>actual</i> locale), and
* <tt>en_US</tt> may be the most specific locale that exists (the
* <i>valid</i> locale).
*
* <p>Note: This method will be implemented in ICU 3.0; ICU 2.8
* contains a partial preview implementation. The <i>actual</i>
* locale is returned correctly, but the <i>valid</i> locale is
* not, in most cases.
* @param type type of information requested, either {@link
* com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
* com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
* @return the information specified by <i>type</i>, or null if
* this object was not constructed from locale data.
* @see com.ibm.icu.util.ULocale
* @see com.ibm.icu.util.ULocale#VALID_LOCALE
* @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
* @draft ICU 2.8 (retain)
* @provisional This API might change or be removed in a future release.
*/
public final ULocale getLocale(ULocale.Type type) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Set information about the locales that were used to create this
* object. If the object was not constructed from locale data,
* both arguments should be set to null. Otherwise, neither
* should be null. The actual locale must be at the same level or
* less specific than the valid locale. This method is intended
* for use by factories or other entities that create objects of
* this class.
* @param valid the most specific locale containing any resource
* data, or null
* @param actual the locale containing data used to construct this
* object, or null
* @see com.ibm.icu.util.ULocale
* @see com.ibm.icu.util.ULocale#VALID_LOCALE
* @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
*/
final void setLocale(ULocale valid, ULocale actual) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
}

View file

@ -1,14 +1,14 @@
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class UnicodeSet {
private UnicodeSet() {}
}
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.text;
/*
* Empty stub
*/
public class UnicodeSet {
private UnicodeSet() {}
}

View file

@ -1,420 +1,420 @@
/**
*******************************************************************************
* Copyright (C) 2001-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.util;
import java.io.Serializable;
import java.text.ParsePosition;
import java.util.Date;
import java.util.Locale;
/**
* A class encapsulating a currency, as defined by ISO 4217. A
* <tt>Currency</tt> object can be created given a <tt>Locale</tt> or
* given an ISO 4217 code. Once created, the <tt>Currency</tt> object
* can return various data necessary to its proper display:
*
* <ul><li>A display symbol, for a specific locale
* <li>The number of fraction digits to display
* <li>A rounding increment
* </ul>
*
* The <tt>DecimalFormat</tt> class uses these data to display
* currencies.
*
* <p>Note: This class deliberately resembles
* <tt>java.util.Currency</tt> but it has a completely independent
* implementation, and adds features not present in the JDK.
* @author Alan Liu
* @stable ICU 2.2
*/
public class Currency implements Serializable {
private static final long serialVersionUID = 1L;
/**
* @internal
*/
public final java.util.Currency currency;
/**
* @internal
* @param delegate the NumberFormat to which to delegate
*/
public Currency(java.util.Currency delegate) {
this.currency = delegate;
}
/**
* Selector for getName() indicating a symbolic name for a
* currency, such as "$" for USD.
* @stable ICU 2.6
*/
public static final int SYMBOL_NAME = 0;
/**
* Selector for ucurr_getName indicating the long name for a
* currency, such as "US Dollar" for USD.
* @stable ICU 2.6
*/
public static final int LONG_NAME = 1;
/**
* Selector for getName() indicating the plural long name for a
* currency, such as "US dollar" for USD in "1 US dollar",
* and "US dollars" for USD in "2 US dollars".
* @stable ICU 4.2
*/
public static final int PLURAL_LONG_NAME = 2;
/**
* Returns a currency object for the default currency in the given
* locale.
* @param locale the locale
* @return the currency object for this locale
* @stable ICU 2.2
*/
public static Currency getInstance(Locale locale) {
return new Currency(java.util.Currency.getInstance(locale));
}
/**
* Returns a currency object for the default currency in the given
* locale.
* @stable ICU 3.2
*/
public static Currency getInstance(ULocale locale) {
return new Currency(java.util.Currency.getInstance(locale.toLocale()));
}
/**
* Returns an array of Strings which contain the currency
* identifiers that are valid for the given locale on the
* given date. If there are no such identifiers, returns null.
* Returned identifiers are in preference order.
* @param loc the locale for which to retrieve currency codes.
* @param d the date for which to retrieve currency codes for the given locale.
* @return The array of ISO currency codes.
* @stable ICU 4.0
*/
public static String[] getAvailableCurrencyCodes(ULocale loc, Date d) {
throw new UnsupportedOperationException("Method not supproted by com.ibm.icu.base");
}
/**
* Returns a currency object given an ISO 4217 3-letter code.
* @param theISOCode the iso code
* @return the currency for this iso code
* @throws NullPointerException if <code>theISOCode</code> is null.
* @throws IllegalArgumentException if <code>theISOCode</code> is not a
* 3-letter alpha code.
* @stable ICU 2.2
*/
public static Currency getInstance(String theISOCode) {
return new Currency(java.util.Currency.getInstance(theISOCode));
}
/**
* Registers a new currency for the provided locale. The returned object
* is a key that can be used to unregister this currency object.
* @param currency the currency to register
* @param locale the ulocale under which to register the currency
* @return a registry key that can be used to unregister this currency
* @see #unregister
* @stable ICU 3.2
*/
public static Object registerInstance(Currency currency, ULocale locale) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Unregister the currency associated with this key (obtained from
* registerInstance).
* @param registryKey the registry key returned from registerInstance
* @see #registerInstance
* @stable ICU 2.6
*/
public static boolean unregister(Object registryKey) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Return an array of the locales for which a currency
* is defined.
* @return an array of the available locales
* @stable ICU 2.2
*/
public static Locale[] getAvailableLocales() {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Return an array of the ulocales for which a currency
* is defined.
* @return an array of the available ulocales
* @stable ICU 3.2
*/
public static ULocale[] getAvailableULocales() {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Given a key and a locale, returns an array of values for the key for which data
* exists. If commonlyUsed is true, these are the values that typically are used
* with this locale, otherwise these are all values for which data exists.
* This is a common service API.
* <p>
* The only supported key is "currency", other values return an empty array.
* <p>
* Currency information is based on the region of the locale. If the locale does not
* indicate a region, {@link ULocale#addLikelySubtags(ULocale)} is used to infer a region,
* except for the 'und' locale.
* <p>
* If commonlyUsed is true, only the currencies known to be in use as of the current date
* are returned. When there are more than one, these are returned in preference order
* (typically, this occurs when a country is transitioning to a new currency, and the
* newer currency is preferred), see
* <a href="http://unicode.org/reports/tr35/#Supplemental_Currency_Data">Unicode TR#35 Sec. C1</a>.
* If commonlyUsed is false, all currencies ever used in any locale are returned, in no
* particular order.
*
* @param key key whose values to look up. the only recognized key is "currency"
* @param locale the locale
* @param commonlyUsed if true, return only values that are currently used in the locale.
* Otherwise returns all values.
* @return an array of values for the given key and the locale. If there is no data, the
* array will be empty.
* @stable ICU 4.2
*/
public static final String[] getKeywordValuesForLocale(String key, ULocale locale,
boolean commonlyUsed) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Return a hashcode for this currency.
* @stable ICU 2.2
*/
public int hashCode() {
return currency.hashCode();
}
/**
* Return true if rhs is a Currency instance,
* is non-null, and has the same currency code.
* @stable ICU 2.2
*/
public boolean equals(Object rhs) {
try {
return currency.equals(((Currency)rhs).currency);
}
catch (Exception e) {
return false;
}
}
/**
* Returns the ISO 4217 3-letter code for this currency object.
* @stable ICU 2.2
*/
public String getCurrencyCode() {
return currency.getCurrencyCode();
}
/**
* Convenience and compatibility override of getName that
* requests the symbol name.
* @see #getName
* @stable ICU 3.4
*/
public String getSymbol() {
return currency.getSymbol();
}
/**
* Convenience and compatibility override of getName that
* requests the symbol name.
* @param loc the Locale for the symbol
* @see #getName
* @stable ICU 3.4
*/
public String getSymbol(Locale loc) {
return currency.getSymbol(loc);
}
/**
* Convenience and compatibility override of getName that
* requests the symbol name.
* @param uloc the ULocale for the symbol
* @see #getName
* @stable ICU 3.4
*/
public String getSymbol(ULocale uloc) {
return currency.getSymbol(uloc.toLocale());
}
/**
* Returns the display name for the given currency in the
* given locale.
* This is a convenient method for
* getName(ULocale, int, boolean[]);
* @stable ICU 3.2
*/
public String getName(Locale locale,
int nameStyle,
boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the display name for the given currency in the
* given locale. For example, the display name for the USD
* currency object in the en_US locale is "$".
* @param locale locale in which to display currency
* @param nameStyle selector for which kind of name to return.
* The nameStyle should be either SYMBOL_NAME or
* LONG_NAME. Otherwise, throw IllegalArgumentException.
* @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true
* if the returned value is a ChoiceFormat pattern; otherwise it
* is set to false
* @return display string for this currency. If the resource data
* contains no entry for this currency, then the ISO 4217 code is
* returned. If isChoiceFormat[0] is true, then the result is a
* ChoiceFormat pattern. Otherwise it is a static string. <b>Note:</b>
* as of ICU 4.4, choice formats are not used, and the value returned
* in isChoiceFormat is always false.
* <p>
* @throws IllegalArgumentException if the nameStyle is not SYMBOL_NAME
* or LONG_NAME.
* @see #getName(ULocale, int, String, boolean[])
* @stable ICU 3.2
*/
public String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the display name for the given currency in the given locale.
* This is a convenience overload of getName(ULocale, int, String, boolean[]);
* @stable ICU 4.2
*/
public String getName(Locale locale, int nameStyle, String pluralCount,
boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the display name for the given currency in the
* given locale. For example, the SYMBOL_NAME for the USD
* currency object in the en_US locale is "$".
* The PLURAL_LONG_NAME for the USD currency object when the currency
* amount is plural is "US dollars", such as in "3.00 US dollars";
* while the PLURAL_LONG_NAME for the USD currency object when the currency
* amount is singular is "US dollar", such as in "1.00 US dollar".
* @param locale locale in which to display currency
* @param nameStyle selector for which kind of name to return
* @param pluralCount plural count string for this locale
* @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true
* if the returned value is a ChoiceFormat pattern; otherwise it
* is set to false
* @return display string for this currency. If the resource data
* contains no entry for this currency, then the ISO 4217 code is
* returned. If isChoiceFormat[0] is true, then the result is a
* ChoiceFormat pattern. Otherwise it is a static string. <b>Note:</b>
* as of ICU 4.4, choice formats are not used, and the value returned
* in isChoiceFormat is always false.
* @throws IllegalArgumentException if the nameStyle is not SYMBOL_NAME,
* LONG_NAME, or PLURAL_LONG_NAME.
* @stable ICU 4.2
*/
public String getName(ULocale locale, int nameStyle, String pluralCount,
boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Attempt to parse the given string as a currency, either as a
* display name in the given locale, or as a 3-letter ISO 4217
* code. If multiple display names match, then the longest one is
* selected. If both a display name and a 3-letter ISO code
* match, then the display name is preferred, unless it's length
* is less than 3.
*
* @param locale the locale of the display names to match
* @param text the text to parse
* @param type parse against currency type: LONG_NAME only or not
* @param pos input-output position; on input, the position within
* text to match; must have 0 <= pos.getIndex() < text.length();
* on output, the position after the last matched character. If
* the parse fails, the position in unchanged upon output.
* @return the ISO 4217 code, as a string, of the best match, or
* null if there is no match
*
* @internal
* @deprecated This API is ICU internal only.
*/
public static String parse(ULocale locale, String text, int type, ParsePosition pos) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the number of the number of fraction digits that should
* be displayed for this currency.
* @return a non-negative number of fraction digits to be
* displayed
* @stable ICU 2.2
*/
public int getDefaultFractionDigits() {
return currency.getDefaultFractionDigits();
}
/**
* Returns the rounding increment for this currency, or 0.0 if no
* rounding is done by this currency.
* @return the non-negative rounding increment, or 0.0 if none
* @stable ICU 2.2
*/
public double getRoundingIncrement() {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the ISO 4217 code for this currency.
* @stable ICU 2.2
*/
public String toString() {
return currency.toString();
}
/**
* Return the locale that was used to create this object, or null.
* This may may differ from the locale requested at the time of
* this object's creation. For example, if an object is created
* for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
* drawn from <tt>en</tt> (the <i>actual</i> locale), and
* <tt>en_US</tt> may be the most specific locale that exists (the
* <i>valid</i> locale).
*
* <p>Note: This method will be obsoleted. The implementation is
* no longer locale-specific and so there is no longer a valid or
* actual locale associated with the Currency object. Until
* it is removed, this method will return the root locale.
* @param type type of information requested, either {@link
* com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
* com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
* @return the information specified by <i>type</i>, or null if
* this object was not constructed from locale data.
* @see com.ibm.icu.util.ULocale
* @see com.ibm.icu.util.ULocale#VALID_LOCALE
* @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
* @obsolete ICU 3.2 to be removed
* @deprecated This API is obsolete.
*/
public final ULocale getLocale(ULocale.Type type) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
}
//eof
/**
*******************************************************************************
* Copyright (C) 2001-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.util;
import java.io.Serializable;
import java.text.ParsePosition;
import java.util.Date;
import java.util.Locale;
/**
* A class encapsulating a currency, as defined by ISO 4217. A
* <tt>Currency</tt> object can be created given a <tt>Locale</tt> or
* given an ISO 4217 code. Once created, the <tt>Currency</tt> object
* can return various data necessary to its proper display:
*
* <ul><li>A display symbol, for a specific locale
* <li>The number of fraction digits to display
* <li>A rounding increment
* </ul>
*
* The <tt>DecimalFormat</tt> class uses these data to display
* currencies.
*
* <p>Note: This class deliberately resembles
* <tt>java.util.Currency</tt> but it has a completely independent
* implementation, and adds features not present in the JDK.
* @author Alan Liu
* @stable ICU 2.2
*/
public class Currency implements Serializable {
private static final long serialVersionUID = 1L;
/**
* @internal
*/
public final java.util.Currency currency;
/**
* @internal
* @param delegate the NumberFormat to which to delegate
*/
public Currency(java.util.Currency delegate) {
this.currency = delegate;
}
/**
* Selector for getName() indicating a symbolic name for a
* currency, such as "$" for USD.
* @stable ICU 2.6
*/
public static final int SYMBOL_NAME = 0;
/**
* Selector for ucurr_getName indicating the long name for a
* currency, such as "US Dollar" for USD.
* @stable ICU 2.6
*/
public static final int LONG_NAME = 1;
/**
* Selector for getName() indicating the plural long name for a
* currency, such as "US dollar" for USD in "1 US dollar",
* and "US dollars" for USD in "2 US dollars".
* @stable ICU 4.2
*/
public static final int PLURAL_LONG_NAME = 2;
/**
* Returns a currency object for the default currency in the given
* locale.
* @param locale the locale
* @return the currency object for this locale
* @stable ICU 2.2
*/
public static Currency getInstance(Locale locale) {
return new Currency(java.util.Currency.getInstance(locale));
}
/**
* Returns a currency object for the default currency in the given
* locale.
* @stable ICU 3.2
*/
public static Currency getInstance(ULocale locale) {
return new Currency(java.util.Currency.getInstance(locale.toLocale()));
}
/**
* Returns an array of Strings which contain the currency
* identifiers that are valid for the given locale on the
* given date. If there are no such identifiers, returns null.
* Returned identifiers are in preference order.
* @param loc the locale for which to retrieve currency codes.
* @param d the date for which to retrieve currency codes for the given locale.
* @return The array of ISO currency codes.
* @stable ICU 4.0
*/
public static String[] getAvailableCurrencyCodes(ULocale loc, Date d) {
throw new UnsupportedOperationException("Method not supproted by com.ibm.icu.base");
}
/**
* Returns a currency object given an ISO 4217 3-letter code.
* @param theISOCode the iso code
* @return the currency for this iso code
* @throws NullPointerException if <code>theISOCode</code> is null.
* @throws IllegalArgumentException if <code>theISOCode</code> is not a
* 3-letter alpha code.
* @stable ICU 2.2
*/
public static Currency getInstance(String theISOCode) {
return new Currency(java.util.Currency.getInstance(theISOCode));
}
/**
* Registers a new currency for the provided locale. The returned object
* is a key that can be used to unregister this currency object.
* @param currency the currency to register
* @param locale the ulocale under which to register the currency
* @return a registry key that can be used to unregister this currency
* @see #unregister
* @stable ICU 3.2
*/
public static Object registerInstance(Currency currency, ULocale locale) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Unregister the currency associated with this key (obtained from
* registerInstance).
* @param registryKey the registry key returned from registerInstance
* @see #registerInstance
* @stable ICU 2.6
*/
public static boolean unregister(Object registryKey) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Return an array of the locales for which a currency
* is defined.
* @return an array of the available locales
* @stable ICU 2.2
*/
public static Locale[] getAvailableLocales() {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Return an array of the ulocales for which a currency
* is defined.
* @return an array of the available ulocales
* @stable ICU 3.2
*/
public static ULocale[] getAvailableULocales() {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Given a key and a locale, returns an array of values for the key for which data
* exists. If commonlyUsed is true, these are the values that typically are used
* with this locale, otherwise these are all values for which data exists.
* This is a common service API.
* <p>
* The only supported key is "currency", other values return an empty array.
* <p>
* Currency information is based on the region of the locale. If the locale does not
* indicate a region, {@link ULocale#addLikelySubtags(ULocale)} is used to infer a region,
* except for the 'und' locale.
* <p>
* If commonlyUsed is true, only the currencies known to be in use as of the current date
* are returned. When there are more than one, these are returned in preference order
* (typically, this occurs when a country is transitioning to a new currency, and the
* newer currency is preferred), see
* <a href="http://unicode.org/reports/tr35/#Supplemental_Currency_Data">Unicode TR#35 Sec. C1</a>.
* If commonlyUsed is false, all currencies ever used in any locale are returned, in no
* particular order.
*
* @param key key whose values to look up. the only recognized key is "currency"
* @param locale the locale
* @param commonlyUsed if true, return only values that are currently used in the locale.
* Otherwise returns all values.
* @return an array of values for the given key and the locale. If there is no data, the
* array will be empty.
* @stable ICU 4.2
*/
public static final String[] getKeywordValuesForLocale(String key, ULocale locale,
boolean commonlyUsed) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Return a hashcode for this currency.
* @stable ICU 2.2
*/
public int hashCode() {
return currency.hashCode();
}
/**
* Return true if rhs is a Currency instance,
* is non-null, and has the same currency code.
* @stable ICU 2.2
*/
public boolean equals(Object rhs) {
try {
return currency.equals(((Currency)rhs).currency);
}
catch (Exception e) {
return false;
}
}
/**
* Returns the ISO 4217 3-letter code for this currency object.
* @stable ICU 2.2
*/
public String getCurrencyCode() {
return currency.getCurrencyCode();
}
/**
* Convenience and compatibility override of getName that
* requests the symbol name.
* @see #getName
* @stable ICU 3.4
*/
public String getSymbol() {
return currency.getSymbol();
}
/**
* Convenience and compatibility override of getName that
* requests the symbol name.
* @param loc the Locale for the symbol
* @see #getName
* @stable ICU 3.4
*/
public String getSymbol(Locale loc) {
return currency.getSymbol(loc);
}
/**
* Convenience and compatibility override of getName that
* requests the symbol name.
* @param uloc the ULocale for the symbol
* @see #getName
* @stable ICU 3.4
*/
public String getSymbol(ULocale uloc) {
return currency.getSymbol(uloc.toLocale());
}
/**
* Returns the display name for the given currency in the
* given locale.
* This is a convenient method for
* getName(ULocale, int, boolean[]);
* @stable ICU 3.2
*/
public String getName(Locale locale,
int nameStyle,
boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the display name for the given currency in the
* given locale. For example, the display name for the USD
* currency object in the en_US locale is "$".
* @param locale locale in which to display currency
* @param nameStyle selector for which kind of name to return.
* The nameStyle should be either SYMBOL_NAME or
* LONG_NAME. Otherwise, throw IllegalArgumentException.
* @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true
* if the returned value is a ChoiceFormat pattern; otherwise it
* is set to false
* @return display string for this currency. If the resource data
* contains no entry for this currency, then the ISO 4217 code is
* returned. If isChoiceFormat[0] is true, then the result is a
* ChoiceFormat pattern. Otherwise it is a static string. <b>Note:</b>
* as of ICU 4.4, choice formats are not used, and the value returned
* in isChoiceFormat is always false.
* <p>
* @throws IllegalArgumentException if the nameStyle is not SYMBOL_NAME
* or LONG_NAME.
* @see #getName(ULocale, int, String, boolean[])
* @stable ICU 3.2
*/
public String getName(ULocale locale, int nameStyle, boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the display name for the given currency in the given locale.
* This is a convenience overload of getName(ULocale, int, String, boolean[]);
* @stable ICU 4.2
*/
public String getName(Locale locale, int nameStyle, String pluralCount,
boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the display name for the given currency in the
* given locale. For example, the SYMBOL_NAME for the USD
* currency object in the en_US locale is "$".
* The PLURAL_LONG_NAME for the USD currency object when the currency
* amount is plural is "US dollars", such as in "3.00 US dollars";
* while the PLURAL_LONG_NAME for the USD currency object when the currency
* amount is singular is "US dollar", such as in "1.00 US dollar".
* @param locale locale in which to display currency
* @param nameStyle selector for which kind of name to return
* @param pluralCount plural count string for this locale
* @param isChoiceFormat fill-in; isChoiceFormat[0] is set to true
* if the returned value is a ChoiceFormat pattern; otherwise it
* is set to false
* @return display string for this currency. If the resource data
* contains no entry for this currency, then the ISO 4217 code is
* returned. If isChoiceFormat[0] is true, then the result is a
* ChoiceFormat pattern. Otherwise it is a static string. <b>Note:</b>
* as of ICU 4.4, choice formats are not used, and the value returned
* in isChoiceFormat is always false.
* @throws IllegalArgumentException if the nameStyle is not SYMBOL_NAME,
* LONG_NAME, or PLURAL_LONG_NAME.
* @stable ICU 4.2
*/
public String getName(ULocale locale, int nameStyle, String pluralCount,
boolean[] isChoiceFormat) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Attempt to parse the given string as a currency, either as a
* display name in the given locale, or as a 3-letter ISO 4217
* code. If multiple display names match, then the longest one is
* selected. If both a display name and a 3-letter ISO code
* match, then the display name is preferred, unless it's length
* is less than 3.
*
* @param locale the locale of the display names to match
* @param text the text to parse
* @param type parse against currency type: LONG_NAME only or not
* @param pos input-output position; on input, the position within
* text to match; must have 0 <= pos.getIndex() < text.length();
* on output, the position after the last matched character. If
* the parse fails, the position in unchanged upon output.
* @return the ISO 4217 code, as a string, of the best match, or
* null if there is no match
*
* @internal
* @deprecated This API is ICU internal only.
*/
public static String parse(ULocale locale, String text, int type, ParsePosition pos) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the number of the number of fraction digits that should
* be displayed for this currency.
* @return a non-negative number of fraction digits to be
* displayed
* @stable ICU 2.2
*/
public int getDefaultFractionDigits() {
return currency.getDefaultFractionDigits();
}
/**
* Returns the rounding increment for this currency, or 0.0 if no
* rounding is done by this currency.
* @return the non-negative rounding increment, or 0.0 if none
* @stable ICU 2.2
*/
public double getRoundingIncrement() {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
/**
* Returns the ISO 4217 code for this currency.
* @stable ICU 2.2
*/
public String toString() {
return currency.toString();
}
/**
* Return the locale that was used to create this object, or null.
* This may may differ from the locale requested at the time of
* this object's creation. For example, if an object is created
* for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
* drawn from <tt>en</tt> (the <i>actual</i> locale), and
* <tt>en_US</tt> may be the most specific locale that exists (the
* <i>valid</i> locale).
*
* <p>Note: This method will be obsoleted. The implementation is
* no longer locale-specific and so there is no longer a valid or
* actual locale associated with the Currency object. Until
* it is removed, this method will return the root locale.
* @param type type of information requested, either {@link
* com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
* com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
* @return the information specified by <i>type</i>, or null if
* this object was not constructed from locale data.
* @see com.ibm.icu.util.ULocale
* @see com.ibm.icu.util.ULocale#VALID_LOCALE
* @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
* @obsolete ICU 3.2 to be removed
* @deprecated This API is obsolete.
*/
public final ULocale getLocale(ULocale.Type type) {
throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base");
}
}
//eof

View file

@ -1,14 +1,14 @@
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.util;
/*
* Empty stub
*/
public class CurrencyAmount {
private CurrencyAmount() {}
}
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.util;
/*
* Empty stub
*/
public class CurrencyAmount {
private CurrencyAmount() {}
}

View file

@ -0,0 +1,73 @@
/*
*******************************************************************************
* Copyright (C) 2009-2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.util;
/**
* Thrown by methods in {@link ULocale} and {@link ULocale.Builder} to
* indicate that an argument is not a well-formed BCP 47 tag.
*
* @see ULocale
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public class IllformedLocaleException extends RuntimeException {
private static final long serialVersionUID = 1L;
private int _errIdx = -1;
/**
* Constructs a new <code>IllformedLocaleException</code> with no
* detail message and -1 as the error index.
* @draft ICU 4.6
* @provisional This API might change or be removed in a future release.
*/
public IllformedLocaleException() {
super();
}
/**
* Constructs a new <code>IllformedLocaleException</code> with the
* given message and -1 as the error index.
*
* @param message the message
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public IllformedLocaleException(String message) {
super(message);
}
/**
* Constructs a new <code>IllformedLocaleException</code> with the
* given message and the error index. The error index is the approximate
* offset from the start of the ill-formed value to the point where the
* parse first detected an error. A negative error index value indicates
* either the error index is not applicable or unknown.
*
* @param message the message
* @param errorIndex the index
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public IllformedLocaleException(String message, int errorIndex) {
super(message + ((errorIndex < 0) ? "" : " [at index " + errorIndex + "]"));
_errIdx = errorIndex;
}
/**
* Returns the index where the error was found. A negative value indicates
* either the error index is not applicable or unknown.
*
* @return the error index
* @draft ICU 4.2
* @provisional This API might change or be removed in a future release.
*/
public int getErrorIndex() {
return _errIdx;
}
}

View file

@ -1,14 +1,14 @@
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.util;
/*
* Empty stub
*/
public final class VersionInfo {
private VersionInfo() {}
}
/*
*******************************************************************************
* Copyright (C) 2011, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package com.ibm.icu.util;
/*
* Empty stub
*/
public final class VersionInfo {
private VersionInfo() {}
}

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:17 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:30 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:42 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:52 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:58 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:04 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:21 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:37 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:26 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -23,7 +23,7 @@
<echo message="source: ${javac.source}"/>
<echo message="target: ${javac.target}"/>
<echo message="debug: ${javac.debug}"/>
<echo message="encoding: ${javac.encoding}"/>
<echo message="encoding: ${java.src.encoding}"/>
<echo message="compiler arg: ${javac.compilerarg}"/>
<echo message="----------------------------------------------------"/>
@ -34,6 +34,7 @@
classpathref="javac.classpathref"
source="${javac.source}"
target="${javac.target}"
encoding="${java.src.encoding}"
debug="${javac.debug}">
<compilerarg value="${javac.compilerarg}"/>
</javac>

View file

@ -22,8 +22,8 @@ jar.dir = ${out.dir}/lib
javac.source = 1.5
javac.target = 1.5
javac.debug = on
javac.encoding = ascii
javac.compilerarg = -Xlint:none
java.src.encoding = UTF-8
# Manifest attributes
jar.spec.version = ${icu4j.spec.version}

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c35d58240ba0d7a92fce6316791c1808950d0a0ec01bc120174ae29aab9dace8
size 6991911
oid sha256:a27948afa5863dc9ba7a87f8514ac90bf79934f66f4c0f479ddf79cf243f7c4b
size 6992059

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:23 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:36 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:48:47 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:32 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:10 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:15 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:49:43 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:51:40 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,3 @@
#Wed Aug 31 03:51:30 EDT 2011
eclipse.preferences.version=1
encoding/<project>=UTF-8