List of usage examples for java.text NumberFormat getInstance
public static final NumberFormat getInstance()
From source file:io.plaidapp.ui.DribbbleShot.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dribbble_shot); shot = getIntent().getParcelableExtra(EXTRA_SHOT); setupDribbble();/*w w w . j a v a2 s. com*/ setExitSharedElementCallback(fabLoginSharedElementCallback); getWindow().getSharedElementReturnTransition().addListener(shotReturnHomeListener); circleTransform = new CircleTransform(this); Resources res = getResources(); ButterKnife.bind(this); View shotDescription = getLayoutInflater().inflate(R.layout.dribbble_shot_description, commentsList, false); shotSpacer = shotDescription.findViewById(R.id.shot_spacer); title = shotDescription.findViewById(R.id.shot_title); description = shotDescription.findViewById(R.id.shot_description); shotActions = (LinearLayout) shotDescription.findViewById(R.id.shot_actions); likeCount = (Button) shotDescription.findViewById(R.id.shot_like_count); viewCount = (Button) shotDescription.findViewById(R.id.shot_view_count); share = (Button) shotDescription.findViewById(R.id.shot_share_action); playerName = (TextView) shotDescription.findViewById(R.id.player_name); playerAvatar = (ImageView) shotDescription.findViewById(R.id.player_avatar); shotTimeAgo = (TextView) shotDescription.findViewById(R.id.shot_time_ago); commentsList = (ListView) findViewById(R.id.dribbble_comments); commentsList.addHeaderView(shotDescription); setupCommenting(); commentsList.setOnScrollListener(scrollListener); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { expandImageAndFinish(); } }); fab.setOnClickListener(fabClick); chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(getWindow()) { @Override public void onDragDismissed() { expandImageAndFinish(); } }; // load the main image final int[] imageSize = shot.images.bestSize(); Glide.with(this).load(shot.images.best()).listener(shotLoadListener) .diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.IMMEDIATE) .override(imageSize[0], imageSize[1]).into(imageView); imageView.setOnClickListener(shotClick); shotSpacer.setOnClickListener(shotClick); postponeEnterTransition(); imageView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { imageView.getViewTreeObserver().removeOnPreDrawListener(this); calculateFabPosition(); enterAnimation(savedInstanceState != null); startPostponedEnterTransition(); return true; } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { ((FabOverlapTextView) title).setText(shot.title); } else { ((TextView) title).setText(shot.title); } if (!TextUtils.isEmpty(shot.description)) { final Spanned descText = shot.getParsedDescription( ContextCompat.getColorStateList(this, R.color.dribbble_links), ContextCompat.getColor(this, R.color.dribbble_link_highlight)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { ((FabOverlapTextView) description).setText(descText); } else { HtmlUtils.setTextWithNiceLinks((TextView) description, descText); } } else { description.setVisibility(View.GONE); } NumberFormat nf = NumberFormat.getInstance(); likeCount.setText( res.getQuantityString(R.plurals.likes, (int) shot.likes_count, nf.format(shot.likes_count))); // TODO onClick show likes viewCount.setText( res.getQuantityString(R.plurals.views, (int) shot.views_count, nf.format(shot.views_count))); share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new ShareDribbbleImageTask(DribbbleShot.this, shot).execute(); } }); if (shot.user != null) { playerName.setText("" + shot.user.name); Glide.with(this).load(shot.user.avatar_url).transform(circleTransform) .placeholder(R.drawable.avatar_placeholder).into(playerAvatar); playerAvatar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DribbbleShot.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(shot.user.html_url))); } }); if (shot.created_at != null) { shotTimeAgo.setText(DateUtils.getRelativeTimeSpanString(shot.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS)); } } else { playerName.setVisibility(View.GONE); playerAvatar.setVisibility(View.GONE); shotTimeAgo.setVisibility(View.GONE); } if (shot.comments_count > 0) { loadComments(); } else { commentsList.setAdapter(getNoCommentsAdapter()); } }
From source file:correlation.and.regression.analysis.MainWindow.java
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed NumberFormat f = NumberFormat.getInstance(); f.setGroupingUsed(false);/*from w ww . j a v a 2 s.c o m*/ try { if (arr[0] == null) { jFileChooser1.showDialog(null, "Open file"); arr[0] = new OrderedSeries(); arr[0].loadFromFile(jFileChooser1.getSelectedFile().getPath()); } else { if (arr[1] == null) { jFileChooser1.showDialog(null, "Open file"); arr[1] = new OrderedSeries(); arr[1].loadFromFile(jFileChooser1.getSelectedFile().getPath()); showCorrelationField(); jTblStatistic.setModel(arr[0].showStatisticsForLab4(modelStatistic, 1 - 0.05 / 2)); jTblStatistic.setModel(arr[1].showStatisticsForLab4(modelStatistic, 1 - 0.05 / 2)); /*Show coef correlation*/ modelCoefCorr.setValueAt(f.format(StaticFunctions.pairCorrelationCoef(arr[0], arr[1])), 0, 1); modelCoefCorr.setValueAt(f.format(StaticFunctions.significancePairCor(arr[0], arr[1])), 0, 2); modelCoefCorr.setValueAt(f.format(Quantiles.Student(1 - 0.05 / 2, arr[0].size() - 2)), 0, 3); if (Math.abs(StaticFunctions.significancePairCor(arr[0], arr[1])) <= Quantiles .Student(1 - 0.05 / 2, arr[0].size() - 2)) { modelCoefCorr.setValueAt("? ", 0, 4); } else { modelCoefCorr.setValueAt("", 0, 4); } modelCoefCorr.setValueAt(StaticFunctions.getIntervalForPairCorr( StaticFunctions.pairCorrelationCoef(arr[0], arr[1]), arr[0].size()), 0, 5); modelCoefCorr.setValueAt(f.format(StaticFunctions.markCorrelationRatio(arr[0], arr[1])), 1, 1); modelCoefCorr.setValueAt(f.format(StaticFunctions.statisticsCorrelationRatio( StaticFunctions.markCorrelationRatio(arr[0], arr[1]), arr[0])), 1, 2); modelCoefCorr .setValueAt(f.format(Quantiles.Fisher(1 - 0.05, StaticFunctions.getK(arr[0].size()) - 1, arr[0].size() - StaticFunctions.getK(arr[0].size()))), 1, 3); if (StaticFunctions.statisticsCorrelationRatio( StaticFunctions.markCorrelationRatio(arr[0], arr[1]), arr[0]) <= Quantiles.Fisher(1 - 0.05, StaticFunctions.getK(arr[0].size()) - 1, arr[0].size() - StaticFunctions.getK(arr[0].size()))) { modelCoefCorr.setValueAt("? ", 1, 4); } else { modelCoefCorr.setValueAt("", 1, 4); } modelCoefCorr.setValueAt( f.format(StaticFunctions.spirmenCoef(arr[0].toArrayDouble(0), arr[1].toArrayDouble(0))), 2, 1); modelCoefCorr.setValueAt(f.format( StaticFunctions.statisticsSpirmen(arr[0].toArrayDouble(0), arr[1].toArrayDouble(0))), 2, 2); modelCoefCorr.setValueAt(f.format(StaticFunctions.tDistrib(arr[0].size() - 2)), 2, 3); if (Math.abs(StaticFunctions.statisticsSpirmen(arr[0].toArrayDouble(0), arr[1].toArrayDouble(0))) <= StaticFunctions.tDistrib(arr[0].size() - 2)) { modelCoefCorr.setValueAt("? ", 2, 4); } else { modelCoefCorr.setValueAt("", 2, 4); } modelCoefCorr.setValueAt( f.format( StaticFunctions.kendallsCoef(arr[0].toArrayDouble(0), arr[1].toArrayDouble(0))), 3, 1); modelCoefCorr.setValueAt(f.format( StaticFunctions.staticticsKendall(arr[0].toArrayDouble(0), arr[1].toArrayDouble(0))), 3, 2); modelCoefCorr.setValueAt(f.format(Quantiles.Norm(1 - 0.05 / 2)), 3, 3); if (Math.abs(StaticFunctions.staticticsKendall(arr[0].toArrayDouble(0), arr[1].toArrayDouble(0))) <= Quantiles.Norm(1 - 0.05 / 2)) { modelCoefCorr.setValueAt("? ", 3, 4); } else { modelCoefCorr.setValueAt("", 3, 4); } /*Show estemate parametrs*/ modelEstem.setValueAt(StaticFunctions.estimateA(arr[0], arr[1]), 0, 1); modelEstem.setValueAt(f.format(StaticFunctions.dispersiaA(arr[0], arr[1])), 0, 2); modelEstem.setValueAt(f.format(StaticFunctions.statisticA(arr[0], arr[1])), 0, 3); modelEstem.setValueAt(f.format(Quantiles.Student(1 - 0.05 / 2, arr[0].size() - 2)), 0, 4); modelEstem.setValueAt(StaticFunctions.significanceA(arr[0], arr[1]), 0, 5); modelEstem.setValueAt(StaticFunctions.getIntervalForEstemateA(arr[0], arr[1]), 0, 6); modelEstem.setValueAt(StaticFunctions.estimateB(arr[0], arr[1]), 1, 1); modelEstem.setValueAt(f.format(StaticFunctions.dispersiaB(arr[0], arr[1])), 1, 2); modelEstem.setValueAt(f.format(StaticFunctions.statisticB(arr[0], arr[1])), 1, 3); modelEstem.setValueAt(f.format(Quantiles.Student(1 - 0.05 / 2, arr[0].size() - 2)), 1, 4); modelEstem.setValueAt(StaticFunctions.significanceB(arr[0], arr[1]), 1, 5); modelEstem.setValueAt(StaticFunctions.getIntervalForEstemateB(arr[0], arr[1]), 1, 6); double[] tmp = new double[arr[0].size()]; double a = StaticFunctions.estimateA(arr[0], arr[1]); double b = StaticFunctions.estimateB(arr[0], arr[1]); for (int i = 0; i < arr[0].size(); i++) { tmp[i] = StaticFunctions.regression(arr[0].getNumber(i), a, b); } OrderedSeries t = new OrderedSeries(); t.loadFromArray(tmp); jLabelDet.setText(f.format(Math.pow(StaticFunctions.pairCorrelationCoef(arr[0], t), 2) * 100)); jLabelFtest.setText("" + f.format(StaticFunctions.getFtest(arr[0], arr[1]))); if (StaticFunctions.getFtest(arr[0], arr[1]) > Math .pow(Quantiles.Student(1 - 0.05 / 2, arr[0].size() - 2), 2)) { jLabelRes.setText("??? "); } else { jLabelRes.setText("??? "); } } else { arr[0] = null; arr[1] = null; clearAll(); jMenuItem1ActionPerformed(evt); } } } catch (IOException ex) { JOptionPane.showMessageDialog(null, "File has wrong information"); } }
From source file:com.alibaba.druid.benckmark.pool.Case4.java
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception { final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch endLatch = new CountDownLatch(threadCount); final CountDownLatch dumpLatch = new CountDownLatch(1); Thread[] threads = new Thread[threadCount]; final TableOperator operator = new TableOperator(); operator.setDataSource(dataSource);/*from w w w.j a va 2 s.c o m*/ operator.createTable(); for (int i = 0; i < threadCount; ++i) { Thread thread = new Thread() { public void run() { try { startLatch.await(); for (int i = 0; i < LOOP_COUNT; ++i) { operator.insert(); } } catch (Exception ex) { ex.printStackTrace(); } endLatch.countDown(); try { dumpLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }; threads[i] = thread; thread.start(); } long startMillis = System.currentTimeMillis(); long startYGC = TestUtil.getYoungGC(); long startFullGC = TestUtil.getFullGC(); startLatch.countDown(); endLatch.await(); long[] threadIdArray = new long[threads.length]; for (int i = 0; i < threads.length; ++i) { threadIdArray[i] = threads[i].getId(); } ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray); dumpLatch.countDown(); operator.dropTable(); long blockedCount = 0; long waitedCount = 0; for (int i = 0; i < threadInfoArray.length; ++i) { ThreadInfo threadInfo = threadInfoArray[i]; blockedCount += threadInfo.getBlockedCount(); waitedCount += threadInfo.getWaitedCount(); } long millis = System.currentTimeMillis() - startMillis; long ygc = TestUtil.getYoungGC() - startYGC; long fullGC = TestUtil.getFullGC() - startFullGC; System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC + " blocked " + NumberFormat.getInstance().format(blockedCount) // + " waited " + NumberFormat.getInstance().format(waitedCount)); }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initRangeAxis(ChartDefinitionVO chartDefinition) { int axisNumber = 0; int datasetNumber = 0; for (AxisDefinitionVO axisDefinition : chartDefinition.getAxisDefinitions()) { // configure the axis NumberAxis rangeAxis = new NumberAxis(axisDefinition.getLabel()); // set the properteis rangeAxis.setAutoRange(axisDefinition.isAutoRange()); if (axisDefinition.isAutoRange()) { rangeAxis.setAutoRangeIncludesZero(axisDefinition.isAutoRangeIncludesZero()); } else {//ww w . ja v a2s . c om rangeAxis.setLowerBound(axisDefinition.getLowerBound()); rangeAxis.setUpperBound(axisDefinition.getUpperBound()); } if (axisDefinition.getNumberFormat() != null) { rangeAxis.setNumberFormatOverride(new DecimalFormat(axisDefinition.getNumberFormat())); //##0.00% / "##0.000" } getPlot().setRangeAxis(axisNumber, rangeAxis); getPlot().setRangeAxisLocation(axisNumber, AxisLocation.BOTTOM_OR_RIGHT); // initialize datasets for (DatasetDefinitionVO datasetDefinition : axisDefinition.getDatasetDefinitions()) { XYDataset dataset; if (DatasetType.TIME.equals(datasetDefinition.getType())) { // create the time series collection dataset = new TimeSeriesCollection(); getPlot().setDataset(datasetNumber, dataset); // create the renderer XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); getPlot().setRenderer(datasetNumber, renderer); } else if (DatasetType.OHLC.equals(datasetDefinition.getType())) { // create the ohlc series collection dataset = new OHLCSeriesCollection(); getPlot().setDataset(datasetNumber, dataset); // create the renderer HideableCandlestickRenderer renderer = new HideableCandlestickRenderer(); renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator( new SimpleDateFormat("dd.MM.yyyy kk:mm:ss"), NumberFormat.getInstance())); getPlot().setRenderer(datasetNumber, renderer); } else { throw new IllegalArgumentException("illegal dataset type " + datasetDefinition.getType()); } getPlot().mapDatasetToRangeAxis(datasetNumber, axisNumber); // initialize series initSeries(datasetNumber, datasetDefinition, dataset); datasetNumber++; } axisNumber++; } }
From source file:com.nextgis.maplibui.fragment.CompassFragment.java
public static String formatNumber(Object value, int max, int min) { NumberFormat f = NumberFormat.getInstance(); f.setMaximumFractionDigits(max);//from w w w .j a v a 2 s .c o m f.setMinimumFractionDigits(min); f.setGroupingUsed(false); try { return f.format(value); } catch (IllegalArgumentException e) { return e.getLocalizedMessage(); } }
From source file:Bouncer.java
public AnimationFrame(Bouncer ac) { super();/*w ww .ja va 2s .c o m*/ setLayout(new BorderLayout()); add(ac, BorderLayout.CENTER); add(mStatusLabel = new Label(), BorderLayout.SOUTH); // Create a number formatter. mFormat = NumberFormat.getInstance(); mFormat.setMaximumFractionDigits(1); // Listen for the frame rate changes. ac.setRateListener(this); // Kick off the animation. Thread t = new Thread(ac); t.start(); }
From source file:com.glaf.dts.transform.MxTransformThread.java
@SuppressWarnings("unchecked") public void run() { logger.debug(taskId + "----------------execution-----------------"); TransformTask task = transformTaskService.getTransformTask(taskId); if (task != null) { if (task.getStatus() == 9 || task.getRetryTimes() > 3) { return; }/*from w w w . j a va 2 s . c o m*/ task.setStartTime(new java.util.Date()); task.setRetryTimes(task.getRetryTimes() + 1); task.setStatus(1); transformTaskService.save(task); } List<TableModel> resultList = new java.util.ArrayList<TableModel>(); Map<String, Object> singleDataMap = new HashMap<String, Object>(); Connection conn = null; PreparedStatement psmt = null; ResultSet rs = null; ResultSetMetaData rsmd = null; boolean success = true; long start = System.currentTimeMillis(); logger.debug("start:" + DateUtils.getDateTime(new java.util.Date())); try { Database database = getDatabaseService().getDatabaseById(queryDefinition.getDatabaseId()); if (database != null) { conn = DBConnectionFactory.getConnection(database.getName()); } else { conn = DBConnectionFactory.getConnection(); } logger.debug("conn:" + conn.toString()); String sql = queryDefinition.getSql(); sql = QueryUtils.replaceSQLVars(sql); List<Object> values = null; if (paramMap != null) { SqlExecutor sqlExecutor = JdbcUtils.rebuildSQL(sql, paramMap); sql = sqlExecutor.getSql(); values = (List<Object>) sqlExecutor.getParameter(); } logger.debug("--------------execute query----------------------"); logger.debug(queryDefinition.getTitle()); logger.debug("::sql::" + sql); psmt = conn.prepareStatement(sql); if (values != null && !values.isEmpty()) { JdbcUtils.fillStatement(psmt, values); logger.debug("::values::" + values); } List<ColumnDefinition> columns = new java.util.ArrayList<ColumnDefinition>(); rs = psmt.executeQuery(); rsmd = rs.getMetaData(); int count = rsmd.getColumnCount(); for (int i = 1; i <= count; i++) { int sqlType = rsmd.getColumnType(i); ColumnDefinition column = new ColumnDefinition(); column.setColumnName(rsmd.getColumnName(i)); column.setColumnLabel(rsmd.getColumnLabel(i)); column.setJavaType(FieldType.getJavaType(sqlType)); column.setPrecision(rsmd.getPrecision(i)); column.setScale(rsmd.getScale(i)); columns.add(column); } Set<String> cols = new HashSet<String>(); while (rs.next()) { int index = 0; TableModel rowModel = new TableModel(); ColumnModel cell01 = new ColumnModel(); cell01.setColumnName("ID"); cell01.setType("String"); rowModel.addColumn(cell01); rowModel.setIdColumn(cell01); cols.add(cell01.getColumnName()); ColumnModel cell04 = new ColumnModel(); cell04.setColumnName("AGGREGATIONKEY"); cell04.setType("String"); rowModel.addColumn(cell04); cols.add(cell04.getColumnName()); Iterator<ColumnDefinition> iterator = columns.iterator(); while (iterator.hasNext()) { ColumnDefinition column = iterator.next(); /** * ???? */ if (cols.contains(column.getColumnName())) { continue; } ColumnModel cell = new ColumnModel(); String columnName = column.getColumnName(); String javaType = column.getJavaType(); cell.setColumnName(columnName); cell.setType(javaType); index = index + 1; if ("String".equals(javaType)) { String value = rs.getString(columnName); cell.setStringValue(value); cell.setValue(value); } else if ("Integer".equals(javaType)) { try { Integer value = rs.getInt(columnName); cell.setIntValue(value); cell.setValue(value); } catch (Exception e) { String str = rs.getString(columnName); logger.error("integer:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); cell.setIntValue(num.intValue()); cell.setValue(cell.getIntValue()); logger.debug("?:" + num.intValue()); } } else if ("Long".equals(javaType)) { try { Long value = rs.getLong(columnName); cell.setLongValue(value); cell.setValue(value); } catch (Exception e) { String str = rs.getString(columnName); logger.error("long:" + str); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); cell.setLongValue(num.longValue()); cell.setValue(cell.getLongValue()); logger.debug("?:" + num.longValue()); } } else if ("Double".equals(javaType)) { try { Double d = rs.getDouble(columnName); cell.setDoubleValue(d); cell.setValue(d); } catch (Exception e) { String str = rs.getString(columnName); logger.error("double:" + str); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); cell.setDoubleValue(num.doubleValue()); cell.setValue(cell.getDoubleValue()); logger.debug("?:" + num.doubleValue()); } } else if ("Boolean".equals(javaType)) { Boolean value = rs.getBoolean(columnName); cell.setBooleanValue(value); cell.setValue(value); } else if ("Date".equals(javaType)) { Date value = rs.getTimestamp(columnName); cell.setDateValue(value); cell.setValue(value); } else { String value = rs.getString(columnName); cell.setStringValue(value); cell.setValue(value); } rowModel.addColumn(cell); if (resultList.isEmpty()) { singleDataMap.put(column.getColumnLabel(), cell.getValue()); } } resultList.add(rowModel); } logger.debug("--------------------resultList size:" + resultList.size()); } catch (Exception ex) { success = false; ex.printStackTrace(); logger.error(ex); throw new RuntimeException(ex); } finally { JdbcUtils.close(rs); JdbcUtils.close(psmt); JdbcUtils.close(conn); if (!success) { if (task != null) { task.setStatus(2); transformTaskService.save(task); } } } logger.debug("--------------execute mybatis save----------------------"); try { if (!StringUtils.equalsIgnoreCase(queryDefinition.getRotatingFlag(), "R2C")) { TransformTable tbl = new TransformTable(); tbl.createOrAlterTable(tableDefinition); } List<ColumnDefinition> columns = DBUtils.getColumnDefinitions(tableDefinition.getTableName()); if (columns != null && !columns.isEmpty()) { tableDefinition.setColumns(columns); } if (resultList != null && !resultList.isEmpty() && tableDefinition.getTableName() != null && tableDefinition.getAggregationKeys() != null) { logger.debug("RotatingFlag:" + queryDefinition.getRotatingFlag()); logger.debug("RotatingColumn:" + queryDefinition.getRotatingColumn()); /** * ???? */ if (StringUtils.equalsIgnoreCase(queryDefinition.getRotatingFlag(), "R2C") && StringUtils.isNotEmpty(queryDefinition.getRotatingColumn()) && resultList.size() == 1) { logger.debug("?dataMap?:" + singleDataMap); logger.debug("AggregationKeys:" + tableDefinition.getAggregationKeys()); ColumnDefinition idField = columnMap.get(tableDefinition.getAggregationKeys().toLowerCase()); ColumnDefinition field = columnMap.get(queryDefinition.getRotatingColumn().toLowerCase()); logger.debug("idField:" + idField); logger.debug("field:" + field); if (idField != null && field != null) { String javaType = field.getJavaType(); List<TableModel> list = new ArrayList<TableModel>(); Set<Entry<String, Object>> entrySet = singleDataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { continue; } TableModel tableModel = new TableModel(); tableModel.setTableName(queryDefinition.getTargetTableName()); ColumnModel cell = new ColumnModel(); cell.setColumnName(queryDefinition.getRotatingColumn()); cell.setType(javaType); // logger.debug(cell.getColumnName()+"->"+javaType); if ("String".equals(javaType)) { cell.setStringValue(ParamUtils.getString(singleDataMap, key)); cell.setValue(cell.getStringValue()); } else if ("Integer".equals(javaType)) { cell.setIntValue(ParamUtils.getInt(singleDataMap, key)); cell.setValue(cell.getIntValue()); } else if ("Long".equals(javaType)) { cell.setLongValue(ParamUtils.getLong(singleDataMap, key)); cell.setValue(cell.getLongValue()); } else if ("Double".equals(javaType)) { cell.setDoubleValue(ParamUtils.getDouble(singleDataMap, key)); cell.setValue(cell.getDoubleValue()); } else if ("Date".equals(javaType)) { cell.setDateValue(ParamUtils.getDate(singleDataMap, key)); cell.setValue(cell.getDateValue()); } else { cell.setValue(value); } tableModel.addColumn(cell); ColumnModel idColumn = new ColumnModel(); idColumn.setColumnName(tableDefinition.getAggregationKeys()); idColumn.setJavaType(idField.getJavaType()); idColumn.setValue(key); tableModel.setIdColumn(idColumn); list.add(tableModel); } logger.debug("update datalist:" + list); tableDataService.updateTableData(list); } } else { tableDataService.saveAll(tableDefinition, null, resultList); } } resultList.clear(); resultList = null; long time = System.currentTimeMillis() - start; if (task != null) { task.setEndTime(new java.util.Date()); task.setStatus(9); task.setDuration(time); } logger.debug("execute time(ms)--------------------------" + time); } catch (Exception ex) { if (task != null) { task.setStatus(2); } ex.printStackTrace(); logger.error(ex); throw new RuntimeException(ex); } finally { if (task != null) { transformTaskService.save(task); if (task.getStatus() != 9) { this.run(); } } } }
From source file:com.nubits.nubot.trading.wrappers.BitcoinCoIDWrapper.java
private ApiResponse enterOrder(String type, CurrencyPair pair, double amount, double price) { ApiResponse apiResponse = new ApiResponse(); String url = API_BASE_URL; String method = API_TRADE;/* ww w . java2 s .c o m*/ HashMap<String, String> args = new HashMap<>(); boolean isGet = false; String order_id = null; args.put("pair", pair.toStringSep()); args.put("type", type.toLowerCase()); NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(8); args.put("price", nf.format(price)); if (type.equals(Constant.SELL)) { args.put(pair.getPaymentCurrency().getCode().toLowerCase(), nf.format(amount * price)); args.put(pair.getOrderCurrency().getCode().toLowerCase(), nf.format(amount)); } else { args.put(pair.getPaymentCurrency().getCode().toLowerCase(), nf.format(amount * price)); } ApiResponse response = getQuery(url, method, args, true, isGet); if (response.isPositive()) { JSONObject httpAnswerJson = (JSONObject) response.getResponseObject(); JSONObject data = (JSONObject) httpAnswerJson.get("return"); order_id = data.get("order_id").toString(); apiResponse.setResponseObject(order_id); } else { apiResponse = response; } return apiResponse; }
From source file:com.liusoft.dlog4j.velocity.VelocityTool.java
/** * (??)// w ww . ja v a 2s. co m * ?,? * @return */ public String festival() { long[] ds = LunarCalendar.today(); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(0); nf.setMinimumIntegerDigits(2); String nongli = nf.format(ds[1]) + nf.format(ds[2]); Calendar cal = Calendar.getInstance(); String yangli = nf.format(cal.get(Calendar.MONTH) + 1) + nf.format(cal.get(Calendar.DATE)); //System.out.printf("nongli=%s,yangli=%s\r\n",nongli,yangli); String f_nl = getMessage(request, "festival", 'Y' + nongli); String f_yl = getMessage(request, "festival", yangli); if (f_nl != null && f_yl != null) return f_yl + "," + f_nl; if (f_nl != null) return f_nl; if (f_yl != null) return f_yl; return null; }
From source file:com.alibaba.druid.benckmark.pool.Case1.java
private void p0(final DataSource dataSource, String name, int threadCount) throws Exception { final CountDownLatch startLatch = new CountDownLatch(1); final CountDownLatch endLatch = new CountDownLatch(threadCount); final CountDownLatch dumpLatch = new CountDownLatch(1); Thread[] threads = new Thread[threadCount]; for (int i = 0; i < threadCount; ++i) { Thread thread = new Thread() { public void run() { try { startLatch.await();//from w w w . jav a2s. c o m for (int i = 0; i < LOOP_COUNT; ++i) { Connection conn = dataSource.getConnection(); conn.close(); } } catch (Exception ex) { ex.printStackTrace(); } endLatch.countDown(); try { dumpLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } } }; threads[i] = thread; thread.start(); } long startMillis = System.currentTimeMillis(); long startYGC = TestUtil.getYoungGC(); long startFullGC = TestUtil.getFullGC(); startLatch.countDown(); endLatch.await(); long[] threadIdArray = new long[threads.length]; for (int i = 0; i < threads.length; ++i) { threadIdArray[i] = threads[i].getId(); } ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray); dumpLatch.countDown(); long blockedCount = 0; long waitedCount = 0; for (int i = 0; i < threadInfoArray.length; ++i) { ThreadInfo threadInfo = threadInfoArray[i]; blockedCount += threadInfo.getBlockedCount(); waitedCount += threadInfo.getWaitedCount(); } long millis = System.currentTimeMillis() - startMillis; long ygc = TestUtil.getYoungGC() - startYGC; long fullGC = TestUtil.getFullGC() - startFullGC; System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC + " blocked " + NumberFormat.getInstance().format(blockedCount) // + " waited " + NumberFormat.getInstance().format(waitedCount) + " physicalConn " + physicalConnStat.get()); }