List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:com.prowidesoftware.swift.model.field.Field98H.java
/** * Set the component2 from a Number object. * <br />// w w w .j a v a2s. co m * <em>If the component being set is a fixed length number, the argument will not be * padded.</em> It is recommended for these cases to use the setComponent2(String) * method. * * @see #setComponent2(String) * * @param component2 the Number with the component2 content to set */ public Field98H setComponent2(java.lang.Number component2) { if (component2 != null) { setComponent(2, "" + component2.intValue()); } return this; }
From source file:net.duckling.ddl.service.resource.dao.ResourceDAOImpl.java
@Override public synchronized int create(final Resource res) { GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); this.getJdbcTemplate().update(new PreparedStatementCreator() { @Override/*from w w w . j a va 2 s . c o m*/ public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = null; ps = conn.prepareStatement(SQL_CREATE, PreparedStatement.RETURN_GENERATED_KEYS); int i = 0; //tid,item_type,title,creator,creator_name,create_time,last_editor,last_editor_name,last_edit_time,last_version,tags,marked_users,bid ps.setInt(++i, res.getTid()); ps.setString(++i, res.getItemType()); ps.setString(++i, res.getTitle()); ps.setString(++i, res.getCreator()); ps.setTimestamp(++i, new Timestamp(res.getCreateTime().getTime())); ps.setString(++i, res.getLastEditor()); ps.setString(++i, res.getLastEditorName()); ps.setTimestamp(++i, new Timestamp(res.getLastEditTime().getTime())); ps.setInt(++i, res.getLastVersion()); ps.setString(++i, JsonUtil.getJSONString(res.getTagMap())); String fileType = (res.getFileType() != null) ? res.getFileType().toLowerCase() : res.getFileType(); ps.setString(++i, fileType); ps.setObject(++i, res.getMarkedUserSet()); ps.setInt(++i, res.getBid()); ps.setInt(++i, res.getOrderType()); ps.setString(++i, res.getStatus()); ps.setLong(++i, res.getSize()); ps.setBoolean(++i, res.isShared()); return ps; } }, keyHolder); Number key = keyHolder.getKey(); return (key == null) ? -1 : key.intValue(); }
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 .jav a 2s . co 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.rapidminer.gui.plotter.charts.ParetoChartPlotter.java
public void paintParetoChart(Graphics graphics) { prepareData();// w w w . j av a 2s. com JFreeChart chart = createChart(); if (chart != null) { // set the background color for the chart... chart.setBackgroundPaint(Color.white); chart.getPlot().setBackgroundPaint(Color.WHITE); // bar renderer --> own 3D effect CategoryPlot plot = chart.getCategoryPlot(); BarRenderer renderer = (BarRenderer) plot.getRenderer(); // renderer.setBarPainter(new StandardBarPainter()); renderer.setBarPainter(new RapidBarPainter()); renderer.setSeriesPaint(0, getColorProvider(true).getPointColor(1)); // labels on top of bars Map<String, String> barItemLabels = new HashMap<>(); Map<String, String> cumulativeItemLabels = new HashMap<>(); int groupSum = 0; int totalSum = 0; for (Object key : totalData.getKeys()) { String k = (String) key; try { Number groupValue = data.getValue(k); Number totalValue = totalData.getValue(k); groupSum += groupValue.intValue(); totalSum += totalValue.intValue(); barItemLabels.put(k, Tools.formatIntegerIfPossible(groupValue.doubleValue()) + " / " + Tools.formatIntegerIfPossible(totalValue.doubleValue())); cumulativeItemLabels.put(k, groupSum + " / " + totalSum); } catch (UnknownKeyException e) { // do nothing } } renderer.setSeriesItemLabelFont(0, LABEL_FONT); if (showBarLabelsFlag) { renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(barItemLabels)); if (isLabelRotating()) { renderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d)); renderer.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0d)); } } LineAndShapeRenderer renderer2 = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer(1); renderer2.setSeriesPaint(0, Color.GRAY.darker().darker()); renderer2.setSeriesItemLabelFont(0, LABEL_FONT); renderer2.setSeriesItemLabelPaint(0, Color.BLACK); if (isLabelRotating()) { renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d)); renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, -Math.PI / 2.0d)); } else { renderer2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT)); renderer2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BOTTOM_RIGHT)); } if (showCumulativeLabelsFlag) { renderer2.setSeriesItemLabelsVisible(0, true); renderer2.setSeriesItemLabelGenerator(0, new ParetoChartItemLabelGenerator(cumulativeItemLabels)); } // draw outlines renderer.setDrawBarOutline(true); // gridline colors plot.setRangeGridlinePaint(Color.BLACK); // legend settings LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); chart.draw((Graphics2D) graphics, drawRect); } }
From source file:com.couchbase.client.java.document.json.JsonObject.java
/** * Retrieves the value from the field name and casts it to {@link Integer}. * * Note that if value was stored as another numerical type, some truncation or rounding may occur. * * @param name the name of the field./* w w w . j a v a2s . c o m*/ * @return the result or null if it does not exist. */ public Integer getInt(String name) { //let it fail in the more general case where it isn't actually a number Number number = (Number) content.get(name); if (number == null) { return null; } else if (number instanceof Integer) { return (Integer) number; } else { return number.intValue(); //autoboxing to Integer } }
From source file:com.enonic.cms.business.core.content.index.ContentIndexServiceImpl.java
/** * @inheritDoc//from w ww . j av a2s . c o m */ public AggregatedResult query(AggregatedQuery query) { AggregatedQueryTranslator translator = new AggregatedQueryTranslator(); TranslatedQuery translated = translator.translate(query); List<Object[]> list = contentIndexDao.findIndexValues(translated.getQuery()); Object[] values = list.get(0); Number count = (Number) values[0]; Number minValue = (Number) values[1]; Number maxValue = (Number) values[2]; Number sumValue = (Number) values[3]; Number averageValue = (Number) values[4]; return new AggregatedResultImpl(count.intValue(), minValue == null ? 0 : minValue.floatValue(), maxValue == null ? 0 : maxValue.floatValue(), sumValue == null ? 0 : sumValue.floatValue(), averageValue == null ? 0 : averageValue.floatValue()); }
From source file:de.instantouch.model.io.SnakeJSONReader.java
public void read(SnakeType type, Object value) throws SnakeModelException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { if (type.hasReference()) { SnakeReference ref = type.getReference(); if (ref == null) { throw new SnakeNotInitializedException("reference is not initialized"); }/*from w ww. j a v a 2 s .co m*/ SnakeType key = ref.getKey(); if (key == null) { throw new SnakeNotInitializedException("no reference key container os given"); } read(key, value); } else { if (type instanceof SnakeEntity) { readEntity((SnakeEntity) type, value); } else if (type instanceof SnakeList) { readList((SnakeList) type, value); } else if (type instanceof SnakeMap) { readMap((SnakeMap) type, value); } else if (value == null) { type.setNull(); } else if (value instanceof String) { type.set(value.toString()); } else if (value instanceof Boolean) { type.set(value.toString()); } else if (value instanceof Number) { Number number = (Number) value; if (value instanceof Double) { type.set(number.doubleValue()); } else if (value instanceof Float) { type.set(number.floatValue()); } else if (value instanceof Byte) { type.set(number.byteValue()); } else if (value instanceof Short) { type.set(number.shortValue()); } else if (value instanceof Integer) { type.set(number.intValue()); } else if (value instanceof Long) { type.set(number.longValue()); } } } }
From source file:it.geosolutions.geobatch.destination.ingestion.OriginalArcsIngestionProcess.java
/** * @return/*from ww w .j av a2s. com*/ * @throws IOException */ private int getMaxIncidentalitaYear() throws IOException { Function max = filterFactory.function("Collection_Max", filterFactory.property("anno")); Number maxValue = (Number) max.evaluate(dataStore.getFeatureSource(INCIDENTALITA_FEATURE).getFeatures()); if (maxValue != null) { return maxValue.intValue(); } return Calendar.getInstance().get(Calendar.YEAR); }
From source file:com.ebay.pulsar.analytics.metricstore.druid.query.DruidQueryProcessor.java
private List<String> resortTopN(DruidSpecs druidSpecs, String dimension, List<Map<String, Object>> listOfResult) { StreamSummary<String> topN = new StreamSummary<String>(TOPN_MAX); for (Map<String, Object> map : listOfResult) { @SuppressWarnings("unchecked") List<Map<String, Object>> resultList = (List<Map<String, Object>>) map.get(RESULT); if (resultList != null) { for (Map<String, Object> result : resultList) { Number metricNum = (Number) result.get(druidSpecs.getSort()); ;// w ww . ja v a 2 s . co m String dimStr = (String) result.get(dimension); if (dimStr == null) { dimStr = ""; } topN.offer(dimStr, metricNum.intValue()); } } } return FluentIterable.from(topN.topK(druidSpecs.getLimit())) .transform(new Function<Counter<String>, String>() { @Override public String apply(Counter<String> input) { return input.getItem(); } }).toList(); }
From source file:name.wramner.jmstools.analyzer.DataProvider.java
private int findWithIntResult(String sql) { Number n = findWithCachedScalarResult(sql, Number.class); return n != null ? n.intValue() : 0; }