diff --git a/.gitattributes b/.gitattributes index de08dc34cd2..034bb2e7bf9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -56,6 +56,7 @@ icu4c/source/test/testdata/iscii.bin -text icu4c/source/test/testdata/testdata_icu26_testtypes.res -text icu4c/source/test/testdata/testdata_icu26e_testtypes.res -text icu4c/source/test/testdata/uni-text.bin -text +icu4j/ee.foundation.jar -text icu4j/src/com/ibm/icu/dev/data/rbbi/english.dict -text icu4j/src/com/ibm/icu/dev/data/testdata.jar -text icu4j/src/com/ibm/icu/dev/data/thai6.ucs -text diff --git a/icu4c/source/tools/cpysearch/cpyskip.txt b/icu4c/source/tools/cpysearch/cpyskip.txt index 3f36eae9175..afc5968bf13 100644 --- a/icu4c/source/tools/cpysearch/cpyskip.txt +++ b/icu4c/source/tools/cpysearch/cpyskip.txt @@ -96,7 +96,9 @@ icu4j/src/com/ibm/icu/dev/data/unicode/ucdterms.txt icu4j/src/com/ibm/icu/dev/data/unicode/UnicodeData.txt icu4j/src/com/ibm/icu/dev/data/IDNATestInput.txt icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu/.classpath +icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu/.project icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/.classpath +icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/.project icu4j/src/com/ibm/icu/dev/test/serializable/*/*.dat icu4j/src/com/ibm/icu/dev/tool/ime/indic/services/java.awt.im.spi.InputMethodDescriptor icu4j/src/com/ibm/icu/dev/tool/ime/translit/services/java.awt.im.spi.InputMethodDescriptor diff --git a/icu4j/build.xml b/icu4j/build.xml index c1b82dc1eeb..f16291a9c7f 100644 --- a/icu4j/build.xml +++ b/icu4j/build.xml @@ -87,6 +87,7 @@ + @@ -263,13 +264,12 @@ - - - + + - + @@ -306,6 +306,16 @@ debug="on" deprecation="off"/> + + + + @@ -442,22 +452,6 @@ manifest="${icu4j.manifest}"/> - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/icu4j/eclipseCoreArgs.txt b/icu4j/eclipseCoreArgs.txt new file mode 100644 index 00000000000..263e950d218 --- /dev/null +++ b/icu4j/eclipseCoreArgs.txt @@ -0,0 +1,16 @@ +# Copyright (C) 2005, International Business Machines Corporation and +# others. All Rights Reserved. +src/com/ibm/icu/impl/CollectionUtilities.java +src/com/ibm/icu/impl/ICUResourceBundle.java +src/com/ibm/icu/impl/ICUResourceBundleImpl.java +src/com/ibm/icu/impl/ICUResourceBundleReader.java +src/com/ibm/icu/impl/Utility.java +src/com/ibm/icu/lang/UCharacter.java +src/com/ibm/icu/math/BigDecimal.java +src/com/ibm/icu/text/DecimalFormat.java +src/com/ibm/icu/text/DigitList.java +src/com/ibm/icu/text/NumberFormat.java +src/com/ibm/icu/text/RuleBasedCollator.java +src/com/ibm/icu/text/RuleBasedNumberFormat.java +src/com/ibm/icu/util/ByteArrayWrapper.java +src/com/ibm/icu/util/GlobalizationPreferences.java diff --git a/icu4j/eclipseTestArgs.txt b/icu4j/eclipseTestArgs.txt new file mode 100644 index 00000000000..aa7314dc4e5 --- /dev/null +++ b/icu4j/eclipseTestArgs.txt @@ -0,0 +1,10 @@ +# Copyright (C) 2005, International Business Machines Corporation and +# others. All Rights Reserved. +src/com/ibm/icu/dev/test/bigdec/DiagBigDecimal.java +src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java +src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java +src/com/ibm/icu/dev/test/format/NumberFormatTest.java +src/com/ibm/icu/dev/test/util/ICUResourceBundleTest.java +src/com/ibm/icu/dev/test/util/UtilityTest.java +src/com/ibm/icu/dev/test/TestAll.java + diff --git a/icu4j/ee.foundation.jar b/icu4j/ee.foundation.jar new file mode 100644 index 00000000000..60168e82209 --- /dev/null +++ b/icu4j/ee.foundation.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f730fd4a8ca71fcddc61a4f62490cea7805efffc7eb2b8669942f6d123f7249 +size 1059077 diff --git a/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/META-INF/MANIFEST.MF b/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..ceb6b211570 --- /dev/null +++ b/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ICU4J Tests +Bundle-SymbolicName: com.ibm.icu.tests +Bundle-Version: 3.4.1 +Bundle-Vendor: IBM +Bundle-Copyright: Licensed Materials - Property of IBM + (C) Copyright IBM Corp. 2000, 2005. All Rights Reserved. + IBM is a registered trademark of IBM Corp. +Bundle-Localization: plugin +Require-Bundle: org.junit, + com.ibm.icu +Bundle-ClassPath: icu4jtests.jar diff --git a/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/src/com/ibm/icu/tests/UnitTest.java b/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/src/com/ibm/icu/tests/UnitTest.java new file mode 100644 index 00000000000..e2776934953 --- /dev/null +++ b/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu.tests/src/com/ibm/icu/tests/UnitTest.java @@ -0,0 +1,170 @@ +/* + ****************************************************************************** + * Copyright (C) 2005, International Business Machines Corporation and * + * others. All Rights Reserved. * + ****************************************************************************** + */ +package com.ibm.icu.tests; + +import junit.framework.TestCase; +import com.ibm.icu.dev.test.TestAll; +import com.ibm.icu.dev.test.TestFmwk; +import com.ibm.icu.dev.test.TestFmwk.TestParams; +import com.ibm.icu.dev.test.TestFmwk.NullWriter; +import com.ibm.icu.dev.test.TestFmwk.ASCIIWriter; + +//import com.ibm.icu.text.DateFormat; +//import com.ibm.icu.util.Calendar; +//import com.ibm.icu.util.GregorianCalendar; +//import com.ibm.icu.util.TimeZone; +//import com.ibm.icu.util.ULocale; + +public class UnitTest extends TestCase { + +// public static void main(String[] args) throws Exception { +// String[] names = { +// "Calendar", "Collator", "Compression", "DiagBigDecimal", "Format", "Impl", +// "Normalizer", "Property", "RBBI", "SearchTest", "StringPrep", "TestCharsetDetector", +// "TestUCharacterIterator", "TimeScale", "TimeZone", "Translit", "Util", +// }; +// for (int i = 0; i < names.length; ++i) { +// String name = names[i]; +// System.out.println(); +// System.out.println("public void test" + name + "() throws Exception {"); +// System.out.println(" runUtility(\"" + name + "\");"); +// System.out.println("}"); +// } +// } + + public void testCalendar() throws Exception { + runUtility("Calendar"); + } + + public void testCollator() throws Exception { + runUtility("Collator"); + } + + public void testCompression() throws Exception { + runUtility("Compression"); + } + + public void testDiagBigDecimal() throws Exception { + runUtility("DiagBigDecimal"); + } + + public void testFormat() throws Exception { + runUtility("Format"); + } + + public void testImpl() throws Exception { + runUtility("Impl"); + } + + public void testNormalizer() throws Exception { + runUtility("Normalizer"); + } + + public void testProperty() throws Exception { + runUtility("Property"); + } + + public void testRBBI() throws Exception { + runUtility("RBBI"); + } + + public void testSearchTest() throws Exception { + runUtility("SearchTest"); + } + + public void testStringPrep() throws Exception { + runUtility("StringPrep"); + } + + public void testTestCharsetDetector() throws Exception { + runUtility("TestCharsetDetector"); + } + + public void testTestUCharacterIterator() throws Exception { + runUtility("TestUCharacterIterator"); + } + + public void testTimeScale() throws Exception { + runUtility("TimeScale"); + } + + public void testTimeZone() throws Exception { + runUtility("TimeZone"); + } + + public void testTranslit() throws Exception { + runUtility("Translit"); + } + + public void testUtil() throws Exception { + runUtility("Util"); + } + + public void runUtility(String testname) throws Exception { + TestParams params = new TestParams(); + params.nothrow = true; + params.log = new NullWriter(); + TestFmwk test = new TestAll(); + test.resolveTarget(params, testname).run(); + if (params.errorCount > 0) { + fail(params.errorSummary.toString()); + } + } + + // sample tests from ICU4J test suite + + // Calendar +// public void testCalendarSimple() throws Exception { +// TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); +// GregorianCalendar gc = new GregorianCalendar(tz); +// gc.set(2005,9,17,14,15,33); +// Date time = gc.getTime(); +// +// final String[] calendars = { +// "buddhist", "chinese", "coptic", "ethiopic", "gregorian", +// "hebrew", "islamic", "islamic-civil", "japanese" +// }; +// final String[] ustimes = { +// "Monday, October 17, 2548 BE 2:15:33 PM PDT", +// "Monday 22x78-9-15 2:15:33 PM PDT", +// "Monday, Baba 7, 1722 2:15:33 PM PDT", +// "Monday, Tekemt 7, 1998 2:15:33 PM PDT", +// "Monday, October 17, 2005 2:15:33 PM PDT", +// "Monday, Tishri 14, 5766 2:15:33 PM PDT", +// "Monday, Ramadan 14, 1426 2:15:33 PM PDT", +// "Monday, Ramadan 14, 1426 2:15:33 PM PDT", +// "Monday, October 17, 17 Heisei 2:15:33 PM PDT", +// }; +// final String[] detimes = { +// "Montag, Oktober 17, 2548 BE 2:15:33 nachm. GMT-07:00", +// "Montag 22x78-9-15 2:15:33 nachm. GMT-07:00", +// "Montag, 7. Baba 1722 14:15 Uhr GMT-07:00", +// "Montag, 7. Tekemt 1998 14:15 Uhr GMT-07:00", +// "Montag, 17. Oktober 2005 14:15 Uhr GMT-07:00", +// "Montag, 14. Tishri 5766 14:15 Uhr GMT-07:00", +// "Montag, 14. Ramadan 1426 14:15 Uhr GMT-07:00", +// "Montag, 14. Ramadan 1426 14:15 Uhr GMT-07:00", +// "Montag, Oktober 17, 17 Heisei 2:15:33 nachm. GMT-07:00", +// }; +// +// ULocale[] locales = {ULocale.US, ULocale.GERMANY }; +// String[][] times = { ustimes, detimes }; +// for (int j = 0; j < locales.length; ++j) { +// ULocale ul = new ULocale("en_US"); +// for (int i = 0; i < calendars.length; ++i) { +// ul = ul.setKeywordValue("calendar", calendars[i]); +// Calendar cal = Calendar.getInstance(ul); +// DateFormat fmt = cal.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, locales[j]); +// String result = fmt.format(time); +// System.out.println(calendars[i] + ": " + result); +// if (!result.equals(times[j][i])) { +// fail("calendar: " + calendars[i]); +// } +// } +// } +// } +} diff --git a/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu/META-INF/MANIFEST.MF b/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..cd0e787146d --- /dev/null +++ b/icu4j/src/com/ibm/icu/dev/eclipse/com.ibm.icu/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: International Components for Unicode for Java (ICU4J) +Bundle-SymbolicName: com.ibm.icu +Bundle-Version: 3.4.1 +Bundle-Vendor: IBM +Bundle-Localization: plugin +Bundle-Copyright: Licensed Materials - Property of IBM + (C) Copyright IBM Corp. 2000, 2005. All Rights Reserved. + IBM is a registered trademark of IBM Corp. +Eclipse-AutoStart: true +Export-Package: com.ibm.icu.impl;x-friends:="com.ibm.icu.tests", + com.ibm.icu.impl.data;x-internal:=true, + com.ibm.icu.lang, + com.ibm.icu.math, + com.ibm.icu.text, + com.ibm.icu.util +Bundle-ClassPath: icu4j.jar +Eclipse-LazyStart: true diff --git a/icu4j/src/com/ibm/icu/dev/test/TestAll.java b/icu4j/src/com/ibm/icu/dev/test/TestAll.java index 1aa3d84c5ed..b91c29566c7 100755 --- a/icu4j/src/com/ibm/icu/dev/test/TestAll.java +++ b/icu4j/src/com/ibm/icu/dev/test/TestAll.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ******************************************************************************* * Copyright (C) 1996-2005, International Business Machines Corporation and * @@ -38,7 +39,9 @@ public class TestAll extends TestGroup { "com.ibm.icu.dev.test.stringprep.TestAll", "com.ibm.icu.dev.test.timescale.TestAll", "com.ibm.icu.dev.test.charsetdet.TestCharsetDetector", +//#ifndef FOUNDATION "com.ibm.icu.dev.test.serializable.SerializableTest" // *is* a group +//#endif }, "All tests in ICU"); } diff --git a/icu4j/src/com/ibm/icu/dev/test/bigdec/DiagBigDecimal.java b/icu4j/src/com/ibm/icu/dev/test/bigdec/DiagBigDecimal.java index b27c3be2110..82410183f40 100755 --- a/icu4j/src/com/ibm/icu/dev/test/bigdec/DiagBigDecimal.java +++ b/icu4j/src/com/ibm/icu/dev/test/bigdec/DiagBigDecimal.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* Generated from 'DiagBigDecimal.nrx' 27 Mar 2000 22:38:44 [v1.162] */ /* Options: Binary Comments Crossref Format Java Logo Trace1 Verbose3 */ package com.ibm.icu.dev.test.bigdec; @@ -365,6 +366,7 @@ public class DiagBigDecimal extends TestFmwk{ (new Test("con006")).ok=(com.ibm.icu.math.BigDecimal.TEN.intValueExact())==10; // [java.math.] BigDecimal +//#ifndef FOUNDATION (new Test("cbd001")).ok=((new com.ibm.icu.math.BigDecimal(new java.math.BigDecimal("0"))).toString()).equals("0"); (new Test("cbd002")).ok=((new com.ibm.icu.math.BigDecimal(new java.math.BigDecimal("1"))).toString()).equals("1"); (new Test("cbd003")).ok=((new com.ibm.icu.math.BigDecimal(new java.math.BigDecimal("10"))).toString()).equals("10"); @@ -384,6 +386,7 @@ public class DiagBigDecimal extends TestFmwk{ num="0.00000123456789"; (new Test("cbd013")).ok=((new com.ibm.icu.math.BigDecimal(new java.math.BigDecimal(num))).toString()).equals(num); num="0.000000123456789"; + // ignore format change issues with 1.5 if (!isJDK15OrLater) (new Test("cbd014")).ok=((new com.ibm.icu.math.BigDecimal(new java.math.BigDecimal(num))).toString()).equals(num); @@ -396,6 +399,7 @@ public class DiagBigDecimal extends TestFmwk{ flag=true; }/*checknull*/ (new Test("cbi015")).ok=flag; +//#endif // BigInteger bip=new BigInteger("987654321987654321987654321"); // biggie +ve @@ -550,6 +554,7 @@ public class DiagBigDecimal extends TestFmwk{ }/*checkbound3*/ (new Test("cca204")).ok=flag; +//#ifndef FOUNDATION // double [deprecated] // Note that many of these differ from the valueOf(double) results. dzer=(double)0; @@ -604,7 +609,7 @@ public class DiagBigDecimal extends TestFmwk{ d=d/((double)10); if (!isJDK15OrLater) (new Test("cdo018")).ok=((new com.ibm.icu.math.BigDecimal(d)).toString()).equals("0.000000008999999999999997872197332322678764437995369007694534957408905029296875"); - +//#endif try{checkpin:do{ new com.ibm.icu.math.BigDecimal(java.lang.Double.POSITIVE_INFINITY); @@ -4018,8 +4023,9 @@ public class DiagBigDecimal extends TestFmwk{ /* ----------------------------------------------------------------- */ /** Test the {@link com.ibm.icu.math.BigDecimal#toBigDecimal} method. */ - + public void diagtobigdecimal(){ +//#ifndef FOUNDATION (new Test("tbd001")).ok=((new com.ibm.icu.math.BigDecimal("0")).toBigDecimal().toString()).equals("0"); (new Test("tbd002")).ok=((new com.ibm.icu.math.BigDecimal("-1")).toBigDecimal().toString()).equals("-1"); (new Test("tbd003")).ok=((new com.ibm.icu.math.BigDecimal("+1")).toBigDecimal().toString()).equals("1"); @@ -4033,7 +4039,9 @@ public class DiagBigDecimal extends TestFmwk{ (new Test("tbd009")).ok=((new com.ibm.icu.math.BigDecimal("1E10")).toBigDecimal().toString()).equals("10000000000"); (new Test("tbd010")).ok=((new com.ibm.icu.math.BigDecimal("1E12")).toBigDecimal().toString()).equals("1000000000000"); summary("toBigDecimal"); +//#endif } + /* ----------------------------------------------------------------- */ /** Test the {@link com.ibm.icu.math.BigDecimal#toBigInteger} method. */ diff --git a/icu4j/src/com/ibm/icu/dev/test/format/DateFormatTest.java b/icu4j/src/com/ibm/icu/dev/test/format/DateFormatTest.java index 3d15c7cad74..92229f7cbf9 100755 --- a/icu4j/src/com/ibm/icu/dev/test/format/DateFormatTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/format/DateFormatTest.java @@ -2072,7 +2072,8 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk { } } - { + // TODO: revisit toLocalizedPattern + if (false) { SimpleDateFormat fmt = new SimpleDateFormat("aabbcc"); try { String pat = fmt.toLocalizedPattern(); diff --git a/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java b/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java index 4143d55daf5..6e64f8ac1d4 100644 --- a/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/format/GlobalizationPreferencesTest.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ******************************************************************************* * Copyright (C) 2004-2005, International Business Machines Corporation and * @@ -44,7 +45,7 @@ public class GlobalizationPreferencesTest { out.println("\tWarning: some of this is just mockup -- real data will be accessed later."); out.println(); - +//#ifndef FOUNDATION out.println("Check defaulting"); String[] localeList = {"fr_BE;q=0.5,de", "fr_BE,de", "fr", "en_NZ", "en", "en-TH", "zh-Hant", "zh-MO", "zh", "it", "as", "haw", "ar-EG", "ar", "qqq"}; for (int i = 0; i < localeList.length; ++i) { @@ -59,6 +60,8 @@ public class GlobalizationPreferencesTest { } out.println(); +//#endif + out.println("Date Formatting"); out.println("\tdate: \t" + lPreferences.getDateFormat(DateFormat.FULL, GlobalizationPreferences.NONE).format(now)); @@ -142,4 +145,4 @@ public class GlobalizationPreferencesTest { System.out.println("done"); } } -} \ No newline at end of file +} diff --git a/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java b/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java index 513c7d63317..d7ee471098f 100755 --- a/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRegressionTest.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ******************************************************************************* * Copyright (C) 2001-2005, International Business Machines Corporation and * @@ -160,6 +161,7 @@ public class NumberFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk { //Test New serialized DecimalFormat(2.0) read old serialized forms of DecimalFormat(1.3.1.1) public void TestSerialization() throws IOException, ClassNotFoundException{ +//#ifndef FOUNDATION byte[][] contents = NumberFormatSerialTestData.getContent(); double data = 1234.56; String[] expected = { @@ -178,5 +180,8 @@ public class NumberFormatRegressionTest extends com.ibm.icu.dev.test.TestFmwk { warnln("FAIL: " + e.getMessage()); } } +//#else +//## warnln("FOUNDATION"); +//#endif } -} \ No newline at end of file +} diff --git a/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatTest.java b/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatTest.java index ddff68cbdc3..d3417e7ac2b 100755 --- a/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatTest.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ******************************************************************************* * Copyright (C) 2001-2005, International Business Machines Corporation and * @@ -847,7 +848,11 @@ public class NumberFormatTest extends com.ibm.icu.dev.test.TestFmwk { expect2(df, 2.0, "2.00 *&' Rs. '&*"); expect2(df, -1.0, "-1.00 *&' Re. '&*"); +//#ifndef FOUNDATION java.math.BigDecimal r = df.getRoundingIncrement(); +//#else +//## com.ibm.icu.math.BigDecimal r = df.getRoundingIncrement(); +//#endif if (r != null) { errln("FAIL: rounding = " + r + ", expect null"); } diff --git a/icu4j/src/com/ibm/icu/dev/test/util/ICUResourceBundleTest.java b/icu4j/src/com/ibm/icu/dev/test/util/ICUResourceBundleTest.java index 1ccdc36552f..c164a6f487a 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/ICUResourceBundleTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/ICUResourceBundleTest.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /** ******************************************************************************* * Copyright (C) 2001-2005, International Business Machines Corporation and * @@ -14,7 +15,11 @@ import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.net.JarURLConnection; +//#ifndef FOUNDATION import java.nio.ByteBuffer; +//#else +//##import com.ibm.icu.impl.ByteBuffer; +//#endif import java.util.MissingResourceException; import java.util.Enumeration; import java.util.jar.JarEntry; diff --git a/icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java b/icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java index d15145dc632..813e4658ff2 100644 --- a/icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java +++ b/icu4j/src/com/ibm/icu/dev/test/util/UtilityTest.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ********************************************************************** * Copyright (c) 2003-2005, International Business Machines @@ -112,7 +113,11 @@ public class UtilityTest extends TestFmwk { { byte[] ba = {0x00, 0x01, 0x02}; byte[] bb = {0x00, 0x01, 0x02, -1}; +//#ifndef FOUNDATION java.nio.ByteBuffer buffer = java.nio.ByteBuffer.wrap(ba); +//#else +//## com.ibm.icu.impl.ByteBuffer buffer = com.ibm.icu.impl.ByteBuffer.wrap(ba); +//#endif ByteArrayWrapper x = new ByteArrayWrapper(buffer); ByteArrayWrapper y = new ByteArrayWrapper(ba, 3); diff --git a/icu4j/src/com/ibm/icu/dev/tool/docs/CodeMangler.java b/icu4j/src/com/ibm/icu/dev/tool/docs/CodeMangler.java index fa741541d67..abc324ed687 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/docs/CodeMangler.java +++ b/icu4j/src/com/ibm/icu/dev/tool/docs/CodeMangler.java @@ -17,8 +17,10 @@ import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; +import java.util.Iterator; import java.util.Map; import java.util.HashMap; +import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,38 +28,48 @@ import java.util.regex.Pattern; * A simple facility for adding C-like preprocessing to .java files. * This only understands a subset of the C preprocessing syntax. * Its used to manage files that with only small differences can be - * compiled for different JVMs. Input is generally a '.jpp' file, - * output is a '.java' file with the same name, that can then be - * compiled. + * compiled for different JVMs. This changes files in place, + * commenting out lines based on the current flag settings. */ public class CodeMangler { private File indir; // root of input private File outdir; // root of output private String suffix; // suffix to process, default '.jpp' private boolean recurse; // true if recurse on directories - private Map map; // defines + private boolean force; // true if force reprocess of files + private boolean clean; // true if output is to be cleaned + private HashMap map; // defines private ArrayList names; // files/directories to process + private String header; // sorted list of defines passed in private boolean verbose; // true if we emit debug output + private static final String IGNORE_PREFIX = "//##"; + private static final String HEADER_PREFIX = "//##header"; + public static void main(String[] args) { new CodeMangler(args).run(); } private static final String usage = "Usage:\n" + - " CodeMangler [flags] file... dir...\n" + + " CodeMangler [flags] file... dir... @argfile... \n" + "-in[dir] path - root directory of input files, otherwise use current directory\n" + - "-out[dir] path - root directory of output files, otherwise use current directory\n" + - "-suffix string - suffix of files to process, otherwise use '.jpp' (directories only)\n" + - "-r - if present, recursively process subdirectories\n" + - "-d[efine] NAME[=VALUE] - define NAME with optional value VALUE\n" + + "-out[dir] path - root directory of output files, otherwise use input directory\n" + + "-s[uffix] string - suffix of inputfiles to process, otherwise use '.java' (directories only)\n" + + "-c[lean] - remove all control flags from code on output (does not proceed if overwriting)\n" + + "-r[ecurse] - if present, recursively process subdirectories\n" + + "-f[orce] - force reprocessing of files even if timestamp and headers match\n" + + "-dNAME[=VALUE] - define NAME with optional value VALUE\n" + + " (or -d NAME[=VALUE])\n" + "-help - print this usage message and exit.\n" + "\n" + "For file arguments, output '.java' files using the same path/name under the output directory.\n" + "For directory arguments, process all files with the defined suffix in the directory.\n" + " (if recursing, do the same for all files recursively under each directory)\n" + + "For @argfile arguments, read the specified text file (strip the '@'), and process each line of that file as \n" + + "an argument.\n" + "\n" + - "Directives in the file are one of the following:\n" + + "Directives are one of the following:\n" + " #ifdef, #ifndef, #else, #endif, #if, #elif, #define, #undef\n" + "These may optionally be preceeded by whitespace or //.\n" + "#if, #elif args are of the form 'key == value' or 'key != value'.\n" + @@ -67,7 +79,8 @@ public class CodeMangler { CodeMangler(String[] args) { map = new HashMap(); names = new ArrayList(); - suffix = ".jpp"; + suffix = ".java"; + clean = false; String inname = null; String outname = null; @@ -84,7 +97,10 @@ public class CodeMangler { } else if (arg.startsWith("-out")) { outname = args[++i]; } else if (arg.startsWith("-d")) { - String id = args[++i]; + String id = arg.substring(2); + if (id.length() == 0) { + id = args[++i]; + } String val = ""; int ix = id.indexOf('='); if (ix >= 0) { @@ -92,11 +108,15 @@ public class CodeMangler { id = id.substring(0,ix); } map.put(id, val); - } else if ("-suffix".equals(arg)) { + } else if (arg.startsWith("-s")) { suffix = args[++i]; - } else if ("-r".equals(arg)) { + } else if (arg.startsWith("-r")) { recurse = true; - } else if (arg.startsWith("-help")) { + } else if (arg.startsWith("-f")) { + force = true; + } else if (arg.startsWith("-c")) { + clean = true; + } else if (arg.startsWith("-h")) { System.out.print(usage); break; // stop before processing arguments, so we will do nothing } else if (arg.startsWith("-v")) { @@ -107,7 +127,32 @@ public class CodeMangler { throw new IllegalArgumentException(arg); } } else { - names.add(arg); + if (arg.charAt(0) == '@') { + File argfile = new File(arg.substring(1)); + if (argfile.exists() && !argfile.isDirectory()) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(argfile))); + ArrayList list = new ArrayList(); + for (int x = 0; x < args.length; ++x) { + list.add(args[x]); + } + String line; + while (null != (line = br.readLine())) { + line = line.trim(); + if (line.length() > 0 && line.charAt(0) != '#') { + if (verbose) System.out.println("adding argument: " + line); + list.add(line); + } + } + args = (String[])list.toArray(new String[list.size()]); + } + catch (IOException e) { + System.err.println("error reading arg file: " + e); + } + } + } else { + names.add(arg); + } } } } catch (IndexOutOfBoundsException e) { @@ -135,10 +180,10 @@ public class CodeMangler { } else if (!indir.isDirectory()) { throw new IllegalArgumentException("Input path '" + indir.getAbsolutePath() + "' is not a directory."); } - if (verbose) System.err.println("indir: " + indir.getAbsolutePath()); + if (verbose) System.out.println("indir: " + indir.getAbsolutePath()); if (outname == null) { - outname = username; + outname = inname; } else if (!(outname.startsWith("\\") || outname.startsWith("/"))) { outname = username + File.separator + outname; } @@ -154,11 +199,42 @@ public class CodeMangler { } else if (!outdir.isDirectory()) { throw new IllegalArgumentException("Output path '" + outdir.getAbsolutePath() + "' is not a directory."); } - if (verbose) System.err.println("outdir: " + outdir.getAbsolutePath()); + if (verbose) System.out.println("outdir: " + outdir.getAbsolutePath()); + + + if (clean && suffix.equals(".java")) { + try { + if (outdir.getCanonicalPath().equals(indir.getCanonicalPath())) { + throw new IllegalArgumentException("Cannot use 'clean' to overwrite .java files in same directory tree"); + } + } + catch (IOException e) { + System.err.println("possible overwrite, error: " + e.getMessage()); + throw new IllegalArgumentException("Cannot use 'clean' to overrwrite .java files"); + } + } if (names.isEmpty()) { names.add("."); } + + TreeMap sort = new TreeMap(String.CASE_INSENSITIVE_ORDER); + sort.putAll(map); + Iterator iter = sort.entrySet().iterator(); + StringBuffer buf = new StringBuffer(); + while (iter.hasNext()) { + Map.Entry e = (Map.Entry)iter.next(); + if (buf.length() > 0) { + buf.append(", "); + } + buf.append(e.getKey()); + String v = (String)e.getValue(); + if (v != null && v.length() > 0) { + buf.append('='); + buf.append(v); + } + } + header = buf.toString(); } public int run() { @@ -166,10 +242,10 @@ public class CodeMangler { } public int process(String path, String[] filenames) { - if (verbose) System.err.println("path: '" + path + "'"); + if (verbose) System.out.println("path: '" + path + "'"); int count = 0; for (int i = 0; i < filenames.length; ++i) { - if (verbose) System.err.println("name " + i + " of " + filenames.length + ": '" + filenames[i] + "'"); + if (verbose) System.out.println("name " + i + " of " + filenames.length + ": '" + filenames[i] + "'"); String name = path + filenames[i]; File fin = new File(indir, name); try { @@ -182,7 +258,7 @@ public class CodeMangler { continue; } if (fin.isFile()) { - if (verbose) System.err.println("processing file: '" + fin.getAbsolutePath() + "'"); + if (verbose) System.out.println("processing file: '" + fin.getAbsolutePath() + "'"); String oname; int ix = name.lastIndexOf("."); if (ix != -1) { @@ -192,19 +268,11 @@ public class CodeMangler { } oname += ".java"; File fout = new File(outdir, oname); - String foutpname = fout.getParent(); - if (foutpname != null) { - File foutp = new File(foutpname); - if (!(foutp.exists() || foutp.mkdirs())) { - System.err.println("could not create directory: '" + foutpname + "'"); - continue; - } - } if (processFile(fin, fout)) { ++count; } } else if (fin.isDirectory()) { - if (verbose) System.err.println("recursing on directory '" + fin.getAbsolutePath() + "'"); + if (verbose) System.out.println("recursing on directory '" + fin.getAbsolutePath() + "'"); String npath = ".".equals(name) ? path : path + fin.getName() + File.separator; count += process(npath, fin.list(filter)); // recursive call } @@ -221,62 +289,121 @@ public class CodeMangler { }; public boolean processFile(File infile, File outfile) { - Pattern pat = Pattern.compile( - "(?i)^\\s*(?://+)??\\s*#(ifdef\\s|ifndef\\s|else|endif|undef\\s|define\\s|if\\s|elif\\s)\\s*(.*)$"); - Pattern pat2 = Pattern.compile("([^=!]+)\\s*([!=]=)??\\s*(\\w+)"); + File backup = null; + + class State { + int lc; + String line; + boolean emit = true; + boolean tripped; + private State next; + + public String toString() { + return "line " + lc + + ": '" + line + + "' (emit: " + emit + + " tripped: " + tripped + + ")"; + } + + void trip(boolean trip) { + if (!tripped & trip) { + tripped = true; + emit = next != null ? next.emit : true; + } else { + emit = false; + } + } + + State push(int lc, String line, boolean trip) { + this.lc = lc; + this.line = line; + State ret = new State(); + ret.next = this; + ret.emit = this.emit & trip; + ret.tripped = trip; + return ret; + } + + State pop() { + return next; + } + }; + + final Pattern pat = Pattern.compile( + "(?i)^(\\s*(?://+)??\\s*)#(ifdef\\s|ifndef\\s|else|endif|undef\\s|define\\s|if\\s|elif\\s)\\s*(.*)$"); + final Pattern pat2 = Pattern.compile("([^=!]+)\\s*([!=]?=)??\\s*(\\w+)"); + final Pattern pat3 = Pattern.compile("^(\\s*//##).*"); + HashMap oldMap = null; + + long outModTime = 0; + try { - PrintStream outstream = new PrintStream(new FileOutputStream(outfile)); + PrintStream outstream = null; InputStream instream = new FileInputStream(infile); - class State { - int lc; - String line; - boolean emit = true; - boolean tripped; - private State next; + BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); + int lc = 0; + State state = new State(); + String line; + while ((line = reader.readLine()) != null) { + if (lc == 0) { // check and write header for output file if needed + boolean hasHeader = line.startsWith(HEADER_PREFIX); + if (hasHeader && !force) { + long expectLastModified = ((infile.lastModified() + 999)/1000)*1000; + String headerline = HEADER_PREFIX + ' ' + String.valueOf(expectLastModified) + ' ' + header; + if (line.equals(headerline)) { + if (verbose) System.out.println("no changes necessary to " + infile.getCanonicalPath()); + instream.close(); + return false; // nothing to do + } + if (verbose) { + System.out.println(" old header: " + line); + System.out.println(" != expected: " + headerline); + } + } - public String toString() { - return "line " + lc - + ": '" + line - + "' (emit: " + emit - + " tripped: " + tripped - + ")"; - } + // create output file directory structure + String outpname = outfile.getParent(); + if (outpname != null) { + File outp = new File(outpname); + if (!(outp.exists() || outp.mkdirs())) { + System.err.println("could not create directory: '" + outpname + "'"); + return false; + } + } - void trip(boolean trip) { - if (!tripped & trip) { - tripped = true; - emit = next != null ? next.emit : true; - } else { - emit = false; + // if we're overwriting, use a temporary file + if (suffix.equals(".java")) { + backup = outfile; + try { + outfile = File.createTempFile(outfile.getName(), null, outfile.getParentFile()); + } + catch (IOException ex) { + System.err.println(ex.getMessage()); + return false; + } + } + + outModTime = ((outfile.lastModified()+999)/1000)*1000; // round up + outstream = new PrintStream(new FileOutputStream(outfile)); + String headerline = HEADER_PREFIX + ' ' + String.valueOf(outModTime) + ' ' + header; + outstream.println(headerline); + if (verbose) System.out.println("header: " + headerline); + + // discard the old header if we had one, otherwise match this line like any other + if (hasHeader) { + ++lc; // mark as having read a line so we never reexecute this block + continue; } } - State push(int lc, String line, boolean trip) { - this.lc = lc; - this.line = line; - State ret = new State(); - ret.next = this; - ret.emit = this.emit & trip; - ret.tripped = trip; - return ret; - } - - State pop() { - return next; - } - } - - BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); - String line = null; - int lc = 0; - State state = new State(); - while ((line = reader.readLine()) != null) { Matcher m = pat.matcher(line); if (m.find()) { - String key = m.group(1).toLowerCase().trim(); - String val = m.group(2).trim(); - if (verbose) outstream.println("directive: " + line + String lead = m.group(1); + String key = m.group(2).toLowerCase().trim(); + String val = m.group(3).trim(); + if (verbose) System.out.println("directive: " + line + " key: '" + key + "' val: '" + val + "' " + state); @@ -290,15 +417,18 @@ public class CodeMangler { state = state.pop(); } else if (key.equals("undef")) { if (state.emit) { + if (oldMap == null) { + oldMap = (HashMap)map.clone(); + } map.remove(val); } - } else { + } else { // #define, #if, #elif Matcher m2 = pat2.matcher(val); if (m2.find()) { String key2 = m2.group(1).trim(); boolean neq = "!=".equals(m2.group(2)); // optional String val2 = m2.group(3).trim(); - if (verbose) outstream.println("val2: '" + val2 + if (verbose) System.out.println("val2: '" + val2 + "' neq: '" + neq + "' key2: '" + key2 + "'"); @@ -308,32 +438,71 @@ public class CodeMangler { state.trip(val2.equals(map.get(key2)) != neq); } else if (key.equals("define")) { if (state.emit) { + if (oldMap == null) { + oldMap = (HashMap)map.clone(); + } map.put(key2, val2); } } } } + if (!clean) { + lc++; + if (!lead.equals("//")) { + outstream.print("//"); + line = line.substring(lead.length()); + } + outstream.println(line); + } continue; } lc++; - if (state.emit) { + m = pat3.matcher(line); + boolean hasIgnore = m.find(); + if (state.emit == hasIgnore) { + if (state.emit) { + line = line.substring(m.group(1).length()); + } else { + line = IGNORE_PREFIX + line; + } + } else if (hasIgnore && !m.group(1).equals(IGNORE_PREFIX)) { + line = IGNORE_PREFIX + line.substring(m.group(1).length()); + } + if (!clean || state.emit) { outstream.println(line); - } else { - if (verbose) outstream.println("skipping: " + line); } } state = state.pop(); if (state != null) { - System.out.println("Error: unclosed directive(s):"); + System.err.println("Error: unclosed directive(s):"); do { System.err.println(state); } while ((state = state.pop()) != null); + System.err.println(" in file: " + outfile.getCanonicalPath()); + if (oldMap != null) { + map = oldMap; + } + outstream.close(); + return false; } outstream.close(); instream.close(); + + if (backup != null) { + if (backup.exists()) { + backup.delete(); + } + outfile.renameTo(backup); + } + + outfile.setLastModified(outModTime); // synch with timestamp + + if (oldMap != null) { + map = oldMap; + } } catch (IOException e) { System.err.println(e); diff --git a/icu4j/src/com/ibm/icu/dev/tool/docs/ICUTaglet.jpp b/icu4j/src/com/ibm/icu/dev/tool/docs/ICUTaglet.java similarity index 87% rename from icu4j/src/com/ibm/icu/dev/tool/docs/ICUTaglet.jpp rename to icu4j/src/com/ibm/icu/dev/tool/docs/ICUTaglet.java index 40215b5bf22..418440f8a6c 100644 --- a/icu4j/src/com/ibm/icu/dev/tool/docs/ICUTaglet.jpp +++ b/icu4j/src/com/ibm/icu/dev/tool/docs/ICUTaglet.java @@ -1,3 +1,4 @@ +//##header VERSION_1.4 /** ******************************************************************************* * Copyright (C) 2002-2005, International Business Machines Corporation and * @@ -16,15 +17,15 @@ package com.ibm.icu.dev.tool.docs; import com.sun.javadoc.*; import com.sun.tools.doclets.*; //#ifdef VERSION_1.5 - -import com.sun.tools.doclets.internal.toolkit.taglets.*; -import com.sun.tools.doclets.internal.toolkit.taglets.Taglet; - -// jdk 1.5 contains both com.sun.tools.doclets.Taglet and -// com.sun.tools.doclets.internal.toolkit.taglets.Taglet. -// Their registration code casts to the second, not the first, and the -// second doesn't implement the first, so if you just implement the -// first, you die. +//## +//##import com.sun.tools.doclets.internal.toolkit.taglets.*; +//##import com.sun.tools.doclets.internal.toolkit.taglets.Taglet; +//## +//##// jdk 1.5 contains both com.sun.tools.doclets.Taglet and +//##// com.sun.tools.doclets.internal.toolkit.taglets.Taglet. +//##// Their registration code casts to the second, not the first, and the +//##// second doesn't implement the first, so if you just implement the +//##// first, you die. //#endif import java.text.BreakIterator; @@ -113,22 +114,22 @@ public abstract class ICUTaglet implements Taglet { return null; } //#ifdef VERSION_1.5 - - public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) throws IllegalArgumentException { - TagletOutput out = writer.getTagletOutputInstance(); - out.setOutput(toString(tag)); - return out; - } - - public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) throws IllegalArgumentException { - TagletOutput out = writer.getTagletOutputInstance(); - Tag[] tags = holder.tags(getName()); - if (tags.length == 0) { - return null; - } - out.setOutput(toString(tags[0])); - return out; - } +//## +//## public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) throws IllegalArgumentException { +//## TagletOutput out = writer.getTagletOutputInstance(); +//## out.setOutput(toString(tag)); +//## return out; +//## } +//## +//## public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) throws IllegalArgumentException { +//## TagletOutput out = writer.getTagletOutputInstance(); +//## Tag[] tags = holder.tags(getName()); +//## if (tags.length == 0) { +//## return null; +//## } +//## out.setOutput(toString(tags[0])); +//## return out; +//## } //#endif protected static final String STATUS = "
Status:
"; diff --git a/icu4j/src/com/ibm/icu/impl/CollectionUtilities.java b/icu4j/src/com/ibm/icu/impl/CollectionUtilities.java index e56c2497d03..0ef60483a6a 100644 --- a/icu4j/src/com/ibm/icu/impl/CollectionUtilities.java +++ b/icu4j/src/com/ibm/icu/impl/CollectionUtilities.java @@ -1,3 +1,4 @@ +//##header 1132615046000 /* ******************************************************************************* * Copyright (C) 1996-2005, International Business Machines Corporation and * @@ -12,8 +13,9 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.SortedSet; +//#ifndef FOUNDATION import java.util.regex.Matcher; - +//#endif import com.ibm.icu.text.Transliterator; import com.ibm.icu.text.UTF16; import com.ibm.icu.text.UnicodeSet; @@ -378,6 +380,7 @@ public final class CollectionUtilities { } } +//#ifndef FOUNDATION public static class RegexIterator extends FilteredIterator { private Matcher matcher; public RegexIterator set(Iterator baseIterator, Matcher matcher) { @@ -389,5 +392,5 @@ public final class CollectionUtilities { return matcher.reset((String)item).matches(); } } - -} \ No newline at end of file +//#endif +} diff --git a/icu4j/src/com/ibm/icu/impl/ICUResourceBundle.java b/icu4j/src/com/ibm/icu/impl/ICUResourceBundle.java index f4957783a00..4b3235f9d02 100644 --- a/icu4j/src/com/ibm/icu/impl/ICUResourceBundle.java +++ b/icu4j/src/com/ibm/icu/impl/ICUResourceBundle.java @@ -1,3 +1,4 @@ +//##header 1132616027000 /* * ***************************************************************************** * Copyright (C) 2005, International Business Machines Corporation and * others. @@ -13,7 +14,6 @@ import java.io.InputStreamReader; import java.io.IOException; import java.lang.ref.SoftReference; import java.net.URL; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -25,8 +25,12 @@ import java.util.Map; import java.util.MissingResourceException; import java.util.Set; import java.util.Vector; -import java.util.regex.Pattern; +//#ifndef FOUNDATION +import java.nio.ByteBuffer; +//#else +//##import com.ibm.icu.impl.ByteBuffer; +//#endif import com.ibm.icu.impl.URLHandler.URLVisitor; import com.ibm.icu.util.StringTokenizer; import com.ibm.icu.util.ULocale; @@ -959,9 +963,8 @@ public abstract class ICUResourceBundle extends UResourceBundle { if (handler != null) { final ArrayList list = new ArrayList(); URLVisitor v = new URLVisitor() { - private Pattern p = Pattern.compile(".*\\.res"); public void visit(String s) { - if (p.matcher(s).matches() && !"res_index.res".equals(s)) { + if (s.endsWith(".res") && !"res_index.res".equals(s)) { list.add(s.substring(0, s.length() - 4)); // strip '.res' } } diff --git a/icu4j/src/com/ibm/icu/impl/ICUResourceBundleImpl.java b/icu4j/src/com/ibm/icu/impl/ICUResourceBundleImpl.java index f37be626a7b..b27ac5d0b5b 100644 --- a/icu4j/src/com/ibm/icu/impl/ICUResourceBundleImpl.java +++ b/icu4j/src/com/ibm/icu/impl/ICUResourceBundleImpl.java @@ -1,3 +1,4 @@ +//##header 1132616027000 /* ****************************************************************************** * Copyright (C) 2004-2005, International Business Machines Corporation and * @@ -6,7 +7,6 @@ */ package com.ibm.icu.impl; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -15,6 +15,11 @@ import com.ibm.icu.util.StringTokenizer; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; import com.ibm.icu.util.UResourceTypeMismatchException; + +//#ifndef FOUNDATION +import java.nio.ByteBuffer; +//#endif + /** * @author ram */ @@ -27,6 +32,8 @@ public class ICUResourceBundleImpl extends ICUResourceBundle { private ULocale ulocale; private ClassLoader loader; + private static final boolean ASSERT = false; + /** * * @param baseName @@ -500,7 +507,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle { } private static int getInt(byte[] data, int offset){ - assert offset < data.length; + if (ASSERT) Assert.assrt("offset < data.length", offset < data.length); return makeInt(data[offset], data[offset+1], data[offset+2], data[offset+3]); } @@ -515,7 +522,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle { int length = ICUResourceBundleImpl.getInt(rawData,offset); int byteOffset = offset + getIntOffset(1); byte[] dst = new byte[length]; - assert byteOffset+length < rawData.length; + if (ASSERT) Assert.assrt("byteOffset+length < rawData.length", byteOffset+length < rawData.length); System.arraycopy(rawData, byteOffset, dst, 0, length); return dst; } @@ -551,7 +558,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle { int[] val = new int[length]; int byteLength = getIntOffset(length); - assert (intOffset+byteLength) finalYear) { // [sic] >, not >=; see above - assert(finalZone != null); + if (ASSERT) Assert.assrt("(finalZone != null)", finalZone != null); return finalZone.getOffset(era, year, month, dom, dow, millis, monthLength); } @@ -225,7 +226,7 @@ public class OlsonTimeZone extends TimeZone { double remainder; double[] ret = new double[2]; // Only designed to work for positive divisors - assert(divisor > 0); + if (ASSERT) Assert.assrt("divisor > 0", divisor > 0); double quotient = Math.floor(dividend/divisor); remainder = dividend - (quotient * divisor); // N.B. For certain large dividends, on certain platforms, there @@ -252,7 +253,7 @@ public class OlsonTimeZone extends TimeZone { remainder = dividend - (quotient * divisor); } } - assert(0 <= remainder && remainder < divisor); + if (ASSERT) Assert.assrt("0 <= remainder && remainder < divisor", 0 <= remainder && remainder < divisor); ret[0]=quotient; ret[1]=remainder; return ret; @@ -282,7 +283,7 @@ public class OlsonTimeZone extends TimeZone { int year=it[0], month=it[1], dom=it[2], dow=it[3]; if (year > finalYear) { // [sic] >, not >=; see above - assert(finalZone != null && finalZone.useDaylightTime()); + if (ASSERT) Assert.assrt("finalZone != null && finalZone.useDaylightTime()", finalZone != null && finalZone.useDaylightTime()); return true; } @@ -406,7 +407,7 @@ public class OlsonTimeZone extends TimeZone { // using > rather than >=. This allows us to use // INT32_MAX as an exclusive upper limit for all // years, including INT32_MAX. - assert(data[1] > Integer.MIN_VALUE); + if (ASSERT) Assert.assrt("data[1] > Integer.MIN_VALUE", data[1] > Integer.MIN_VALUE); finalYear = data[1] - 1; // Also compute the millis for Jan 1, 0:00 GMT of the // finalYear. This reduces runtime computations. @@ -482,17 +483,21 @@ public class OlsonTimeZone extends TimeZone { } } - assert(i>=0 && i=0 && i=0 && i= transitionTimes[i]); - assert(local || i == transitionCount-1 || time < transitionTimes[i+1]); + if (ASSERT) { + Assert.assrt("local || time < transitionTimes[0] || time >= transitionTimes[i]", + local || time < transitionTimes[0] || time >= transitionTimes[i]); + Assert.assrt("local || i == transitionCount-1 || time < transitionTimes[i+1]", + local || i == transitionCount-1 || time < transitionTimes[i+1]); + } i = typeData[i]; } - assert(i>=0 && i=0 && i=0 && i0", vector.length>0); String[] ret = new String[vector.length]; for (int i=0; i= 0 && vector[i] < OLSON_ZONE_COUNT); + if (ASSERT) Assert.assrt("vector[i] >= 0 && vector[i] < OLSON_ZONE_COUNT", + vector[i] >= 0 && vector[i] < OLSON_ZONE_COUNT); ret[i] = names.getString(vector[i]); } return ret; diff --git a/icu4j/src/com/ibm/icu/lang/UCharacter.java b/icu4j/src/com/ibm/icu/lang/UCharacter.java index a1a127f751c..502b570d395 100755 --- a/icu4j/src/com/ibm/icu/lang/UCharacter.java +++ b/icu4j/src/com/ibm/icu/lang/UCharacter.java @@ -1,3 +1,4 @@ +//##header 1132615046000 /** ******************************************************************************* * Copyright (C) 1996-2005, International Business Machines Corporation and * @@ -2949,7 +2950,8 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection * @deprecated (Java) */ public static boolean isSpace(int ch) { - return java.lang.Character.isSpace((char)(ch & 0xffff)); + return ch <= 0x20 && + (ch == 0x20 || ch == 0x09 || ch == 0x0a || ch == 0x0c || ch == 0x0d); } /** @@ -5266,7 +5268,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection * @draft ICU 3.0 * @deprecated This is a draft API and might change in a future release of ICU. */ +//#ifndef FOUNDATION public static final int codePointAt(CharSequence seq, int index) { +//#else +//## public static final int codePointAt(String seq, int index) { +//#endif char c1 = seq.charAt(index++); if (isHighSurrogate(c1)) { if (index < seq.length()) { @@ -5278,6 +5284,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection } return c1; } +//#ifdef FOUNDATION +//## public static final int codePointAt(StringBuffer seq, int index) { +//## return codePointAt(seq.toString(), index); +//## } +//#endif /** * Cover the JDK 1.5 API, for convenience. Return the code point at index. @@ -5339,7 +5350,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection * @draft ICU 3.0 * @deprecated This is a draft API and might change in a future release of ICU. */ +//#ifndef FOUNDATION public static final int codePointBefore(CharSequence seq, int index) { +//#else +//## public static final int codePointBefore(String seq, int index) { +//#endif char c2 = seq.charAt(--index); if (isLowSurrogate(c2)) { if (index > 0) { @@ -5351,6 +5366,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection } return c2; } +//#ifdef FOUNDATION +//## public static final int codePointBefore(StringBuffer seq, int index) { +//## return codePointBefore(seq.toString(), index); +//## } +//#endif /** * Cover the JDK 1.5 API, for convenience. Return the code point before index. @@ -5479,25 +5499,29 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection * @draft ICU 3.0 * @deprecated This is a draft API and might change in a future release of ICU. */ +//#ifndef FOUNDATION public static int codePointCount(CharSequence text, int start, int limit) { - if (start < 0 || limit < start || limit > text.length()) { - throw new IndexOutOfBoundsException("start (" + start + - ") or limit (" + limit + - ") invalid or out of range 0, " + text.length()); - } +//#else +//## public static int codePointCount(String text, int start, int limit) { +//#endif + if (start < 0 || limit < start || limit > text.length()) { + throw new IndexOutOfBoundsException("start (" + start + + ") or limit (" + limit + + ") invalid or out of range 0, " + text.length()); + } - int len = limit - start; - while (limit > start) { - char ch = text.charAt(--limit); - while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && limit > start) { - ch = text.charAt(--limit); - if (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE) { - --len; - break; + int len = limit - start; + while (limit > start) { + char ch = text.charAt(--limit); + while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && limit > start) { + ch = text.charAt(--limit); + if (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE) { + --len; + break; + } + } } - } - } - return len; + return len; } /** @@ -5510,24 +5534,24 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection * @deprecated This is a draft API and might change in a future release of ICU. */ public static int codePointCount(char[] text, int start, int limit) { - if (start < 0 || limit < start || limit > text.length) { - throw new IndexOutOfBoundsException("start (" + start + - ") or limit (" + limit + - ") invalid or out of range 0, " + text.length); - } + if (start < 0 || limit < start || limit > text.length) { + throw new IndexOutOfBoundsException("start (" + start + + ") or limit (" + limit + + ") invalid or out of range 0, " + text.length); + } - int len = limit - start; - while (limit > start) { - char ch = text[--limit]; - while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && limit > start) { - ch = text[--limit]; - if (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE) { - --len; - break; + int len = limit - start; + while (limit > start) { + char ch = text[--limit]; + while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && limit > start) { + ch = text[--limit]; + if (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE) { + --len; + break; + } + } } - } - } - return len; + return len; } /** @@ -5539,40 +5563,44 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection * @draft ICU 3.0 * @deprecated This is a draft API and might change in a future release of ICU. */ +//#ifndef FOUNDATION public static int offsetByCodePoints(CharSequence text, int index, int codePointOffset) { - if (index < 0 || index > text.length()) { - throw new IndexOutOfBoundsException("index ( " + index + - ") out of range 0, " + text.length()); - } +//#else +//## public static int offsetByCodePoints(String text, int index, int codePointOffset) { +//#endif + if (index < 0 || index > text.length()) { + throw new IndexOutOfBoundsException("index ( " + index + + ") out of range 0, " + text.length()); + } - if (codePointOffset < 0) { - while (++codePointOffset <= 0) { - char ch = text.charAt(--index); - while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && index > 0) { - ch = text.charAt(--index); - if (ch < MIN_HIGH_SURROGATE || ch > MAX_HIGH_SURROGATE) { - if (++codePointOffset > 0) { - return index+1; + if (codePointOffset < 0) { + while (++codePointOffset <= 0) { + char ch = text.charAt(--index); + while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && index > 0) { + ch = text.charAt(--index); + if (ch < MIN_HIGH_SURROGATE || ch > MAX_HIGH_SURROGATE) { + if (++codePointOffset > 0) { + return index+1; + } + } + } } + } else { + int limit = text.length(); + while (--codePointOffset >= 0) { + char ch = text.charAt(index++); + while (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE && index < limit) { + ch = text.charAt(index++); + if (ch < MIN_LOW_SURROGATE || ch > MAX_LOW_SURROGATE) { + if (--codePointOffset < 0) { + return index-1; + } + } + } } } - } - } else { - int limit = text.length(); - while (--codePointOffset >= 0) { - char ch = text.charAt(index++); - while (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE && index < limit) { - ch = text.charAt(index++); - if (ch < MIN_LOW_SURROGATE || ch > MAX_LOW_SURROGATE) { - if (--codePointOffset < 0) { - return index-1; - } - } - } - } - } - return index; + return index; } /** @@ -5587,51 +5615,51 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection * @deprecated This is a draft API and might change in a future release of ICU. */ public static int offsetByCodePoints(char[] text, int start, int count, int index, int codePointOffset) { - int limit = start + count; - if (start < 0 || limit < start || limit > text.length || index < start || index > limit) { - throw new IndexOutOfBoundsException("index ( " + index + - ") out of range " + start + - ", " + limit + - " in array 0, " + text.length); - } - - if (codePointOffset < 0) { - while (++codePointOffset <= 0) { - char ch = text[--index]; - if (index < start) { + int limit = start + count; + if (start < 0 || limit < start || limit > text.length || index < start || index > limit) { throw new IndexOutOfBoundsException("index ( " + index + - ") < start (" + start + - ")"); + ") out of range " + start + + ", " + limit + + " in array 0, " + text.length); } - while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && index > start) { - ch = text[--index]; - if (ch < MIN_HIGH_SURROGATE || ch > MAX_HIGH_SURROGATE) { - if (++codePointOffset > 0) { - return index+1; - } - } - } - } - } else { - while (--codePointOffset >= 0) { - char ch = text[index++]; - if (index > limit) { - throw new IndexOutOfBoundsException("index ( " + index + - ") > limit (" + limit + - ")"); - } - while (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE && index < limit) { - ch = text[index++]; - if (ch < MIN_LOW_SURROGATE || ch > MAX_LOW_SURROGATE) { - if (--codePointOffset < 0) { - return index-1; - } - } - } - } - } - return index; + if (codePointOffset < 0) { + while (++codePointOffset <= 0) { + char ch = text[--index]; + if (index < start) { + throw new IndexOutOfBoundsException("index ( " + index + + ") < start (" + start + + ")"); + } + while (ch >= MIN_LOW_SURROGATE && ch <= MAX_LOW_SURROGATE && index > start) { + ch = text[--index]; + if (ch < MIN_HIGH_SURROGATE || ch > MAX_HIGH_SURROGATE) { + if (++codePointOffset > 0) { + return index+1; + } + } + } + } + } else { + while (--codePointOffset >= 0) { + char ch = text[index++]; + if (index > limit) { + throw new IndexOutOfBoundsException("index ( " + index + + ") > limit (" + limit + + ")"); + } + while (ch >= MIN_HIGH_SURROGATE && ch <= MAX_HIGH_SURROGATE && index < limit) { + ch = text[index++]; + if (ch < MIN_LOW_SURROGATE || ch > MAX_LOW_SURROGATE) { + if (--codePointOffset < 0) { + return index-1; + } + } + } + } + } + + return index; } // protected data members -------------------------------------------- diff --git a/icu4j/src/com/ibm/icu/math/BigDecimal.java b/icu4j/src/com/ibm/icu/math/BigDecimal.java index 019abd7e45b..621c1fff782 100755 --- a/icu4j/src/com/ibm/icu/math/BigDecimal.java +++ b/icu4j/src/com/ibm/icu/math/BigDecimal.java @@ -1,3 +1,4 @@ +//##header 1132615046000 /* Generated from 'BigDecimal.nrx' 8 Sep 2000 11:10:50 [v2.00] */ /* Options: Binary Comments Crossref Format Java Logo Strictargs Strictcase Trace2 Verbose3 */ package com.ibm.icu.math; @@ -449,6 +450,7 @@ public class BigDecimal extends java.lang.Number implements java.io.Serializable /* Constructors */ /* ---------------------------------------------------------------- */ +//#ifndef FOUNDATION /** * Constructs a BigDecimal object from a * java.math.BigDecimal. @@ -471,6 +473,7 @@ public class BigDecimal extends java.lang.Number implements java.io.Serializable public BigDecimal(java.math.BigDecimal bd){ this(bd.toString()); return;} +//#ENDIF /** * Constructs a BigDecimal object from a @@ -828,9 +831,12 @@ public class BigDecimal extends java.lang.Number implements java.io.Serializable // 2000.01.01: note that this constructor does give an exact result, // so perhaps it should not be deprecated // 2000.06.18: no longer deprecated +//#ifndef FOUNDATION this((new java.math.BigDecimal(num)).toString()); +//#else +//## this(String.valueOf(num)); +//#endif return;} - /** * Constructs a BigDecimal object directly from a * int. @@ -3140,6 +3146,7 @@ public class BigDecimal extends java.lang.Number implements java.io.Serializable return (int)this.ind; // [note this assumes values for ind.] } +//#ifndef FOUNDATION /** * Converts this BigDecimal to a * java.math.BigDecimal. @@ -3162,6 +3169,7 @@ public class BigDecimal extends java.lang.Number implements java.io.Serializable public java.math.BigDecimal toBigDecimal(){ return new java.math.BigDecimal(this.unscaledValue(),this.scale()); } +//#ENDIF /** * Converts this BigDecimal to a diff --git a/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java b/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java index af07ae3fd65..0ad804f63e0 100644 --- a/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java +++ b/icu4j/src/com/ibm/icu/text/BreakIteratorFactory.java @@ -12,6 +12,7 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import com.ibm.icu.impl.Assert; import com.ibm.icu.impl.ICUData; import com.ibm.icu.impl.ICULocaleData; import com.ibm.icu.impl.ICULocaleService; @@ -29,6 +30,7 @@ import com.ibm.icu.util.ULocale; * Window>Preferences>Java>Code Generation. */ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim { + private static final boolean ASSERT = false; public Object registerInstance(BreakIterator iter, ULocale locale, int kind) { iter.setText(new java.text.StringCharacterIterator("")); @@ -156,10 +158,10 @@ final class BreakIteratorFactory extends BreakIterator.BreakIteratorServiceShim iter = new DictionaryBasedBreakIterator(rules, dictionary); } catch(IOException e) { - assert false : e; + if (ASSERT) Assert.fail(e); } catch(MissingResourceException e) { - assert false : e; + if (ASSERT) Assert.fail(e); } // TODO: we don't have 'bad' resource data, so this should never happen // in our current tests. diff --git a/icu4j/src/com/ibm/icu/text/DateFormatSymbols.java b/icu4j/src/com/ibm/icu/text/DateFormatSymbols.java index 3f24863f906..444978b9a0f 100755 --- a/icu4j/src/com/ibm/icu/text/DateFormatSymbols.java +++ b/icu4j/src/com/ibm/icu/text/DateFormatSymbols.java @@ -19,9 +19,9 @@ import com.ibm.icu.impl.ZoneMeta; import com.ibm.icu.util.ULocale; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -675,7 +675,7 @@ public class DateFormatSymbols implements Serializable, Cloneable { public void setZoneStrings(String[][] newZoneStrings) { zoneStrings = duplicate(newZoneStrings); if(zoneStringsHash==null){ - zoneStringsHash = new LinkedHashMap(); + zoneStringsHash = new HashMap(); } initZoneStrings(newZoneStrings); // reset the zone strings. @@ -966,7 +966,7 @@ public class DateFormatSymbols implements Serializable, Cloneable { } zoneStrings = new String[zoneStringsHash.size()][8]; int i = 0; - for (Iterator it = zoneStringsHash.keySet().iterator(); it.hasNext();) { + for (Iterator it = zoneStringsKeyList.iterator(); it.hasNext();) { String key = (String)it.next(); String[] strings = (String[])zoneStringsHash.get(key); zoneStrings[i][0] = key; @@ -990,13 +990,14 @@ public class DateFormatSymbols implements Serializable, Cloneable { } private void initZoneStringsHash(){ - zoneStringsHash = new LinkedHashMap(); + zoneStringsHash = new HashMap(); + zoneStringsKeyList = new ArrayList(); for (ULocale tempLocale = requestedLocale; tempLocale != null; tempLocale = tempLocale.getFallback()) { ICUResourceBundle bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, tempLocale); ICUResourceBundle zoneStringsBundle = bundle.getWithFallback("zoneStrings"); for(int i=0; iDecimalFormat is a concrete subclass of @@ -581,9 +583,9 @@ import java.io.ObjectInputStream; * not affect parsing or change any numerical values. * *
  • A rounding mode determines how values are rounded; see the - * {@link java.math.BigDecimal} documentation for a description of the + * {@link com.ibm.icu.math.BigDecimal} documentation for a description of the * modes. Rounding increments specified in patterns use the default mode, - * {@link java.math.BigDecimal#ROUND_HALF_EVEN}. + * {@link com.ibm.icu.math.BigDecimal#ROUND_HALF_EVEN}. * *
  • Some locales use rounding in their currency formats to reflect the * smallest currency denomination. @@ -781,17 +783,17 @@ public class DecimalFormat extends NumberFormat { int mode, boolean isNegative) { double div = number / roundingInc; switch (mode) { - case java.math.BigDecimal.ROUND_CEILING: + case com.ibm.icu.math.BigDecimal.ROUND_CEILING: return (isNegative ? Math.floor(div) : Math.ceil(div)) * roundingInc; - case java.math.BigDecimal.ROUND_FLOOR: + case com.ibm.icu.math.BigDecimal.ROUND_FLOOR: return (isNegative ? Math.ceil(div) : Math.floor(div)) * roundingInc; - case java.math.BigDecimal.ROUND_DOWN: + case com.ibm.icu.math.BigDecimal.ROUND_DOWN: return (Math.floor(div)) * roundingInc; - case java.math.BigDecimal.ROUND_UP: + case com.ibm.icu.math.BigDecimal.ROUND_UP: return (Math.ceil(div)) * roundingInc; - case java.math.BigDecimal.ROUND_UNNECESSARY: + case com.ibm.icu.math.BigDecimal.ROUND_UNNECESSARY: if (div != Math.floor(div)) { throw new ArithmeticException("Rounding necessary"); } @@ -804,7 +806,7 @@ public class DecimalFormat extends NumberFormat { double floor = Math.floor(div); double floordiff = number - (floor * roundingInc); switch (mode) { - case java.math.BigDecimal.ROUND_HALF_EVEN: + case com.ibm.icu.math.BigDecimal.ROUND_HALF_EVEN: // We should be able to just return Math.rint(a), but this // doesn't work in some VMs. if (ceildiff != floordiff) { @@ -814,9 +816,9 @@ public class DecimalFormat extends NumberFormat { return (floor == Math.floor(floor) ? Math.floor(div) : (Math.floor(div) + 1.0)) * roundingInc; - case java.math.BigDecimal.ROUND_HALF_DOWN: + case com.ibm.icu.math.BigDecimal.ROUND_HALF_DOWN: return ((floordiff <= ceildiff) ? floor : ceil) * roundingInc; - case java.math.BigDecimal.ROUND_HALF_UP: + case com.ibm.icu.math.BigDecimal.ROUND_HALF_UP: return ((ceildiff <= floordiff) ? ceil : floor) * roundingInc; default: throw new IllegalArgumentException("Invalid rounding mode: " + mode); @@ -835,8 +837,8 @@ public class DecimalFormat extends NumberFormat { // If we are to do rounding, we need to move into the BigDecimal // domain in order to do divide/multiply correctly. // [NEW] - if (roundingIncrement != null) { - return format(java.math.BigDecimal.valueOf(number), result, fieldPosition); + if (roundingIncrementICU != null) { + return format(com.ibm.icu.math.BigDecimal.valueOf(number), result, fieldPosition); } boolean isNegative = (number < 0); @@ -880,8 +882,8 @@ public class DecimalFormat extends NumberFormat { FieldPosition fieldPosition) { // If we are to do rounding, we need to move into the BigDecimal // domain in order to do divide/multiply correctly. - if (roundingIncrement != null) { - return format(new java.math.BigDecimal(number), result, fieldPosition); + if (roundingIncrementICU != null) { + return format(new com.ibm.icu.math.BigDecimal(number), result, fieldPosition); } if (multiplier != 1) { @@ -896,6 +898,7 @@ public class DecimalFormat extends NumberFormat { } } +//#ifndef FOUNDATION /** * NEW * Format a BigDecimal number. @@ -918,7 +921,8 @@ public class DecimalFormat extends NumberFormat { return subformat(result, fieldPosition, number.signum() < 0, false); } } - +//#endif + /** * NEW * Format a BigDecimal number. @@ -936,10 +940,9 @@ public class DecimalFormat extends NumberFormat { number = number.multiply(com.ibm.icu.math.BigDecimal.valueOf(multiplier)); } - if (roundingIncrement != null) { - com.ibm.icu.math.BigDecimal ri = new com.ibm.icu.math.BigDecimal(roundingIncrement); - number = number.divide(ri, 0, roundingMode) - .multiply(ri); + if (roundingIncrementICU != null) { + number = number.divide(roundingIncrementICU, 0, roundingMode) + .multiply(roundingIncrementICU); } synchronized(digitList) { @@ -1482,11 +1485,11 @@ public class DecimalFormat extends NumberFormat { // Handle non-integral values else { - java.math.BigDecimal big = digitList.getBigDecimal(status[STATUS_POSITIVE]); + com.ibm.icu.math.BigDecimal big = digitList.getBigDecimalICU(status[STATUS_POSITIVE]); n = big; if (mult != 1) { - n = big.divide(java.math.BigDecimal.valueOf(mult), - java.math.BigDecimal.ROUND_HALF_EVEN); + n = big.divide(com.ibm.icu.math.BigDecimal.valueOf(mult), + com.ibm.icu.math.BigDecimal.ROUND_HALF_EVEN); } } } @@ -2222,10 +2225,19 @@ public class DecimalFormat extends NumberFormat { * @see #setRoundingMode * @stable ICU 2.0 */ +//#ifndef FOUNDATION public java.math.BigDecimal getRoundingIncrement() { - return roundingIncrement; + if (roundingIncrementICU == null) return null; + return new java.math.BigDecimal(roundingIncrementICU.toString()); } - +//#else +//## public com.ibm.icu.math.BigDecimal getRoundingIncrement() { +//## if (roundingIncrementICU == null) return null; +//## return new com.ibm.icu.math.BigDecimal(roundingIncrementICU.toString()); +//## } +//#endif + +//#ifndef FOUNDATION /** * NEW * Set the rounding increment. This method also controls whether @@ -2245,15 +2257,44 @@ public class DecimalFormat extends NumberFormat { throw new IllegalArgumentException("Illegal rounding increment"); } if (i == 0) { - roundingIncrement = null; + roundingIncrementICU = null; roundingDouble = 0.0; } else { - roundingIncrement = newValue; + roundingIncrementICU = new com.ibm.icu.math.BigDecimal(newValue); roundingDouble = newValue.doubleValue(); } } - - /** +//#endif + +//#ifdef FOUNDATION +//## /** +//## * Set the rounding increment. This method also controls whether +//## * rounding is enabled. +//## * @param newValue A positive rounding increment, or null or +//## * BigDecimal(0.0) to disable rounding. +//## * @exception IllegalArgumentException if newValue is < 0.0 +//## * @see #getRoundingIncrement +//## * @see #getRoundingMode +//## * @see #setRoundingMode +//## * @draft ICU 3.6 +//## */ +//## public void setRoundingIncrement(com.ibm.icu.math.BigDecimal newValue) { +//## int i = newValue == null +//## ? 0 : newValue.compareTo(com.ibm.icu.math.BigDecimal.valueOf(0)); +//## if (i < 0) { +//## throw new IllegalArgumentException("Illegal rounding increment"); +//## } +//## if (i == 0) { +//## roundingIncrementICU = null; +//## roundingDouble = 0.0; +//## } else { +//## roundingIncrementICU = newValue; +//## roundingDouble = newValue.doubleValue(); +//## } +//## } +//#endif + + /** * NEW * Set the rounding increment. This method also controls whether * rounding is enabled. @@ -2270,8 +2311,8 @@ public class DecimalFormat extends NumberFormat { throw new IllegalArgumentException("Illegal rounding increment"); } roundingDouble = newValue; - roundingIncrement = (newValue > 0.0) - ? new java.math.BigDecimal(String.valueOf(newValue)) : null; + roundingIncrementICU = (newValue > 0.0) + ? new com.ibm.icu.math.BigDecimal(String.valueOf(newValue)) : null; } /** @@ -2305,8 +2346,8 @@ public class DecimalFormat extends NumberFormat { * @stable ICU 2.0 */ public void setRoundingMode(int roundingMode) { - if (roundingMode < java.math.BigDecimal.ROUND_UP - || roundingMode > java.math.BigDecimal.ROUND_UNNECESSARY) { + if (roundingMode < com.ibm.icu.math.BigDecimal.ROUND_UP + || roundingMode > com.ibm.icu.math.BigDecimal.ROUND_UNNECESSARY) { throw new IllegalArgumentException("Invalid rounding mode: " + roundingMode); } @@ -3025,9 +3066,9 @@ public class DecimalFormat extends NumberFormat { append(localized ? symbols.getPadEscape() : PATTERN_PAD_ESCAPE). append(pad).toString() : null; - if (roundingIncrement != null) { - i = roundingIncrement.scale(); - roundingDigits = roundingIncrement.movePointRight(i).toString(); + if (roundingIncrementICU != null) { + i = roundingIncrementICU.scale(); + roundingDigits = roundingIncrementICU.movePointRight(i).toString(); roundingDecimalPos = roundingDigits.length() - i; } for (int part=0; part<2; ++part) { @@ -3649,14 +3690,14 @@ public class DecimalFormat extends NumberFormat { // BigDecimal scale cannot be negative (even though // this makes perfect sense), so we need to handle this. int scale = incrementPos - effectiveDecimalPos; - roundingIncrement = - java.math.BigDecimal.valueOf(incrementVal, scale > 0 ? scale : 0); + roundingIncrementICU = + com.ibm.icu.math.BigDecimal.valueOf(incrementVal, scale > 0 ? scale : 0); if (scale < 0) { - roundingIncrement = - roundingIncrement.movePointRight(-scale); + roundingIncrementICU = + roundingIncrementICU.movePointRight(-scale); } - roundingDouble = roundingIncrement.doubleValue(); - roundingMode = java.math.BigDecimal.ROUND_HALF_EVEN; + roundingDouble = roundingIncrementICU.doubleValue(); + roundingMode = com.ibm.icu.math.BigDecimal.ROUND_HALF_EVEN; } else { setRoundingIncrement(null); } @@ -3898,6 +3939,16 @@ public class DecimalFormat extends NumberFormat { super.setMinimumFractionDigits(Math.min(newValue, DOUBLE_FRACTION_DIGITS)); } +//#ifndef FOUNDATION + private void writeObject(ObjectOutputStream stream) throws IOException, ClassNotFoundException { + if (roundingIncrementICU != null) { + roundingIncrement = new java.math.BigDecimal(roundingIncrementICU.toString()); + } + + stream.defaultWriteObject(); + } +//#endif + /** * First, read the default serializable fields from the stream. Then * if serialVersionOnStream is less than 1, indicating that @@ -3933,8 +3984,8 @@ public class DecimalFormat extends NumberFormat { if (serialVersionOnStream < 2) { exponentSignAlwaysShown = false; roundingDouble = 0.0; - roundingIncrement = null; - roundingMode = java.math.BigDecimal.ROUND_HALF_EVEN; + roundingIncrementICU = null; + roundingMode = com.ibm.icu.math.BigDecimal.ROUND_HALF_EVEN; formatWidth = 0; pad = ' '; padPosition = PAD_BEFORE_PREFIX; @@ -3950,6 +4001,11 @@ public class DecimalFormat extends NumberFormat { } serialVersionOnStream = currentSerialVersion; digitList = new DigitList(); +//#ifndef FOUNDATION + if (roundingIncrement != null && roundingIncrementICU == null) { + roundingIncrementICU = new com.ibm.icu.math.BigDecimal(roundingIncrement); + } +//#endif } //---------------------------------------------------------------------- @@ -4165,6 +4221,7 @@ public class DecimalFormat extends NumberFormat { */ private boolean exponentSignAlwaysShown = false; +//#ifndef FOUNDATION /** * NEW * The value to which numbers are rounded during formatting. For example, @@ -4176,12 +4233,13 @@ public class DecimalFormat extends NumberFormat { * @since AlphaWorks NumberFormat */ private java.math.BigDecimal roundingIncrement = null; +//#endif /** * NEW * The rounding increment as a double. If this value is <= 0, then no * rounding is done. This value is - * roundingIncrement.doubleValue(). Default value 0.0. + * roundingIncrementICU.doubleValue(). Default value 0.0. */ private transient double roundingDouble = 0.0; @@ -4195,7 +4253,7 @@ public class DecimalFormat extends NumberFormat { * @serial * @since AlphaWorks NumberFormat */ - private int roundingMode = java.math.BigDecimal.ROUND_HALF_EVEN; + private int roundingMode = com.ibm.icu.math.BigDecimal.ROUND_HALF_EVEN; /** * NEW @@ -4359,14 +4417,16 @@ public class DecimalFormat extends NumberFormat { */ static final int MAX_SCIENTIFIC_INTEGER_DIGITS = 8; +//#ifdef FOUNDATION +//## // we're not compatible with other versions, since we have no java.math.BigDecimal field +//## private static final long serialVersionUID = 2; +//#else // Proclaim JDK 1.1 serial compatibility. private static final long serialVersionUID = 864413376551465018L; +//#endif - /** - * Cache to hold the NumberPattern of a Locale. - * [NEW] No longer needed -- share the NumberFormat cache - */ - // private static Hashtable cachedLocaleData = new Hashtable(3); + // 'foundationize' by converting to ICU's BigDecimal only + private com.ibm.icu.math.BigDecimal roundingIncrementICU; } //eof diff --git a/icu4j/src/com/ibm/icu/text/DigitList.java b/icu4j/src/com/ibm/icu/text/DigitList.java index 9ab8120d39e..f46fb90ba3c 100755 --- a/icu4j/src/com/ibm/icu/text/DigitList.java +++ b/icu4j/src/com/ibm/icu/text/DigitList.java @@ -1,6 +1,7 @@ +//##header 1132615047000 /* ******************************************************************************* - * Copyright (C) 1996-2004, International Business Machines Corporation and * + * Copyright (C) 1996-2005, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -200,15 +201,8 @@ final class DigitList { } } - /** - * Return a BigDecimal representing the value stored in this - * DigitList. - * [bnf] - * @param isPositive determines the sign of the returned result - * @return the value of this object as a BigDecimal - */ - public java.math.BigDecimal getBigDecimal(boolean isPositive) { - if (isZero()) return java.math.BigDecimal.valueOf(0); + private String getStringRep(boolean isPositive) { + if (isZero()) return "0"; StringBuffer stringRep = new StringBuffer(count+1); if (!isPositive) { stringRep.append('-'); @@ -231,7 +225,33 @@ final class DigitList { while (d-- > count) { stringRep.append('0'); } - return new java.math.BigDecimal(stringRep.toString()); + return stringRep.toString(); + } + +//#ifndef FOUNDATION + /** + * Return a BigDecimal representing the value stored in this + * DigitList. + * [bnf] + * @param isPositive determines the sign of the returned result + * @return the value of this object as a BigDecimal + */ + public java.math.BigDecimal getBigDecimal(boolean isPositive) { + if (isZero()) return java.math.BigDecimal.valueOf(0); + return new java.math.BigDecimal(getStringRep(isPositive)); + } +//#endif + + /** + * Return an ICU BigDecimal representing the value stored in this + * DigitList. + * [bnf] + * @param isPositive determines the sign of the returned result + * @return the value of this object as a BigDecimal + */ + public com.ibm.icu.math.BigDecimal getBigDecimalICU(boolean isPositive) { + if (isZero()) return com.ibm.icu.math.BigDecimal.valueOf(0); + return new com.ibm.icu.math.BigDecimal(getStringRep(isPositive)); } /** @@ -640,6 +660,7 @@ final class DigitList { round(fixedPoint ? (maximumDigits + decimalAt) : maximumDigits == 0 ? -1 : maximumDigits); } +//#ifndef FOUNDATION /** * Set the digit list to a representation of the given BigDecimal value. * [bnf] @@ -654,6 +675,7 @@ final class DigitList { int maximumDigits, boolean fixedPoint) { setBigDecimalDigits(source.toString(), maximumDigits, fixedPoint); } +//#endif /* * Set the digit list to a representation of the given BigDecimal value. diff --git a/icu4j/src/com/ibm/icu/text/NumberFormat.java b/icu4j/src/com/ibm/icu/text/NumberFormat.java index b4dc0e565b8..60c09c2003e 100755 --- a/icu4j/src/com/ibm/icu/text/NumberFormat.java +++ b/icu4j/src/com/ibm/icu/text/NumberFormat.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ******************************************************************************* * Copyright (C) 1996-2005, International Business Machines Corporation and * @@ -192,8 +193,10 @@ public abstract class NumberFormat extends UFormat { return format(((Long)number).longValue(), toAppendTo, pos); } else if (number instanceof BigInteger) { return format((BigInteger) number, toAppendTo, pos); +//#ifndef FOUNDATION } else if (number instanceof java.math.BigDecimal) { return format((java.math.BigDecimal) number, toAppendTo, pos); +//#endif } else if (number instanceof com.ibm.icu.math.BigDecimal) { return format((com.ibm.icu.math.BigDecimal) number, toAppendTo, pos); } else if (number instanceof CurrencyAmount) { @@ -246,6 +249,7 @@ public abstract class NumberFormat extends UFormat { new FieldPosition(0)).toString(); } +//#ifndef FOUNDATION /** * NEW * Convenience method to format a BigDecimal. @@ -255,6 +259,7 @@ public abstract class NumberFormat extends UFormat { return format(number, new StringBuffer(), new FieldPosition(0)).toString(); } +//#endif /** * NEW @@ -304,7 +309,7 @@ public abstract class NumberFormat extends UFormat { public abstract StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos); - +//#ifndef FOUNDATION /** * NEW * Format a BigDecimal. @@ -314,6 +319,7 @@ public abstract class NumberFormat extends UFormat { public abstract StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos); +//#endif /** * NEW diff --git a/icu4j/src/com/ibm/icu/text/RBNFChinesePostProcessor.java b/icu4j/src/com/ibm/icu/text/RBNFChinesePostProcessor.java index c2c3330a268..3ec007eaeaa 100644 --- a/icu4j/src/com/ibm/icu/text/RBNFChinesePostProcessor.java +++ b/icu4j/src/com/ibm/icu/text/RBNFChinesePostProcessor.java @@ -7,6 +7,8 @@ package com.ibm.icu.text; +import com.ibm.icu.impl.Utility; + /** * A post-processor for Chinese text. */ @@ -45,7 +47,7 @@ final class RBNFChinesePostProcessor extends RBNFPostProcessor { } if (longForm) { - for (int i = buf.indexOf("*"); i != -1; i = buf.indexOf("*", i)) { + for (int i = Utility.indexOf(buf,"*"); i != -1; i = Utility.indexOf(buf, "*", i)) { buf.delete(i, i+1); } return; @@ -79,14 +81,14 @@ final class RBNFChinesePostProcessor extends RBNFPostProcessor { { String[] m = markers[format]; for (int i = 0; i < m.length-1; ++i) { - int n = buf.indexOf(m[i]); + int n = Utility.indexOf(buf, m[i]); if (n != -1) { buf.insert(n+m[i].length(), '|'); } } } - int x = buf.indexOf(DIAN); + int x = Utility.indexOf(buf, DIAN); if (x == -1) { x = buf.length(); } @@ -94,8 +96,8 @@ final class RBNFChinesePostProcessor extends RBNFPostProcessor { int n = -1; // previous optional ling String ling = markers[format][3]; while (x >= 0) { - int m = buf.lastIndexOf("|", x); - int nn = buf.lastIndexOf(ling, x); + int m = Utility.lastIndexOf(buf, "|", x); + int nn = Utility.lastIndexOf(buf, ling, x); int ns = 0; if (nn > m) { ns = (nn > 0 && buf.charAt(nn-1) != '*') ? 2 : 1; diff --git a/icu4j/src/com/ibm/icu/text/RuleBasedBreakIterator_New.java b/icu4j/src/com/ibm/icu/text/RuleBasedBreakIterator_New.java index 8337c3a0ae5..62d57225ac3 100644 --- a/icu4j/src/com/ibm/icu/text/RuleBasedBreakIterator_New.java +++ b/icu4j/src/com/ibm/icu/text/RuleBasedBreakIterator_New.java @@ -6,9 +6,11 @@ */ package com.ibm.icu.text; -import java.text.CharacterIterator; import java.io.IOException; import java.io.InputStream; +import java.text.CharacterIterator; + +import com.ibm.icu.impl.Assert; /** @@ -23,6 +25,7 @@ import java.io.InputStream; * @internal */ public class RuleBasedBreakIterator_New extends RuleBasedBreakIterator { + private static final boolean ASSERT = false; private static final int START_STATE = 1; // The state number of the starting state private static final int STOP_STATE = 0; // The state-transition value indicating "stop" @@ -526,7 +529,7 @@ public boolean isBoundary(int offset) { */ public int current() { return (fText != null) ? fText.getIndex() : BreakIterator.DONE; - } +} @@ -542,11 +545,14 @@ private void makeRuleStatusValid() { int pa = current(); previous(); int pb = next(); - assert pa == pb; + if (ASSERT) Assert.assrt("pa == pb", pa == pb); } } - assert fLastStatusIndexValid == true; - assert fLastRuleStatusIndex >= 0 && fLastRuleStatusIndex < fRData.fStatusTable.length; + if (ASSERT) { + Assert.assrt("fLastStatusIndexValid == true", fLastStatusIndexValid == true); + Assert.assrt("fLastRuleStatusIndex >= 0 && fLastRuleStatusIndex < fRData.fStatusTable.length", + fLastRuleStatusIndex >= 0 && fLastRuleStatusIndex < fRData.fStatusTable.length); + } } diff --git a/icu4j/src/com/ibm/icu/text/RuleBasedCollator.java b/icu4j/src/com/ibm/icu/text/RuleBasedCollator.java index 015d8d52181..1127532fa40 100755 --- a/icu4j/src/com/ibm/icu/text/RuleBasedCollator.java +++ b/icu4j/src/com/ibm/icu/text/RuleBasedCollator.java @@ -1,3 +1,4 @@ +//##header 1132615671000 /** ******************************************************************************* * Copyright (C) 1996-2005, International Business Machines Corporation and * @@ -7,12 +8,17 @@ package com.ibm.icu.text; import java.io.IOException; -import java.nio.ByteBuffer; import java.text.CharacterIterator; import java.text.ParseException; import java.util.Arrays; import java.util.MissingResourceException; +//#ifndef FOUNDATION +import java.nio.ByteBuffer; +//#else +//##import com.ibm.icu.impl.ByteBuffer; +//#endif + import com.ibm.icu.impl.BOCU; import com.ibm.icu.impl.ICUDebug; import com.ibm.icu.impl.ICUResourceBundle; diff --git a/icu4j/src/com/ibm/icu/text/RuleBasedNumberFormat.java b/icu4j/src/com/ibm/icu/text/RuleBasedNumberFormat.java index 1e1a8e82ba4..9594b3aa8f2 100755 --- a/icu4j/src/com/ibm/icu/text/RuleBasedNumberFormat.java +++ b/icu4j/src/com/ibm/icu/text/RuleBasedNumberFormat.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ******************************************************************************* * Copyright (C) 1996-2005, International Business Machines Corporation and * @@ -11,6 +12,7 @@ package com.ibm.icu.text; import com.ibm.icu.impl.ICUDebug; import com.ibm.icu.impl.ICUResourceBundle; import com.ibm.icu.impl.UCharacterProperty; +import com.ibm.icu.impl.Utility; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; @@ -1096,6 +1098,7 @@ public class RuleBasedNumberFormat extends NumberFormat { return format(new com.ibm.icu.math.BigDecimal(number), toAppendTo, pos); } +//#ifndef FOUNDATION /** * NEW * Implement com.ibm.icu.text.NumberFormat: @@ -1107,6 +1110,7 @@ public class RuleBasedNumberFormat extends NumberFormat { FieldPosition pos) { return format(new com.ibm.icu.math.BigDecimal(number), toAppendTo, pos); } +//#endif /** * NEW @@ -1373,7 +1377,7 @@ public class RuleBasedNumberFormat extends NumberFormat { */ private String extractSpecial(StringBuffer description, String specialName) { String result = null; - int lp = description.indexOf(specialName); + int lp = Utility.indexOf(description, specialName); if (lp != -1) { // we've got to make sure we're not in the middle of a rule // (where specialName would actually get treated as @@ -1382,7 +1386,7 @@ public class RuleBasedNumberFormat extends NumberFormat { // locate the beginning and end of the actual special // rules (there may be whitespace between the name and // the first token in the description) - int lpEnd = description.indexOf(";%", lp); + int lpEnd = Utility.indexOf(description, ";%", lp); if (lpEnd == -1) { lpEnd = description.length() - 1; // later we add 1 back to get the '%' @@ -1433,7 +1437,7 @@ public class RuleBasedNumberFormat extends NumberFormat { // rule sets (";%" marks the end of one rule set and the beginning // of the next) int numRuleSets = 0; - for (int p = descBuf.indexOf(";%"); p != -1; p = descBuf.indexOf(";%", p)) { + for (int p = Utility.indexOf(descBuf, ";%"); p != -1; p = Utility.indexOf(descBuf, ";%", p)) { ++numRuleSets; ++p; } @@ -1453,7 +1457,7 @@ public class RuleBasedNumberFormat extends NumberFormat { int curRuleSet = 0; int start = 0; - for (int p = descBuf.indexOf(";%"); p != -1; p = descBuf.indexOf(";%", start)) { + for (int p = Utility.indexOf(descBuf, ";%"); p != -1; p = Utility.indexOf(descBuf, ";%", start)) { ruleSetDescriptions[curRuleSet] = descBuf.substring(start, p + 1); ruleSets[curRuleSet] = new NFRuleSet(ruleSetDescriptions, curRuleSet); ++curRuleSet; diff --git a/icu4j/src/com/ibm/icu/text/Transliterator.java b/icu4j/src/com/ibm/icu/text/Transliterator.java index 70ae13bfac5..bd48b45f3aa 100755 --- a/icu4j/src/com/ibm/icu/text/Transliterator.java +++ b/icu4j/src/com/ibm/icu/text/Transliterator.java @@ -1358,7 +1358,7 @@ public abstract class Transliterator { // assert(list.size() > 0); Transliterator t = null; - if (list.size() > 1 || canonID.indexOf(";") >= 0) { + if (list.size() > 1 || Utility.indexOf(canonID, ";") >= 0) { // [NOTE: If it's a compoundID, we instantiate a CompoundTransliterator even if it only // has one child transliterator. This is so that toRules() will return the right thing // (without any inactive ID), but our main ID still comes out correct. That is, if we diff --git a/icu4j/src/com/ibm/icu/text/UnicodeSet.java b/icu4j/src/com/ibm/icu/text/UnicodeSet.java index 13a1e4d4f70..6656bf09667 100755 --- a/icu4j/src/com/ibm/icu/text/UnicodeSet.java +++ b/icu4j/src/com/ibm/icu/text/UnicodeSet.java @@ -31,7 +31,6 @@ import java.util.MissingResourceException; import java.util.TreeSet; import java.util.Iterator; import java.util.Collection; -import java.util.regex.Pattern; /** * A mutable set of Unicode characters and multicharacter strings. Objects of this class diff --git a/icu4j/src/com/ibm/icu/util/ByteArrayWrapper.java b/icu4j/src/com/ibm/icu/util/ByteArrayWrapper.java index 723744f0304..cc40276d344 100644 --- a/icu4j/src/com/ibm/icu/util/ByteArrayWrapper.java +++ b/icu4j/src/com/ibm/icu/util/ByteArrayWrapper.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /** ******************************************************************************* * Copyright (C) 1996-2005, International Business Machines Corporation and * @@ -7,8 +8,11 @@ package com.ibm.icu.util; +//#ifndef FOUNDATION import java.nio.ByteBuffer; - +//#else +//##import com.ibm.icu.impl.ByteBuffer; +//#endif import com.ibm.icu.impl.Utility; /** diff --git a/icu4j/src/com/ibm/icu/util/GlobalizationPreferences.java b/icu4j/src/com/ibm/icu/util/GlobalizationPreferences.java index ee058cc151a..5e6b574bf3c 100644 --- a/icu4j/src/com/ibm/icu/util/GlobalizationPreferences.java +++ b/icu4j/src/com/ibm/icu/util/GlobalizationPreferences.java @@ -1,3 +1,4 @@ +//##header 1132615047000 /* ******************************************************************************* * Copyright (C) 2004-2005, International Business Machines Corporation and * @@ -14,8 +15,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; + +//#ifndef FOUNDATION import java.util.regex.Matcher; import java.util.regex.Pattern; +//#endif import com.ibm.icu.impl.Utility; import com.ibm.icu.impl.ZoneMeta; @@ -43,6 +47,9 @@ import com.ibm.icu.text.SimpleDateFormat; * in Breton if available, otherwise in French if available, otherwise in English. *

    This is at a prototype stage, and has not incorporated all the design changes * that we would like yet; further feedback is welcome. + * + * @internal + * @deprecated ICU 3.4.2 */ public class GlobalizationPreferences { /** @@ -110,6 +117,8 @@ public class GlobalizationPreferences { public GlobalizationPreferences setULocales(ULocale uLocale) { return setULocales(new ULocale[]{uLocale}); } + +//#ifndef FOUNDATION /** * Convenience routine for setting the locale priority list from an Accept-Language string. * @see #setULocales(List locales) @@ -153,7 +162,8 @@ public class GlobalizationPreferences { } return setULocales(result); } - +//#endif + /** * Sets the territory, which is a valid territory according to for RFC 3066 (or successor). * If not otherwise set, default currency and timezone values will be set from this. @@ -318,7 +328,10 @@ public class GlobalizationPreferences { // TODO, have method that doesn't require us to create a timezone // fix other hacks // hack for couldn't match + // note, compiling with FOUNDATION omits this check for now +//#ifndef FOUNDATION if (badTimezone.reset(result).matches()) continue; +//#endif break; default: throw new IllegalArgumentException("Unknown type: " + type); @@ -329,8 +342,10 @@ public class GlobalizationPreferences { } return result; } +//#ifndef FOUNDATION // TODO remove need for this private static final Matcher badTimezone = Pattern.compile("[A-Z]{2}|.*\\s\\([A-Z]{2}\\)").matcher(""); +//#endif /** * Set an explicit date format. Overrides both the date locale, and the locale priority list @@ -378,7 +393,11 @@ public class GlobalizationPreferences { } return result; } catch (RuntimeException e) { - throw (IllegalArgumentException) new IllegalArgumentException("Cannot create DateFormat").initCause(e); + IllegalArgumentException ex = new IllegalArgumentException("Cannot create DateFormat"); +//#ifndef FOUNDATION + ex.initCause(e); +//#endif + throw ex; } } @@ -718,4 +737,4 @@ public class GlobalizationPreferences { territory_tzid_hack_map.put(territory_tzid_hack[i][0],territory_tzid_hack[i][1]); } } -} \ No newline at end of file +} diff --git a/icu4j/src/com/ibm/icu/util/ULocale.java b/icu4j/src/com/ibm/icu/util/ULocale.java index f672719f21c..a8affd7d00c 100644 --- a/icu4j/src/com/ibm/icu/util/ULocale.java +++ b/icu4j/src/com/ibm/icu/util/ULocale.java @@ -16,9 +16,10 @@ import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.TreeMap; -import com.ibm.icu.impl.LocaleUtility; +import com.ibm.icu.impl.LocaleUtility; import com.ibm.icu.impl.ICUResourceBundle; +import com.ibm.icu.lang.UCharacter; /** * A class analogous to {@link java.util.Locale} that provides additional @@ -2669,19 +2670,19 @@ public final class ULocale implements Serializable { if((paramEnd != -1) && (paramEnd < itemEnd)) { /* semicolon (;) is closer than end (,) */ int t = paramEnd + 1; - while(Character.isSpace(acceptLanguageList.charAt(t))) { + while(UCharacter.isWhitespace(acceptLanguageList.charAt(t))) { t++; } if(acceptLanguageList.charAt(t)=='q') { t++; } - while(Character.isSpace(acceptLanguageList.charAt(t))) { + while(UCharacter.isWhitespace(acceptLanguageList.charAt(t))) { t++; } if(acceptLanguageList.charAt(t)=='=') { t++; } - while(Character.isSpace(acceptLanguageList.charAt(t))) { + while(UCharacter.isWhitespace(acceptLanguageList.charAt(t))) { t++; } try { diff --git a/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java b/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java index 22a49a50e3a..0d5b2a4fce3 100644 --- a/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java +++ b/icu4j/src/com/ibm/icu/util/UniversalTimeScale.java @@ -531,7 +531,7 @@ public final class UniversalTimeScale public static BigDecimal bigDecimalFrom(double otherTime, int timeScale) { TimeScaleData data = getTimeScaleData(timeScale); - BigDecimal other = new BigDecimal(otherTime); + BigDecimal other = new BigDecimal(String.valueOf(otherTime)); BigDecimal units = new BigDecimal(data.units); BigDecimal epochOffset = new BigDecimal(data.epochOffset);