Java Code Examples for java.util.Locale#equals()
The following examples show how to use
java.util.Locale#equals() .
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: TrueTypeFont.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public String getFontName(Locale locale) { if (locale == null) { return fullName; } else if (locale.equals(nameLocale) && localeFullName != null) { return localeFullName; } else { short localeID = getLCIDFromLocale(locale); String name = lookupName(localeID, FULL_NAME_ID); if (name == null) { return fullName; } else { return name; } } }
Example 2
Source File: NbBundle.java From netbeans with Apache License 2.0 | 6 votes |
/** Creates new LocaleIterator for given locale. * @param locale given Locale */ public LocaleIterator(Locale locale) { this.locale = this.initLocale = locale; if (locale.equals(Locale.getDefault())) { defaultInProgress = true; } current = '_' + locale.toString(); if (brandingToken == null) { branding = null; } else { branding = "_" + brandingToken; // NOI18N } //System.err.println("Constructed: " + this); }
Example 3
Source File: TimeFormatter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public TimeFormatter() { synchronized (TimeFormatter.class) { Locale locale = Locale.getDefault(); if (sLocale == null || !(locale.equals(sLocale))) { sLocale = locale; sLocaleData = LocaleData.get(locale); Resources r = Resources.getSystem(); sTimeOnlyFormat = r.getString(com.android.internal.R.string.time_of_day); sDateOnlyFormat = r.getString(com.android.internal.R.string.month_day_year); sDateTimeFormat = r.getString(com.android.internal.R.string.date_and_time); } this.dateTimeFormat = sDateTimeFormat; this.timeOnlyFormat = sTimeOnlyFormat; this.dateOnlyFormat = sDateOnlyFormat; localeData = sLocaleData; } }
Example 4
Source File: TrueTypeFont.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public String getFamilyName(Locale locale) { if (locale == null) { return familyName; } else if (locale.equals(nameLocale) && localeFamilyName != null) { return localeFamilyName; } else { short localeID = getLCIDFromLocale(locale); String name = lookupName(localeID, FAMILY_NAME_ID); if (name == null) { return familyName; } else { return name; } } }
Example 5
Source File: ImageReader.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 6
Source File: TrueTypeFont.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public String getFontName(Locale locale) { if (locale == null) { return fullName; } else if (locale.equals(nameLocale) && localeFullName != null) { return localeFullName; } else { short localeID = getLCIDFromLocale(locale); String name = lookupName(localeID, FULL_NAME_ID); if (name == null) { return fullName; } else { return name; } } }
Example 7
Source File: Scanner.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Sets this scanner's locale to the specified locale. * * <p>A scanner's locale affects many elements of its default * primitive matching regular expressions; see * <a href= "#localized-numbers">localized numbers</a> above. * * <p>Invoking the {@link #reset} method will set the scanner's locale to * the <a href= "#initial-locale">initial locale</a>. * * @param locale A string specifying the locale to use * @return this scanner */ public Scanner useLocale(Locale locale) { if (locale.equals(this.locale)) return this; this.locale = locale; DecimalFormat df = (DecimalFormat)NumberFormat.getNumberInstance(locale); DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale); // These must be literalized to avoid collision with regex // metacharacters such as dot or parenthesis groupSeparator = "\\" + dfs.getGroupingSeparator(); decimalSeparator = "\\" + dfs.getDecimalSeparator(); // Quoting the nonzero length locale-specific things // to avoid potential conflict with metacharacters nanString = "\\Q" + dfs.getNaN() + "\\E"; infinityString = "\\Q" + dfs.getInfinity() + "\\E"; positivePrefix = df.getPositivePrefix(); if (positivePrefix.length() > 0) positivePrefix = "\\Q" + positivePrefix + "\\E"; negativePrefix = df.getNegativePrefix(); if (negativePrefix.length() > 0) negativePrefix = "\\Q" + negativePrefix + "\\E"; positiveSuffix = df.getPositiveSuffix(); if (positiveSuffix.length() > 0) positiveSuffix = "\\Q" + positiveSuffix + "\\E"; negativeSuffix = df.getNegativeSuffix(); if (negativeSuffix.length() > 0) negativeSuffix = "\\Q" + negativeSuffix + "\\E"; // Force rebuilding and recompilation of locale dependent // primitive patterns integerPattern = null; floatPattern = null; return this; }
Example 8
Source File: PageableController.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Set the local for the resources. * * @param locale */ public void setLocale(Locale locale) { Locale oldLocale = this.locale; this.locale = locale; if (!oldLocale.equals(locale)) { notifyListenersForLocaleChanged(oldLocale, locale); } }
Example 9
Source File: DateFormatSymbolsTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @tests java.text.DateFormatSymbols#getAvailableLocales() */ public void test_getAvailableLocales_no_provider() throws Exception { Locale[] locales = DateFormatSymbols.getAvailableLocales(); assertNotNull(locales); // must contain Locale.US boolean flag = false; for (Locale locale : locales) { if (locale.equals(Locale.US)) { flag = true; break; } } assertTrue(flag); }
Example 10
Source File: X11InputMethod.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 11
Source File: InternationalBAT.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static boolean testRequiredEncodings() { boolean pass = true; for (int i = 0; i < requiredEncodings.length; i++) { String encoding = requiredEncodings[i]; Locale sampleLocale = sampleLocales[i]; try { int index = 0; while (!sampleLocale.equals(requiredLocales[index])) { index++; } byte[] out = requiredLocaleDates[index].getBytes(encoding); byte[] expected = expectedBytes[i]; if (out.length != expected.length) { reportConversionError(encoding, expected, out); pass = false; } else { for (int j = 0; j < out.length; j++) { if (out[j] != expected[j]) { reportConversionError(encoding, expected, out); pass = false; break; } } } } catch (UnsupportedEncodingException e) { System.out.println("Encoding not available: " + encoding); pass = false; } } return pass; }
Example 12
Source File: LocaleSelector.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public void localeChanged() { Locale current = LocaleManager.getLocale(); LocaleOption sel = null; for (int i = 0; i < items.length; i++) { items[i].update(current); if (current.equals(items[i].locale)) sel = items[i]; } if (sel != null) { setSelectedValue(sel, true); } }
Example 13
Source File: ResourceBundleMessageResolver.java From oval with Eclipse Public License 2.0 | 5 votes |
@Override public String getMessage(final String key) { final Locale currentLocale = Validator.getLocaleProvider().getLocale(); final String msg = getMessage(key, currentLocale); if (msg != null) return msg; final Locale defaultLocale = Locale.getDefault(); if (!currentLocale.equals(defaultLocale)) return getMessage(key, defaultLocale); return null; }
Example 14
Source File: LocaleList.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@IntRange(from=0, to=1) private static int matchScore(Locale supported, Locale desired) { if (supported.equals(desired)) { return 1; // return early so we don't do unnecessary computation } if (!supported.getLanguage().equals(desired.getLanguage())) { return 0; } if (isPseudoLocale(supported) || isPseudoLocale(desired)) { // The locales are not the same, but the languages are the same, and one of the locales // is a pseudo-locale. So this is not a match. return 0; } final String supportedScr = getLikelyScript(supported); if (supportedScr.isEmpty()) { // If we can't guess a script, we don't know enough about the locales' language to find // if the locales match. So we fall back to old behavior of matching, which considered // locales with different regions different. final String supportedRegion = supported.getCountry(); return (supportedRegion.isEmpty() || supportedRegion.equals(desired.getCountry())) ? 1 : 0; } final String desiredScr = getLikelyScript(desired); // There is no match if the two locales use different scripts. This will most imporantly // take care of traditional vs simplified Chinese. return supportedScr.equals(desiredScr) ? 1 : 0; }
Example 15
Source File: IdentifyTvShowEpisodeFragment.java From Mizuu with Apache License 2.0 | 4 votes |
private boolean hasLocale(Locale l) { for (Locale locale : mSystemLocales) if (locale.equals(l)) return true; return false; }
Example 16
Source File: SunFontManager.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Get a list of installed fonts in the requested {@link Locale}. * The list contains the fonts Family Names. * If Locale is null, the default locale is used. * * @param requestedLocale, if null the default locale is used. * @return list of installed fonts in the system. */ public String[] getInstalledFontFamilyNames(Locale requestedLocale) { if (requestedLocale == null) { requestedLocale = Locale.getDefault(); } if (allFamilies != null && lastDefaultLocale != null && requestedLocale.equals(lastDefaultLocale)) { String[] copyFamilies = new String[allFamilies.length]; System.arraycopy(allFamilies, 0, copyFamilies, 0, allFamilies.length); return copyFamilies; } TreeMap<String,String> familyNames = new TreeMap<String,String>(); // these names are always there and aren't localised String str; str = Font.SERIF; familyNames.put(str.toLowerCase(), str); str = Font.SANS_SERIF; familyNames.put(str.toLowerCase(), str); str = Font.MONOSPACED; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG; familyNames.put(str.toLowerCase(), str); str = Font.DIALOG_INPUT; familyNames.put(str.toLowerCase(), str); /* Platform APIs may be used to get the set of available family * names for the current default locale so long as it is the same * as the start-up system locale, rather than loading all fonts. */ if (requestedLocale.equals(getSystemStartupLocale()) && getFamilyNamesFromPlatform(familyNames, requestedLocale)) { /* Augment platform names with JRE font family names */ getJREFontFamilyNames(familyNames, requestedLocale); } else { loadFontFiles(); Font2D[] physicalfonts = getPhysicalFonts(); for (int i=0; i < physicalfonts.length; i++) { if (!(physicalfonts[i] instanceof NativeFont)) { String name = physicalfonts[i].getFamilyName(requestedLocale); familyNames.put(name.toLowerCase(requestedLocale), name); } } } // Add any native font family names here addNativeFontFamilyNames(familyNames, requestedLocale); String[] retval = new String[familyNames.size()]; Object [] keyNames = familyNames.keySet().toArray(); for (int i=0; i < keyNames.length; i++) { retval[i] = (String)familyNames.get(keyNames[i]); } if (requestedLocale.equals(Locale.getDefault())) { lastDefaultLocale = requestedLocale; allFamilies = new String[retval.length]; System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length); } return retval; }
Example 17
Source File: LocaleProviderAdapter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Returns a LocaleProviderAdapter for the given locale service provider that * best matches the given locale. This method returns the LocaleProviderAdapter * for JRE if none is found for the given locale. * * @param providerClass the class for the locale service provider * @param locale the desired locale. * @return a LocaleProviderAdapter */ public static LocaleProviderAdapter getAdapter(Class<? extends LocaleServiceProvider> providerClass, Locale locale) { LocaleProviderAdapter adapter; // cache lookup ConcurrentMap<Locale, LocaleProviderAdapter> adapterMap = adapterCache.get(providerClass); if (adapterMap != null) { if ((adapter = adapterMap.get(locale)) != null) { return adapter; } } else { adapterMap = new ConcurrentHashMap<>(); adapterCache.putIfAbsent(providerClass, adapterMap); } // Fast look-up for the given locale adapter = findAdapter(providerClass, locale); if (adapter != null) { adapterMap.putIfAbsent(locale, adapter); return adapter; } // Try finding an adapter in the normal candidate locales path of the given locale. List<Locale> lookupLocales = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT) .getCandidateLocales("", locale); for (Locale loc : lookupLocales) { if (loc.equals(locale)) { // We've already done with this loc. continue; } adapter = findAdapter(providerClass, loc); if (adapter != null) { adapterMap.putIfAbsent(locale, adapter); return adapter; } } // returns the adapter for FALLBACK as the last resort adapterMap.putIfAbsent(locale, forType(Type.FALLBACK)); return forType(Type.FALLBACK); }
Example 18
Source File: LocaleSpanCompatUtils.java From Indic-Keyboard with Apache License 2.0 | 4 votes |
/** * Ensures that the specified range is covered with only one {@link LocaleSpan} with the given * locale. If the region is already covered by one or more {@link LocaleSpan}, their ranges are * updated so that each character has only one locale. * @param spannable the spannable object to be updated. * @param start the start index from which {@link LocaleSpan} is attached (inclusive). * @param end the end index to which {@link LocaleSpan} is attached (exclusive). * @param locale the locale to be attached to the specified range. */ @UsedForTesting public static void updateLocaleSpan(final Spannable spannable, final int start, final int end, final Locale locale) { if (end < start) { Log.e(TAG, "Invalid range: start=" + start + " end=" + end); return; } if (!isLocaleSpanAvailable()) { return; } // A brief summary of our strategy; // 1. Enumerate all LocaleSpans between [start - 1, end + 1]. // 2. For each LocaleSpan S: // - Update the range of S so as not to cover [start, end] if S doesn't have the // expected locale. // - Mark S as "to be merged" if S has the expected locale. // 3. Merge all the LocaleSpans that are marked as "to be merged" into one LocaleSpan. // If no appropriate span is found, create a new one with newLocaleSpan method. final int searchStart = Math.max(start - 1, 0); final int searchEnd = Math.min(end + 1, spannable.length()); // LocaleSpans found in the target range. See the step 1 in the above comment. final Object[] existingLocaleSpans = spannable.getSpans(searchStart, searchEnd, LOCALE_SPAN_TYPE); // LocaleSpans that are marked as "to be merged". See the step 2 in the above comment. final ArrayList<Object> existingLocaleSpansToBeMerged = new ArrayList<>(); boolean isStartExclusive = true; boolean isEndExclusive = true; int newStart = start; int newEnd = end; for (final Object existingLocaleSpan : existingLocaleSpans) { final Locale attachedLocale = getLocaleFromLocaleSpan(existingLocaleSpan); if (!locale.equals(attachedLocale)) { // This LocaleSpan does not have the expected locale. Update its range if it has // an intersection with the range [start, end] (the first case of the step 2 in the // above comment). removeLocaleSpanFromRange(existingLocaleSpan, spannable, start, end); continue; } final int spanStart = spannable.getSpanStart(existingLocaleSpan); final int spanEnd = spannable.getSpanEnd(existingLocaleSpan); if (spanEnd < spanStart) { Log.e(TAG, "Invalid span: spanStart=" + spanStart + " spanEnd=" + spanEnd); continue; } if (spanEnd < start || end < spanStart) { // No intersection found. continue; } // Here existingLocaleSpan has the expected locale and an intersection with the // range [start, end] (the second case of the the step 2 in the above comment). final int spanFlag = spannable.getSpanFlags(existingLocaleSpan); if (spanStart < newStart) { newStart = spanStart; isStartExclusive = ((spanFlag & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) == Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } if (newEnd < spanEnd) { newEnd = spanEnd; isEndExclusive = ((spanFlag & Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) == Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } existingLocaleSpansToBeMerged.add(existingLocaleSpan); } int originalLocaleSpanFlag = 0; Object localeSpan = null; if (existingLocaleSpansToBeMerged.isEmpty()) { // If there is no LocaleSpan that is marked as to be merged, create a new one. localeSpan = newLocaleSpan(locale); } else { // Reuse the first LocaleSpan to avoid unnecessary object instantiation. localeSpan = existingLocaleSpansToBeMerged.get(0); originalLocaleSpanFlag = spannable.getSpanFlags(localeSpan); // No need to keep other instances. for (int i = 1; i < existingLocaleSpansToBeMerged.size(); ++i) { spannable.removeSpan(existingLocaleSpansToBeMerged.get(i)); } } final int localeSpanFlag = getSpanFlag(originalLocaleSpanFlag, isStartExclusive, isEndExclusive); spannable.setSpan(localeSpan, newStart, newEnd, localeSpanFlag); }
Example 19
Source File: Cardumen_0073_t.java From coming with MIT License | 3 votes |
/** * Returns a new formatter with a different locale that will be used * for printing and parsing. * <p> * A DateTimeFormatter is immutable, so a new instance is returned, * and the original is unaltered and still usable. * * @param locale the locale to use; if null, formatter uses default locale * at invocation time * @return the new formatter */ public DateTimeFormatter withLocale(Locale locale) { if (locale == getLocale() || (locale != null && locale.equals(getLocale()))) { return this; } return new DateTimeFormatter(iPrinter, iParser, locale, iOffsetParsed, iChrono, iZone, iPivotYear, iDefaultYear); }
Example 20
Source File: DecimalFormatFilter.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 3 votes |
/** * Returns the formatted string. The value is read using the data source given and formated using the formatter of * this object. The formating is guaranteed to completly form the object to an string or to return the defined * NullValue. * <p/> * If format, datasource or object are null, the NullValue is returned. * * @param runtime * the expression runtime that is used to evaluate formulas and expressions when computing the value of this * filter. * @param element * @return The formatted value. */ public Object getValue( final ExpressionRuntime runtime, final ReportElement element ) { if ( keepState == false && runtime != null ) { final Locale locale = runtime.getResourceBundleFactory().getLocale(); if ( locale != null && locale.equals( lastLocale ) == false ) { lastLocale = locale; getDecimalFormat().setDecimalFormatSymbols( new DecimalFormatSymbols( locale ) ); invalidateCache(); } } return super.getValue( runtime, element ); }