List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:com.prowidesoftware.swift.model.field.Field29G.java
/** * Set the component17 from a Number object. * <br />// ww w . j av a 2s . c o 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 setComponent17(String) * method. * * @see #setComponent17(String) * * @param component17 the Number with the component17 content to set */ public Field29G setComponent17(java.lang.Number component17) { if (component17 != null) { setComponent(17, "" + component17.intValue()); } return this; }
From source file:com.android.ddmuilib.HeapPanel.java
/** * Creates the chart below the statistics table *///from w w w .j av a2s . co m private void createChart() { mAllocCountDataSet = new DefaultCategoryDataset(); mChart = ChartFactory.createBarChart(null, "Size", "Count", mAllocCountDataSet, PlotOrientation.VERTICAL, false, true, false); // get the font to make a proper title. We need to convert the swt font, // into an awt font. Font f = mStatisticsBase.getFont(); FontData[] fData = f.getFontData(); // event though on Mac OS there could be more than one fontData, we'll only use // the first one. FontData firstFontData = fData[0]; java.awt.Font awtFont = SWTUtils.toAwtFont(mStatisticsBase.getDisplay(), firstFontData, true /* ensureSameSize */); mChart.setTitle(new TextTitle("Allocation count per size", awtFont)); Plot plot = mChart.getPlot(); if (plot instanceof CategoryPlot) { // get the plot CategoryPlot categoryPlot = (CategoryPlot) plot; // set the domain axis to draw labels that are displayed even with many values. CategoryAxis domainAxis = categoryPlot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); CategoryItemRenderer renderer = categoryPlot.getRenderer(); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { // get the key for the size of the allocation ByteLong columnKey = (ByteLong) dataset.getColumnKey(column); String rowKey = (String) dataset.getRowKey(row); Number value = dataset.getValue(rowKey, columnKey); return String.format("%1$d %2$s of %3$d bytes", value.intValue(), rowKey, columnKey.getValue()); } }); } mChartComposite = new ChartComposite(mStatisticsBase, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH, ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH, ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 3000, // max draw width. We don't want it to zoom, so we put a big number 3000, // max draw height. We don't want it to zoom, so we put a big number true, // off-screen buffer true, // properties true, // save true, // print false, // zoom true); // tooltips mChartComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); }
From source file:com.google.code.pentahoflashcharts.charts.AbstractChartFactory.java
public Axis setupDomain() { String[] labels = null;/*from w w w. j a va 2s. com*/ Number domainMin = null; Number domainMax = null; Integer stepforchart = null; if (CATEGORY_TYPE.equals(datasetType)) { int rowCount = getRowCount(); labels = new String[rowCount]; for (int j = 0; j < rowCount; j++) { labels[j] = getRowHeader(j); } } else if (XYZ_TYPE.equals(datasetType) || XY_TYPE.equals(datasetType)) { domainMin = ((Number) getValueAt(0, 0)).intValue(); domainMax = domainMin; // Iterate over rows for (int r = 1; r < getRowCount(); r++) { if (domainMin.intValue() > ((Number) getValueAt(r, 0)).intValue()) { domainMin = ((Number) getValueAt(r, 0)).intValue(); } if (domainMax.intValue() < ((Number) getValueAt(r, 0)).intValue()) { domainMax = ((Number) getValueAt(r, 0)).intValue(); } } int steps = 9; int diff = domainMax.intValue() - domainMin.intValue(); Node temp = chartNode.selectSingleNode(DOMAIN_STEPS_NODE_LOC); if (getValue(temp) != null) { steps = new Integer(getValue(temp)).intValue(); } int chunksize = diff / steps; if (chunksize > 0) { stepforchart = new Integer(chunksize); } // If actual min is positive, don't go below ZERO if (domainMin.intValue() > 0 && domainMin.intValue() - chunksize < 0) { domainMin = 0; } else { domainMin = domainMin.intValue() - chunksize; } domainMax = domainMin.intValue() + (chunksize * (steps + 2)); temp = chartNode.selectSingleNode(DOMAIN_MINIMUM_NODE_LOC); if (getValue(temp) != null) { domainMin = new Integer(getValue(temp)).intValue(); } temp = chartNode.selectSingleNode(DOMAIN_MAXIMUM_NODE_LOC); if (getValue(temp) != null) { domainMax = new Integer(getValue(temp)).intValue(); } } String domainColor = AXIS_COLOR_DEFAULT; String domainGridColor = AXIS_GRID_COLOR_DEFAULT; int domainStroke = 1; Node temp = chartNode.selectSingleNode(DOMAIN_COLOR_NODE_LOC); if (getValue(temp) != null) { domainColor = getValue(temp); } temp = chartNode.selectSingleNode(DOMAIN_GRID_COLOR_NODE_LOC); if (getValue(temp) != null) { domainGridColor = getValue(temp); } temp = chartNode.selectSingleNode(DOMAIN_STROKE_NODE_LOC); if (getValue(temp) != null) { domainStroke = Integer.parseInt(getValue(temp)); } // Orientation temp = chartNode.selectSingleNode(ORIENTATION_NODE_LOC); if (getValue(temp) != null) { orientation = getValue(temp); } else { orientation = ORIENTATION_DEFAULT; } if (HORIZONTAL_ORIENTATION.equals(orientation)) { YAxis yaxis = new YAxis(); if (labels != null) { // BISERVER-3075: must reverse the category labels on hbar // charts due to bug in OFC2. String[] reversedLabels = new String[labels.length]; int reversedLabelCount = 0; for (int i = reversedLabels.length - 1; i >= 0; i--) { reversedLabels[reversedLabelCount++] = labels[i]; } yaxis.setLabels(reversedLabels); } yaxis.setStroke(domainStroke); yaxis.setColour(domainColor); yaxis.setGridColour(domainGridColor); if (domainMin != null && domainMax != null) { yaxis.setRange(domainMin.intValue(), domainMax.intValue(), stepforchart); } chart.setYAxis(yaxis); return yaxis; } else { XAxis xaxis = new XAxis(); if (labels != null) { xaxis.addLabels(labels); } xaxis.setStroke(domainStroke); xaxis.setColour(domainColor); xaxis.setGridColour(domainGridColor); if (domainMin != null && domainMax != null) { xaxis.setRange(domainMin.intValue(), domainMax.intValue(), stepforchart); } chart.setXAxis(xaxis); return xaxis; } }
From source file:com.glaf.core.jdbc.QueryHelper.java
/** * @param conn//from w w w . jav a2 s . co m * ? * @param start * 0 * @param pageSize * ? * @param sql * ? * @param paramMap * ? * @return */ @SuppressWarnings("unchecked") public ResultModel getResultList(Connection conn, String sql, Map<String, Object> paramMap, int start, int pageSize) { if (!DBUtils.isLegalQuerySql(sql)) { throw new RuntimeException(" SQL statement illegal "); } ResultModel resultModel = new ResultModel(); boolean supportsPhysicalPage = false; PreparedStatement psmt = null; ResultSetMetaData rsmd = null; ResultSet rs = null; Dialect dialect = null; try { dialect = DBConfiguration.getDatabaseDialect(conn); if (dialect != null && dialect.supportsPhysicalPage()) { logger.debug("sql=" + sql); supportsPhysicalPage = dialect.supportsPhysicalPage(); sql = dialect.getLimitString(sql, start, pageSize); logger.debug(">>sql=" + sql); } List<Object> values = null; if (paramMap != null) { SqlExecutor sqlExecutor = DBUtils.replaceSQL(sql, paramMap); sql = sqlExecutor.getSql(); values = (List<Object>) sqlExecutor.getParameter(); } logger.debug("sql:\n" + sql); logger.debug("values:" + values); psmt = conn.prepareStatement(sql); if (values != null && !values.isEmpty()) { JdbcUtils.fillStatement(psmt, values); } List<ColumnDefinition> columns = new 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.setIndex(i); 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)); if (column.getScale() == 0 && sqlType == Types.NUMERIC) { column.setJavaType("Long"); } column.setName(StringTools.lower(StringTools.camelStyle(column.getColumnLabel()))); columns.add(column); } resultModel.setHeaders(columns); if (!supportsPhysicalPage) { this.skipRows(rs, start); } int k = 0; while (rs.next() && k++ < pageSize) { int index = 0; RowModel rowModel = new RowModel(); Iterator<ColumnDefinition> iterator = columns.iterator(); while (iterator.hasNext()) { ColumnDefinition column = iterator.next(); ColumnDefinition c = new ColumnDefinition(); c.setColumnName(column.getColumnName()); c.setColumnLabel(column.getColumnLabel()); c.setName(column.getName()); c.setJavaType(column.getJavaType()); c.setPrecision(column.getPrecision()); c.setScale(column.getScale()); String javaType = column.getJavaType(); index = index + 1; if ("String".equals(javaType)) { String value = rs.getString(column.getIndex()); c.setValue(value); } else if ("Integer".equals(javaType)) { try { Integer value = rs.getInt(column.getIndex()); c.setValue(value); } catch (Exception e) { String str = rs.getString(column.getIndex()); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); c.setValue(num.intValue()); } } else if ("Long".equals(javaType)) { try { Long value = rs.getLong(column.getIndex()); c.setValue(value); } catch (Exception e) { String str = rs.getString(column.getIndex()); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); c.setValue(num.longValue()); } } else if ("Double".equals(javaType)) { try { Double value = rs.getDouble(column.getIndex()); c.setValue(value); } catch (Exception e) { String str = rs.getString(column.getIndex()); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); c.setValue(num.doubleValue()); } } else if ("Boolean".equals(javaType)) { Boolean value = rs.getBoolean(column.getIndex()); c.setValue(value); } else if ("Date".equals(javaType)) { Timestamp value = rs.getTimestamp(column.getIndex()); c.setValue(value); } else { c.setValue(rs.getObject(column.getIndex())); } rowModel.addColumn(c); } resultModel.addRow(rowModel); } } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(psmt); JdbcUtils.close(rs); } return resultModel; }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
@Override public int getProductCount() { StringBuilder sql = new StringBuilder(); sql.append("select count(*) from business_unit"); Query query = entityManager.createNativeQuery(sql.toString()); Number result = (Number) query.getSingleResult(); return result.intValue(); }
From source file:it.drwolf.ridire.index.cwb.CWBConcordancer.java
private boolean isFunctionalDomain(String domainDescription) { Number n = (Number) this.entityManager .createQuery("select count(fm.id) from FunctionalMetadatum fm where fm.description=:des") .setParameter("des", domainDescription).getSingleResult(); if (n.intValue() > 0) { return true; }// ww w.j ava2 s .c o m return false; }
From source file:com.floreantpos.model.dao.TicketDAO.java
public int getNumTickets(Date start, Date end) { Session session = null;//w w w . j a v a 2 s . c o m Criteria criteria = null; try { session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); if (start != null) criteria.add(Restrictions.ge(Ticket.PROP_DELIVERY_DATE, start)); if (end != null) criteria.add(Restrictions.le(Ticket.PROP_DELIVERY_DATE, end)); criteria.add(Restrictions.isNotNull(Ticket.PROP_DELIVERY_DATE)); criteria.setProjection(Projections.rowCount()); Number rowCount = (Number) criteria.uniqueResult(); if (rowCount != null) { return rowCount.intValue(); } return 0; } finally { closeSession(session); } }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
/** * dao????//w w w . j av a 2 s . com */ @Override public boolean verificationNameOrLic(String val, String type) throws DaoException { int count = 0; try { String jpql = ""; if (type.equals("name")) { jpql = "SELECT count(*) FROM business_unit WHERE name=?1"; } else { jpql = "SELECT count(*) FROM business_unit WHERE license_no=?1"; } Query query = entityManager.createNativeQuery(jpql).setParameter(1, val); Number result = (Number) query.getSingleResult(); count = result.intValue(); } catch (Exception e) { throw new DaoException("dao????", e); } return count > 0 ? true : false; }
From source file:com.glaf.core.jdbc.QueryHelper.java
/** * @param conn/*from w w w .j av a2 s .c om*/ * ? * @param sqlExecutor * * @return */ @SuppressWarnings("unchecked") public List<Map<String, Object>> getResultList(Connection conn, SqlExecutor sqlExecutor) { if (!DBUtils.isLegalQuerySql(sqlExecutor.getSql())) { throw new RuntimeException(" SQL statement illegal "); } List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); PreparedStatement psmt = null; ResultSet rs = null; ResultSetMetaData rsmd = null; try { psmt = conn.prepareStatement(sqlExecutor.getSql()); if (sqlExecutor.getParameter() != null) { List<Object> values = (List<Object>) sqlExecutor.getParameter(); JdbcUtils.fillStatement(psmt, values); } rs = psmt.executeQuery(); if (conf.getBoolean("useMyBatisResultHandler", false)) { resultList = this.getResults(rs); } else { rsmd = rs.getMetaData(); int count = rsmd.getColumnCount(); List<ColumnDefinition> columns = new ArrayList<ColumnDefinition>(); for (int index = 1; index <= count; index++) { int sqlType = rsmd.getColumnType(index); ColumnDefinition column = new ColumnDefinition(); column.setIndex(index); column.setColumnName(rsmd.getColumnName(index)); column.setColumnLabel(rsmd.getColumnLabel(index)); column.setJavaType(FieldType.getJavaType(sqlType)); column.setPrecision(rsmd.getPrecision(index)); column.setScale(rsmd.getScale(index)); if (column.getScale() == 0 && sqlType == Types.NUMERIC) { column.setJavaType("Long"); } column.setName(StringTools.camelStyle(column.getColumnLabel().toLowerCase())); columns.add(column); } int startIndex = 1; while (rs.next() && startIndex <= 50000) { int index = 0; startIndex++; Map<String, Object> rowMap = new HashMap<String, Object>(); Iterator<ColumnDefinition> iterator = columns.iterator(); while (iterator.hasNext()) { ColumnDefinition column = iterator.next(); String columnLabel = column.getColumnLabel(); String columnName = column.getColumnName(); if (StringUtils.isEmpty(columnName)) { columnName = column.getColumnLabel(); } columnName = columnName.toLowerCase(); String javaType = column.getJavaType(); index = index + 1; if ("String".equals(javaType)) { String value = rs.getString(column.getIndex()); if (value != null) { value = value.trim(); rowMap.put(columnName, value); rowMap.put(columnLabel, value); } } else if ("Integer".equals(javaType)) { try { Integer value = rs.getInt(column.getIndex()); rowMap.put(columnName, value); rowMap.put(columnLabel, value); } catch (Exception e) { String str = rs.getString(column.getIndex()); 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); rowMap.put(columnName, num.intValue()); rowMap.put(columnLabel, rowMap.get(columnName)); logger.debug("?:" + num.intValue()); } } else if ("Long".equals(javaType)) { try { Long value = rs.getLong(column.getIndex()); rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("long:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.longValue()); rowMap.put(columnLabel, num.longValue()); logger.debug("?:" + num.longValue()); } } else if ("Double".equals(javaType)) { try { Double d = rs.getDouble(column.getIndex()); rowMap.put(columnName, d); rowMap.put(columnLabel, d); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("double:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.doubleValue()); rowMap.put(columnLabel, num.doubleValue()); logger.debug("?:" + num.doubleValue()); } } else if ("Boolean".equals(javaType)) { rowMap.put(columnName, rs.getBoolean(column.getIndex())); rowMap.put(columnLabel, rowMap.get(columnName)); } else if ("Date".equals(javaType)) { rowMap.put(columnName, rs.getTimestamp(column.getIndex())); rowMap.put(columnLabel, rowMap.get(columnName)); } else if ("Blob".equals(javaType)) { // ignore } else { Object value = rs.getObject(column.getIndex()); if (value != null) { if (value instanceof String) { value = (String) value.toString().trim(); } rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } } } rowMap.put("startIndex", startIndex); resultList.add(rowMap); } } logger.debug(">resultList size=" + resultList.size()); return resultList; } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(psmt); JdbcUtils.close(rs); } }
From source file:cc.tooyoung.common.db.JdbcTemplate.java
public int queryForInt(String sql) throws DataAccessException { Number number = (Number) queryForObject(sql, Integer.class); return (number != null ? number.intValue() : 0); }