List of usage examples for java.text NumberFormat getInstance
public static final NumberFormat getInstance()
From source file:net.sourceforge.eclipsetrader.charts.ChartsPlugin.java
public static NumberFormat getPriceFormat() { if (priceFormat == null) { priceFormat = NumberFormat.getInstance(); priceFormat.setGroupingUsed(true); priceFormat.setMinimumIntegerDigits(1); priceFormat.setMinimumFractionDigits(4); priceFormat.setMaximumFractionDigits(4); }//from w w w . j a v a 2 s .c om return priceFormat; }
From source file:com.googlecode.concurrentlinkedhashmap.MemoryLeakTest.java
private Runnable newStatusTask() { return new Runnable() { long runningTime; @Override/*from www .ja v a 2 s .com*/ public void run() { long reads = 0; for (int i = 0; i < map.readBuffers.length; i++) { for (int j = 0; j < map.readBuffers[i].length; j++) { if (map.readBuffers[i][j].get() != null) { reads++; } } } runningTime += SECONDS.toMillis(statusInterval); String elapsedTime = formatDuration(runningTime, "H:mm:ss"); String pendingReads = NumberFormat.getInstance().format(reads); String pendingWrites = NumberFormat.getInstance().format(map.writeBuffer.size()); System.out.printf("---------- %s ----------\n", elapsedTime); System.out.printf("Pending reads = %s\n", pendingReads); System.out.printf("Pending write = %s\n", pendingWrites); System.out.printf("Drain status = %s\n", map.drainStatus); } }; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.FastNumberTickUnit.java
/** * Creates a new number tick unit.//from w w w . jav a 2 s .c o m * * @param size the size of the tick unit. * @param formatter a number formatter for the tick unit (<code>null</code> not permitted). * @param minorTickCount the number of minor ticks. * @since 1.0.7 */ public FastNumberTickUnit(final double size, final FastDecimalFormat formatter, final int minorTickCount) { super(size, NumberFormat.getInstance(), minorTickCount); if (formatter == null) { throw new IllegalArgumentException("Null 'formatter' argument."); } this.formatter = formatter; }
From source file:com.saiton.ccs.validations.FormatAndValidate.java
public String FormatDecimal(double d) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2);// w ww . jav a 2s. co m nf.setMinimumFractionDigits(2); return nf.format(d); }
From source file:de.tor.tribes.util.bb.PointStatsFormatter.java
private String[] getStatSpecificReplacements(Stats pStats) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0);/*from www . j av a 2 s . co m*/ nf.setMaximumFractionDigits(0); String tribe = pStats.getParent().getTribe().toBBCode(); String pointsBefore = nf.format(pStats.getPointStart()); String pointsAfter = nf.format(pStats.getPointEnd()); String pointsDiff = nf.format(pStats.getPointDiff()); if (pStats.getPointDiff() > 0) { pointsDiff = "[color=green]" + pointsDiff + "[/color]"; } else { pointsDiff = "[color=red]" + pointsDiff + "[/color]"; } double perc = pStats.getExpansion(); String percentDiff = ((perc >= 0) ? "+" : "") + nf.format(perc) + "%"; if (perc > 0) { percentDiff = "[color=green]" + percentDiff + "[/color]"; } else { percentDiff = "[color=red]" + percentDiff + "[/color]"; } String killsPerPoints = nf.format(pStats.getKillPerPoint()); return new String[] { tribe, pointsBefore, pointsAfter, pointsDiff, percentDiff, killsPerPoints }; }
From source file:de.thingweb.util.encoding.ContentHelper.java
public static <T> T ensureClass(Object o, Class<T> clazz) { try {/*from w w w . j a va 2 s.com*/ return clazz.cast(o); } catch (ClassCastException e) { final String msg = String.format("expected value to be of type %s, not %s in %s", clazz, o.getClass(), o.toString()); if (o instanceof String) { try { return clazz.cast(NumberFormat.getInstance().parse((String) o)); } catch (ParseException e1) { log.warn(msg); throw new IllegalArgumentException(msg); } } else throw new IllegalArgumentException(msg); } }
From source file:de.tor.tribes.util.bb.WinnerLoserStatsFormatter.java
private String[] getStatSpecificReplacements(List<Stats> pStats, boolean pExtended) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0);//from w w w .j a va 2s . c o m nf.setMaximumFractionDigits(0); //point titles Collections.sort(pStats, Stats.POINTS_COMPARATOR); String winnerByPoints = pStats.get(0).getParent().getTribe().toBBCode(); winnerByPoints += " (" + formatValue(pStats.get(0).getPointDiff(), nf) + " Punkte)"; long pointsLost = pStats.get(pStats.size() - 1).getPointDiff(); String loserByPoints = ""; if (pointsLost < 0) { loserByPoints = pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByPoints += " (" + formatValue(pStats.get(pStats.size() - 1).getPointDiff(), nf) + " Punkte)"; } else { loserByPoints = "-Keine Punkteverluste vorhanden-"; } //conquer titles Collections.sort(pStats, Stats.VILLAGE_COMPARATOR); String winnerByConquers = pStats.get(0).getParent().getTribe().toBBCode(); winnerByConquers += " (" + formatValue(pStats.get(0).getVillageDiff(), nf) + " Drfer)"; long conquerLost = pStats.get(pStats.size() - 1).getVillageDiff(); String loserByConquers = ""; if (conquerLost < 0) { pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByConquers += " (" + formatValue(pStats.get(pStats.size() - 1).getVillageDiff(), nf) + " Drfer)"; } else { loserByConquers = "-Keine Dorfverluste vorhanden-"; } //off bash titles Collections.sort(pStats, Stats.BASH_OFF_COMPARATOR); String winnerByOffense = pStats.get(0).getParent().getTribe().toBBCode(); winnerByOffense += " (" + formatValue(pStats.get(0).getBashOffDiff(), nf) + " besiegte Gegner)"; String loserByOffense = pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByOffense += " (" + formatValue(pStats.get(pStats.size() - 1).getBashOffDiff(), nf) + " besiegte Gegner)"; //def bash titles Collections.sort(pStats, Stats.BASH_DEF_COMPARATOR); String winnerByDefense = pStats.get(0).getParent().getTribe().toBBCode(); winnerByDefense += " (" + formatValue(pStats.get(0).getBashDefDiff(), nf) + " besiegte Gegner)"; String loserByDefense = pStats.get(pStats.size() - 1).getParent().getTribe().toBBCode(); loserByDefense += " (" + formatValue(pStats.get(pStats.size() - 1).getBashDefDiff(), nf) + " besiegte Gegner)"; //kpp titles Collections.sort(pStats, Stats.KILLS_PER_POINT_COMPARATOR); String winnerByKillsPerPoint = pStats.get(0).getParent().getTribe().toBBCode(); winnerByKillsPerPoint += " (" + formatValue(pStats.get(0).getKillPerPoint(), nf) + " Kills pro Punkt)"; //expansion title Collections.sort(pStats, Stats.EXPANSION_COMPARATOR); String winnerByExpansion = pStats.get(0).getParent().getTribe().toBBCode(); winnerByExpansion += " (" + formatValue(pStats.get(0).getExpansion(), nf) + "% Punktezuwachs)"; double expansionLost = pStats.get(pStats.size() - 1).getExpansion(); String loserByExpansion = ""; if (expansionLost < 0) { loserByExpansion = " (" + formatValue(pStats.get(pStats.size() - 1).getExpansion(), nf) + "% Punktezuwachs)"; } else { loserByExpansion = "-Keine negatives Wachstum vorhanden-"; } return new String[] { winnerByPoints, winnerByExpansion, winnerByConquers, winnerByOffense, winnerByDefense, winnerByKillsPerPoint, loserByPoints, loserByExpansion, loserByConquers, loserByOffense, loserByDefense }; }
From source file:ru.iris.noolite4j.gateway.HTTPCommand.java
/** * ? ??//from ww w.j av a 2 s. c o m * @return ?? ?? */ public List<Sensor> getSensors() { List<Sensor> sensors = new ArrayList<>(); try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse("http://" + PR1132.getHost() + "/sens.xml"); doc.getDocumentElement().normalize(); String text = doc.getDocumentElement().getTextContent(); String[] values = text.split("\n"); for (int idx = 1; idx <= values.length - 1; idx++) { if (values[idx].isEmpty()) continue; double value = 0; if (!values[idx].equals("-")) { NumberFormat format = NumberFormat.getInstance(); Number number = format.parse(values[idx]); value = number.doubleValue(); } /** * ? ?? ? ?? */ byte channel = 0; if (idx <= 3) channel = 1; else if (idx >= 4 && idx <= 6) channel = 2; else if (idx >= 7 && idx <= 9) channel = 3; else if (idx >= 10 && idx <= 12) channel = 4; Sensor sensor; if (sensors.size() >= channel) { sensor = sensors.get(channel - 1); } else { sensor = new Sensor(); } if (sensor == null) sensor = new Sensor(); sensor.setChannel(channel); /** * */ if (idx == 1 || idx == 4 || idx == 7 || idx == 10) { value /= 10; sensor.setTemperature(value); } else if (idx == 2 || idx == 5 || idx == 8 || idx == 11) { sensor.setHumidity((byte) value); } else if (idx == 3 || idx == 6 || idx == 9 || idx == 12) { sensor.setState(SensorState.values()[(int) value]); } boolean isNew = true; for (int i = 0; i < sensors.size(); i++) { if (sensors.get(i).getChannel() == sensor.getChannel()) { sensors.remove(i); sensors.add(i, sensor); isNew = false; } } if (isNew) { sensors.add(sensor); } } } catch (Exception e) { LOGGER.error(" ? PR1132: " + e.getMessage()); e.printStackTrace(); } return sensors; }
From source file:com.jaspersoft.studio.components.chart.wizard.fragments.data.DSPie.java
@Override public void setData(JSSDrawVisitor drawVisitor, JRDesignElement jrChart, JRDesignElementDataset eDataset, JasperReportsConfiguration jrContext) { Assert.isTrue(eDataset instanceof JRDesignPieDataset); super.setData(drawVisitor, jrChart, eDataset, jrContext); dataset = (JRDesignPieDataset) eDataset; setSeries(0);/* w ww .j av a 2s. c o m*/ if (dataset.getMinPercentage() != null) minSlice.setText(NumberFormat.getInstance().format(dataset.getMinPercentage())); else minSlice.setText(""); //$NON-NLS-1$ maxSlice.setSelection(dataset.getMaxCount() != null ? dataset.getMaxCount().intValue() : 0); }
From source file:net.sf.infrared.web.action.PerfDataCallTracesAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException { HttpSession session = request.getSession(); TreeFactory treeFactory = null;/*from w w w . j a va 2 s.co m*/ String apiName = request.getParameter("api"); if (apiName != null) { session.setAttribute("api", apiName); } // This parameter corresponds to the actual layer name to // which the api belongs String actualLayerName = request.getParameter("layerName"); if (actualLayerName != null) { session.setAttribute("layerName", actualLayerName); } String className = request.getParameter("ctx"); if (className != null) { session.setAttribute("ctx", className); } // This parameter corresponds to hierarchical layer if the navigation // is in the context of the hierarchical layer. Else it corresponds to // the absolute layer. String type = request.getParameter("type"); if (type != null) { session.setAttribute("type", type); } final PerformanceDataSnapshot perData = (PerformanceDataSnapshot) session.getAttribute("perfData"); final String layerType = (String) session.getAttribute("layerType"); AggregateOperationTree aggrOptree = perData.getStats().getTree(); String hierarchicalLayerName = null; if (layerType.equals("hier")) { hierarchicalLayerName = type; } TreeNode mergedHead = TreeUtil.getMergedExecutionContextTreeNode(aggrOptree, apiName, actualLayerName, className, hierarchicalLayerName); if (mergedHead != null) { final long OVERALL_TIME = ((AggregateExecutionTime) mergedHead.getValue()).getTotalInclusiveTime(); final NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); NodeToStringConverter nodeToStringConverterMergedTree = new NodeToStringConverter() { public String toString(AggregateExecutionTime aggApiTime) { StringBuffer display = new StringBuffer(); if (OVERALL_TIME == 0) { display.append(aggApiTime.getContext().toString()).append(" [ ").append(" Total Time = ") .append(aggApiTime.getTotalInclusiveTime()).append(" Exclusive Time = ") .append(aggApiTime.getTotalExclusiveTime()).append(" Count = ") .append(aggApiTime.getExecutionCount()).append(" ] "); } else { display.append(aggApiTime.getContext().toString()).append(" [ ") .append(nf.format((aggApiTime.getTotalInclusiveTime() * 100.0) / OVERALL_TIME)) .append("% -").append(" Total Time = ").append(aggApiTime.getTotalInclusiveTime()) .append(" Exclusive Time = ").append(aggApiTime.getTotalExclusiveTime()) .append(" Count = ").append(aggApiTime.getExecutionCount()).append(" ] "); } return display.toString(); } public String getHref(AggregateExecutionTime apiTime) { ExecutionContext ctx = apiTime.getContext(); String name = ctx.getName(); String layer = ctx.getLayer(); String layerName = ""; String temp = null; if (layerType.equals("abs")) { layerName = ctx.getLayer(); } else if (layerType.equals("hier")) { layerName = apiTime.getLayerName(); } try { temp = "perfData_apiSumm_callTracesAction.do?" + "api=" + URLEncoder.encode(name, "UTF-8") + "&type=" + layerName + "&ctx=" + ctx.getClass().getName() + "&layerName=" + layer; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return temp; } public boolean isContextRelative() { return false; } }; String tree = "InfraTree"; treeFactory = new TreeFactoryImpl(mergedHead, tree, nodeToStringConverterMergedTree); } AggregateExecutionTime[] mergedTreeJdbcSummaries = new AggregateExecutionTime[0]; SqlStatistics[] mergedTreeSqlStatistics = new SqlStatistics[0]; if (mergedHead != null) { mergedTreeJdbcSummaries = ViewUtil.getJDBCSummary(mergedHead); mergedTreeSqlStatistics = ViewUtil.getSqlStatistics(mergedHead); } ArrayList jdbcSummaries = new ArrayList(); for (int i = 0; i < mergedTreeJdbcSummaries.length; i++) { AggrExecTimeFormBean formBean = new AggrExecTimeFormBean(); BeanUtils.copyProperties(formBean, mergedTreeJdbcSummaries[i]); jdbcSummaries.add(formBean); } ArrayList sqlStatisticsByExec = new ArrayList(); int n = 5; SqlStatistics[] topNQueriesByExecution = ViewUtil.getTopNQueriesByExecutionTime(mergedTreeSqlStatistics, n); for (int i = 0; i < topNQueriesByExecution.length; i++) { SqlStatisticsFormBean formBean = new SqlStatisticsFormBean(); BeanUtils.copyProperties(formBean, topNQueriesByExecution[i]); sqlStatisticsByExec.add(formBean); } ArrayList sqlStatisticsByCount = new ArrayList(); SqlStatistics[] topNQueriesByCount = ViewUtil.getTopNQueriesByCount(mergedTreeSqlStatistics, n); for (int i = 0; i < topNQueriesByCount.length; i++) { SqlStatisticsFormBean formBean = new SqlStatisticsFormBean(); BeanUtils.copyProperties(formBean, topNQueriesByCount[i]); sqlStatisticsByCount.add(formBean); } // These have been put in the session because the expansion // and contraction of the tree cause a new request which does // go through the struts action. The page is directly called. session.setAttribute("mergedHead", mergedHead); session.setAttribute("jdbcSummaries", jdbcSummaries); session.setAttribute("sqlStatisticsByExec", sqlStatisticsByExec); session.setAttribute("sqlStatisticsByCount", sqlStatisticsByCount); session.setAttribute("treeFactory", treeFactory); return mapping.findForward("repeat"); }