List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:org.apache.mahout.classifier.RegressionResultAnalyzer.java
@Override public String toString() { double sumActual = 0.0; double sumActualSquared = 0.0; double sumResult = 0.0; double sumResultSquared = 0.0; double sumActualResult = 0.0; double sumAbsolute = 0.0; double sumAbsoluteSquared = 0.0; int predictable = 0; int unpredictable = 0; for (Result res : results) { double actual = res.getActual(); double result = res.getResult(); if (Double.isNaN(result)) { unpredictable++;/* w w w .j a va 2s . c o m*/ } else { sumActual += actual; sumActualSquared += actual * actual; sumResult += result; sumResultSquared += result * result; sumActualResult += actual * result; double absolute = Math.abs(actual - result); sumAbsolute += absolute; sumAbsoluteSquared += absolute * absolute; predictable++; } } StringBuilder returnString = new StringBuilder(); returnString.append("=======================================================\n"); returnString.append("Summary\n"); returnString.append("-------------------------------------------------------\n"); if (predictable > 0) { double varActual = sumActualSquared - sumActual * sumActual / predictable; double varResult = sumResultSquared - sumResult * sumResult / predictable; double varCo = sumActualResult - sumActual * sumResult / predictable; double correlation; if (varActual * varResult <= 0) { correlation = 0.0; } else { correlation = varCo / Math.sqrt(varActual * varResult); } Locale.setDefault(Locale.US); NumberFormat decimalFormatter = new DecimalFormat("0.####"); returnString.append(StringUtils.rightPad("Correlation coefficient", 40)).append(": ") .append(StringUtils.leftPad(decimalFormatter.format(correlation), 10)).append('\n'); returnString.append(StringUtils.rightPad("Mean absolute error", 40)).append(": ") .append(StringUtils.leftPad(decimalFormatter.format(sumAbsolute / predictable), 10)) .append('\n'); returnString.append(StringUtils.rightPad("Root mean squared error", 40)).append(": ") .append(StringUtils .leftPad(decimalFormatter.format(Math.sqrt(sumAbsoluteSquared / predictable)), 10)) .append('\n'); } returnString.append(StringUtils.rightPad("Predictable Instances", 40)).append(": ") .append(StringUtils.leftPad(Integer.toString(predictable), 10)).append('\n'); returnString.append(StringUtils.rightPad("Unpredictable Instances", 40)).append(": ") .append(StringUtils.leftPad(Integer.toString(unpredictable), 10)).append('\n'); returnString.append(StringUtils.rightPad("Total Regressed Instances", 40)).append(": ") .append(StringUtils.leftPad(Integer.toString(results.size()), 10)).append('\n'); returnString.append('\n'); return returnString.toString(); }
From source file:org.pdfsam.context.DefaultI18nContext.java
private DefaultI18nContext() { Locale locale = getBestLocale(); LOG.trace("Loading i18n bundle for {}", locale); Locale.setDefault(locale); this.i18n = I18nFactory.getI18n(DefaultI18nContext.class, locale); LOG.debug("Locale set to {}", locale.getDisplayLanguage()); }
From source file:org.pdfsam.i18n.DefaultI18nContext.java
DefaultI18nContext() { Locale.setDefault(getBestLocale()); refreshBundles(); eventStudio().addAnnotatedListeners(this); }
From source file:com.android.email.mail.store.imap.ImapStringTest.java
/** * Confirms that getDateOrNull() works fine regardless of the current locale. *///from w w w . ja v a 2 s . com public void testGetDateOrNullOnDifferentLocales() throws Exception { Locale savedLocale = Locale.getDefault(); try { Locale.setDefault(Locale.US); checkGetDateOrNullOnDifferentLocales(); Locale.setDefault(Locale.JAPAN); checkGetDateOrNullOnDifferentLocales(); } finally { Locale.setDefault(savedLocale); } }
From source file:com.iCo6.iConomy.java
public void onEnable() { final long startTime = System.nanoTime(); final long endTime; try {/*from w w w . j av a 2 s .c om*/ // Localize locale to prevent issues. Locale.setDefault(Locale.US); // Server & Terminal Support Server = getServer(); if (getServer().getServerName().equalsIgnoreCase("craftbukkit")) { TerminalSupport = ((CraftServer) getServer()).getReader().getTerminal().isAnsiSupported(); } // Get general plugin information info = getDescription(); // Plugin directory setup directory = getDataFolder(); if (!directory.exists()) directory.mkdir(); // Extract Files Common.extract("Config.yml", "Template.yml"); // Setup Configuration Constants.load(new File(directory, "Config.yml")); // Setup Template Template = new Template(directory.getPath(), "Template.yml"); // Upgrade Template to 6.0.9b LinkedHashMap<String, String> nodes = new LinkedHashMap<String, String>(); nodes.put("top.opening", "<green>-----[ <white>Wealthiest Accounts <green>]-----"); nodes.put("top.item", "<gray>+i. <green>+name <gray>- <white>+amount"); try { Template.update(nodes); } catch (IOException ex) { System.out.println(ex.getMessage()); } // Check Drivers if needed Type type = Database.getType(Constants.Nodes.DatabaseType.toString()); if (!(type.equals(Type.InventoryDB) || type.equals(Type.MiniDB))) { Drivers driver = null; switch (type) { case H2DB: driver = Constants.Drivers.H2; break; case MySQL: driver = Constants.Drivers.MySQL; break; case SQLite: driver = Constants.Drivers.SQLite; break; case Postgre: driver = Constants.Drivers.Postgre; break; } if (driver != null) if (!(new File("lib", driver.getFilename()).exists())) { System.out.println("[iConomy] Downloading " + driver.getFilename() + "..."); wget.fetch(driver.getUrl(), driver.getFilename()); System.out.println("[iConomy] Finished Downloading."); } } // Setup Commands Commands.add("/money +name", new Money(this)); Commands.setPermission("money", "iConomy.holdings"); Commands.setPermission("money+", "iConomy.holdings.others"); Commands.setHelp("money", new String[] { "", "Check your balance." }); Commands.setHelp("money+", new String[] { " [name]", "Check others balance." }); Commands.add("/money -h|?|help +command", new Help(this)); Commands.setPermission("help", "iConomy.help"); Commands.setHelp("help", new String[] { " (command)", "For Help & Information." }); Commands.add("/money -t|top", new Top(this)); Commands.setPermission("top", "iConomy.top"); Commands.setHelp("top", new String[] { "", "View top economical accounts." }); Commands.add("/money -p|pay +name +amount:empty", new Payment(this)); Commands.setPermission("pay", "iConomy.payment"); Commands.setHelp("pay", new String[] { " [name] [amount]", "Send money to others." }); Commands.add("/money -c|create +name", new Create(this)); Commands.setPermission("create", "iConomy.accounts.create"); Commands.setHelp("create", new String[] { " [name]", "Create an account." }); Commands.add("/money -r|remove +name", new Remove(this)); Commands.setPermission("remove", "iConomy.accounts.remove"); Commands.setHelp("remove", new String[] { " [name]", "Remove an account." }); Commands.add("/money -g|give +name +amount:empty", new Give(this)); Commands.setPermission("give", "iConomy.accounts.give"); Commands.setHelp("give", new String[] { " [name] [amount]", "Give money." }); Commands.add("/money -t|take +name +amount:empty", new Take(this)); Commands.setPermission("take", "iConomy.accounts.take"); Commands.setHelp("take", new String[] { " [name] [amount]", "Take money." }); Commands.add("/money -s|set +name +amount:empty", new Set(this)); Commands.setPermission("set", "iConomy.accounts.set"); Commands.setHelp("set", new String[] { " [name] [amount]", "Set account balance." }); Commands.add("/money -u|status +name +status:empty", new Status(this)); Commands.setPermission("status", "iConomy.accounts.status"); Commands.setPermission("status+", "iConomy.accounts.status.set"); Commands.setHelp("status", new String[] { " [name] (status)", "Check/Set account status." }); Commands.add("/money -x|purge", new Purge(this)); Commands.setPermission("purge", "iConomy.accounts.purge"); Commands.setHelp("purge", new String[] { "", "Purge all accounts with initial holdings." }); Commands.add("/money -e|empty", new Empty(this)); Commands.setPermission("empty", "iConomy.accounts.empty"); Commands.setHelp("empty", new String[] { "", "Empty database of accounts." }); // Setup Database. try { Database = new Database(Constants.Nodes.DatabaseType.toString(), Constants.Nodes.DatabaseUrl.toString(), Constants.Nodes.DatabaseUsername.toString(), Constants.Nodes.DatabasePassword.toString()); // Check to see if it's a binary database, if so, check the database existance // If it doesn't exist, Create one. if (Database.isSQL()) { if (!Database.tableExists(Constants.Nodes.DatabaseTable.toString())) { String SQL = Common.resourceToString( "SQL/Core/Create-Table-" + Database.getType().toString().toLowerCase() + ".sql"); SQL = String.format(SQL, Constants.Nodes.DatabaseTable.getValue()); try { QueryRunner run = new QueryRunner(); Connection c = iConomy.Database.getConnection(); try { run.update(c, SQL); } catch (SQLException ex) { System.out.println("[iConomy] Error creating database: " + ex); } finally { DbUtils.close(c); } } catch (SQLException ex) { System.out.println("[iConomy] Database Error: " + ex); } } } else { this.onConversion(); } } catch (MissingDriver ex) { System.out.println(ex.getMessage()); } getServer().getPluginManager().registerEvents(new players(), this); } finally { endTime = System.nanoTime(); } // Setup Interest if (Constants.Nodes.Interest.getBoolean()) { Thrun.init(new Runnable() { public void run() { long time = Constants.Nodes.InterestTime.getLong() * 1000L; Interest = new Timer(); Interest.scheduleAtFixedRate(new Interest(getDataFolder().getPath()), time, time); } }); } if (Constants.Nodes.Purging.getBoolean()) { Thrun.init(new Runnable() { public void run() { Queried.purgeDatabase(); System.out.println("[" + info.getName() + " - " + Constants.Nodes.CodeName.toString() + "] Purged accounts with default balance."); } }); } final long duration = endTime - startTime; // Finish System.out.println("[" + info.getName() + " - " + Constants.Nodes.CodeName.toString() + "] Enabled (" + Common.readableProfile(duration) + ")"); }
From source file:com.siberhus.easyexecutor.EasyExecutor.java
private EasyExecutor(File configFile, String[] args) throws Exception { this.executionTime = new Date(); this.configurationFile = configFile; this.commandLineArgs = args; DomElementFinder def = DomElementFinder.newInstance(configFile); this.singleInstance = def.getRootElement().getAttribute(Boolean.class, "single-instance"); // boolean showTray = def.getRootElement().getAttribute(Boolean.class, "show-tray"); this.locale = def.getRootElement().getAttribute(Locale.class, "locale"); Locale.setDefault(getLocale()); //=========== Recursive configure =============// configure(def);//from w ww .jav a 2s. c om //=============================================// appTask = new ApplicationTask(); DataElement appElem = def.findElement("application"); String appId = appElem.getAttribute("id"); String appMode = appElem.getAttribute("mode"); String appName = def.getElement(appElem, "name").getValue(appId); String appVersion = def.getElement(appElem, "version").getValue("0.0"); String appDesc = def.getElement(appElem, "description").getValue(); //=========== System Properties ==================// System.setProperty("easyx.locale", locale.toString()); System.setProperty("easyx.app.id", appId); System.setProperty("easyx.app.name", appName); System.setProperty("easyx.app.version", appVersion); applicationInfo = new ApplicationInfo(); applicationInfo.setId(appId); applicationInfo.setMode(appMode); applicationInfo.setName(appName); applicationInfo.setVersion(appVersion); applicationInfo.setDescription(appDesc); //=========== Init Logger =======================// DataElement logElem = def.findElement(appElem, "logger"); if (logElem != null) { LOG_IMPL logImpl = logElem.getAttribute(LOG_IMPL.class, "impl", LOG_IMPL.log4j); File logConfigFile = ResourceUtils.getFile(logElem.getAttribute("config")); if (logConfigFile.exists()) { if (logImpl == LOG_IMPL.log4j) { org.apache.log4j.Logger.getRootLogger().removeAllAppenders(); if (logConfigFile.getName().endsWith(".xml")) { DOMConfigurator.configure(logConfigFile.getAbsolutePath()); } else { PropertyConfigurator.configure(logConfigFile.getAbsolutePath()); } } else if (logImpl == LOG_IMPL.jdk) { System.setProperty("java.util.logging.config.file", logConfigFile.getAbsolutePath()); } } } DataElement cronElem = def.findElement(appElem, "cron"); if (cronElem != null) { scheduled = true; String cronExpression = cronElem.getAttribute("expression"); cronExpression = CronEntries.resolveEntry(cronExpression); Scheduler scheduler = new Scheduler(); scheduler.schedule(cronExpression, appTask); scheduler.start(); } logger = LoggerFactory.getLogger(EasyExecutor.class); logger.info("Allow multiple instances? {}", !singleInstance); logger.info("Default locale: {}", locale); //=========== Ensure only one instance is run at a time =========// ensureSingleInstance(appId); //===============================================================// beanExecutorMap = new LinkedHashMap<String, BeanExecutor>(); List<DataElement> beanElems = def.findElements(appElem, "beans/bean"); for (DataElement beanElem : beanElems) { BeanExecutor be = createBeanExecutor(def, beanElem, args); beanExecutorMap.put(be.getId(), be); } }
From source file:com.mendhak.gpslogger.common.Systems.java
public static void setLocale(String userSpecifiedLocale, Context baseContext, Resources resources) { if (!Strings.isNullOrEmpty(userSpecifiedLocale)) { LOG.debug("Setting language to " + userSpecifiedLocale); String language, country = ""; if (userSpecifiedLocale.contains("-")) { language = userSpecifiedLocale.split("-")[0]; country = userSpecifiedLocale.split("-")[1]; } else {/* ww w .j a v a 2 s . co m*/ language = userSpecifiedLocale; } Locale locale = new Locale(language, country); Locale.setDefault(locale); resources.getConfiguration().locale = locale; baseContext.getResources().updateConfiguration(resources.getConfiguration(), baseContext.getResources().getDisplayMetrics()); } }
From source file:ch.ralscha.extdirectspring_itest.UserServiceTest.java
@Test public void testPostWithMoreErrors() throws IOException { Locale.setDefault(Locale.ENGLISH); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("extTID", "3")); formparams.add(new BasicNameValuePair("extAction", "userService")); formparams.add(new BasicNameValuePair("extMethod", "updateUser")); formparams.add(new BasicNameValuePair("extType", "rpc")); formparams.add(new BasicNameValuePair("extUpload", "false")); formparams.add(new BasicNameValuePair("name", "Oliver")); formparams.add(new BasicNameValuePair("age", "35")); formparams.add(new BasicNameValuePair("addemailerror", "1")); UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); this.post.setEntity(postEntity); CloseableHttpResponse response = this.client.execute(this.post); try {// w ww . j av a 2 s . c om HttpEntity entity = response.getEntity(); assertThat(entity).isNotNull(); String responseString = EntityUtils.toString(entity); Map<String, Object> rootAsMap = this.mapper.readValue(responseString, Map.class); assertThat(rootAsMap).hasSize(5); assertThat(rootAsMap.get("method")).isEqualTo("updateUser"); assertThat(rootAsMap.get("type")).isEqualTo("rpc"); assertThat(rootAsMap.get("action")).isEqualTo("userService"); assertThat(rootAsMap.get("tid")).isEqualTo(3); Map<String, Object> result = (Map<String, Object>) rootAsMap.get("result"); assertThat(result).hasSize(4); assertThat(result.get("name")).isEqualTo("Oliver"); assertThat(result.get("age")).isEqualTo(35); assertThat(result.get("success")).isEqualTo(Boolean.FALSE); Map<String, Object> errors = (Map<String, Object>) result.get("errors"); assertThat(errors).hasSize(2); assertThat((List<String>) errors.get("email")).contains("may not be empty", "another email error"); assertThat((List<String>) errors.get("name")).contains("a name error"); } finally { IOUtils.closeQuietly(response); } }
From source file:org.silverpeas.core.test.extention.LocalizationBundleStub.java
protected void clear() { Locale.setDefault(currentLocale); bundleNames.forEach(bundleCache::remove); }
From source file:ch.ralscha.extdirectspring_itest.UserControllerTest.java
@Test public void testPostWithMoreErrors() throws IOException { Locale.setDefault(Locale.ENGLISH); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("extTID", "3")); formparams.add(new BasicNameValuePair("extAction", "userController")); formparams.add(new BasicNameValuePair("extMethod", "updateUser")); formparams.add(new BasicNameValuePair("extType", "rpc")); formparams.add(new BasicNameValuePair("extUpload", "false")); formparams.add(new BasicNameValuePair("name", "Oliver")); formparams.add(new BasicNameValuePair("age", "35")); formparams.add(new BasicNameValuePair("addemailerror", "1")); UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(formparams, "UTF-8"); this.post.setEntity(postEntity); CloseableHttpResponse response = this.client.execute(this.post); try {/*from w ww. java 2s . c o m*/ HttpEntity entity = response.getEntity(); assertThat(entity).isNotNull(); String responseString = EntityUtils.toString(entity); Map<String, Object> rootAsMap = this.mapper.readValue(responseString, Map.class); assertThat(rootAsMap).hasSize(5); assertThat(rootAsMap.get("method")).isEqualTo("updateUser"); assertThat(rootAsMap.get("type")).isEqualTo("rpc"); assertThat(rootAsMap.get("action")).isEqualTo("userController"); assertThat(rootAsMap.get("tid")).isEqualTo(3); Map<String, Object> result = (Map<String, Object>) rootAsMap.get("result"); assertThat(result).hasSize(4); assertThat(result.get("name")).isEqualTo("Oliver"); assertThat(result.get("age")).isEqualTo(35); assertThat(result.get("success")).isEqualTo(Boolean.FALSE); Map<String, Object> errors = (Map<String, Object>) result.get("errors"); assertThat(errors).hasSize(2); assertThat((List<String>) errors.get("email")).contains("may not be empty", "another email error"); assertThat((List<String>) errors.get("name")).contains("a name error"); } finally { IOUtils.closeQuietly(response); } }