Java Code Examples for java.util.Locale#setDefault()

The following examples show how to use java.util.Locale#setDefault() . 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: NumberRegressionTests.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * DecimalFormat.format() incorrectly formats negative doubles.
 */
@Test
public void Test4106658()
{
    Locale savedLocale = Locale.getDefault();
    Locale.setDefault(Locale.US);
    DecimalFormat df = new DecimalFormat(); // Corrected; see 4147706
    double d1 = -0.0;
    double d2 = -0.0001;
    StringBuffer buffer = new StringBuffer();
    logln("pattern: \"" + df.toPattern() + "\"");
    df.format(d1, buffer, new FieldPosition(0));
    if (!buffer.toString().equals("-0")) { // Corrected; see 4147706
        errln(d1 + "      is formatted as " + buffer);
    }
    buffer.setLength(0);
    df.format(d2, buffer, new FieldPosition(0));
    if (!buffer.toString().equals("-0")) { // Corrected; see 4147706
        errln(d2 + "      is formatted as " + buffer);
    }
    Locale.setDefault(savedLocale);
}
 
Example 2
Source File: LocaleContextWrapper.java    From px-android with MIT License 6 votes vote down vote up
@SuppressWarnings("PMD.AvoidReassigningParameters")
@NonNull
private static Context applyNewLocaleConfig(@NonNull Context context, @NonNull final Locale newLocale) {
    final Configuration newLocaleConfig = context.getResources().getConfiguration();
    final Resources res = context.getResources();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        final LocaleList localeList = new LocaleList(newLocale);
        newLocaleConfig.setLocales(localeList);
        newLocaleConfig.setLocale(newLocale);
        context = context.createConfigurationContext(newLocaleConfig);
    } else {
        newLocaleConfig.locale = newLocale;
    }

    Locale.setDefault(newLocale);
    res.updateConfiguration(newLocaleConfig, res.getDisplayMetrics());
    return context;
}
 
Example 3
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDefaultFormatVector3D() {
    Locale defaultLocal = Locale.getDefault();
    Locale.setDefault(getLocale());

    Vector3D c = new Vector3D(232.22222222222, -342.3333333333, 432.44444444444);
    String expected =
        "{232"    + getDecimalCharacter() +
        "2222222222; -342" + getDecimalCharacter() +
        "3333333333; 432" + getDecimalCharacter() +
        "4444444444}";
    String actual = (new Vector3DFormat()).format(c);
    Assert.assertEquals(expected, actual);

    Locale.setDefault(defaultLocal);
}
 
Example 4
Source File: CalendarTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void Test4374886() {
    Locale savedLocale = Locale.getDefault();
    TimeZone savedTimeZone = TimeZone.getDefault();

    try {
        Locale.setDefault(Locale.US);
        TimeZone.setDefault(TimeZone.getTimeZone("PST"));

        Calendar cal = Calendar.getInstance();
        cal.set(YEAR, 2001);
        cal.set(MONTH, OCTOBER);
        cal.set(WEEK_OF_YEAR, 4);
        cal.set(DAY_OF_WEEK, 2);

        if (cal.get(YEAR) != 2001
                || cal.get(MONTH) != JANUARY
                || cal.get(DATE) != 22
                || cal.get(DAY_OF_WEEK) != MONDAY) {
            errln("Failed : got " + cal.getTime() + ", expected Mon Jan 22, 2001");
        }
    } finally {
        Locale.setDefault(savedLocale);
        TimeZone.setDefault(savedTimeZone);
    }
}
 
Example 5
Source File: Test4314141.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies the example from the getBundle specification.
 */
static void testExample() {
    Locale.setDefault(new Locale("en", "UK"));
    doTestExample("fr", "CH", new String[] {"_fr_CH.class", "_fr.properties", ".class"});
    doTestExample("fr", "FR", new String[] {"_fr.properties", ".class"});
    doTestExample("de", "DE", new String[] {"_en.properties", ".class"});
    doTestExample("en", "US", new String[] {"_en.properties", ".class"});
    doTestExample("es", "ES", new String[] {"_es_ES.class", ".class"});
}
 
Example 6
Source File: RealVectorFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testStaticFormatRealVectorImpl() {
    Locale defaultLocal = Locale.getDefault();
    Locale.setDefault(getLocale());

    ArrayRealVector c = new ArrayRealVector(new double[] {232.222, -342.33, 432.444});
    String expected =
        "{232"    + getDecimalCharacter() +
        "22; -342" + getDecimalCharacter() +
        "33; 432" + getDecimalCharacter() +
        "44}";
    String actual = RealVectorFormat.formatRealVector(c);
    assertEquals(expected, actual);

    Locale.setDefault(defaultLocal);
}
 
Example 7
Source File: SimpleTimestampFormatTest.java    From hop with Apache License 2.0 5 votes vote down vote up
@Test
public void testToPattern() throws Exception {
  for ( Locale locale : locales ) {
    Locale.setDefault( Locale.Category.FORMAT, locale );
    tdb = ResourceBundle.getBundle( "org/apache/hop/core/row/value/timestamp/messages/testdates", locale );
    String patternExample = tdb.getString( "PATTERN.HOP" );
    SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() );
    assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.DATE" ), stf.toPattern() );
    stf = new SimpleTimestampFormat( patternExample, Locale.GERMANY );
    assertEquals( locale.toLanguageTag(), patternExample, stf.toPattern() );
    stf = new SimpleTimestampFormat( patternExample, Locale.US );
    assertEquals( locale.toLanguageTag(), patternExample, stf.toPattern() );
  }
}
 
Example 8
Source File: LevelTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test that dotted lower I + "nfo" is recognized as INFO
 * even in Turkish locale.
 */
@Test
public void testDottedLowerI() {
    final Locale defaultLocale = Locale.getDefault();
    final Locale turkey = new Locale("tr", "TR");
    Locale.setDefault(turkey);
    final Level level = Level.toLevel("info");
    Locale.setDefault(defaultLocale);
    assertEquals("INFO", level.toString());
}
 
Example 9
Source File: TestInstant_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(zone);
    java.util.TimeZone.setDefault(zone.toTimeZone());
    Locale.setDefault(locale);
    zone = null;
}
 
Example 10
Source File: Test4314141.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Locale reservedLocale = Locale.getDefault();
    try {
        testCandidateOmission();
        testExample();
    } finally {
        // restore the reserved locale
        Locale.setDefault(reservedLocale);
    }
}
 
Example 11
Source File: TestAllPackages.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    // setup a time zone other than one tester is in
    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
    
    // setup a locale other than one the tester is in
    Locale.setDefault(new Locale("th", "TH"));
    
    // run tests
    String[] testCaseName = {
        TestAllPackages.class.getName()
    };
    junit.textui.TestRunner.main(testCaseName);
}
 
Example 12
Source File: Test6341798.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Locale reservedLocale = Locale.getDefault();
    try {
        test(ENGLISH, DATA.getBytes());
        test(TURKISH, DATA.getBytes());
    } finally {
        // restore the reserved locale
        Locale.setDefault(reservedLocale);
    }
}
 
Example 13
Source File: MillisecondTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getEnd() method.
 */
@Test
public void testGetEnd() {
    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, 555);
    Millisecond m = new Millisecond(555, 55, 47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), m.getEnd());
    Locale.setDefault(saved);
}
 
Example 14
Source File: Test4314141.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that candidate bundle names where the final component is an empty string are omitted.
 * Previous versions of ResourceBundle might attempt to load bundles with a trailing
 * underscore (e.g., "Test4314141_") resulting from concatenation with an empty string.
 * This is no longer permitted.
 */
static void testCandidateOmission() {
    Locale.setDefault(Locale.US);
    doTestCandidateOmission("de", "DE", "EURO", new String[] {"_de", ""});
    doTestCandidateOmission("de", "DE", "", new String[] {"_de", ""});
    doTestCandidateOmission("de", "", "EURO", new String[] {"_de", ""});
    doTestCandidateOmission("de", "", "", new String[] {"_de", ""});
    doTestCandidateOmission("", "DE", "EURO", new String[] {"__DE", ""});
    doTestCandidateOmission("", "DE", "", new String[] {"__DE", ""});
    doTestCandidateOmission("", "", "EURO", new String[] {"___EURO", ""});
    doTestCandidateOmission("", "", "", new String[] {""});
}
 
Example 15
Source File: TestNullConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
protected void tearDown() throws Exception {
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(originalDateTimeZone);
    TimeZone.setDefault(originalTimeZone);
    Locale.setDefault(originalLocale);
    originalDateTimeZone = null;
    originalTimeZone = null;
    originalLocale = null;
}
 
Example 16
Source File: AbstractTemplateEngineRenderingTest.java    From jbake with MIT License 4 votes vote down vote up
@After
public void cleanup() {
    DocumentTypes.resetDocumentTypes();
    ModelExtractors.getInstance().reset();
    Locale.setDefault(currentLocale);
}
 
Example 17
Source File: My5250.java    From tn5250j with GNU General Public License v2.0 4 votes vote down vote up
static public void main(String[] args) {

		if (!isSpecified("-nc",args)) {

			if (!checkBootStrapper(args)) {

				// if we did not find a running instance and the -d options is
				//    specified start up the bootstrap daemon to allow checking
				//    for running instances
				if (isSpecified("-d",args)) {
					strapper = new BootStrapper();

					strapper.start();
				}
			}
			else {

				System.exit(0);
			}
		}

		My5250 m = new My5250();

		if (strapper != null)
			strapper.addBootListener(m);

		if (args.length > 0) {

			if (isSpecified("-width",args) ||
					isSpecified("-height",args)) {
				int width = m.frame1.getWidth();
				int height = m.frame1.getHeight();

				if (isSpecified("-width",args)) {
					width = Integer.parseInt(My5250.getParm("-width",args));
				}
				if (isSpecified("-height",args)) {
					height = Integer.parseInt(My5250.getParm("-height",args));
				}

				m.frame1.setSize(width,height);
				m.frame1.centerFrame();


			}

			/**
			 * @todo this crap needs to be rewritten it is a mess
			 */
			if (args[0].startsWith("-")) {

				// check if a session parameter is specified on the command line
				if (isSpecified("-s",args)) {

					String sd = getParm("-s",args);
					if (sessions.containsKey(sd)) {
						sessions.setProperty("emul.default",sd);
					}
					else {
						args = null;
					}

				}

				// check if a locale parameter is specified on the command line
				if (isSpecified("-L",args)) {
					Locale.setDefault(parseLocal(getParm("-L",args)));
				}
				LangTool.init();
			}
			else {
				LangTool.init();
			}
		}
		else {
			LangTool.init();
		}

		List<String> lastViewNames = new ArrayList<String>();
		lastViewNames.addAll(loadLastSessionViewNames());
		lastViewNames.addAll(loadLastSessionViewNamesFrom(args));
		lastViewNames = filterExistingViewNames(lastViewNames);

		if (lastViewNames.size() > 0) {
			insertDefaultSessionIfConfigured(lastViewNames);
			startSessionsFromList(m, lastViewNames);
			if (sessions.containsKey("emul.showConnectDialog")) {
				m.openConnectSessionDialogAndStartSelectedSession();
			}
		}
		else {
			m.startNewSession();
		}

	}
 
Example 18
Source File: Application.java    From fluent-validator with Apache License 2.0 4 votes vote down vote up
@Bean
public Validator hibernateValidator() {
    Locale.setDefault(Locale.US);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    return factory.getValidator();
}
 
Example 19
Source File: OSMApiTest.java    From open with GNU General Public License v3.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
    Locale.setDefault(Locale.US);
}
 
Example 20
Source File: ConfigurationModuleDefaultLanguage.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public void unload() throws TechnicalConnectorException {
   LOG.debug("Unloading ConfigurationModule " + this.getClass().getName());
   Locale.setDefault(this.oldLocale);
}