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:Main.java

public static void main(String[] argv) throws Exception {

    Locale.setDefault(Locale.FRENCH);

}

From source file:Main.java

public static void main(String[] args) {
    Locale locale1 = new Locale("en", "US", "WIN");

    System.out.println("Locale:" + locale1);

    // set another default locale
    Locale.setDefault(new Locale("fr", "FRANCE", "MAC"));

    Locale locale2 = Locale.getDefault();

    // print the new locale
    System.out.println("Locale::" + locale2);
}

From source file:Test.java

public static void main(String[] args) {
    BigDecimal value = new BigDecimal(12345);
    Locale.setDefault(Locale.JAPAN);
    System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName());
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    String formattedCurrency = nf.format(value);
    System.out.printf("%s\n", formattedCurrency);
    nf.setCurrency(Currency.getInstance(Locale.US));
    formattedCurrency = nf.format(value);
    System.out.printf("%s\n\n", formattedCurrency);

    Locale.setDefault(Locale.US);
    System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName());
    nf = NumberFormat.getCurrencyInstance();
    formattedCurrency = nf.format(value);
    System.out.printf("%s\n", formattedCurrency);
    nf.setCurrency(Currency.getInstance("JPY"));
    formattedCurrency = nf.format(value);
    System.out.printf("%s\n\n", formattedCurrency);

    Locale.setDefault(Locale.FRANCE);
    System.out.printf("Default locale: %s\n", Locale.getDefault().getDisplayName());
    nf = NumberFormat.getCurrencyInstance();
    formattedCurrency = nf.format(value);
    System.out.printf("%s\n", formattedCurrency);
    nf.setCurrency(Currency.getInstance("USD"));
    formattedCurrency = nf.format(value);
    System.out.printf("%s\n\n", formattedCurrency);
}

From source file:Main.java

public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("MessagesBundle", Locale.UK);
        System.out.println("Message in " + Locale.UK + ": " + bundle.getString("greeting"));

        Locale.setDefault(new Locale("in", "ID"));
        bundle = ResourceBundle.getBundle("MessagesBundle");
        System.out.println("Message in " + Locale.getDefault() + ": " + bundle.getString("greeting"));
    }//from   w  w  w .j  ava  2s .c  o  m

From source file:Main.java

public static void main(String[] args) {
    NumberFormat formatter = new DecimalFormat();
    Locale locale = Locale.getDefault();
    System.out.println("Locale = " + locale);
    System.out.println(formatter.format(123.123));

    locale = Locale.ITALY;/*w w  w. j  a  v  a 2s  .  c  o  m*/
    Locale.setDefault(locale);
    formatter = new DecimalFormat();
    System.out.println("Locale = " + locale);
    System.out.println(formatter.format(123.123));
}

From source file:Test.java

public static void main(String[] args) {
    Calendar calendar = Calendar.getInstance();
    calendar.setWeekDate(2012, 16, 3);//w ww.j  a v a  2s.c  om

    Builder builder = new Builder();
    builder.setLanguage("hy");
    builder.setScript("Latn");
    builder.setRegion("IT");
    builder.setVariant("arevela");

    Locale locale = builder.build();
    Locale.setDefault(locale);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

    builder.setLanguage("zh");
    builder.setScript("Hans");
    builder.setRegion("CN");

    locale = builder.build();
    Locale.setDefault(locale);

    System.out.println(
            DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(calendar.getTime()));
    System.out.println("" + locale.getDisplayLanguage());

}

From source file:org.eclipse.winery.librarytests.DateTest.java

public static void main(String[] args) throws ParseException {
    // In case the following line is commented, this method throws a ParseException
    Locale.setDefault(Locale.ENGLISH);
    String modified = "Fri, 23 Mar 2012 11:04:56 GMT";
    Date modifiedDate = DateUtils.parseDate(modified, org.apache.http.impl.cookie.DateUtils.DEFAULT_PATTERNS);
    System.out.println(modifiedDate);
}

From source file:br.com.etec.Main.java

@SuppressWarnings("ALL")
public static void main(String args[]) {
    Locale.setDefault(new Locale("pt", "BR"));

    SwingUtilities.invokeLater(new Runnable() {
        @Override// w w w.j a  va  2  s.  c  o m
        public void run() {
            try {
                // Define o look and feel.
                initLookAndFeel();
                installSmartLookAndFeel();
            } catch (Exception ex) {
                LOGGER.log(Level.WARN, null, ex);
            } finally {
                new ClassPathXmlApplicationContext("META-INF/spring-config.xml");
            }

        }
    });

}

From source file:it.acubelab.smaph.learn.GenerateModel.java

public static void main(String[] args) throws Exception {
    Locale.setDefault(Locale.US);
    String freebKey = "";

    SmaphConfig.setConfigFile("smaph-config.xml");
    String bingKey = SmaphConfig.getDefaultBingKey();

    WikipediaApiInterface wikiApi = new WikipediaApiInterface("wid.cache", "redirect.cache");
    FreebaseApi freebApi = new FreebaseApi(freebKey, "freeb.cache");
    double[][] paramsToTest = new double[][] {
            /*//from   w ww . ja  v a 2s.  c  o m
             * {0.035, 0.5 }, {0.035, 1 }, {0.035, 4 }, {0.035, 8 }, {0.035, 10 },
             * {0.035, 16 }, {0.714, .5 }, {0.714, 1 }, {0.714, 4 }, {0.714, 8 },
             * {0.714, 10 }, {0.714, 16 }, {0.9, .5 }, {0.9, 1 }, {0.9, 4 }, {0.9, 8
             * }, {0.9, 10 }, {0.9, 16 },
             * 
             * { 1.0/15.0, 1 }, { 1.0/27.0, 1 },
             */

            /*
             * {0.01, 1}, {0.01, 5}, {0.01, 10}, {0.03, 1}, {0.03, 5}, {0.03, 10},
             * {0.044, 1}, {0.044, 5}, {0.044, 10}, {0.06, 1}, {0.06, 5}, {0.06,
             * 10},
             */
            { 0.03, 5 }, };
    double[][] weightsToTest = new double[][] {

            /*
             * { 3, 4 }
             */
            { 3.8, 3 }, { 3.8, 4 }, { 3.8, 5 }, { 3.8, 6 }, { 3.8, 7 }, { 3.8, 8 }, { 3.8, 9 }, { 3.8, 10 },

    };
    Integer[][] featuresSetsToTest = new Integer[][] {
            //{ 1, 2, 3, 6, 7, 8,   9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 },
            { 1, 2, 3, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 },
            /*
             * { 1, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18},
             */

    }; // < -------------------------------------- MIND THIS
    int wikiSearckTopK = 10; // <---------------------------
    String filePrefix = "_ANW";// <---------------------------

    WikipediaToFreebase wikiToFreebase = new WikipediaToFreebase("mapdb");
    List<ModelConfigurationResult> mcrs = new Vector<>();
    for (double editDistanceThr = 0.7; editDistanceThr <= 0.7; editDistanceThr += 0.7) {
        SmaphAnnotator bingAnnotator = GenerateTrainingAndTest.getDefaultBingAnnotator(wikiApi, wikiToFreebase,
                editDistanceThr, wikiSearckTopK, bingKey);
        WATAnnotator.setCache("wikisense.cache");
        SmaphAnnotator.setCache(SmaphConfig.getDefaultBingCache());

        BinaryExampleGatherer trainEntityFilterGatherer = new BinaryExampleGatherer();
        BinaryExampleGatherer testEntityFilterGatherer = new BinaryExampleGatherer();
        GenerateTrainingAndTest.gatherExamplesTrainingAndDevel(bingAnnotator, trainEntityFilterGatherer,
                testEntityFilterGatherer, wikiApi, wikiToFreebase, freebApi);

        SmaphAnnotator.unSetCache();
        BinaryExampleGatherer trainGatherer = trainEntityFilterGatherer; // //////////////
        // <----------------------
        BinaryExampleGatherer testGatherer = testEntityFilterGatherer; // //////////////
        // <----------------------

        int count = 0;
        for (Integer[] ftrToTestArray : featuresSetsToTest) {
            // double gamma = 1.0 / ftrToTestArray.length; //
            // <--------------------- MIND THIS
            // double C = 1;// < -------------------------------------- MIND
            // THIS
            for (double[] paramsToTestArray : paramsToTest) {
                double gamma = paramsToTestArray[0];
                double C = paramsToTestArray[1];
                for (double[] weightsPosNeg : weightsToTest) {
                    double wPos = weightsPosNeg[0], wNeg = weightsPosNeg[1];
                    Vector<Integer> features = new Vector<>(Arrays.asList(ftrToTestArray));
                    Triple<svm_problem, double[], double[]> ftrsMinsMaxs = TuneModel
                            .getScaledTrainProblem(features, trainGatherer);
                    svm_problem trainProblem = ftrsMinsMaxs.getLeft();

                    String fileBase = getModelFileNameBaseEF(features.toArray(new Integer[0]), wPos, wNeg,
                            editDistanceThr, gamma, C) + filePrefix;
                    /*
                     * String fileBase = getModelFileNameBaseEQF(
                     * features.toArray(new Integer[0]), wPos, wNeg);
                     */// < -------------------------
                    LibSvmUtils.dumpRanges(ftrsMinsMaxs.getMiddle(), ftrsMinsMaxs.getRight(),
                            fileBase + ".range");
                    svm_model model = TuneModel.trainModel(wPos, wNeg, features, trainProblem, gamma, C);
                    svm.svm_save_model(fileBase + ".model", model);

                    MetricsResultSet metrics = TuneModel.ParameterTester.computeMetrics(model,
                            TuneModel.getScaledTestProblems(features, testGatherer, ftrsMinsMaxs.getMiddle(),
                                    ftrsMinsMaxs.getRight()));

                    int tp = metrics.getGlobalTp();
                    int fp = metrics.getGlobalFp();
                    int fn = metrics.getGlobalFn();
                    float microF1 = metrics.getMicroF1();
                    float macroF1 = metrics.getMacroF1();
                    float macroRec = metrics.getMacroRecall();
                    float macroPrec = metrics.getMacroPrecision();
                    int totVects = testGatherer.getExamplesCount();
                    mcrs.add(new ModelConfigurationResult(features, wPos, wNeg, editDistanceThr, tp, fp, fn,
                            totVects - tp - fp - fn, microF1, macroF1, macroRec, macroPrec));

                    System.err.printf("Trained %d/%d models.%n", ++count,
                            weightsToTest.length * featuresSetsToTest.length * paramsToTest.length);
                }
            }
        }
    }
    for (ModelConfigurationResult mcr : mcrs)
        System.out.printf("%.5f%%\t%.5f%%\t%.5f%%%n", mcr.getMacroPrecision() * 100, mcr.getMacroRecall() * 100,
                mcr.getMacroF1() * 100);
    for (double[] weightPosNeg : weightsToTest)
        System.out.printf("%.5f\t%.5f%n", weightPosNeg[0], weightPosNeg[1]);
    for (ModelConfigurationResult mcr : mcrs)
        System.out.println(mcr.getReadable());
    for (double[] paramGammaC : paramsToTest)
        System.out.printf("%.5f\t%.5f%n", paramGammaC[0], paramGammaC[1]);
    WATAnnotator.flush();
}

From source file:fr.ericlab.mabed.app.Main.java

public static void main(String[] args) throws IOException {
    Locale.setDefault(Locale.US);
    Configuration configuration = new Configuration();
    Corpus corpus = new Corpus(configuration);
    System.out.println("MABED: Mention-Anomaly-Based Event Detection");
    if (args.length == 0 || args[0].equals("-help")) {
        System.out.println("For more information on how to run MABED, see the README.txt file");
    } else {//from w ww  . jav a2  s  . c  om
        if (args[0].equals("-run")) {
            try {
                if (configuration.numberOfThreads > 1) {
                    System.out.println("Running the parallelized implementation with "
                            + configuration.numberOfThreads + " threads (this computer has "
                            + Runtime.getRuntime().availableProcessors() + " available threads)");
                } else {
                    System.out.println("Running the centralized implementation");
                }
                corpus.loadCorpus(configuration.numberOfThreads > 1);
                String output = "MABED: Mention-Anomaly-Based Event Detection\n" + corpus.output + "\n";
                System.out.println("-------------------------\n" + Util.getDate()
                        + " MABED is running\n-------------------------");
                output += "-------------------------\n" + Util.getDate()
                        + " MABED is running\n-------------------------\n";
                System.out.println(Util.getDate() + " Reading parameters:\n   - k = " + configuration.k
                        + ", p = " + configuration.p + ", theta = " + configuration.theta + ", sigma = "
                        + configuration.sigma);
                MABED mabed = new MABED();
                if (configuration.numberOfThreads > 1) {
                    output += mabed.applyParallelized(corpus, configuration);
                } else {
                    output += mabed.applyCentralized(corpus, configuration);
                }
                System.out.println(
                        "--------------------\n" + Util.getDate() + " MABED ended\n--------------------");
                output += "--------------------\n" + Util.getDate() + " MABED ended\n--------------------\n";
                File outputDir = new File("output");
                if (!outputDir.isDirectory()) {
                    outputDir.mkdir();
                }
                File textFile = new File("output/MABED.tex");
                FileUtils.writeStringToFile(textFile, mabed.events.toLatex(corpus), false);
                textFile = new File("output/MABED.log");
                FileUtils.writeStringToFile(textFile, output, false);
                mabed.events.printLatex(corpus);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            System.out.println("Unknown option '" + args[0]
                    + "'\nType 'java -jar MABED.jar -help' for more information on how to run MABED");
        }
    }
}