Example usage for java.util Locale equals

List of usage examples for java.util Locale equals

Introduction

In this page you can find the example usage for java.util Locale equals.

Prototype

@Override
public boolean equals(Object obj) 

Source Link

Document

Returns true if this Locale is equal to another object.

Usage

From source file:jp.ne.sakura.kkkon.android.exceptionhandler.DefaultUploaderWeb.java

public static AlertDialog.Builder setupAlertDialog(final Context context) {
    final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
    final Locale defaultLocale = Locale.getDefault();

    String title = "";
    String message = "";
    String positive = "";
    String negative = "";

    boolean needDefaultLang = true;
    if (null != defaultLocale) {
        if (defaultLocale.equals(Locale.JAPANESE) || defaultLocale.equals(Locale.JAPAN)) {
            title = "";
            message = "???????";
            positive = "?";
            negative = "";
            needDefaultLang = false;//from w  ww  .j a  v a2 s .co  m
        }
    }
    if (needDefaultLang) {
        title = "INFO";
        message = "Now uploading error information. Cancel upload?";
        positive = "Wait";
        negative = "Cancel";
    }
    alertDialog.setTitle(title);
    alertDialog.setMessage(message);
    alertDialog.setPositiveButton(positive, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface di, int i) {
            if (null != thread) {
                if (thread.isAlive()) {
                    alertDialog.show();
                } else {
                    terminate();
                }
            }
        }
    });

    alertDialog.setNegativeButton(negative, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface di, int i) {
            if (null != thread) {
                if (thread.isAlive()) {
                    Log.d(TAG, "request interrupt");
                    terminate();
                } else {
                    // nothing
                    terminate();
                }
            }
        }
    });

    alertDialog.setCancelable(false);

    return alertDialog;
}

From source file:com.evolveum.midpoint.web.security.MidPointApplication.java

public static boolean containsLocale(Locale locale) {
    if (locale == null) {
        return false;
    }//from  w w w. jav  a  2s. c  o  m

    for (LocaleDescriptor descriptor : AVAILABLE_LOCALES) {
        if (locale.equals(descriptor.getLocale())) {
            return true;
        }
    }

    return false;
}

From source file:com.android.providers.contacts.LocaleSet.java

public static boolean isLocaleSimplifiedChinese(Locale locale) {
    // language must match
    if (locale == null || !TextUtils.equals(locale.getLanguage(), CHINESE_LANGUAGE)) {
        return false;
    }/* w  ww .  j  a  v a  2 s. co m*/

    // script is optional but if present must match
    if (!TextUtils.isEmpty(ICUCompat.maximizeAndGetScript(locale))) {
        return ICUCompat.maximizeAndGetScript(locale).equals(SCRIPT_SIMPLIFIED_CHINESE);
    }
    // if no script, must match known country
    return locale.equals(Locale.SIMPLIFIED_CHINESE);
}

From source file:Dates.java

/**
 * Get the year of a date in the specified locale.
 * /*from w  ww  .java 2  s  .c om*/
 * <p>
 * Currenty, only Locale.ZH_TW is supported, i.e., "year - 1911" and it's may
 * be less than 0. Otherwise, it is the same as {@link #yearOfDate}.
 * 
 * @param when
 *          The date.
 * @param locale
 *          the locale; if null, the current locale is assumed.
 * @param tz
 *          The time zone; if null, the current time zone is assumed.
 * @see #yearOfDate
 */
public static final int localizedYearOfDate(Date when, Locale locale, TimeZone tz) {
    final int year = yearOfDate(when, tz);
    if (locale.equals(Locale.TAIWAN))
        return year - 1911;
    return year;
}

From source file:org.jahia.utils.LanguageCodeConverters.java

public static List<Locale> getAvailableBundleLocales(String resourceBundleName, Locale defaultLocale) {
    final List<Locale> availableBundleLocales = new LinkedList<Locale>();
    // first let's add the default locale if it exists.
    if (defaultLocale != null && ResourceBundle.getBundle(resourceBundleName, defaultLocale) != null) {
        availableBundleLocales.add(defaultLocale);
    }//w ww  . j a  v a2 s  .  c  o m
    for (Locale locale : getAvailableLocales()) {
        if (!StringUtils.isEmpty(locale.getDisplayName())) { // Avoid "default/system" empty locale
            ResourceBundle res = ResourceBundle.getBundle(resourceBundleName, locale);
            if (res != null && res.getLocale().equals(locale)
                    && (defaultLocale == null || !locale.equals(defaultLocale))) {
                availableBundleLocales.add(locale);
            }
        }
    }

    return availableBundleLocales;
}

From source file:it.cnr.icar.eric.client.xml.registry.infomodel.InternationalStringImpl.java

/**
 * Gets a List of possible keys to be used when searching for the closest
 * LocalizedString for a given locale/charset pair. The List starts with a
 * key for the specific locale (ignored if null) followed by a lookup
 * precedence list of alternative keys (inspired on
 * <code>java.util.ResourceBundle</code>) as shown bellow.
 *
 * <ul>//from  w w  w  . j a  va  2  s. co m
 * <li> charset + "_" + language1 + "_" + country1 + "_" + variant1 </li>
 * <li> charset + "_" + language1 + "_" + country1                  </li>
 * <li> charset + "_" + language1                                   </li>
 * <li> charset + "_" + language2 + "_" + country2 + "_" + variant2 </li>
 * <li> charset + "_" + language2 + "_" + country2                  </li>
 * <li> charset + "_" + language2                                   </li>
 * <li> charset + "_" + language3 + "_" + country3 + "_" + variant3 </li>
 * <li> charset + "_" + language3 + "_" + country3                  </li>
 * <li> charset + "_" + language3                                   </li>
 * </ul>
 *
 * Where:
 * <ul>
 * <li> Candidate keys where the final component is an empty string are omitted.
 *      For example, if country1 is an empty string, charset + "_" + language1 +
 *      "_" + country1 is omitted; </li>
 * <li> language1, contry1, variant1 come from the 'locale' parameter;</li>
 * <li> language2, contry2, variant2 come from JVM default Locale (Locale.getDefault());</li>
 * <li> language3, contry3, variant3 come from ebxmlrr default Locale (default "en-US");</li>
 * </ul>
 *
 * @param charset the charset name
 * @param locale the locale
 * @return List with the keys along the search path.
 */
public static List<String> getClosestKeys(Locale locale, String charset) {
    // TO DO: Cache generated ClosestKeysLists (??)
    // TO DO: get it from ProviderProperties
    Locale ebxmlrrDefaultLocale = new Locale("en", "US");
    charset = LocalizedStringImpl.DEFAULT_CHARSET_NAME;

    List<String> keysList = calculateKeys(locale, charset);

    if (!locale.equals(Locale.getDefault())) {
        keysList.addAll(calculateKeys(Locale.getDefault(), charset));
    }

    if (!Locale.getDefault().equals(ebxmlrrDefaultLocale) && !locale.equals(ebxmlrrDefaultLocale)) {
        // TO DO: Decide if default locale should be expanded, too.
        keysList.addAll(calculateKeys(ebxmlrrDefaultLocale, charset));
    }

    return keysList;
}

From source file:org.apereo.portal.i18n.LocaleManager.java

/**
 * Creates an XML representation of a list of locales.
 * If a selected locale is supplied, the XML element representing
 * the selected locale will have an attribute of selected with value
 * of true.  This is helpful when constructing user interfaces that
 * indicate which locale is selected./*from  w w w  . j ava  2  s .co  m*/
 * @param locales the locale list
 * @param selectedLocale a locale that should be selected if it is in the list
 * @return the locale list as XML
 */
public static Document xmlValueOf(Locale[] locales, Locale selectedLocale) {
    Document doc = DocumentFactory.getThreadDocument();

    // <locales>
    Element localesE = doc.createElement("locales");
    for (int i = 0; i < locales.length; i++) {
        Element locE = doc.createElement("locale");
        locE.setAttribute("displayName", locales[i].getDisplayName(locales[0]));
        locE.setAttribute("code", locales[i].toString());

        // Mark which locale is the user's preference
        if (selectedLocale != null && selectedLocale.equals(locales[i])) {
            locE.setAttribute("selected", "true");
        }

        // <language iso2="..." iso3="..." displayName="..."/>
        Element languageE = doc.createElement("language");
        languageE.setAttribute("iso2", locales[i].getLanguage());
        try {
            languageE.setAttribute("iso3", locales[i].getISO3Language());
        } catch (Exception e) {
            // Do nothing
        }
        languageE.setAttribute("displayName", locales[i].getDisplayLanguage(locales[0]));
        locE.appendChild(languageE);

        // <country iso2="..." iso3="..." displayName="..."/>
        Element countryE = doc.createElement("country");
        countryE.setAttribute("iso2", locales[i].getCountry());
        try {
            countryE.setAttribute("iso3", locales[i].getISO3Country());
        } catch (Exception e) {
            // Do nothing
        }
        countryE.setAttribute("displayName", locales[i].getDisplayCountry(locales[0]));
        locE.appendChild(countryE);

        // <variant code="..." displayName="..."/>
        Element variantE = doc.createElement("variant");
        variantE.setAttribute("code", locales[i].getVariant());
        variantE.setAttribute("displayName", locales[i].getDisplayVariant(locales[0]));
        locE.appendChild(variantE);

        localesE.appendChild(locE);
    }
    doc.appendChild(localesE);
    return doc;
}

From source file:org.lockss.util.MetadataUtil.java

static void setDefaultMetadataLocale(Configuration config) {
    String lstr = config.get(PARAM_DEFAULT_LOCALE, "");
    lstr = lstr.trim();//  ww  w .j a v a 2 s.c o  m
    if (StringUtil.isNullString(lstr)) {
        defaultLocale = DEFAULT_DEFAULT_LOCALE;
        return;
    }
    try {
        Locale loc = LocaleUtils.toLocale(lstr);
        Locale goodLoc = findClosestAvailableLocale(loc);
        if (goodLoc != null) {
            if (goodLoc.equals(loc)) {
                log.debug("Requested Locale: " + loc + " not found, using closest match: " + goodLoc);
            }
            defaultLocale = goodLoc;
        } else {
            log.error("Unknown Locale: " + loc + ", using default locale: " + DEFAULT_DEFAULT_LOCALE);
            defaultLocale = DEFAULT_DEFAULT_LOCALE;
        }
    } catch (IllegalArgumentException e) {
        log.error("Illegal Locale spec: " + lstr + ", " + e.getMessage());
        defaultLocale = DEFAULT_DEFAULT_LOCALE;
    }
}

From source file:Main.java

public DateFormat getTimeInstance(int style, Locale locale) {
    if (locale.equals(ca)) {
        return new SimpleDateFormat("HH.mm.ss");
    }/* w  w w  .  j  a  v a  2s .  c  om*/
    return null;
}

From source file:Main.java

public DateFormat getDateTimeInstance(int dateStyle, Locale locale) {
    if (locale.equals(ca)) {
        return new SimpleDateFormat("yyyy");
    }/*from  w  w w .  j  a  v  a 2 s  . com*/
    return null;
}