public Set getSupportedLocaleIDs() {
if (ids == null) {
HashSet set = new HashSet();
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
ULocale locale = (ULocale)iter.next();
String id = locale.toString();
set.add(id);
}
ids = Collections.unmodifiableSet(set);
}
return ids;
}
}
class TestFactoryWrapper extends CollatorFactory {
CollatorFactory delegate;
TestFactoryWrapper(CollatorFactory delegate) {
this.delegate = delegate;
}
public Collator createCollator(ULocale loc) {
return delegate.createCollator(loc);
}
// use CollatorFactory getDisplayName(ULocale, ULocale) for coverage
public Set getSupportedLocaleIDs() {
return delegate.getSupportedLocaleIDs();
}
}
ULocale fu_FU = new ULocale("fu_FU");
ULocale fu_FU_FOO = new ULocale("fu_FU_FOO");
Map fuFUNames = new HashMap();
fuFUNames.put(fu_FU, "ze leetle bunny Fu-Fu");
fuFUNames.put(fu_FU_FOO, "zee leetel bunny Foo-Foo");
fuFUNames.put(ULocale.US, "little bunny Foo Foo");
Collator frcol = Collator.getInstance(ULocale.FRANCE);
/* Collator uscol = */Collator.getInstance(ULocale.US);
Collator gecol = Collator.getInstance(ULocale.GERMANY);
Collator jpcol = Collator.getInstance(ULocale.JAPAN);
Collator fucol = Collator.getInstance(fu_FU);
CollatorInfo[] info = {
new CollatorInfo(ULocale.US, frcol, null),
new CollatorInfo(ULocale.FRANCE, gecol, null),
new CollatorInfo(fu_FU, jpcol, fuFUNames),
};
TestFactory factory = null;
try{
factory = new TestFactory(info);
}catch(MissingResourceException ex){
warnln("Could not load locale data.");
}
// coverage
{
TestFactoryWrapper wrapper = new TestFactoryWrapper(factory); // in java, gc lets us easily multiply reference!
Object key = Collator.registerFactory(wrapper);
String name = null;
try{
name = Collator.getDisplayName(fu_FU, fu_FU_FOO);
}catch(MissingResourceException ex){
warnln("Could not load locale data.");
}
logln("*** default name: " + name);
Collator.unregister(key);
ULocale bar_BAR = new ULocale("bar_BAR");
Collator col = Collator.getInstance(bar_BAR);
if (!col.getLocale(ULocale.VALID_LOCALE).equals(ULocale.getDefault())) {
errln("Collation from bar_BAR is really " + col.getLocale(ULocale.VALID_LOCALE));
}
}