List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:org.jfree.data.time.MonthTest.java
/** * Some checks for the getLastMillisecond() method. *///from ww w . j ava 2 s. c om @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Month m = new Month(3, 1970); assertEquals(7772399999L, m.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.talend.dataquality.statistics.datetime.CustomDateTimePatternManagerTest.java
@Test public void testDateWithLocaleDE() { // simulate a JVM Locale.setDefault(Locale.GERMANY); final List<String> pattern = Collections.<String>singletonList("MMMM d ?? yyyy"); final String[] dates = new String[] { "January 9 ?? 1970", // EN "janvier 9 ?? 1970", // FR "Januar 9 ?? 1970", // DE " 9 ?? 1970", // CN };//from w w w . ja v a 2 s .c o m final boolean[] EXPECTED_IS_DATE_DEFAULT = new boolean[] { true, false, false, false }; final boolean[] EXPECTED_IS_DATE_US = new boolean[] { true, false, false, false }; final boolean[] EXPECTED_IS_DATE_FR = new boolean[] { true, true, false, false }; final boolean[] EXPECTED_IS_DATE_DE = new boolean[] { true, false, true, false }; final boolean[] EXPECTED_IS_DATE_CN = new boolean[] { true, false, false, true }; // final String[] EXPECTED_PATTERN_STRING = new String[] { "", }; StringBuilder sb = new StringBuilder("\n"); sb.append("-------------- JVM Locale: " + Locale.getDefault().toString() + " ------\n"); sb.append("Input \\ UserLocale\tN/A\tEN\tFR\tDE\tCN\n"); for (int i = 0; i < dates.length; i++) { sb.append(dates[i]).append(" \t"); sb.append(CustomDateTimePatternManager.isDate(dates[i], pattern)).append("\t"); sb.append(CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.US)).append("\t"); sb.append(CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.FRANCE)).append("\t"); sb.append(CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.GERMANY)).append("\t"); sb.append(CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.CHINA)).append("\t"); sb.append("\n"); assertEquals(EXPECTED_IS_DATE_DEFAULT[i], CustomDateTimePatternManager.isDate(dates[i], pattern)); assertEquals(EXPECTED_IS_DATE_US[i], CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.US)); assertEquals(EXPECTED_IS_DATE_FR[i], CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.FRANCE)); assertEquals(EXPECTED_IS_DATE_DE[i], CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.GERMANY)); assertEquals(EXPECTED_IS_DATE_CN[i], CustomDateTimePatternManager.isDate(dates[i], pattern, Locale.CHINA)); } LOGGER.info(sb.toString()); }
From source file:ca.psiphon.PsiphonTunnel.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private boolean startVpn() throws Exception { mVpnMode.set(true);/*from w w w.j a va 2 s. co m*/ mPrivateAddress = selectPrivateAddress(); Locale previousLocale = Locale.getDefault(); final String errorMessage = "startVpn failed"; try { // Workaround for https://code.google.com/p/android/issues/detail?id=61096 Locale.setDefault(new Locale("en")); ParcelFileDescriptor tunFd = ((VpnService.Builder) mHostService.newVpnServiceBuilder()) .setSession(mHostService.getAppName()).setMtu(VPN_INTERFACE_MTU) .addAddress(mPrivateAddress.mIpAddress, mPrivateAddress.mPrefixLength).addRoute("0.0.0.0", 0) .addRoute(mPrivateAddress.mSubnet, mPrivateAddress.mPrefixLength) .addDnsServer(mPrivateAddress.mRouter).establish(); if (tunFd == null) { // As per http://developer.android.com/reference/android/net/VpnService.Builder.html#establish%28%29, // this application is no longer prepared or was revoked. return false; } mTunFd.set(tunFd); mRoutingThroughTunnel.set(false); mHostService.onDiagnosticMessage("VPN established"); } catch (IllegalArgumentException e) { throw new Exception(errorMessage, e); } catch (IllegalStateException e) { throw new Exception(errorMessage, e); } catch (SecurityException e) { throw new Exception(errorMessage, e); } finally { // Restore the original locale. Locale.setDefault(previousLocale); } return true; }
From source file:org.jfree.data.time.DayTest.java
/** * Some checks for the getLastMillisecond() method. *///from w ww .j a v a 2 s . co m @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Day d = new Day(1, 1, 1970); assertEquals(82799999L, d.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.jfree.data.time.junit.HourTest.java
/** * Some checks for the getLastMillisecond() method. */// www .ja va 2s . co m public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(1, 1, 1, 1970); assertEquals(3599999L, h.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.apache.jsp.happyaxis_jsp.java
/** * Get a ResourceBundle object.// w w w . java 2s . c o m * @return a ResourceBundle object */ ResourceBundle getRB() { String strLocale = getRequest().getParameter("locale"); ResourceBundle objRb = null; Locale objLcl = null; if (strLocale != null) { objLcl = new Locale(strLocale, ""); } else { objLcl = getRequest().getLocale(); } Locale.setDefault(objLcl); objRb = ResourceBundle.getBundle(getResouceBase(), objLcl); return objRb; }
From source file:org.jfree.data.time.WeekTest.java
/** * A test case for bug 1498805./*from www. jav a 2 s. co m*/ */ @Test public void testBug1498805() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); try { TimeZone zone = TimeZone.getTimeZone("GMT"); GregorianCalendar gc = new GregorianCalendar(zone); gc.set(2005, Calendar.JANUARY, 1, 12, 0, 0); Week w = new Week(gc.getTime(), zone); assertEquals(53, w.getWeek()); assertEquals(new Year(2004), w.getYear()); } finally { Locale.setDefault(saved); } }
From source file:org.jfree.data.time.MinuteTest.java
/** * Some checks for the getStart() method. *///from ww w . j a v a2 s . c o m @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0); cal.set(Calendar.MILLISECOND, 0); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.jfree.data.time.QuarterTest.java
/** * Some checks for the getLastMillisecond() method. *///from w w w.ja va2 s . c o m @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(23583599999L, q.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); }
From source file:org.jfree.data.time.SecondTest.java
/** * Some checks for the getStart() method. *///from w ww . ja v a 2 s . co m @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 0); Second s = new Second(55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), s.getStart()); Locale.setDefault(saved); }