List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:com.googlecode.flyway.core.metadatatable.MetaDataTable.java
/** * Converts this number into an Integer. * * @param number The Number to convert./*ww w. j a v a 2 s.co m*/ * @return The matching Integer. */ private Integer toInteger(Number number) { if (number == null) { return null; } return number.intValue(); }
From source file:arena.validation.PasswordStrengthValidation.java
public ValidationFailure validate(Object value) { if (value == null) { return null; }//w w w. ja v a 2s . c om /* adapted from the logic described at geekwisdom.com in the passwordchecker.js file: */ String strValue = value.toString(); int score = lengthScore(strValue); log.debug("Scores: length=" + score); int letterScore = lettersScore(strValue); score += letterScore; log.debug("Scores: letters=" + letterScore); int numberScore = numbersScore(strValue); score += numberScore; log.debug("Scores: numbers=" + numberScore); int specialCharsScore = specialCharsScore(strValue); score += specialCharsScore; log.debug("Scores: special=" + specialCharsScore); /* combinations: level 0 (1 points): letters and numbers exist level 1 (1 points): mixed case letters level 1 (2 points): letters, numbers and special characters exist level 1 (2 points): mixed case letters, numbers and special characters exist */ if (numberScore > 0 && letterScore > 0) { score += 1; } if (numberScore > 0 && letterScore > 0 && specialCharsScore > 0) { score += 2; } if (numberScore > 0 && letterScore >= 7 && specialCharsScore > 0) { score += 2; } Number minScore = (Number) getExtraInfo(); if (minScore == null) { minScore = new Integer(30); } log.debug("Scores: final=" + score + ", min=" + minScore); return (minScore.intValue() > score) ? new ValidationFailure(getFieldName(), Validation.PASSWORD_STRENGTH, value, new Integer(score)) : null; }
From source file:edu.uci.ics.jung.algorithms.flows.EdmondsKarpMaxFlow.java
private void updateResidualCapacities() { Number augmentingPathCapacity = parentCapacityMap.get(target); mMaxFlow += augmentingPathCapacity.intValue(); V currentVertex = target;/*from w ww.j a v a 2s .com*/ V parentVertex = null; while ((parentVertex = parentMap.get(currentVertex)) != currentVertex) { E currentEdge = mFlowGraph.findEdge(parentVertex, currentVertex); Number residualCapacity = residualCapacityMap.get(currentEdge); residualCapacity = residualCapacity.intValue() - augmentingPathCapacity.intValue(); residualCapacityMap.put(currentEdge, residualCapacity); E backEdge = mFlowGraph.findEdge(currentVertex, parentVertex); residualCapacity = residualCapacityMap.get(backEdge); residualCapacity = residualCapacity.intValue() + augmentingPathCapacity.intValue(); residualCapacityMap.put(backEdge, residualCapacity); currentVertex = parentVertex; } }
From source file:net.solarnetwork.node.dao.jdbc.consumption.JdbcConsumptionDatumDao.java
@Override @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List<ConsumptionDatum> getDatumNotUploaded(String destination) { return findDatumNotUploaded(new RowMapper<ConsumptionDatum>() { @Override//from w w w. j a va 2s. c om public ConsumptionDatum mapRow(ResultSet rs, int rowNum) throws SQLException { if (log.isTraceEnabled()) { log.trace("Handling result row " + rowNum); } ConsumptionDatum datum = new ConsumptionDatum(); int col = 1; datum.setCreated(rs.getTimestamp(col++)); datum.setSourceId(rs.getString(col++)); Number val = (Number) rs.getObject(col++); datum.setLocationId(val == null ? null : val.longValue()); val = (Number) rs.getObject(col++); datum.setWatts(val == null ? null : val.intValue()); val = (Number) rs.getObject(col++); datum.setWattHourReading(val == null ? null : val.longValue()); return datum; } }); }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert//from www. j a v a 2s .c o m * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class<?> targetClass) throws IllegalArgumentException { // Assert.notNull(number, "Number must not be null"); // Assert.notNull(targetClass, "Target class must not be null"); if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:com.opengamma.financial.analytics.volatility.surface.BloombergEquityFutureOptionVolatilitySurfaceInstrumentProvider.java
@Override /**//from w w w . j a v a2 s. c o m * Provides ExternalID for Bloomberg ticker, * given a reference date and an integer offset, the n'th subsequent option <p> * The format is prefix + date + callPutFlag + strike + postfix <p> * eg DJX 12/21/13 C145.0 Index * <p> * @param futureNumber n'th future following curve date * @param strike option's strike, expressed as price in %, e.g. 98.750 * @param surfaceDate date of curve validity; valuation date */ public ExternalId getInstrument(Number futureOptionNumber, Double strike, LocalDate surfaceDate) { Validate.notNull(futureOptionNumber, "futureOptionNumber"); final StringBuffer ticker = new StringBuffer(); ticker.append(getFutureOptionPrefix()); ticker.append(" "); LocalDate expiry = EXPIRY_UTILS.getFutureOptionExpiry(futureOptionNumber.intValue(), surfaceDate); ticker.append(FORMAT.print(expiry)); ticker.append(" "); ticker.append(strike > useCallAboveStrike() ? "C" : "P"); ticker.append(strike); ticker.append(" "); ticker.append(getPostfix()); return ExternalId.of(SCHEME, ticker.toString()); }
From source file:edu.ku.brc.af.ui.forms.validation.ValSpinner.java
public void setValue(Object value, String defaultValue) { Integer val = null; if (value == null && StringUtils.isNotEmpty(defaultValue)) { val = Integer.parseInt(defaultValue); } else if (value instanceof Number) { Number num = (Number) value; val = num.intValue(); } else if (value instanceof String) { val = Integer.parseInt((String) value); } else {// w ww . j a v a2s . c om val = 0; } if (val < minValue) { val = minValue; } else if (val > maxValue) { val = maxValue; } this.setValue(val); }
From source file:org.trade.ui.chart.renderer.VolumeBarRenderer.java
private void configureToolTips() { setBaseToolTipGenerator(new XYToolTipGenerator() { public String generateToolTip(XYDataset dataset, int series, int item) { StringBuilder result = new StringBuilder("<html>"); if (dataset instanceof VolumeDataset) { VolumeDataset d = (VolumeDataset) dataset; Number time = d.getX(series, item); Number volume = d.getVolume(series, item); result.append("<b>Volume:</b> ").append(new Quantity(volume.intValue())).append("<br/>"); result.append("<b>Date:</b> ").append(TOOLTIP_DATE_FORMAT.format(time)).append("<br/>"); }/*from w ww . ja va 2 s . c o m*/ return result.toString(); } }); }
From source file:com.krawler.br.nodes.Activity.java
/** * converts the given object value to the given primitive type's wrapper class * if possible (if it is a <tt>Number</tt>) * * @param type the premitive type name, may be: * <ul>/*from w ww. j a v a 2 s . c om*/ * <li><tt>byte</tt> * <li><tt>char</tt> * <li><tt>short</tt> * <li><tt>int</tt> * <li><tt>long</tt> * <li><tt>float</tt> * <li><tt>double</tt> * </ul> * @param value the original value * @return the converted value */ private Object convert(String type, Object value) { Object val = value; if (value instanceof Number) { Number num = (Number) value; if (Byte.class.getCanonicalName().equals(type)) val = new Byte(num.byteValue()); else if (Character.class.getCanonicalName().equals(type)) val = new Character((char) num.intValue()); else if (Short.class.getCanonicalName().equals(type)) val = new Short(num.shortValue()); else if (Integer.class.getCanonicalName().equals(type)) val = new Integer(num.intValue()); else if (Long.class.getCanonicalName().equals(type)) val = new Long(num.longValue()); else if (Float.class.getCanonicalName().equals(type)) val = new Float(num.floatValue()); else if (Double.class.getCanonicalName().equals(type)) val = new Double(num.doubleValue()); } return val; }
From source file:edu.uci.ics.jung.algorithms.flows.EdmondsKarpMaxFlow.java
protected boolean hasAugmentingPath() { mSinkPartitionNodes.clear();/*w w w.j av a 2s. c o m*/ mSourcePartitionNodes.clear(); mSinkPartitionNodes.addAll(mFlowGraph.getVertices()); Set<E> visitedEdgesMap = new HashSet<E>(); Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(source); while (!queue.isEmpty()) { V currentVertex = queue.remove(); mSinkPartitionNodes.remove(currentVertex); mSourcePartitionNodes.add(currentVertex); Number currentCapacity = parentCapacityMap.get(currentVertex); Collection<E> neighboringEdges = mFlowGraph.getOutEdges(currentVertex); for (E neighboringEdge : neighboringEdges) { V neighboringVertex = mFlowGraph.getDest(neighboringEdge); Number residualCapacity = residualCapacityMap.get(neighboringEdge); if (residualCapacity.intValue() <= 0 || visitedEdgesMap.contains(neighboringEdge)) continue; V neighborsParent = parentMap.get(neighboringVertex); Number neighborCapacity = parentCapacityMap.get(neighboringVertex); int newCapacity = Math.min(residualCapacity.intValue(), currentCapacity.intValue()); if ((neighborsParent == null) || newCapacity > neighborCapacity.intValue()) { parentMap.put(neighboringVertex, currentVertex); parentCapacityMap.put(neighboringVertex, new Integer(newCapacity)); visitedEdgesMap.add(neighboringEdge); if (neighboringVertex != target) { queue.add(neighboringVertex); } } } } boolean hasAugmentingPath = false; Number targetsParentCapacity = parentCapacityMap.get(target); if (targetsParentCapacity != null && targetsParentCapacity.intValue() > 0) { updateResidualCapacities(); hasAugmentingPath = true; } clearParentValues(); return hasAugmentingPath; }