ICU-4914 merge 3.4.1 branch back into HEAD

X-SVN-Rev: 18760
This commit is contained in:
Doug Felt 2005-11-05 00:13:48 +00:00
parent aded11936e
commit 4dbb53ac7a
10 changed files with 156 additions and 75 deletions

View File

@ -85,6 +85,8 @@
<property name="testjar.file" value="icu4jtests.jar"/>
<property name="jar.file" value="icu4j.jar"/>
<property name="jarSrc.file" value="icu4jsrc.jar"/>
<property name="zipCoreSrc.file" value="icu4jcsrc.zip"/>
<property name="zipTestSrc.file" value="icu4jtsrc.zip"/>
<property name="jarDocs.file" value="icu4jdocs.jar"/>
<property name="icu4j.manifest" value="${src.dir}/com/ibm/icu/manifest.stub"/>
<property name="icu4j.module.manifest" value="${src.dir}/com/ibm/icu/manifest.module.stub"/>
@ -439,10 +441,26 @@
<jar jarfile="${jarSrc.file}"
compress="true"
basedir="."
excludes="${richedit.dir}/**/*,test_*,${src.dir}/com/ibm/icu/dev/data/unicode//UnicodeData-*.txt,${src.dir}/com/ibm/icu/dev/data/unicode/SpecialCasing-*.txt,${src.dir}/com/ibm/icu/dev/data/unicode/CompositionExclusions-*.txt,${obsolete.dir}/**,**/*~,${src.dir}/**/*.class,${build.dir}/**,**/CVS/**/*,${doc.dir}/**,${jar.file}"
excludes="${richedit.dir}/**/*,test_*,${src.dir}/com/ibm/icu/dev/data/unicode//UnicodeData-*.txt,${src.dir}/com/ibm/icu/dev/data/unicode/SpecialCasing-*.txt,${src.dir}/com/ibm/icu/dev/data/unicode/CompositionExclusions-*.txt,${obsolete.dir}/**,**/*~,${src.dir}/**/*.class,${build.dir}/**,**/CVS/**/*,${doc.dir}/**,*.jar,*.zip, *.gz"
manifest="${icu4j.manifest}"/>
</target>
<target name="zipCoreSrc" depends="init" description="build zip of core sources for debugging">
<!-- for eclipse -->
<zip destfile="${zipCoreSrc.file}"
compress="true"
basedir="${src.dir}"
includes="com/ibm/icu/impl/**/*,com/ibm/icu/lang/**/*,com/ibm/icu/math/**/*,com/ibm/icu/text/**/*,com/ibm/icu/util/**/*"/>
</target>
<target name="zipTestSrc" depends="init" description="build zip of test sources for debugging">
<!-- for eclipse -->
<zip destfile="${zipTestSrc.file}"
compress="true"
basedir="${src.dir}"
includes="com/ibm/icu/dev/test/**/*"/>
</target>
<target name="jarDocs" depends="docs" description="build documentation 'icu4jdocs.jar' jar file">
<jar jarfile="${jarDocs.file}"
compress="true"
@ -585,7 +603,6 @@
<jvmarg value="-Djava.security.policy=${src.dir}/com/ibm/icu/dev/test/security.policy"/>
<!-- jvmarg value="-Djava.security.debug=access:failure"/ -->
<arg value="-w"/>
<!-- arg value="Serializable/CoverageTest"/ -->
<classpath>
<pathelement location="clover.jar"/>
<pathelement location="${jar.file}"/>
@ -652,11 +669,10 @@
<arg value="-old:"/>
<arg value="${api.dir}/icu4j34.api.gz"/>
<arg value="-new:"/>
<arg value="${api.dir}/icu4j34.1.api.gz"/>
<arg value="${api.dir}/icu4j341.api.gz"/>
<arg value="-html"/>
<arg value="-out:"/>
<arg value="${api.dir}/icu4j_compare_34_341.html"/>
<!-- arg value="icu4j_compare_32_34.txt"/> -->
</java>
</target>

View File

@ -69,6 +69,7 @@ public class TestFmwk extends AbstractTestLog {
}
String msg = ex.getMessage();
System.err.println("TF handleException msg: " + msg);
if (ex instanceof MissingResourceException || ex instanceof NoClassDefFoundError) {
if (params.warnings || params.nodata) {
warnln(msg);
@ -989,9 +990,9 @@ public class TestFmwk extends AbstractTestLog {
public State stack;
private StringBuffer errorSummary;
public StringBuffer errorSummary;
private PrintWriter log;
public PrintWriter log;
public int indentLevel;
private boolean needLineFeed;
private boolean suppressIndent;

View File

@ -17,6 +17,7 @@ package com.ibm.icu.dev.test.timezone;
import com.ibm.icu.dev.test.*;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.util.*;
import com.ibm.icu.text.SimpleDateFormat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -316,8 +317,10 @@ public class TimeZoneTest extends TestFmwk
TimeZone zone = TimeZone.getTimeZone("PST");
String name = zone.getDisplayName(Locale.ENGLISH);
logln("PST->" + name);
if (!name.equals("Pacific Standard Time"))
errln("Fail: Expected \"Pacific Standard Time\", got " + name +
// dlf - we now (3.4.1) return generic time
if (!name.equals("Pacific Time"))
errln("Fail: Expected \"Pacific Time\", got " + name +
" for " + zone);
//*****************************************************************
@ -344,14 +347,16 @@ public class TimeZoneTest extends TestFmwk
// Make sure that we don't display the DST name by constructing a fake
// PST zone that has DST all year long.
// dlf - this test is no longer relevant, we display generic time now
// so the behavior of the timezone doesn't matter
SimpleTimeZone zone2 = new SimpleTimeZone(0, "PST");
zone2.setStartRule(Calendar.JANUARY, 1, 0);
zone2.setEndRule(Calendar.DECEMBER, 31, 0);
logln("Modified PST inDaylightTime->" + zone2.inDaylightTime(new Date()));
name = zone2.getDisplayName(Locale.ENGLISH);
logln("Modified PST->" + name);
if (!name.equals("Pacific Standard Time"))
errln("Fail: Expected \"Pacific Standard Time\"");
if (!name.equals("Pacific Time"))
errln("Fail: Expected \"Pacific Time\"");
// Make sure we get the default display format for Locales
// with no display name data.
@ -378,16 +383,18 @@ public class TimeZoneTest extends TestFmwk
if (!name.equals("Pacific Standard Time"))
errln("Fail: Expected Pacific Standard Time for PST in mt_MT but got ");
}
else if(!name.equals("Pacific Standard Time") &&
// dlf - we will use generic time, or if unavailable, GMT for standard time in the zone
// - we now (3.4.1) have localizations for this zone, so change test string
else if(!name.equals("Los Angeles (Stati Uniti)") &&
!name.equals("GMT-08:00") &&
!name.equals("GMT-8:00") &&
!name.equals("GMT-0800") &&
!name.equals("GMT-800")) {
errln("Fail: Expected GMT-08:00 or something similar");
errln("************************************************************");
errln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED");
errln("************************************************************");
errln("Fail: got '" + name + "', expected GMT-08:00 or something similar\n" +
"************************************************************\n" +
"THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED\n" +
"************************************************************");
}
// Now try a non-existent zone
@ -413,6 +420,30 @@ public class TimeZoneTest extends TestFmwk
ULocale.setDefault(save);
}
public void TestDisplayName2() {
// Date now = new Date();
Date then = new Date(2005, 0, 1);
String[] timezones = {"America/Chicago", "Europe/Moscow", "Europe/Rome", "Asia/Shanghai", "WET" };
String[] locales = {"en", "fr", "de", "ja", "zh_TW", "zh_Hans" };
for (int j = 0; j < locales.length; ++j) {
ULocale locale = new ULocale(locales[j]);
for (int i = 0; i < timezones.length; ++i) {
TimeZone tz = TimeZone.getTimeZone(timezones[i]);
String displayName0 = tz.getDisplayName(locale); // doesn't work???
SimpleDateFormat dt = new SimpleDateFormat("vvvv", locale);
dt.setTimeZone(tz);
String displayName1 = dt.format(then); // date value _does_ matter if we fallback to GMT
logln(locale.getDisplayName() + ", " + tz.getID() + ": " + displayName0);
if (!displayName1.equals(displayName0)) {
errln(locale.getDisplayName() + ", " + tz.getID() +
": expected " + displayName1 + " but got: " + displayName0);
}
}
}
}
public void TestGenericAPI() {
String id = "NewGMT";
int offset = 12345;

View File

@ -6,12 +6,18 @@
*/
package com.ibm.icu.dev.test.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.JarURLConnection;
import java.nio.ByteBuffer;
import java.util.MissingResourceException;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.impl.ICUData;
@ -25,6 +31,7 @@ import com.ibm.icu.util.UResourceTypeMismatchException;
public final class ICUResourceBundleTest extends TestFmwk {
private static final ClassLoader testLoader = ICUResourceBundleTest.class.getClassLoader();
public static void main(String args[]) throws Exception {
ICUResourceBundleTest test = new ICUResourceBundleTest();
@ -33,26 +40,34 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
public void TestGetResources(){
try{
ClassLoader loader = getClass().getClassLoader();
Enumeration en = loader.getResources("META-INF");
for(;en.hasMoreElements();){
//URL url = loader.getResource("LocaleElements_en.class");
//File file = new File(url.getPath());
Enumeration en = testLoader.getResources("META-INF");
for(;en.hasMoreElements();) {
URL url = (URL)en.nextElement();
if (url == null) {
warnln("could not load resource data");
return;
}
File file = new File(url.getPath());
File[] files = file.listFiles();
if(files!=null){
for(int i=0; i<files.length; i++){
logln(files[i].getName());
if (url == null) {
warnln("could not load resource data");
return;
}
URLConnection c = url.openConnection();
if (c instanceof JarURLConnection) {
JarURLConnection jc = (JarURLConnection)c;
JarEntry je = jc.getJarEntry();
logln("jar entry: " + je.toString());
} else {
InputStream is = c.getInputStream();
logln("input stream:");
InputStreamReader r = new InputStreamReader(is);
BufferedReader br = new BufferedReader(r);
String line = null;
int n = 0;
while ((line = br.readLine()) != null) {
logln(" " + ++n + ": " + line);
}
}
}
}catch(SecurityException ex) {
warnln("could not load resource data: " + ex);
ex.printStackTrace();
}catch(NullPointerException ex) {
// thrown by ibm 1.4.2 windows jvm security manager
warnln("could not load resource data: " + ex);
@ -70,7 +85,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
errln("Did not get the expected output for Weekend data");
}
bundle = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "bogus", this.getClass().getClassLoader());
bundle = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "bogus");
if(bundle instanceof ICUResourceBundle && bundle.getULocale().equals("en_US")){
logln("wrapper mechanism works for bogus locale");
}else{
@ -78,7 +93,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
try{
bundle = UResourceBundle.getBundleInstance("bogus", "bogus", this.getClass().getClassLoader());
bundle = UResourceBundle.getBundleInstance("bogus", "bogus");
if(bundle!=null){
errln("Did not get the expected exception");
}
@ -92,7 +107,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
// this tests tests loading of root bundle when a resource bundle
// for the default locale is requested
try {
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", ULocale.getDefault());
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", ULocale.getDefault().toString(), testLoader);
if(bundle==null){
errln("could not create the resource bundle");
}
@ -102,7 +117,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
public void TestOpen(){
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "en_US_POSIX", ICUData.class.getClassLoader());
ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "en_US_POSIX");
if(bundle==null){
errln("could not create the resource bundle");
@ -167,7 +182,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
public void TestBasicTypes(){
ICUResourceBundle bundle = null;
try {
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes");
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "testtypes", testLoader);
}
catch (MissingResourceException e) {
warnln("could not load test data: " + e.getMessage());
@ -353,7 +368,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
};
ICUResourceBundle bundle = null;
try {
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testtable32");
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testtable32", testLoader);
}
catch (MissingResourceException ex) {
warnln("could not load resource data: " + ex.getMessage());
@ -435,7 +450,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
public void TestAliases(){
String simpleAlias = "Open";
ICUResourceBundle rb = (ICUResourceBundle)ICUResourceBundle.createBundle("com/ibm/icu/dev/data/testdata","testaliases", ICUResourceBundleTest.class.getClassLoader());
ICUResourceBundle rb = (ICUResourceBundle)ICUResourceBundle.createBundle("com/ibm/icu/dev/data/testdata","testaliases", testLoader);
if (rb == null) {
warnln("could not load testaliases data");
return;
@ -449,7 +464,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
try{
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases");
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
sub = rb.get("nonexisting");
errln("Did not get the expected exception for nonexisting");
}catch(MissingResourceException ex){
@ -457,7 +472,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
{
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases");
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
sub = rb.get("referencingalias");
s1 = sub.getString();
if(s1.equals("Hani")){
@ -467,7 +482,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
{
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases");
rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
sub = rb.get("BreakDictionaryData");
if(sub.getType()!=ICUResourceBundle.BINARY){
errln("Did not get the expected type for BreakDictionaryData");
@ -480,7 +495,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
{
ICUResourceBundle rb1 = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases");
ICUResourceBundle rb1 = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
if(rb1!=rb){
errln("Caching of the resource bundle failed");
}else{
@ -586,7 +601,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
}
public void TestXPathAlias(){
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN",testLoader);
ICUResourceBundle b = rb.get("aliasClient");
String result = b.getString();
String expResult= "correct";
@ -607,7 +622,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
public void TestCircularAliases(){
try{
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases");
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","testaliases",testLoader);
ICUResourceBundle sub = rb.get("aaa");
String s1 = sub.getString();
if(s1!=null){
@ -671,8 +686,6 @@ public final class ICUResourceBundleTest extends TestFmwk {
if(b5.getSize()!=12){
errln("Did not get the expected size for the default monthNames");
}
}
private static final String COLLATION_RESNAME = "collations";
@ -856,7 +869,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
logln("Testing CLDR style aliases......\n");
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "te_IN_REVISED");
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "te_IN_REVISED",testLoader);
ICUResourceBundle alias = rb.get("a");
for(int i = 1; i < 5 ; i++) {
@ -922,7 +935,7 @@ public final class ICUResourceBundleTest extends TestFmwk {
}
logln("Test to verify loading status of getwithFallback");
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "sh_YU");
bundle = (ICUResourceBundle)UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata", "sh_YU",testLoader);
ICUResourceBundle temp = bundle.getWithFallback("a/a2");
status = temp.getLoadingStatus();
if(status != ICUResourceBundle.FROM_LOCALE){

View File

@ -25,6 +25,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
private String localeID;
private String baseName;
private ULocale ulocale;
private ClassLoader loader;
/**
*
@ -47,7 +48,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
byte[] rawData = reader.getData();
long rootResource = (UNSIGNED_INT_MASK) & getInt(rawData, 0);
ICUResourceBundleImpl bundle = new ICUResourceBundleImpl(rawData,
baseName, localeID, rootResource);
baseName, localeID, rootResource, root);
return bundle.getBundle();
}
@ -99,12 +100,13 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
}
}
private ICUResourceBundleImpl(byte[] rawData, String baseName,
String localeID, long rootResource) {
String localeID, long rootResource, ClassLoader loader) {
this.rawData = rawData;
this.rootResource = rootResource;
this.baseName = baseName;
this.localeID = localeID;
this.ulocale = new ULocale(localeID);
this.loader = loader;
}
static final int RES_GET_TYPE(long res) {
return (int) ((res) >> 28L);
@ -600,6 +602,9 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
}
private ICUResourceBundle findResource(String key, long resource,
HashMap table, ICUResourceBundle requested) {
ClassLoader loaderToUse = loader;
String locale = null, keyPath = null;
String bundleName;
String resPath = getStringValue(resource);
@ -623,6 +628,7 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
//there is a path included
if (bundleName.equals(ICUDATA)) {
bundleName = ICU_BASE_NAME;
loaderToUse = ICU_DATA_CLASS_LOADER;
}
} else {
//no path start with locale
@ -643,11 +649,12 @@ public class ICUResourceBundleImpl extends ICUResourceBundle {
keyPath = resPath.substring(LOCALE.length() + 2/* prepending and appending / */, resPath.length());
locale = requested.getLocaleID();
}else if (locale == null) {
// {dlf} must use requestor's class loader to get resources from same jar
bundle = (ICUResourceBundle) getBundleInstance(bundleName, "",
ICU_DATA_CLASS_LOADER, false);
loaderToUse, false);
} else {
bundle = (ICUResourceBundle) getBundleInstance(bundleName, locale,
ICU_DATA_CLASS_LOADER, false);
loaderToUse, false);
}
ICUResourceBundle sub = null;
if (keyPath != null) {

View File

@ -685,7 +685,7 @@ public class OlsonTimeZone extends TimeZone {
transitionCount ^ (transitionCount>>>6) +
typeCount ^ (typeCount>>>8) +
Double.doubleToLongBits(finalMillis)+
finalZone.hashCode() +
(finalZone == null ? 0 : finalZone.hashCode()) +
super.hashCode());
for(int i=0; i<transitionTimes.length; i++){
ret+=transitionTimes[i]^(transitionTimes[i]>>>8);

View File

@ -284,15 +284,14 @@ public final class ZoneMeta {
String country_code = info[1];
if (country_code == null) {
return null; // error!
return null; // error!
}
String country = null;
if (country_code != null) {
ICUResourceBundle rb =
(ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale);
String rblocname = rb.getULocale().getBaseName();
if (LocaleUtility.isFallbackOf(rblocname, locale.getBaseName())) {
if (rb.getLoadingStatus() != rb.FROM_ROOT && rb.getLoadingStatus() != rb.FROM_DEFAULT) {
country = ULocale.getDisplayCountry("xx_" + country_code, locale);
}
if (country == null || country.length() == 0) country = country_code;

View File

@ -248,7 +248,6 @@ public class SimpleDateFormat extends DateFormat {
private DateFormatSymbols formatData;
private transient ULocale locale;
private transient boolean formatDataIsValid;
/**
* We map dates with two-digit years into the century starting at
@ -459,9 +458,6 @@ public class SimpleDateFormat extends DateFormat {
private void initialize(ULocale loc) {
// time zone formatting
locale = loc;
this.formatDataIsValid =
LocaleUtility.isFallbackOf(formatData.getLocale(ULocale.ACTUAL_LOCALE).getBaseName(),
loc.getBaseName());
// The format object must be constructed using the symbols for this zone.
// However, the calendar should use the current default TimeZone.
@ -816,6 +812,7 @@ public class SimpleDateFormat extends DateFormat {
case 17: // 'z' - ZONE_OFFSET
case 24: // 'v' - TIMEZONE_GENERIC
{
String zid;
String res=null;
zid = ZoneMeta.getCanonicalID(cal.getTimeZone().getID());

View File

@ -98,6 +98,16 @@ abstract public class TimeZone implements Serializable, Cloneable {
*/
public static final int LONG = 1;
/**
* @internal
*/
private static final int SHORT_GENERIC = 2;
/**
* @internal
*/
private static final int LONG_GENERIC = 3;
/**
* Cache to hold the SimpleDateFormat objects for a Locale.
*/
@ -368,31 +378,29 @@ abstract public class TimeZone implements Serializable, Cloneable {
/**
* Returns a name of this time zone suitable for presentation to the user
* in the default locale.
* This method returns the long name, not including daylight savings.
* This method returns the long generic name.
* If the display name is not available for the locale,
* then this method returns a string in the format
* <code>GMT[+-]hh:mm</code>.
* a fallback based on the country, city, or time zone id will be used.
* @return the human-readable name of this time zone in the default locale.
* @stable ICU 2.0
*/
public final String getDisplayName() {
return getDisplayName(false, LONG, ULocale.getDefault());
return _getDisplayName(false, LONG_GENERIC, ULocale.getDefault());
}
/**
* Returns a name of this time zone suitable for presentation to the user
* in the specified locale.
* This method returns the long name, not including daylight savings.
* This method returns the long generic name.
* If the display name is not available for the locale,
* then this method returns a string in the format
* <code>GMT[+-]hh:mm</code>.
* a fallback based on the country, city, or time zone id will be used.
* @param locale the locale in which to supply the display name.
* @return the human-readable name of this time zone in the given locale
* or in the default locale if the given locale is not recognized.
* @stable ICU 2.0
*/
public final String getDisplayName(Locale locale) {
return getDisplayName(false, LONG, ULocale.forLocale(locale));
return _getDisplayName(false, LONG_GENERIC, ULocale.forLocale(locale));
}
/**
@ -400,8 +408,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
* in the specified locale.
* This method returns the long name, not including daylight savings.
* If the display name is not available for the locale,
* then this method returns a string in the format
* <code>GMT[+-]hh:mm</code>.
* a fallback based on the country, city, or time zone id will be used.
* @param locale the ulocale in which to supply the display name.
* @return the human-readable name of this time zone in the given locale
* or in the default ulocale if the given ulocale is not recognized.
@ -409,7 +416,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public final String getDisplayName(ULocale locale) {
return getDisplayName(false, LONG, locale);
return _getDisplayName(false, LONG_GENERIC, locale);
}
/**
@ -461,6 +468,18 @@ abstract public class TimeZone implements Serializable, Cloneable {
* @deprecated This is a draft API and might change in a future release of ICU.
*/
public String getDisplayName(boolean daylight, int style, ULocale locale) {
if (style != SHORT && style != LONG) {
throw new IllegalArgumentException("Illegal style: " + style);
}
return _getDisplayName(daylight, style, locale);
}
/**
* The public version of this API only accepts LONG/SHORT, the
* internal version (which this calls) also accepts LONG_GENERIC/SHORT_GENERIC.
* @internal
*/
private String _getDisplayName(boolean daylight, int style, ULocale locale) {
/* NOTES:
* (1) We use SimpleDateFormat for simplicity; we could do this
* more efficiently but it would duplicate the SimpleDateFormat code
@ -471,9 +490,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
* locale upon resurrection; and to somehow handle the special case of
* construction from a DateFormatSymbols object.
*/
if (style != SHORT && style != LONG) {
throw new IllegalArgumentException("Illegal style: " + style);
}
// We keep a cache, indexed by locale. The cache contains a
// SimpleDateFormat object, which we create on demand.
SoftReference data = (SoftReference)cachedLocaleData.get(locale);
@ -497,7 +514,8 @@ abstract public class TimeZone implements Serializable, Cloneable {
} else {
tz = new SimpleTimeZone(getRawOffset(), getID());
}
format.applyPattern(style == LONG ? "zzzz" : "z");
String[] patterns = { "z", "zzzz", "v", "vvvv" };
format.applyPattern(patterns[style]);
format.setTimeZone(tz);
// Format a date in January. We use the value 10*ONE_DAY == Jan 11 1970
// 0:00 GMT.

View File

@ -724,7 +724,7 @@ public final class ULocale implements Serializable {
/**
* Construct a ULocale object from a {@link java.util.Locale}.
* @param loc a JDK locale
* @draft ICU 2.8
* @stable ICU 2.8
* @internal
*/
private ULocale(Locale loc) {
@ -2626,7 +2626,6 @@ public final class ULocale implements Serializable {
availableLocales, boolean[] fallback) {
/**
* @internal ICU 3.4
* @deprecated this is an internal class
*/
class ULocaleAcceptLanguageQ implements Comparable {
private double q;