當前位置: 首頁>>代碼示例>>Java>>正文


Java Locale.equals方法代碼示例

本文整理匯總了Java中java.util.Locale.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Locale.equals方法的具體用法?Java Locale.equals怎麽用?Java Locale.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Locale的用法示例。


在下文中一共展示了Locale.equals方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBundleMessagesMapForKey

import java.util.Locale; //導入方法依賴的package包/類
private static Map <Locale, String> getBundleMessagesMapForKey(
        final String baseName,
        final String key,
        final ClassLoader loader) {
    Map <Locale, String> map = new HashMap <Locale, String> ();
    List <Locale> list = new ArrayList <Locale> ();
    list.add(new Locale(StringUtils.EMPTY_STRING));
    list.addAll(Arrays.asList(Locale.getAvailableLocales()));
    for(Locale locale : list) {
        ResourceBundle bundle = loadBundle(baseName, locale, loader);            
        if(bundle!=null && locale.equals(bundle.getLocale()) && !map.containsKey(bundle.getLocale())) {
            map.put(locale, getBundleMessage(baseName, locale, loader, key));
        }
    }
    return map;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:ResourceUtils.java

示例2: setLocale

import java.util.Locale; //導入方法依賴的package包/類
/**
 * Sets the current <code>Locale</code> of this
 * <code>ImageReader</code> to the given value.  A value of
 * <code>null</code> removes any previous setting, and indicates
 * that the reader should localize as it sees fit.
 *
 * @param locale the desired <code>Locale</code>, or
 * <code>null</code>.
 *
 * @exception IllegalArgumentException if <code>locale</code> is
 * non-<code>null</code> but is not one of the values returned by
 * <code>getAvailableLocales</code>.
 *
 * @see #getLocale
 */
public void setLocale(Locale locale) {
    if (locale != null) {
        Locale[] locales = getAvailableLocales();
        boolean found = false;
        if (locales != null) {
            for (int i = 0; i < locales.length; i++) {
                if (locale.equals(locales[i])) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            throw new IllegalArgumentException("Invalid locale!");
        }
    }
    this.locale = locale;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:34,代碼來源:ImageReader.java

示例3: isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes

import java.util.Locale; //導入方法依賴的package包/類
public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() {
    final Locale systemLocale = mContext.getResources().getConfiguration().locale;
    final Set<InputMethodSubtype> enabledSubtypesOfEnabledImes = new HashSet<>();
    final InputMethodManager inputMethodManager = getInputMethodManager();
    final List<InputMethodInfo> enabledInputMethodInfoList =
            inputMethodManager.getEnabledInputMethodList();
    for (final InputMethodInfo info : enabledInputMethodInfoList) {
        final List<InputMethodSubtype> enabledSubtypes =
                inputMethodManager.getEnabledInputMethodSubtypeList(
                        info, true /* allowsImplicitlySelectedSubtypes */);
        if (enabledSubtypes.isEmpty()) {
            // An IME with no subtypes is found.
            return false;
        }
        enabledSubtypesOfEnabledImes.addAll(enabledSubtypes);
    }
    for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) {
        if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty()
                && !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) {
            return false;
        }
    }
    return true;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:25,代碼來源:RichInputMethodManager.java

示例4: onResume

import java.util.Locale; //導入方法依賴的package包/類
@Override
public void onResume() {
    super.onResume();

    LocaleManager.getInstance()
            .correctLocale(getContext(), getResources(), getResources().getConfiguration());

    if (cachedLocale == null) {
        cachedLocale = Locale.getDefault();
    } else {
        Locale newLocale = LocaleManager.getInstance().getCurrentLocale(getActivity().getApplicationContext());

        if (newLocale == null) {
            // Using system locale:
            newLocale = Locale.getDefault();
        }
        if (!newLocale.equals(cachedLocale)) {
            cachedLocale = newLocale;
            applyLocale();
        }
    }
}
 
開發者ID:mozilla-mobile,項目名稱:firefox-tv,代碼行數:23,代碼來源:LocaleAwareFragment.java

示例5: main

import java.util.Locale; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    int errors = 0;

    for (String loctag : args) {
        Locale locale = Locale.forLanguageTag(loctag);
        if (locale.equals(Locale.ROOT)) {
            continue;
        }
        ResourceBundle rb = ResourceBundle.getBundle("jdk.test.resources.MyResources", locale);
        String tag = locale.toLanguageTag(); // normalized
        String value = rb.getString("key");
        System.out.println("locale = " + tag + ", value = " + value);
        if (!value.startsWith(tag + ':')) {
            errors++;
        }
    }
    if (errors > 0) {
        throw new RuntimeException(errors + " errors");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:Main.java

示例6: readMarketplaceNames

import java.util.Locale; //導入方法依賴的package包/類
public Map<String, String> readMarketplaceNames(Locale locale,
        long periodEnd) {
    SqlQuery sqlQuery = new SqlQuery(QUERY_MARKETPLACE_NAMES);
    sqlQuery.setDate(1, new Date(periodEnd));
    DataSet dataSet = ds.executeQueryForRawData(sqlQuery);
    HashMap<String, String> marketplaceIdMap = new HashMap<String, String>();
    while (dataSet.next()) {
        Locale loc = new Locale(dataSet.getString("locale"));
        String mpId = dataSet.getString("marketplaceid");
        String mpName = dataSet.getString("value");
        if (null != locale && locale.equals(loc)) {
            marketplaceIdMap.put(mpId, mpName);
        } else if (defaultLocale.equals(loc)
                && null == marketplaceIdMap.get(mpId)) {
            marketplaceIdMap.put(mpId, mpName);
        }
    }
    return marketplaceIdMap;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:20,代碼來源:PartnerRevenueDao.java

示例7: readServiceNames

import java.util.Locale; //導入方法依賴的package包/類
public Map<String, String> readServiceNames(Locale locale, long periodEnd) {
    SqlQuery sqlQuery = new SqlQuery(QUERY_SERVICE_NAMES);
    sqlQuery.setDate(1, new Date(periodEnd));
    DataSet dataSet = ds.executeQueryForRawData(sqlQuery);
    HashMap<String, String> marketplaceIdMap = new HashMap<String, String>();
    while (dataSet.next()) {
        Locale loc = new Locale(dataSet.getString("locale"));
        String servId = dataSet.getString("productid");
        String servName = dataSet.getString("value");
        if (null != locale && locale.equals(loc)) {
            marketplaceIdMap.put(servId, servName);
        } else if (defaultLocale.equals(loc)
                && null == marketplaceIdMap.get(servId)) {
            marketplaceIdMap.put(servId, servName);
        }
    }
    return marketplaceIdMap;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:PartnerRevenueDao.java

示例8: main

import java.util.Locale; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    int errors = 0;
    for (String loctag : args) {
        Locale locale = Locale.forLanguageTag(loctag);
        if (locale.equals(Locale.ROOT)) {
            continue;
        }
        ResourceBundle rb = ResourceBundle.getBundle("jdk.test.resources.MyResources",
                                                     locale);
        String tag = locale.toLanguageTag(); // normalized
        String value = rb.getString("key");
        System.out.println(rb.getBaseBundleName() + ": locale = " + tag + ", value = " + value);
        if (!value.startsWith(tag + ':')) {
            System.out.println("ERROR: " + value + " expected: " + tag);
            errors++;
        }

        // inaccessible bundles
        try {
            ResourceBundle.getBundle("jdk.test.internal.resources.Foo", locale);
            System.out.println("ERROR: jdk.test.internal.resources.Foo should not be accessible");
            errors++;
        } catch (MissingResourceException e) {
            e.printStackTrace();

            Throwable cause = e.getCause();
            System.out.println("Expected: " +
                (cause != null ? cause.getMessage() : e.getMessage()));
        }
    }
    if (errors > 0) {
        throw new RuntimeException(errors + " errors");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:Main.java

示例9: loadZoneStrings

import java.util.Locale; //導入方法依賴的package包/類
private static String[][] loadZoneStrings(Locale locale) {
    // If the provider is a TimeZoneNameProviderImpl, call its getZoneStrings
    // in order to avoid per-ID retrieval.
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(TimeZoneNameProvider.class, locale);
    TimeZoneNameProvider provider = adapter.getTimeZoneNameProvider();
    if (provider instanceof TimeZoneNameProviderImpl) {
        String[][] zoneStrings = ((TimeZoneNameProviderImpl)provider).getZoneStrings(locale);

        if (zoneStrings.length == 0 && locale.equals(Locale.ROOT)) {
            // Unlike other *Name provider, zoneStrings search won't do the fallback
            // name search. If the ResourceBundle found for the root locale contains no
            // zoneStrings, just use the one for English, assuming English bundle
            // contains all the tzids and their names.
            zoneStrings= getZoneStrings(Locale.ENGLISH);
        }

        return zoneStrings;
    }

    // Performs per-ID retrieval.
    Set<String> zoneIDs = LocaleProviderAdapter.forJRE().getLocaleResources(locale).getZoneIDs();
    List<String[]> zones = new LinkedList<>();
    for (String key : zoneIDs) {
        String[] names = retrieveDisplayNamesImpl(key, locale);
        if (names != null) {
            zones.add(names);
        }
    }

    String[][] zonesArray = new String[zones.size()][];
    return zones.toArray(zonesArray);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:TimeZoneNameUtility.java

示例10: getLayoutDirectionFromLocale

import java.util.Locale; //導入方法依賴的package包/類
public int getLayoutDirectionFromLocale(@Nullable Locale locale) {
    if (!(locale == null || locale.equals(TextUtilsCompat.ROOT))) {
        String scriptSubtag = ICUCompat.maximizeAndGetScript(locale);
        if (scriptSubtag == null) {
            return getLayoutDirectionFromFirstChar(locale);
        }
        if (scriptSubtag.equalsIgnoreCase(TextUtilsCompat.ARAB_SCRIPT_SUBTAG) || scriptSubtag.equalsIgnoreCase(TextUtilsCompat.HEBR_SCRIPT_SUBTAG)) {
            return 1;
        }
    }
    return 0;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:13,代碼來源:TextUtilsCompat.java

示例11: getLocalValue

import java.util.Locale; //導入方法依賴的package包/類
/**
   * Get the localized value of an entity's attribute
   * @param entityId the id of the entity
   * @param entityClass the class of the entity
   * @param attributeName the name of the attribute that must be defined as Map<Locale, String>
   * @param locale the locale for the value, use null for the current request locale
   * @param returnNull (optional) true if null must be returned when no value is present instead of the empty string
   * @return the localized value in the specified locale, or in the default configured locale if the value is not set for that locale, 
   * or an empty string if no value is found or null if no value is found and returnNull is true.
   */
  public String getLocalValue(long entityId, Class<?> entityClass, String attributeName, Locale locale, Boolean... returnNull) {
  	// select color from YadaArticle_color where YadaArticle_id=123 and locale="en_US"
if (locale==null) {
	locale = LocaleContextHolder.getLocale();
}
  	String className = entityClass.getSimpleName();
  	String tableName = className + "_" + attributeName;
  	String idColumn = className + "_id";
  	YadaSql yadaSql = YadaSql.instance().selectFrom("select " + attributeName + " from " + tableName)
  		.where(idColumn + " = :entityId").and()
  		.where("locale = :localeString").and()
  		.setParameter("entityId", entityId)
  		.setParameter("localeString", locale.toString());
  	List<?> result = yadaSql.nativeQuery(em).getResultList();
  	if (result.isEmpty()) {
  		// Try with the default locale
  		Locale defaultLocale = config.getDefaultLocale();
  		if (defaultLocale!=null && !defaultLocale.equals(locale)) {
  			yadaSql.setParameter("localeString", defaultLocale.toString());
  			result = yadaSql.nativeQuery(em).getResultList();
  		}
  	}
  	if (result.isEmpty()) {
  		if (returnNull!=null && returnNull.length>0 && Boolean.TRUE.equals(returnNull[0])) {
  			return null;
  		}
  		return "";
  	}
  	return (String) result.get(0);
  }
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:41,代碼來源:YadaLocaleDao.java

示例12: setLocale

import java.util.Locale; //導入方法依賴的package包/類
/**
 * Set locale to input. If input method doesn't support specified locale,
 * false will be returned and its behavior is not changed.
 *
 * @param lang locale to input
 * @return the true is returned when specified locale is supported.
 */
public boolean setLocale(Locale lang) {
    if (lang.equals(locale)) {
        return true;
    }
    // special compatibility rule for Japanese and Korean
    if (locale.equals(Locale.JAPAN) && lang.equals(Locale.JAPANESE) ||
            locale.equals(Locale.KOREA) && lang.equals(Locale.KOREAN)) {
        return true;
    }
    return false;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:X11InputMethod.java

示例13: intercept

import java.util.Locale; //導入方法依賴的package包/類
@Override
public String intercept(final ActionInvocation invocation) throws Exception {

    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession(true);

    Locale locale = (Locale) session.getAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE);
    // Locale adminpagelocale = (Locale)
    // session.getAttribute(ADMIN_PAGE_LOCALE);
    // if (locale == null && adminpagelocale == null) {
    if (locale == null) {
        if (request.getLocale().equals(Locale.CHINA) || request.getLocale().equals(Locale.CHINESE)) {
            session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.CHINA);
            logger.debug("Language is set to Chinese. from IP <" + request.getRemoteAddr() + ">");
        } else if (request.getLocale().equals(Locale.JAPAN) || request.getLocale().equals(Locale.JAPANESE)) {
            session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.JAPAN);
            logger.debug("Language is set to Japanese. from IP <" + request.getRemoteAddr() + ">");
        } else {
            session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.US);
            logger.debug("Language is set to English.from IP <" + request.getRemoteAddr() + ">");
        }
    }
    // else if (adminpagelocale != null) {
    // session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE,
    // adminpagelocale);
    // }
    if (invocation.getAction() instanceof AbstractAdminBaseAction
            && (locale == null || !locale.equals(Locale.CHINA))) {
        // 使用中文界麵
        // session.setAttribute(ADMIN_PAGE_LOCALE,
        // session.getAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
        session.setAttribute(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE, Locale.CHINA);
        logger.debug("because access page is admin page. Language is set to Chinese. from IP <"
                + request.getRemoteAddr() + ">");
    }
    return invocation.invoke();
}
 
開發者ID:Chihpin,項目名稱:Yidu,代碼行數:38,代碼來源:SetLanguageInterceptor.java

示例14: onSubtypeChanged

import java.util.Locale; //導入方法依賴的package包/類
public static void onSubtypeChanged(@NonNull final RichInputMethodSubtype subtype,
       final boolean implicitlyEnabledSubtype, @NonNull final Locale systemLocale) {
    final Locale newLocale = subtype.getLocale();
    if (systemLocale.equals(newLocale)) {
        sIsSystemLanguageSameAsInputLanguage = true;
        return;
    }
    if (!systemLocale.getLanguage().equals(newLocale.getLanguage())) {
        sIsSystemLanguageSameAsInputLanguage = false;
        return;
    }
    // If the subtype is enabled explicitly, the language name should be displayed even when
    // the keyboard language and the system language are equal.
    sIsSystemLanguageSameAsInputLanguage = implicitlyEnabledSubtype;
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:16,代碼來源:LanguageOnSpacebarUtils.java

示例15: StringManager

import java.util.Locale; //導入方法依賴的package包/類
/**
 * Creates a new StringManager for a given package. This is a
 * private method and all access to it is arbitrated by the
 * static getManager method call so that only one StringManager
 * per package will be created.
 *
 * @param packageName Name of package to create StringManager for.
 */
private StringManager(String packageName, Locale locale) {
    String bundleName = packageName + ".LocalStrings";
    ResourceBundle bnd = null;
    try {
        bnd = ResourceBundle.getBundle(bundleName, locale);
    } catch (MissingResourceException ex) {
        // Try from the current loader (that's the case for trusted apps)
        // Should only be required if using a TC5 style classloader structure
        // where common != shared != server
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if (cl != null) {
            try {
                bnd = ResourceBundle.getBundle(bundleName, locale, cl);
            } catch (MissingResourceException ex2) {
                // Ignore
            }
        }
    }
    bundle = bnd;
    // Get the actual locale, which may be different from the requested one
    if (bundle != null) {
        Locale bundleLocale = bundle.getLocale();
        if (bundleLocale.equals(Locale.ROOT)) {
            this.locale = Locale.ENGLISH;
        } else {
            this.locale = bundleLocale;
        }
    } else {
        this.locale = null;
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:40,代碼來源:StringManager.java


注:本文中的java.util.Locale.equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。