List of usage examples for java.text NumberFormat format
public final String format(long number)
From source file:com.espertech.esper.example.servershellclient.ServerShellClientMain.java
public ServerShellClientMain() throws Exception { log.info("Loading properties"); Properties properties = new Properties(); InputStream propertiesIS = ServerShellClientMain.class.getClassLoader() .getResourceAsStream(ServerShellConstants.CONFIG_FILENAME); if (propertiesIS == null) { throw new RuntimeException( "Properties file '" + ServerShellConstants.CONFIG_FILENAME + "' not found in classpath"); }/* www . j a va2s . c o m*/ properties.load(propertiesIS); // Attached via JMX to running server log.info("Attach to server via JMX"); JMXServiceURL url = new JMXServiceURL(properties.getProperty(ServerShellConstants.MGMT_SERVICE_URL)); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mBeanName = new ObjectName(ServerShellConstants.MGMT_MBEAN_NAME); EPServiceProviderJMXMBean proxy = (EPServiceProviderJMXMBean) MBeanServerInvocationHandler .newProxyInstance(mbsc, mBeanName, EPServiceProviderJMXMBean.class, true); // Connect to JMS log.info("Connecting to JMS server"); String factory = properties.getProperty(ServerShellConstants.JMS_CONTEXT_FACTORY); String jmsurl = properties.getProperty(ServerShellConstants.JMS_PROVIDER_URL); String connFactoryName = properties.getProperty(ServerShellConstants.JMS_CONNECTION_FACTORY_NAME); String user = properties.getProperty(ServerShellConstants.JMS_USERNAME); String password = properties.getProperty(ServerShellConstants.JMS_PASSWORD); String destination = properties.getProperty(ServerShellConstants.JMS_INCOMING_DESTINATION); boolean isTopic = Boolean.parseBoolean(properties.getProperty(ServerShellConstants.JMS_IS_TOPIC)); JMSContext jmsCtx = JMSContextFactory.createContext(factory, jmsurl, connFactoryName, user, password, destination, isTopic); // Create statement via JMX log.info("Creating a statement via Java Management Extensions (JMX) MBean Proxy"); proxy.createEPL("select * from SampleEvent where duration > 9.9", "filterStatement", new ClientSideUpdateListener()); // Get producer jmsCtx.getConnection().start(); MessageProducer producer = jmsCtx.getSession().createProducer(jmsCtx.getDestination()); Random random = new Random(); String[] ipAddresses = { "127.0.1.0", "127.0.2.0", "127.0.3.0", "127.0.4.0" }; NumberFormat format = NumberFormat.getInstance(); // Send messages for (int i = 0; i < 1000; i++) { String ipAddress = ipAddresses[random.nextInt(ipAddresses.length)]; double duration = 10 * random.nextDouble(); String durationStr = format.format(duration); String payload = ipAddress + "," + durationStr; BytesMessage bytesMessage = jmsCtx.getSession().createBytesMessage(); bytesMessage.writeBytes(payload.getBytes()); bytesMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); producer.send(bytesMessage); if (i % 100 == 0) { log.info("Sent " + i + " messages"); } } // Create statement via JMX log.info("Destroing statement via Java Management Extensions (JMX) MBean Proxy"); proxy.destroy("filterStatement"); log.info("Shutting down JMS client connection"); jmsCtx.destroy(); log.info("Exiting"); System.exit(-1); }
From source file:de.tor.tribes.util.bb.MarkerListFormatter.java
@Override public String formatElements(List<Marker> pElements, boolean pExtended) { StringBuilder b = new StringBuilder(); int cnt = 1;// w ww. j a va 2s. c o m NumberFormat f = getNumberFormatter(pElements.size()); String beforeList = getHeader(); String listItemTemplate = getLineTemplate(); String afterList = getFooter(); String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedStart); for (Marker m : pElements) { String[] replacements = m.getReplacements(pExtended); String itemLine = StringUtils.replaceEach(listItemTemplate, m.getBBVariables(), replacements); itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT }, new String[] { f.format(cnt), f.format(pElements.size()) }); b.append(itemLine).append("\n"); cnt++; } String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedEnd); return b.toString(); }
From source file:de.tor.tribes.util.bb.SosListFormatter.java
@Override public String formatElements(List<SOSRequest> pElements, boolean pExtended) { StringBuilder b = new StringBuilder(); int cnt = 1;// ww w .j ava 2 s . com NumberFormat f = getNumberFormatter(pElements.size()); String beforeList = getHeader(); String listItemTemplate = getLineTemplate(); String afterList = getFooter(); String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedStart); for (SOSRequest s : pElements) { for (Village target : s.getTargets()) { String[] replacements = s.getReplacementsForTarget(target, pExtended); String itemLine = StringUtils.replaceEach(listItemTemplate, s.getBBVariables(), replacements); itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT }, new String[] { f.format(cnt), f.format(pElements.size()) }); b.append(itemLine).append("\n").append("\n"); } cnt++; } String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedEnd); return b.toString(); }
From source file:de.tor.tribes.util.bb.TagListFormatter.java
@Override public String formatElements(List<Tag> pElements, boolean pExtended) { StringBuilder b = new StringBuilder(); int cnt = 1;//from www . jav a2 s.c o m NumberFormat f = getNumberFormatter(pElements.size()); String beforeList = getHeader(); String listItemTemplate = getLineTemplate(); String afterList = getFooter(); String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedStart); for (Tag t : pElements) { String[] replacements = t.getReplacements(pExtended); String itemLine = StringUtils.replaceEach(listItemTemplate, t.getBBVariables(), replacements); itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT }, new String[] { f.format(cnt), f.format(pElements.size()) }); b.append(itemLine).append("\n"); cnt++; } String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedEnd); return b.toString(); }
From source file:de.tor.tribes.util.bb.VillageListFormatter.java
@Override public String formatElements(List<Village> pElements, boolean pExtended) { StringBuilder b = new StringBuilder(); int cnt = 1;//from w ww . j av a 2 s . c o m NumberFormat f = getNumberFormatter(pElements.size()); String beforeList = getHeader(); String listItemTemplate = getLineTemplate(); String afterList = getFooter(); String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedStart); for (Village v : pElements) { String[] replacements = v.getReplacements(pExtended); String itemLine = StringUtils.replaceEach(listItemTemplate, v.getBBVariables(), replacements); itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT }, new String[] { f.format(cnt), f.format(pElements.size()) }); b.append(itemLine).append("\n"); cnt++; } String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedEnd); return b.toString(); }
From source file:guineu.modules.dataanalysis.PCA.PCADataset.java
public String getXLabel() { NumberFormat formatter = new DecimalFormat("#0.00"); String variation = formatter .format((this.mainComponents.get(xAxisPC - 1).eigenValue / this.totalVariation) * 100); if (xAxisPC == 1) { return "1st PC (" + variation + "%)"; }// w ww. j ava2s . c o m if (xAxisPC == 2) { return "2nd PC (" + variation + "%)"; } if (xAxisPC == 3) { return "3rd PC (" + variation + "%)"; } return "" + xAxisPC + "th PC (" + variation + "%)"; }
From source file:LabelXYToolTipGenerator.java
private String format(double num, int minDecimalPlaces, int maxDecimalPlaces) { NumberFormat format = NumberFormat.getInstance(); format.setMinimumFractionDigits(minDecimalPlaces); format.setMaximumFractionDigits(maxDecimalPlaces); return (format.format(num)); }
From source file:org.posterita.businesslogic.performanceanalysis.CustomPOSReportManager.java
public static TabularReport generateTabularReportGroupByDate(Properties ctx, String title, String subtitle, int account_id, Timestamp fromDate, Timestamp toDate, String salesGroup, String priceQtyFilter) throws OperationException { boolean isTaxDue = (account_id == Constants.TAX_DUE.intValue()); boolean isTaxCredit = (account_id == Constants.TAX_CREDIT.intValue()); NumberFormat formatter = new DecimalFormat("###,###,##0.00"); String sql = SalesAnalysisReportManager.getTabularDataSetSQL(ctx, account_id, fromDate, toDate, salesGroup); ArrayList<Object[]> tmpData = ReportManager.getReportData(ctx, sql, true); String currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol(); ArrayList<Object[]> reportData = new ArrayList<Object[]>(); Object[] data = null;//from w ww. ja v a 2s . c o m BigDecimal b = null; if (isTaxCredit || isTaxDue) { reportData.add(tmpData.remove(0)); Iterator<Object[]> iter = tmpData.iterator(); while (iter.hasNext()) { data = iter.next(); if (data.length == 1) { b = (BigDecimal) data[0]; data[0] = formatter.format(b.doubleValue()); } reportData.add(data); } } else { //---------------------------------------------------------------------------------------------------------------------------------------------------------- TreeMap<String, TabularReportRecordBean> map = new TreeMap<String, TabularReportRecordBean>(); String productName = null; BigDecimal price = null; BigDecimal qty = null; TabularReportRecordBean bean = null; ArrayList<Object[]> reportData2 = new ArrayList<Object[]>(); Object[] headers = tmpData.remove(0); //adding headers reportData2.add(new Object[] { headers[0], //headers[1], headers[2] + "(" + currency + ")", headers[3] }); double totalAmt = 0.0d; int totalQty = 0; for (Object[] record : tmpData) { productName = (String) record[0]; price = (BigDecimal) record[2]; qty = (BigDecimal) record[3]; totalAmt += price.doubleValue(); totalQty += qty.intValue(); bean = map.get(productName); if (bean == null) { bean = new TabularReportRecordBean(); bean.setProductName(productName); bean.setDate(""); bean.setPrice(price); bean.setQty(qty); } else { bean.setPrice(bean.getPrice().add(price)); bean.setQty(bean.getQty().add(qty)); } map.put(productName, bean); } //for Collection<TabularReportRecordBean> c = map.values(); for (TabularReportRecordBean tbean : c) { Object[] obj = new Object[] { tbean.getProductName(), tbean.getPrice(), tbean.getQty() }; reportData2.add(obj); } reportData.add(reportData2.remove(0)); Iterator<Object[]> iter = reportData2.iterator(); while (iter.hasNext()) { data = iter.next(); if (data.length > 2) { b = (BigDecimal) data[1]; data[1] = formatter.format(b.doubleValue()); } reportData.add(data); } reportData.add(new Object[] { "Total", "" + formatter.format(totalAmt), totalQty + "" }); } //style for table String tableStyle = "display"; //style for columns String[] styles = new String[] { "string", "currency", "numeric" }; if (isTaxCredit || isTaxDue) { styles = new String[] { "numeric" }; } //constructing the table TabularReport tReport = new TabularReport(reportData); //tReport.setSortable(true); tReport.setHeaderStyle(styles); tReport.setStyle(tableStyle); tReport.setTitle(title); tReport.setSubtitle(subtitle); tReport.createReport(); return tReport; }
From source file:gtu._work.ui.SqlCreaterUI.java
private String formatCellType(Cell cell) { String returnVal = StringUtils.EMPTY; if (cell == null) { return ""; }//from w w w. java2 s . c om if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { if (HSSFDateUtil.isCellDateFormatted(cell)) { Date d = cell.getDateCellValue(); returnVal = " to_date('" + SDF.format(d) + "', 'yyyymmdd' ) "; } else { final NumberFormat formatter = new DecimalFormat("##"); returnVal = formatter.format(Float.valueOf(cell.toString())); } } else { returnVal = cell.toString(); } return returnVal; }
From source file:de.tor.tribes.util.bb.AttackListFormatter.java
@Override public String formatElements(List<Attack> pElements, boolean pExtended) { StringBuilder b = new StringBuilder(); int cnt = 1;//from ww w. j av a 2s. co m NumberFormat f = getNumberFormatter(pElements.size()); String beforeList = getHeader(); String listItemTemplate = getLineTemplate(); String afterList = getFooter(); String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedStart); for (Attack a : pElements) { String[] replacements = a.getReplacements(pExtended); String itemLine = StringUtils.replaceEach(listItemTemplate, a.getBBVariables(), replacements); itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT }, new String[] { f.format(cnt), f.format(pElements.size()) }); b.append(itemLine).append("\n"); cnt++; } String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedEnd); return b.toString(); }