java.util.Locale.equals()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中java.util.Locale.equals()方法的一些代码示例,展示了Locale.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.equals()方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:equals

Locale.equals介绍

[英]Returns true if object is a locale with the same language, country and variant.
[中]如果对象是具有相同语言、国家/地区和变体的区域设置,则返回true。

代码示例

代码示例来源:origin: libgdx/libgdx

/** Returns a <code>Locale</code> to be used as a fallback locale for further bundle searches by the <code>createBundle</code>
 * factory method. This method is called from the factory method every time when no resulting bundle has been found for
 * <code>baseFileHandler</code> and <code>locale</code>, where locale is either the parameter for <code>createBundle</code> or
 * the previous fallback locale returned by this method.
 * 
 * <p>
 * This method returns the {@linkplain Locale#getDefault() default <code>Locale</code>} if the given <code>locale</code> isn't
 * the default one. Otherwise, <code>null</code> is returned.
 * 
 * @param locale the <code>Locale</code> for which <code>createBundle</code> has been unable to find any resource bundles
 *           (except for the base bundle)
 * @return a <code>Locale</code> for the fallback search, or <code>null</code> if no further fallback search is needed.
 * @exception NullPointerException if <code>locale</code> is <code>null</code> */
private static Locale getFallbackLocale (Locale locale) {
  Locale defaultLocale = Locale.getDefault();
  return locale.equals(defaultLocale) ? null : defaultLocale;
}

代码示例来源:origin: libgdx/libgdx

/** Returns a <code>Locale</code> to be used as a fallback locale for further bundle searches by the <code>createBundle</code>
 * factory method. This method is called from the factory method every time when no resulting bundle has been found for
 * <code>baseFileHandler</code> and <code>locale</code>, where locale is either the parameter for <code>createBundle</code> or
 * the previous fallback locale returned by this method.
 * 
 * <p>
 * This method returns the {@linkplain Locale#getDefault() default <code>Locale</code>} if the given <code>locale</code> isn't
 * the default one. Otherwise, <code>null</code> is returned.
 * 
 * @param locale the <code>Locale</code> for which <code>createBundle</code> has been unable to find any resource bundles
 *           (except for the base bundle)
 * @return a <code>Locale</code> for the fallback search, or <code>null</code> if no further fallback search is needed.
 * @exception NullPointerException if <code>locale</code> is <code>null</code> */
private static Locale getFallbackLocale (Locale locale) {
  Locale defaultLocale = Locale.getDefault();
  return locale.equals(defaultLocale) ? null : defaultLocale;
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * <p>Compare another object for equality with this object.</p>
 *
 * @param obj  the object to compare to
 * @return <code>true</code>if equal to this instance
 */
@Override
public boolean equals(final Object obj) {
  if (!(obj instanceof FastDateParser)) {
    return false;
  }
  final FastDateParser other = (FastDateParser) obj;
  return pattern.equals(other.pattern)
    && timeZone.equals(other.timeZone)
    && locale.equals(other.locale);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * <p>Compares two objects for equality.</p>
 *
 * @param obj  the object to compare to
 * @return {@code true} if equal
 */
@Override
public boolean equals(final Object obj) {
  if (!(obj instanceof FastDatePrinter)) {
    return false;
  }
  final FastDatePrinter other = (FastDatePrinter) obj;
  return mPattern.equals(other.mPattern)
    && mTimeZone.equals(other.mTimeZone)
    && mLocale.equals(other.mLocale);
}

代码示例来源:origin: skylot/jadx

@Override
public boolean equals(Object obj) {
  return obj instanceof LangLocale && locale.equals(((LangLocale) obj).get());
}

代码示例来源:origin: prestodb/presto

/**
 * "Mutant factory" method that will return an instance that uses specified
 * {@code Locale}:
 * either {@code this} instance (if setting would not change), or newly
 * constructed instance with different {@code Locale} to use.
 */
public StdDateFormat withLocale(Locale loc) {
  if (loc.equals(_locale)) {
    return this;
  }
  return new StdDateFormat(_timezone, loc, _lenient, _tzSerializedWithColon);
}

代码示例来源:origin: prestodb/presto

public JacksonJodaPeriodFormat withLocale(Locale locale) {
  if ((locale == null) || (_locale != null && _locale.equals(locale))) {
    return this;
  }
  return new JacksonJodaPeriodFormat(this, locale);
}

代码示例来源:origin: prestodb/presto

public JacksonJodaDateFormat withLocale(Locale locale) {
  if ((locale == null) || (_locale != null && _locale.equals(locale))) {
    return this;
  }
  return new JacksonJodaDateFormat(this, locale);
}

代码示例来源:origin: redisson/redisson

/**
 * "Mutant factory" method that will return an instance that uses specified
 * {@code Locale}:
 * either {@code this} instance (if setting would not change), or newly
 * constructed instance with different {@code Locale} to use.
 */
public StdDateFormat withLocale(Locale loc) {
  if (loc.equals(_locale)) {
    return this;
  }
  return new StdDateFormat(_timezone, loc, _lenient, _tzSerializedWithColon);
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Override
public Date parse(final String source) throws ParseException {
  final ParsePosition pp = new ParsePosition(0);
  final Date date= parse(source, pp);
  if (date == null) {
    // Add a note re supported date range
    if (locale.equals(JAPANESE_IMPERIAL)) {
      throw new ParseException(
          "(The " +locale + " locale does not support dates before 1868 AD)\n" +
              "Unparseable date: \""+source, pp.getErrorIndex());
    }
    throw new ParseException("Unparseable date: "+source, pp.getErrorIndex());
  }
  return date;
}

代码示例来源:origin: libgdx/libgdx

private static I18NBundle loadBundleChain (FileHandle baseFileHandle, String encoding, List<Locale> candidateLocales,
  int candidateIndex, I18NBundle baseBundle) {
  Locale targetLocale = candidateLocales.get(candidateIndex);
  I18NBundle parent = null;
  if (candidateIndex != candidateLocales.size() - 1) {
    // Load recursively the parent having the next candidate locale
    parent = loadBundleChain(baseFileHandle, encoding, candidateLocales, candidateIndex + 1, baseBundle);
  } else if (baseBundle != null && targetLocale.equals(ROOT_LOCALE)) {
    return baseBundle;
  }
  // Load the bundle
  I18NBundle bundle = loadBundle(baseFileHandle, encoding, targetLocale);
  if (bundle != null) {
    bundle.parent = parent;
    return bundle;
  }
  return parent;
}

代码示例来源:origin: libgdx/libgdx

private static I18NBundle loadBundleChain (FileHandle baseFileHandle, String encoding, List<Locale> candidateLocales,
  int candidateIndex, I18NBundle baseBundle) {
  Locale targetLocale = candidateLocales.get(candidateIndex);
  I18NBundle parent = null;
  if (candidateIndex != candidateLocales.size() - 1) {
    // Load recursively the parent having the next candidate locale
    parent = loadBundleChain(baseFileHandle, encoding, candidateLocales, candidateIndex + 1, baseBundle);
  } else if (baseBundle != null && targetLocale.equals(ROOT_LOCALE)) {
    return baseBundle;
  }
  // Load the bundle
  I18NBundle bundle = loadBundle(baseFileHandle, encoding, targetLocale);
  if (bundle != null) {
    bundle.parent = parent;
    return bundle;
  }
  return parent;
}

代码示例来源:origin: prestodb/presto

public PeriodFormatter createFormatter(SerializerProvider provider)
{
  PeriodFormatter formatter = _formatter;
  
  if (!_explicitLocale) {
    Locale loc = provider.getLocale();
    if (loc != null && !loc.equals(_locale)) {
      formatter = formatter.withLocale(loc);
    }
  }
  return formatter;
}

代码示例来源:origin: prestodb/presto

public DateTimeFormatter createFormatterWithLocale(SerializerProvider ctxt)
{
  DateTimeFormatter formatter = _formatter;
  if (!_explicitLocale) {
    Locale loc = ctxt.getLocale();
    if (loc != null && !loc.equals(_locale)) {
      formatter = formatter.withLocale(loc);
    }
  }
  return formatter;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  if (!(RequestContextUtils.findWebApplicationContext(request) instanceof SimpleWebApplicationContext)) {
    throw new ServletException("Incorrect WebApplicationContext");
  }
  if (!(RequestContextUtils.getLocaleResolver(request) instanceof AcceptHeaderLocaleResolver)) {
    throw new ServletException("Incorrect LocaleResolver");
  }
  if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
    throw new ServletException("Incorrect Locale");
  }
  return null;
}

代码示例来源:origin: prestodb/presto

private PeriodPrinter getPrinter(Locale locale) {
  if (locale != null && !locale.equals(iFormatter.getLocale())) {
    return wordBased(locale).getPrinter();
  }
  return iFormatter.getPrinter();
}

代码示例来源:origin: prestodb/presto

private PeriodParser getParser(Locale locale) {
    if (locale != null && !locale.equals(iFormatter.getLocale())) {
      return wordBased(locale).getParser();
    }
    return iFormatter.getParser();
  }
}

代码示例来源:origin: joda-time/joda-time

private PeriodPrinter getPrinter(Locale locale) {
  if (locale != null && !locale.equals(iFormatter.getLocale())) {
    return wordBased(locale).getPrinter();
  }
  return iFormatter.getPrinter();
}

代码示例来源:origin: joda-time/joda-time

private PeriodParser getParser(Locale locale) {
    if (locale != null && !locale.equals(iFormatter.getLocale())) {
      return wordBased(locale).getParser();
    }
    return iFormatter.getParser();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void defaultLocale() {
  Locale originalDefaultLocale = Locale.getDefault();
  try {
    Locale newDefaultLocale = originalDefaultLocale.equals(Locale.GERMANY) ? Locale.FRANCE : Locale.GERMANY;
    Locale.setDefault(newDefaultLocale);
    // Create the request after changing the default locale.
    MockHttpServletRequest request = new MockHttpServletRequest();
    assertFalse(newDefaultLocale.equals(request.getLocale()));
    assertEquals(Locale.ENGLISH, request.getLocale());
  }
  finally {
    Locale.setDefault(originalDefaultLocale);
  }
}

相关文章