List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:com.branded.holdings.qpc.repository.jdbc.JdbcOwnerRepositoryImpl.java
@Override public void save(Owner owner) throws DataAccessException { BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner); if (owner.isNew()) { Number newKey = this.insertOwner.executeAndReturnKey(parameterSource); owner.setId(newKey.intValue()); } else {/*w w w .j a va 2 s . co m*/ this.namedParameterJdbcTemplate .update("UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " + "city=:city, telephone=:telephone WHERE id=:id", parameterSource); } }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert// w ww . java 2 s . co 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 { 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.microsoft.azure.management.datalake.store.uploader.UploadMetadataGeneratorTests.java
@Test public void UploadMetadataGenerator_AlignSegmentsToRecordBoundariesTooLargeRecord() throws IOException { //We keep creating a file, by appending a number of bytes to it (taken from FileLengthsInMB). //At each iteration, we append a new blob of data, and then run the whole test on the entire file Random rnd = new Random(0); File folderPath = new File(MessageFormat.format("{0}\\uploadtest", new File(".").getAbsolutePath())); File filePath = new File(folderPath, "verifymetadata.txt"); try {// w w w . ja v a 2 s .co m if (!folderPath.exists()) { folderPath.mkdirs(); } if (filePath.exists()) { filePath.delete(); } for (Number lengthMB : FileLengthsMB) { if (lengthMB.intValue() > MaxAppendLength) { int length = lengthMB.intValue() * 1024 * 1024; AppendToFile(filePath.getAbsolutePath(), length, rnd, MaxAppendLength + 1, MaxAppendLength + 10); String metadataFilePath = filePath + ".metadata.txt"; UploadParameters up = new UploadParameters(filePath.getAbsolutePath(), filePath.getAbsolutePath(), null, 1, false, false, false, 4 * 1024 * 1024, null); UploadMetadataGenerator mg = new UploadMetadataGenerator(up, MaxAppendLength); try { mg.createNewMetadata(metadataFilePath); Assert.assertTrue( "Method createNewMetadata should fail due to record boundaries being being too large for the record, but didn't", false); } catch (Exception e) { // do nothing, expected } } } } finally { if (folderPath.exists()) { FileUtils.deleteQuietly(folderPath); } } }
From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java
private static AbstractInsnNode getIntInsnNode(final Number newNumber) { switch (newNumber.intValue()) { case CONST_M1: return new InsnNode(Opcodes.ICONST_M1); case CONST_0: return new InsnNode(Opcodes.ICONST_0); case CONST_1: return new InsnNode(Opcodes.ICONST_1); case CONST_2: return new InsnNode(Opcodes.ICONST_2); case CONST_3: return new InsnNode(Opcodes.ICONST_3); case CONST_4: return new InsnNode(Opcodes.ICONST_4); case CONST_5: return new InsnNode(Opcodes.ICONST_5); default:/*w ww. j a v a 2 s.c om*/ if (newNumber.intValue() >= CONST_LOW_INT && newNumber.intValue() <= CONST_HIGH_INT) { return new IntInsnNode(getopcodePush(newNumber.intValue()), newNumber.intValue()); } return new LdcInsnNode(newNumber); } }
From source file:org.shredzone.cilla.core.repository.impl.HeaderDaoHibImpl.java
@Transactional(readOnly = true) @Override//from w w w . j a v a2 s . com public Header fetchRandomHeader() { Criterion restriction = Restrictions.eq("enabled", Boolean.TRUE); Number count = (Number) criteria().add(restriction).setProjection(Projections.rowCount()).uniqueResult(); Header result = null; if (count.intValue() != 0) { int index = rnd.nextInt(count.intValue()); result = (Header) criteria().add(restriction).setFirstResult(index).setMaxResults(1).uniqueResult(); } return result; }
From source file:com.ruihu.easyshop.order.dao.OrderDao.java
public int findStatus(String oid) throws SQLException { String sql = "select status from t_order where oid=?"; Number number = (Number) qr.query(sql, new ScalarHandler(), oid); return number.intValue(); }
From source file:com.glaf.core.util.GetterUtils.java
public static int get(Object value, int defaultValue) { if (value == null) { return defaultValue; }/*from w ww . j a va 2 s .c o m*/ if (value instanceof String) { return get((String) value, defaultValue); } Class<?> clazz = value.getClass(); if (Integer.class.isAssignableFrom(clazz)) { return (Integer) value; } if (value instanceof Number) { Number number = (Number) value; return number.intValue(); } return defaultValue; }
From source file:ru.codemine.ccms.counters.kondor.KondorClient.java
@Override public List<Counter> getCounters(Shop shop) { File dbfFile = ftpDownload(shop); if (!dbfFile.exists()) { log.warn(".dbf : " + shop.getName()); return null; }//www . j a va 2 s . co m List<Counter> result = DbfProcessor.loadData(dbfFile, new DbfRowMapper<Counter>() { @Override public Counter mapRow(Object[] row) { Counter c = new Counter(); String dateStr = new String(DbfUtils.trimLeftSpaces((byte[]) row[0])); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.YY"); DateTime dt = formatter.parseDateTime(dateStr); c.setDate(dt); Number inNumber = (Number) row[1]; c.setIn(inNumber.intValue()); Number outNumber = (Number) row[2]; c.setOut(outNumber.intValue()); return c; } }); for (Counter counter : result) counter.setShop(shop); try { Files.delete(dbfFile.toPath()); } catch (IOException e) { log.error("? .dbf : " + dbfFile.getPath()); } return result; }
From source file:org.snaker.engine.spring.SpringJdbcAccess.java
public Integer getLatestProcessVersion(String name) { String where = " where name = ?"; Number number = template.queryForObject(QUERY_VERSION + where, new Object[] { name }, Integer.class); return (number != null ? number.intValue() : -1); }
From source file:com.cosmosource.common.action.CALicenseAction.java
/** * ca????/*from w w w.j av a2 s .c o m*/ * @return */ public String license() { entity.setGencauser(getSession().getAttribute(Constants.USER_NAME).toString()); entity.setGencadate(DateUtil.getSysDate()); List<TAcCauserapply> tAcCauserapplies = camgrManager.findCaUserApplayByNo(entity.getApplyno()); for (TAcCauserapply tAcCauserapply : tAcCauserapplies) { String canum = tAcCauserapply.getCanum(); if (NumberUtils.isNumber(canum)) { Number ncanum = NumberUtils.createNumber(canum); for (int i = 0; i < ncanum.intValue(); i++) { CAUserLicenseModel caUserLicenseModel = new CAUserLicenseModel(); caUserLicenseModel.setLoginname(tAcCauserapply.getLoginname()); caUserLicenseModels.add(caUserLicenseModel); } } } return "license"; }