List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:cc.tooyoung.common.db.JdbcTemplate.java
public int queryForInt(String sql, Object[] args) throws DataAccessException { Number number = (Number) queryForObject(sql, args, Integer.class); return (number != null ? number.intValue() : 0); }
From source file:edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.java
protected void computeWeightedPathsFromSource(V root, int depth) { int pathIdx = 1; for (E e : getGraph().getOutEdges(root)) { this.pathIndices.put(e, pathIdx); this.roots.put(e, root); newVertexEncountered(pathIdx, getGraph().getEndpoints(e).getSecond(), root); pathIdx++;// w ww. ja v a 2s . co m } List<E> edges = new ArrayList<E>(); V virtualNode = vertexFactory.create(); getGraph().addVertex(virtualNode); E virtualSinkEdge = edgeFactory.create(); getGraph().addEdge(virtualSinkEdge, virtualNode, root); edges.add(virtualSinkEdge); int currentDepth = 0; while (currentDepth <= depth) { double currentWeight = Math.pow(mAlpha, -1.0 * currentDepth); for (E currentEdge : edges) { incrementRankScore(getGraph().getEndpoints(currentEdge).getSecond(), // currentWeight); } if ((currentDepth == depth) || (edges.size() == 0)) break; List<E> newEdges = new ArrayList<E>(); for (E currentSourceEdge : edges) { //Iterator sourceEdgeIt = edges.iterator(); sourceEdgeIt.hasNext();) { Number sourcePathIndex = this.pathIndices.get(currentSourceEdge); // from the currentSourceEdge, get its opposite end // then iterate over the out edges of that opposite end V newDestVertex = getGraph().getEndpoints(currentSourceEdge).getSecond(); Collection<E> outs = getGraph().getOutEdges(newDestVertex); for (E currentDestEdge : outs) { V destEdgeRoot = this.roots.get(currentDestEdge); V destEdgeDest = getGraph().getEndpoints(currentDestEdge).getSecond(); if (currentSourceEdge == virtualSinkEdge) { newEdges.add(currentDestEdge); continue; } if (destEdgeRoot == root) { continue; } if (destEdgeDest == getGraph().getEndpoints(currentSourceEdge).getFirst()) {//currentSourceEdge.getSource()) { continue; } Set<Number> pathsSeen = this.pathsSeenMap.get(destEdgeDest); if (pathsSeen == null) { newVertexEncountered(sourcePathIndex.intValue(), destEdgeDest, root); } else if (roots.get(destEdgeDest) != root) { roots.put(destEdgeDest, root); pathsSeen.clear(); pathsSeen.add(sourcePathIndex); } else if (!pathsSeen.contains(sourcePathIndex)) { pathsSeen.add(sourcePathIndex); } else { continue; } this.pathIndices.put(currentDestEdge, sourcePathIndex); this.roots.put(currentDestEdge, root); newEdges.add(currentDestEdge); } } edges = newEdges; currentDepth++; } getGraph().removeVertex(virtualNode); }
From source file:com.evolveum.openicf.lotus.DominoConnector.java
private void addMailQuotaAttributes(ConnectorObjectBuilder object, String mailDbname, Set<String> attrToGet) throws NotesException { LOG.info("Adding mail quota attributes for mail db {0}.", mailDbname); Session session = connection.getSession(); Database db = null;//from ww w. j a v a 2 s .co m try { db = session.getDatabase(null, mailDbname, false); if (db == null) { return; } if (isAttrToGet(attrToGet, MAIL_QUOTA_SIZE_LIMIT)) { object.addAttribute(build(MAIL_QUOTA_SIZE_LIMIT, Integer.valueOf(db.getSizeQuota()))); } if (isAttrToGet(attrToGet, MAIL_QUOTA_WARNING_THRESHOLD)) { Number size = db.getSizeWarning(); object.addAttribute(build(MAIL_QUOTA_WARNING_THRESHOLD, size.intValue())); } } catch (NotesException ex) { if (ex.id == NotesError.NOTES_ERR_DBNOACCESS) { LOG.error("User {0} doesn't have rights to access DB quota limits for {1}, reason: {2}", config.getAdminName(), mailDbname, getExceptionMessage(ex)); return; } LOG.error(ex, "Couldn't get mail quota attributes for user, reason: {0}", getExceptionMessage(ex)); throw ex; } finally { recycleQuietly(db); } }
From source file:com.glaf.core.jdbc.QueryHelper.java
/** * @param conn/*from w ww .j av a2 s . c o m*/ * ? * @param sqlExecutor * ? * @param start * 0 * @param pageSize * ? * @return */ @SuppressWarnings("unchecked") public List<Map<String, Object>> getResultList(Connection conn, SqlExecutor sqlExecutor, int start, int pageSize) { if (!DBUtils.isLegalQuerySql(sqlExecutor.getSql())) { throw new RuntimeException(" SQL statement illegal "); } List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); String sql = sqlExecutor.getSql(); PreparedStatement psmt = null; ResultSet rs = null; ResultSetMetaData rsmd = null; boolean supportsPhysicalPage = false; try { Dialect dialect = DBConfiguration.getDatabaseDialect(conn); if (dialect != null && dialect.supportsPhysicalPage()) { supportsPhysicalPage = true; sql = dialect.getLimitString(sql, start, pageSize); logger.debug("sql=" + sqlExecutor.getSql()); logger.debug(">>sql=" + sql); } psmt = conn.prepareStatement(sql); if (sqlExecutor.getParameter() != null) { List<Object> values = (List<Object>) sqlExecutor.getParameter(); JdbcUtils.fillStatement(psmt, values); logger.debug(">>values=" + 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 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.camelStyle(column.getColumnLabel().toLowerCase())); columns.add(column); } if (!supportsPhysicalPage) { logger.debug("---------------------skipRows:" + start); this.skipRows(rs, start, pageSize); } logger.debug("---------------------columns:" + columns.size()); logger.debug("---------------------start:" + start); logger.debug("---------------------pageSize:" + pageSize); // int index = 0; while (rs.next()) { // index++; // logger.debug("---------------------row index:" + index); 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(); if ("String".equals(javaType)) { String value = rs.getString(column.getIndex()); if (value != null) { value = value.trim(); rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } } else if ("Integer".equals(javaType)) { try { Integer value = rs.getInt(column.getIndex()); rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } 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, rowMap.get(columnName)); logger.debug("?:" + num.longValue()); } } else if ("Double".equals(javaType)) { try { Double d = rs.getDouble(column.getIndex()); rowMap.put(columnName, d); rowMap.put(columnLabel, rowMap.get(columnName)); } 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, rowMap.get(columnName)); 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)) { } 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)); } } } 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, Object[] args, int[] argTypes) throws DataAccessException { Number number = (Number) queryForObject(sql, args, argTypes, Integer.class); return (number != null ? number.intValue() : 0); }
From source file:com.prowidesoftware.swift.model.field.Field331.java
/** * Set the component1 from a Number object. * <br />// ww w . jav a2 s .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 setComponent1(String) * method. * * @see #setComponent1(String) * * @param component1 the Number with the component1 content to set */ public Field331 setComponent1(java.lang.Number component1) { if (component1 != null) { setComponent(1, "" + component1.intValue()); } return this; }
From source file:com.prowidesoftware.swift.model.field.Field331.java
/** * Set the component6 from a Number object. * <br />/* w ww .j av a 2 s . com*/ * <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 setComponent6(String) * method. * * @see #setComponent6(String) * * @param component6 the Number with the component6 content to set */ public Field331 setComponent6(java.lang.Number component6) { if (component6 != null) { setComponent(6, "" + component6.intValue()); } return this; }
From source file:com.prowidesoftware.swift.model.field.Field331.java
/** * Set the component7 from a Number object. * <br />/*from w ww. j ava2s . 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 setComponent7(String) * method. * * @see #setComponent7(String) * * @param component7 the Number with the component7 content to set */ public Field331 setComponent7(java.lang.Number component7) { if (component7 != null) { setComponent(7, "" + component7.intValue()); } return this; }
From source file:com.prowidesoftware.swift.model.field.Field331.java
/** * Set the component8 from a Number object. * <br />/*from w w w . java 2s . com*/ * <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 setComponent8(String) * method. * * @see #setComponent8(String) * * @param component8 the Number with the component8 content to set */ public Field331 setComponent8(java.lang.Number component8) { if (component8 != null) { setComponent(8, "" + component8.intValue()); } return this; }
From source file:com.prowidesoftware.swift.model.field.Field331.java
/** * Set the component9 from a Number object. * <br />//from w w w . j a v a2 s . com * <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 setComponent9(String) * method. * * @see #setComponent9(String) * * @param component9 the Number with the component9 content to set */ public Field331 setComponent9(java.lang.Number component9) { if (component9 != null) { setComponent(9, "" + component9.intValue()); } return this; }