List of usage examples for java.util Locale equals
@Override public boolean equals(Object obj)
From source file:Main.java
public static void main(String[] args) { Locale locale1 = new Locale("ENGLISH", "US"); // print this locale System.out.println("Locale1:" + locale1); // create a second locale Locale locale2 = new Locale("GERMANY", "GERMAN"); // compare two locales System.out.println("Locales are equal:" + locale1.equals(locale2)); // create a third locale Locale locale3 = new Locale("ENGLISH", "US"); // compare locale1 and locale3 System.out.println("Locales are equal:" + locale1.equals(locale3)); }
From source file:Main.java
public static boolean isEnglishLocale(Locale locale) { return locale.equals(Locale.ENGLISH); }
From source file:Main.java
/** * Returns the given amount of meters in rounded yards if the default locale * is US, in rounded meters otherwise./*from w w w .j av a 2 s . c o m*/ * @param meters * @return int */ public static int getLocalizedRoundedMeters(final float meters) { Locale defaultLocale = Locale.getDefault(); if (defaultLocale.equals(Locale.US)) { return Math.round(meters / 0.9144f); } else { return Math.round(meters); } }
From source file:nu.yona.server.Translator.java
private static Object determineLocaleInfix() { Locale locale = LocaleContextHolder.getLocale(); if (locale.equals(EN_US_LOCALE)) { return ""; }//from ww w.j a v a 2 s . co m return "_" + locale.getLanguage(); }
From source file:Main.java
/** * Test for lax Locale equality. More precisely, returns true if * (a) both are equal; (b) general only specifies language, and * specific has the same language; (c) general specifies language and * country, and specific has the same language and country. Else returns false. *//*from ww w . j a va 2 s . co m*/ public static boolean subsumes(Locale general, Locale specific) { if (general == null || specific == null) return false; if (general.equals(specific)) return true; else if (general.getVariant().equals("")) { if (general.getCountry().equals("")) { if (general.getLanguage().equals(specific.getLanguage())) return true; } else { if (general.getLanguage().equals(specific.getLanguage()) && general.getCountry().equals(specific.getCountry())) return true; } } return false; }
From source file:org.xdi.oxauth.model.util.LocaleUtil.java
public static Locale localeMatch(List<String> requestedLocales, List<Locale> availableLocales) { if (requestedLocales == null || availableLocales == null) { return null; }//from w w w . j a v a 2s.c om for (String requestedLocale : requestedLocales) { Locale reqInQuestion = LocaleUtils.toLocale(requestedLocale); List<Locale> lookupList = LocaleUtils.localeLookupList(reqInQuestion); for (Locale localeInQuestion : lookupList) { for (Locale availableLocale : availableLocales) { if (localeInQuestion.equals(availableLocale)) { return availableLocale; } } } for (Locale availableLocale : availableLocales) { if (reqInQuestion.getLanguage().equals(availableLocale.getLanguage())) { return availableLocale; } } } return null; }
From source file:Main.java
/** * Call this method on the Activity onResume. It will recreate the Activity if a Locale change is detected. * @param activity// w ww . j ava 2 s . c o m */ public static void onResume(Activity activity) { Locale previousLocale = localesOnActivities.get(activity.toString()); boolean shouldRestartActivity = previousLocale != null && !previousLocale.equals(Locale.getDefault()); localesOnActivities.put(activity.toString(), Locale.getDefault()); if (shouldRestartActivity) { recreate(activity, false); } }
From source file:org.vosao.i18n.Messages.java
public static boolean isLocaleSupported(Locale locale) { for (Locale l : supportedLocales) { if (l.equals(locale)) { return true; }//from ww w . j a v a2s. c o m } return false; }
From source file:Main.java
/** Return whether or not the given locale is the device's current locale. */ public static boolean isCurrentLocale(Context context, Locale locale) { // TODO: Change the locale on the device using public API if it becomes available. Locale currentLocale = context.getResources().getConfiguration().locale; return locale.equals(currentLocale); }
From source file:org.openmrs.util.LocaleUtility.java
/** * Compatible is a looser matching than that provided by Locale.equals(). Two locales are * considered equal if they are equal, or if either does not have a country specified and the * languages match.//w ww . j a v a 2 s . c o m * * @param lhs left hand side Locale * @param rhs right hand side Locale * @return true if the two locales are compatible, false otherwise * @should confirm different language missing country as compatible * @should confirm same language missing country as compatible * @should not confirm different country as compatible * @should confirm matching country as compatible * @should not confirm different language as compatible * @should confirm matching language as compatible */ public static boolean areCompatible(Locale lhs, Locale rhs) { if (lhs.equals(rhs)) { return true; } else if ((("".equals(lhs.getCountry())) || ("".equals(rhs.getCountry()))) && lhs.getLanguage().equals(rhs.getLanguage())) { // no country specified, so language match is good enough return true; } return false; }