ICU-3301 add getKeywordValues and test

X-SVN-Rev: 15188
This commit is contained in:
Steven R. Loomis 2004-05-06 23:34:55 +00:00
parent 6bb095957e
commit ae00785417
2 changed files with 53 additions and 4 deletions

View File

@ -562,6 +562,33 @@ public final class ICUResourceBundleTest extends TestFmwk {
errln("Did not get the expected result from getObjectWithFallback method."); errln("Did not get the expected result from getObjectWithFallback method.");
} }
} }
public void TestKeywordsAndTrees(){
String kwVals[];
boolean foundStandard = false;
int n;
logln("Testing getting collation values:");
kwVals = ICUResourceBundle.getKeywordValues(UResourceBundle.ICU_COLLATION_BASE_NAME,"collations");
for(n=0;n<kwVals.length;n++) {
logln(new Integer(n).toString() + ": " + kwVals[n]);
if(("default").equals(kwVals[n])) {
errln("getKeywordValues for collation returned 'default' in the list.");
} else if(("standard").equals(kwVals[n])) {
if(foundStandard == false) {
foundStandard = true;
logln("found 'standard'");
} else {
errln("Error - 'standard' is in the keyword list twice!");
}
}
}
if(foundStandard == false) {
errln("Error - 'standard' was not in the collation tree as a keyword.");
} else {
logln("'standard' was found as a collation keyword.");
}
}
} }

View File

@ -95,6 +95,8 @@ public class ICUResourceBundle extends UResourceBundle{
private static final String ICU_RESOURCE_INDEX = "res_index"; private static final String ICU_RESOURCE_INDEX = "res_index";
private static final String DEFAULT_TAG = "default";
/** /**
* Return the version number associated with this UResourceBundle as an * Return the version number associated with this UResourceBundle as an
* VersionInfo object. * VersionInfo object.
@ -349,8 +351,6 @@ public class ICUResourceBundle extends UResourceBundle{
return (UResourceBundle)parent; return (UResourceBundle)parent;
} }
/** /**
* Returns a functionally equivalent locale, considering keywords as well, for the specified keyword. * Returns a functionally equivalent locale, considering keywords as well, for the specified keyword.
* @param BASE resource specifier * @param BASE resource specifier
@ -388,7 +388,29 @@ public class ICUResourceBundle extends UResourceBundle{
* @internal ICU 3.0 * @internal ICU 3.0
*/ */
public static final String[] getKeywordValues(String baseName, String keyword){ public static final String[] getKeywordValues(String baseName, String keyword){
return null; Set keywords = new HashSet();
ULocale locales[] = createULocaleList(baseName,ICU_DATA_CLASS_LOADER);
int i;
for(i=0;i<locales.length;i++) {
try {
UResourceBundle b = UResourceBundle.getBundleInstance(baseName, locales[i]);
// downcast to ICUResourceBundle?
ICUResourceBundle irb = (ICUResourceBundle)(b.getObject(keyword));
Enumeration e = irb.getKeys();
Object s;
while(e.hasMoreElements()) {
s= e.nextElement();
if ((s instanceof String) && !DEFAULT_TAG.equals(s)) { // don't add 'default' items
keywords.add(s);
}
}
} catch (Throwable t){
//System.err.println("Error in - " + new Integer(i).toString() + " - " + t.toString());
// ignore the err - just skip that resource
}
}
return (String[])keywords.toArray(new String[0]);
} }
/** /**