Java Code Examples for java.text.Collator#getAvailableLocales()

The following examples show how to use java.text.Collator#getAvailableLocales() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UEPinyin.java    From Auie with GNU General Public License v2.0 6 votes vote down vote up
public static UEPinyin getInstance() {
    synchronized (UEPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINA) || locale[i].equals(Locale.CHINESE)) {
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new UEPinyin(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new UEPinyin(false);
        return sInstance;
    }
}
 
Example 2
Source File: CollatorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
    * @tests java.text.Collator#getAvailableLocales()
    */
   //FIXME This test fails on Harmony ClassLibrary
public void failing_test_getAvailableLocales() {
	Locale[] locales = Collator.getAvailableLocales();
	assertTrue("No locales", locales.length > 0);
	boolean english = false, german = false;
	for (int i = locales.length; --i >= 0;) {
		if (locales[i].equals(Locale.ENGLISH))
			english = true;
		if (locales[i].equals(Locale.GERMAN))
			german = true;
		// Output the working locale to help diagnose a hang
		Collator c1 = Collator.getInstance(locales[i]);
		assertTrue("Doesn't work", c1.compare("a", "b") < 0);
		assertTrue("Wrong decomposition",
				c1.getDecomposition() == Collator.NO_DECOMPOSITION);
		assertTrue("Wrong strength", c1.getStrength() == Collator.TERTIARY);
	}
	assertTrue("Missing locales", english && german);
}
 
Example 3
Source File: DataValueFactoryImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
   * Verify that JVM has support for the Collator for the datbase's locale.
   *
* @param strength Collator strength or -1 for locale default.
   * @return Collator for database's locale
   * @throws StandardException if JVM does not have support for Collator
   */
  private RuleBasedCollator verifyCollatorSupport(int strength)
  throws StandardException {
  	Locale[] availLocales =  Collator.getAvailableLocales();
  	//Verify that Collator can be instantiated for the given locale.
  	boolean localeFound = false;
  	for (int i=0; i<availLocales.length;i++)
  	{
  		if (availLocales[i].equals(databaseLocale)) {
  			localeFound = true;
  			break;
  		}
  	}
  	if (!localeFound)
	throw StandardException.newException(
			SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE, 
			(databaseLocale != null ? databaseLocale.toString() : "null"));
  	
  	RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);

if (strength != -1)
	collator.setStrength(strength);

return collator;
  }
 
Example 4
Source File: HanziToPinyin.java    From jmessage-android-uikit with MIT License 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        Locale China = new Locale("zh", "");
        Locale newChina = new Locale("zh", "HANS", "CN");
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINA) || locale[i].equals(China)
            || locale[i].equals(newChina)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 5
Source File: HanziToPinyin.java    From Contacts with Apache License 2.0 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINESE)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 6
Source File: HanziToPinyin3.java    From zone-sdk with MIT License 6 votes vote down vote up
public static HanziToPinyin3 getInstance() {
    synchronized (HanziToPinyin3.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINESE) || locale[i].equals(Locale.CHINA)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin3(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin3(false);
        return sInstance;
    }
}
 
Example 7
Source File: HanziToPinyin.java    From AndroidStudyDemo with GNU General Public License v2.0 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINA)) {
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }
        if (DEBUG) {
            Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        }
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 8
Source File: DataValueFactoryImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
   * Verify that JVM has support for the Collator for the datbase's locale.
   *
* @param strength Collator strength or -1 for locale default.
   * @return Collator for database's locale
   * @throws StandardException if JVM does not have support for Collator
   */
  private RuleBasedCollator verifyCollatorSupport(int strength)
  throws StandardException {
  	Locale[] availLocales =  Collator.getAvailableLocales();
  	//Verify that Collator can be instantiated for the given locale.
  	boolean localeFound = false;
  	for (int i=0; i<availLocales.length;i++)
  	{
  		if (availLocales[i].equals(databaseLocale)) {
  			localeFound = true;
  			break;
  		}
  	}
  	if (!localeFound)
	throw StandardException.newException(
			SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE, 
			(databaseLocale != null ? databaseLocale.toString() : "null"));
  	
  	RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);

if (strength != -1)
	collator.setStrength(strength);

return collator;
  }
 
Example 9
Source File: HanziToPinyin3.java    From sctalk with Apache License 2.0 6 votes vote down vote up
public static HanziToPinyin3 getInstance() {
    synchronized (HanziToPinyin3.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINESE)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin3(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin3(false);
        return sInstance;
    }
}
 
Example 10
Source File: HanziToPinyin.java    From KUtils with Apache License 2.0 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINA)) {
                // Do self validation just once.
                if (DEBUG) {

                    android.util.Log.d(TAG, "Self validation. Result: " +
                            doSelfValidation());
                }
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }
        android.util.Log.w(TAG,
                "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 11
Source File: HanziToPinyin.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINESE)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 12
Source File: HanziToPinyin.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale[] locale = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINA)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 13
Source File: HanziToPinyin.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        Locale China = new Locale("zh", "");
        Locale newChina = new Locale("zh", "HANS", "CN");
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINA) || locale[i].equals(China)
            || locale[i].equals(newChina)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }
        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 14
Source File: HanziToPinyin.java    From GetApk with MIT License 6 votes vote down vote up
public static HanziToPinyin getInstance() {
    synchronized (HanziToPinyin.class) {
        if (sInstance != null) {
            return sInstance;
        }
        // Check if zh_CN collation data is available
        final Locale locale[] = Collator.getAvailableLocales();
        for (int i = 0; i < locale.length; i++) {
            if (locale[i].equals(Locale.CHINESE)) {
                // Do self validation just once.
                if (DEBUG) {
                    Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                }
                sInstance = new HanziToPinyin(true);
                return sInstance;
            }
        }

        Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
        sInstance = new HanziToPinyin(false);
        return sInstance;
    }
}
 
Example 15
Source File: HanziToPinyin.java    From IP-Monitor with GNU General Public License v2.0 6 votes vote down vote up
public static HanziToPinyin getInstance() {
        synchronized (HanziToPinyin.class) {
            if (sInstance != null) {
                return sInstance;
            }
            // Check if zh_CN collation data is available
            final Locale locale[] = Collator.getAvailableLocales();
            for (int i = 0; i < locale.length; i++) {
                if (locale[i].equals(Locale.CHINA) || locale[i].equals(Locale.CHINESE)) {
                    // Do self validation just once.
                    if (DEBUG) {
//                        Log.d(TAG, "Self validation. Result: " + doSelfValidation());
                    }
                    sInstance = new HanziToPinyin(true);
                    return sInstance;
                }
            }
            Log.w(TAG, "There is no Chinese collator, HanziToPinyin is disabled");
            sInstance = new HanziToPinyin(false);
            return sInstance;
        }
    }
 
Example 16
Source File: APITest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final void TestGetAll()
{
    Locale[] list = Collator.getAvailableLocales();
    for (int i = 0; i < list.length; ++i) {
        log("Locale name: ");
        log(list[i].toString());
        log(" , the display name is : ");
        logln(list[i].getDisplayName());
    }
}
 
Example 17
Source File: APITest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public final void TestGetAll()
{
    Locale[] list = Collator.getAvailableLocales();
    for (int i = 0; i < list.length; ++i) {
        log("Locale name: ");
        log(list[i].toString());
        log(" , the display name is : ");
        logln(list[i].getDisplayName());
    }
}
 
Example 18
Source File: APITest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public final void TestGetAll()
{
    Locale[] list = Collator.getAvailableLocales();
    for (int i = 0; i < list.length; ++i) {
        log("Locale name: ");
        log(list[i].toString());
        log(" , the display name is : ");
        logln(list[i].getDisplayName());
    }
}
 
Example 19
Source File: APITest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final void TestGetAll()
{
    Locale[] list = Collator.getAvailableLocales();
    for (int i = 0; i < list.length; ++i) {
        log("Locale name: ");
        log(list[i].toString());
        log(" , the display name is : ");
        logln(list[i].getDisplayName());
    }
}
 
Example 20
Source File: APITest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final void TestGetAll()
{
    Locale[] list = Collator.getAvailableLocales();
    for (int i = 0; i < list.length; ++i) {
        log("Locale name: ");
        log(list[i].toString());
        log(" , the display name is : ");
        logln(list[i].getDisplayName());
    }
}