ICU-1949 icuservice coverage, fix sorting of display names
X-SVN-Rev: 10642
This commit is contained in:
parent
e562766f2e
commit
97cc766966
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceTest.java,v $
|
||||
* $Date: 2002/10/09 18:56:57 $
|
||||
* $Revision: 1.9 $
|
||||
* $Date: 2002/12/12 18:02:09 $
|
||||
* $Revision: 1.10 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -29,6 +29,7 @@ import com.ibm.icu.impl.ICULocaleService.ICUResourceBundleFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EventListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -39,6 +40,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class ICUServiceTest extends TestFmwk
|
||||
@ -70,6 +72,10 @@ public class ICUServiceTest extends TestFmwk
|
||||
|
||||
// use locale keys
|
||||
static final class TestService extends ICUService {
|
||||
public TestService() {
|
||||
super("Test Service");
|
||||
}
|
||||
|
||||
public Key createKey(String id) {
|
||||
return LocaleKey.createWithCanonicalFallback(id, null); // no fallback locale
|
||||
}
|
||||
@ -79,6 +85,8 @@ public class ICUServiceTest extends TestFmwk
|
||||
// create a service using locale keys,
|
||||
ICUService service = new TestService();
|
||||
|
||||
logln("service name:" + service.getName());
|
||||
|
||||
// register an object with one locale,
|
||||
// search for an object with a more specific locale
|
||||
// should return the original object
|
||||
@ -194,6 +202,7 @@ public class ICUServiceTest extends TestFmwk
|
||||
service.registerObject(singleton3, "en_US_BAR");
|
||||
result = service.get("en_US_BAR");
|
||||
confirmIdentical("23) override super", result, singleton3);
|
||||
|
||||
}
|
||||
|
||||
// empty service should not recognize anything
|
||||
@ -371,6 +380,28 @@ public class ICUServiceTest extends TestFmwk
|
||||
*/
|
||||
}
|
||||
|
||||
// list only the resources for es, default locale
|
||||
// since we're using the default Key, only "es" is matched
|
||||
{
|
||||
logln("visible ids for es locale: " + service.getVisibleIDs("es"));
|
||||
}
|
||||
|
||||
// list only the spanish display names for es, spanish collation order
|
||||
// since we're using the default Key, only "es" is matched
|
||||
{
|
||||
logln("display names: " + service.getDisplayNames(LocaleUtility.getLocaleFromName("es"), "es"));
|
||||
}
|
||||
|
||||
// list the display names in reverse order
|
||||
{
|
||||
logln("display names in reverse order: " +
|
||||
service.getDisplayNames(Locale.US, new Comparator() {
|
||||
public int compare(Object lhs, Object rhs) {
|
||||
return -String.CASE_INSENSITIVE_ORDER.compare(lhs, rhs);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
// get all the display names of these resources
|
||||
// this should be fast since the display names were cached.
|
||||
{
|
||||
@ -704,6 +735,21 @@ public class ICUServiceTest extends TestFmwk
|
||||
logln("[" + n++ + "] " + iter.next());
|
||||
}
|
||||
}
|
||||
|
||||
// list only the english display names for es, in reverse order
|
||||
// since we're using locale keys, we should get all and only the es locales
|
||||
// hmmm, the default toString function doesn't print in sorted order for TreeMap
|
||||
{
|
||||
SortedMap map = service.getDisplayNames(Locale.US,
|
||||
new Comparator() {
|
||||
public int compare(Object lhs, Object rhs) {
|
||||
return -String.CASE_INSENSITIVE_ORDER.compare(lhs, rhs);
|
||||
}
|
||||
},
|
||||
"es");
|
||||
|
||||
logln("es display names in reverse order " + map);
|
||||
}
|
||||
}
|
||||
|
||||
public void TestWrapFactory() {
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ICULocaleService.java,v $
|
||||
* $Date: 2002/10/09 18:56:58 $
|
||||
* $Revision: 1.11 $
|
||||
* $Date: 2002/12/12 18:02:09 $
|
||||
* $Revision: 1.12 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -280,6 +280,14 @@ public class ICULocaleService extends ICUService {
|
||||
currentID = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a key created from id would eventually fallback to match the
|
||||
* canonical ID of this key, return true.
|
||||
*/
|
||||
public boolean isFallbackOf(String id) {
|
||||
return LocaleUtility.isFallbackOf(canonicalID(), id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ICUService.java,v $
|
||||
* $Date: 2002/10/09 18:56:58 $
|
||||
* $Revision: 1.12 $
|
||||
* $Date: 2002/12/12 18:02:09 $
|
||||
* $Revision: 1.13 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -30,6 +30,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
@ -203,10 +204,10 @@ public class ICUService extends ICUNotifier {
|
||||
|
||||
/**
|
||||
* If a key created from id would eventually fallback to match the
|
||||
* current ID of this key, return true.
|
||||
* canonical ID of this key, return true.
|
||||
*/
|
||||
public boolean isFallbackOf(String id) {
|
||||
return currentID().equals(id);
|
||||
return canonicalID().equals(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -642,7 +643,7 @@ public class ICUService extends ICUNotifier {
|
||||
* the locale as the comparator to sort the display names, and null for
|
||||
* the matchID.
|
||||
*/
|
||||
public Map getDisplayNames() {
|
||||
public SortedMap getDisplayNames() {
|
||||
Locale locale = Locale.getDefault();
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return getDisplayNames(locale, col, null);
|
||||
@ -653,7 +654,7 @@ public class ICUService extends ICUNotifier {
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names, and null for the matchID.
|
||||
*/
|
||||
public Map getDisplayNames(Locale locale) {
|
||||
public SortedMap getDisplayNames(Locale locale) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return getDisplayNames(locale, col, null);
|
||||
}
|
||||
@ -661,8 +662,8 @@ public class ICUService extends ICUNotifier {
|
||||
/**
|
||||
* Convenience override of getDisplayNames(Locale, Comparator, String) that
|
||||
* uses null for the matchID, thus returning all display names.
|
||||
* /
|
||||
public Map getDisplayNames(Locale locale, Comparator col) {
|
||||
*/
|
||||
public SortedMap getDisplayNames(Locale locale, Comparator col) {
|
||||
return getDisplayNames(locale, col, null);
|
||||
}
|
||||
|
||||
@ -671,7 +672,7 @@ public class ICUService extends ICUNotifier {
|
||||
* uses the default collator for the locale as the comparator to
|
||||
* sort the display names.
|
||||
*/
|
||||
public Map getDisplayNames(Locale locale, String matchID) {
|
||||
public SortedMap getDisplayNames(Locale locale, String matchID) {
|
||||
Collator col = Collator.getInstance(locale);
|
||||
return getDisplayNames(locale, col, matchID);
|
||||
}
|
||||
@ -686,11 +687,11 @@ public class ICUService extends ICUNotifier {
|
||||
* those in the set. The display names are sorted based on the
|
||||
* comparator provided.
|
||||
*/
|
||||
public Map getDisplayNames(Locale locale, Comparator col, String matchID) {
|
||||
Map dncache = null;
|
||||
public SortedMap getDisplayNames(Locale locale, Comparator col, String matchID) {
|
||||
SortedMap dncache = null;
|
||||
LocaleRef ref = dnref;
|
||||
if (ref != null) {
|
||||
dncache = ref.get(locale, col);
|
||||
dncache = (SortedMap)ref.get(locale, col);
|
||||
}
|
||||
|
||||
while (dncache == null) {
|
||||
@ -707,7 +708,7 @@ public class ICUService extends ICUNotifier {
|
||||
dncache.put(f.getDisplayName(id, locale), id);
|
||||
}
|
||||
|
||||
dncache = Collections.unmodifiableMap(dncache);
|
||||
dncache = Collections.unmodifiableSortedMap(dncache);
|
||||
dnref = new LocaleRef(dncache, locale, col);
|
||||
} else {
|
||||
ref = dnref;
|
||||
@ -721,7 +722,7 @@ public class ICUService extends ICUNotifier {
|
||||
return dncache;
|
||||
}
|
||||
|
||||
HashMap result = new HashMap(dncache);
|
||||
SortedMap result = new TreeMap(dncache);
|
||||
Iterator iter = result.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Entry e = (Entry)iter.next();
|
||||
@ -745,8 +746,8 @@ public class ICUService extends ICUNotifier {
|
||||
this.ref = new SoftReference(dnCache);
|
||||
}
|
||||
|
||||
Map get(Locale locale, Comparator col) {
|
||||
Map m = (Map)ref.get();
|
||||
SortedMap get(Locale locale, Comparator col) {
|
||||
SortedMap m = (SortedMap)ref.get();
|
||||
if (m != null &&
|
||||
this.locale.equals(locale) &&
|
||||
(this.col == col || (this.col != null && this.col.equals(col)))) {
|
||||
|
Loading…
Reference in New Issue
Block a user