Example usage for java.util Locale setDefault

List of usage examples for java.util Locale setDefault

Introduction

In this page you can find the example usage for java.util Locale setDefault.

Prototype

public static synchronized void setDefault(Locale newLocale) 

Source Link

Document

Sets the default locale for this instance of the Java Virtual Machine.

Usage

From source file:org.jfree.data.time.junit.SecondTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*w  ww .  ja  va 2 s. c o m*/
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Second s = new Second(15, 43, 15, 1, 4, 2006);
    assertEquals(1143902595000L, s.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:com.espertech.esper.regression.resultset.TestOrderBySimple.java

public void testCollatorSortLocale() {
    String frenchForSin = "p\u00E9ch\u00E9";
    String frenchForFruit = "p\u00EAche";

    String[] sortedFrench = (frenchForFruit + "," + frenchForSin).split(",");

    assertEquals(1, frenchForFruit.compareTo(frenchForSin));
    assertEquals(-1, frenchForSin.compareTo(frenchForFruit));
    Locale.setDefault(Locale.FRENCH);
    assertEquals(1, frenchForFruit.compareTo(frenchForSin));
    assertEquals(-1, Collator.getInstance().compare(frenchForFruit, frenchForSin));
    assertEquals(-1, frenchForSin.compareTo(frenchForFruit));
    assertEquals(1, Collator.getInstance().compare(frenchForSin, frenchForFruit));
    assertFalse(frenchForSin.equals(frenchForFruit));

    /*//from www  .  j  av a 2  s .c o m
    Collections.sort(items);
    System.out.println("Sorted default" + items);
            
    Collections.sort(items, new Comparator<String>() {
    Collator collator = Collator.getInstance(Locale.FRANCE);
    public int compare(String o1, String o2)
    {
        return collator.compare(o1, o2);
    }
    });
    System.out.println("Sorted FR" + items);
    */

    Configuration config = SupportConfigFactory.getConfiguration();
    config.getEngineDefaults().getLanguage().setSortUsingCollator(true);
    epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();
    epService.getEPAdministrator().getConfiguration().addEventType("SupportBean", SupportBean.class.getName());

    // test order by
    String stmtText = "select theString from SupportBean.win:keepall() order by theString asc";
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtText);
    epService.getEPRuntime().sendEvent(new SupportBean(frenchForSin, 1));
    epService.getEPRuntime().sendEvent(new SupportBean(frenchForFruit, 1));
    EPAssertionUtil.assertPropsPerRow(stmtOne.iterator(), "theString".split(","),
            new Object[][] { { sortedFrench[0] }, { sortedFrench[1] } });

    // test sort view
    SupportUpdateListener listener = new SupportUpdateListener();
    stmtText = "select irstream theString from SupportBean.ext:sort(2, theString asc)";
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtText);
    stmtTwo.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean(frenchForSin, 1));
    epService.getEPRuntime().sendEvent(new SupportBean(frenchForFruit, 1));
    epService.getEPRuntime().sendEvent(new SupportBean("abc", 1));

    assertEquals(frenchForSin, listener.getLastOldData()[0].get("theString"));
    Locale.setDefault(Locale.US);
}

From source file:org.jfree.data.time.HourTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *///from  w  ww .  ja  v a  2 s  . c o m
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Hour h = new Hour(15, 1, 4, 2006);
    assertEquals(1143900000000L, h.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.squale.squalix.tools.ruleschecking.RulesCheckingTask.java

/**
 * Recupre les paramtres checkstyle du projet; Fait appel au connecteur et recupre l'ensemble des violations
 * gnres par le connector checkstyle.//from w w w. j  a v  a  2s.c  om
 * 
 * @param pVersion La version du fichier de configuration
 * @param pJavaVersion la version de java
 * @return la liste des transgressions
 * @throws IOException si l'analyse ne s'est pas droule correctement
 * @throws RulesCheckingConnectorException si l'analyse ne s'est pas droule correctement
 * @throws ConfigurationException si erreur
 * @throws FileNotFoundException si erreur
 */
public CheckstyleTransgressionBO ckeck(CheckstyleRuleSetBO pVersion, String pJavaVersion)
        throws IOException, RulesCheckingConnectorException, FileNotFoundException, ConfigurationException {
    /*
     * Permet de prciser le pays et le language de l'ordi ... cela permet de contourner un problme de messages
     * avec Checkstyle 3.5
     */
    Locale bufferLocal = Locale.getDefault(); // memoriser la valeur courante
    try {
        Locale.setDefault(Locale.US); // changer cette valeur avec celle des USA

        File file = FileUtility.byteToFile(pVersion.getValue());
        // Configuration Checkstyle
        CheckstyleConfiguration config = new CheckstyleConfiguration();
        config.parse(new FileInputStream("config/checkstyle-config.xml"));
        // rcupration des sources du project
        List srcs = ((ListParameterBO) mProject.getParameters().getParameters()
                .get(ParametersConstants.SOURCES)).getParameters();
        List paths = BuildProjectPath.buildProjectPath((String) mData.getData(TaskData.VIEW_PATH), srcs);
        // On rcupre les sources qui peuvent tre analyses
        List includedFileNames = org.squale.squalix.util.file.FileUtility.getIncludedFiles(
                (String) mData.getData(TaskData.VIEW_PATH), paths,
                (ListParameterBO) mProject.getParameter(ParametersConstants.INCLUDED_PATTERNS),
                (ListParameterBO) mProject.getParameter(ParametersConstants.EXCLUDED_PATTERNS), null,
                new String[] { ".java" });

        File tempDir = new File(config.getTempSourceDir());
        tempDir.mkdir();

        for (Object fl : includedFileNames) {
            File fileToCopy = new File(fl.toString());
            File vPath = new File((String) mData.getData(TaskData.VIEW_PATH));
            String path = fileToCopy.getCanonicalPath().replace(vPath.getCanonicalPath(),
                    tempDir.getCanonicalPath());
            File destFile = new File(path);
            FileUtils.copyFile(fileToCopy, destFile);
        }

        CheckStyleProcess process = new CheckStyleProcess(new File(config.getJarDirectory()),
                new File(config.getReportDirectory()), pJavaVersion);
        File report = process.analyseSources(file, tempDir, "checkstyle-report" + getProject().getId());
        CheckstyleReportParser parser = new CheckstyleReportParser(tempDir.getAbsolutePath());
        CheckStylePersistor persistor = new CheckStylePersistor(pVersion);
        parser.parse(new FileInputStream(report), persistor);
        // On rcupre le transgression
        CheckstyleTransgressionBO transgression = persistor.computeTransgression();

        // positionne les donnes sur la taille du file System
        ArrayList<Object[]> listDirectory = new ArrayList<Object[]>();
        Object[] obj1 = { config.getReportDirectory(), Boolean.FALSE };
        Object[] obj2 = { tempDir, Boolean.FALSE };
        listDirectory.add(obj1);
        listDirectory.add(obj2);
        affectFileSystemSize(listDirectory);

        // Destruction du rapport
        report.delete();
        FileUtils.deleteDirectory(tempDir);
        return transgression;
    } finally {
        Locale.setDefault(bufferLocal); // remettre  la valeur initiale
    }
}

From source file:es.uvigo.ei.sing.laimages.core.entities.datasets.VerticalElementDataTest.java

@Test
public void testVerticalElementDataToCSVVWithLibreOfficeFormatUS() throws IOException {
    Locale.setDefault(new Locale("en", "US"));

    File exportFile = exportElementToTmpCSVFile(TEST_ELEMENT_DATA_VERTICAL, FileFormat.LIBRE_OFFICE);

    assertTrue(FileUtils.contentEquals(TEST_ELEMENT_DATA_VERTICAL_LIBRE_OFFICE_US, exportFile));
}

From source file:org.talend.dataquality.statistics.datetime.CustomDateTimePatternManagerTest.java

@Test
public void testDateWithLocaleFR() {
    // simulate a JVM
    Locale.setDefault(Locale.FRANCE);

    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   ww w  .j  av 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:org.jfree.data.time.YearTest.java

/**
 * Some checks for the getFirstMillisecond() method.
 *//*from  ww  w.ja  v a  2 s  .co  m*/
@Test
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Year y = new Year(1970);
    // TODO: Check this result...
    assertEquals(-3600000L, y.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:org.jfree.data.time.MinuteTest.java

/**
 * Some checks for the getLastMillisecond() method.
 *///from ww w.  ja va  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"));
    Minute m = new Minute(1, 1, 1, 1, 1970);
    assertEquals(119999L, m.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}

From source file:mp.paschalis.App.java

public static void updateLanguage(Context ctx) {

    // Change locale
    Locale locale = new Locale(App.lang);
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;//from ww w  .ja  va 2  s.  c  o  m
    ctx.getResources().updateConfiguration(config, ctx.getResources().getDisplayMetrics());

}

From source file:org.jfree.data.time.SecondTest.java

/**
 * Some checks for the getLastMillisecond() method.
 *///from  ww w .j a v a 2  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"));
    Second s = new Second(1, 1, 1, 1, 1, 1970);
    assertEquals(61999L, s.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}