List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:org.lightadmin.core.util.NumberUtils.java
@SuppressWarnings("unchecked") public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> 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 (T) number; } else if (targetClass.equals(byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); }/*from www . jav a 2 s . c o m*/ return (T) 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 (T) new Short(number.shortValue()); } else if (targetClass.equals(int.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return (T) new Integer(number.intValue()); } else if (targetClass.equals(long.class)) { return (T) new Long(number.longValue()); } else if (targetClass.equals(float.class)) { return (T) Float.valueOf(number.toString()); } else if (targetClass.equals(double.class)) { return (T) Double.valueOf(number.toString()); } else { return org.springframework.util.NumberUtils.convertNumberToTargetClass(number, targetClass); } }
From source file:gov.nih.nci.caintegrator.common.CentralTendencyCalculatorTest.java
/** * Calculate central tendency with variance as a percentage. *///from www .j av a 2 s .c o m @Test public void calculateCentralTendencyValueWithVarianceAsPercentage() { calculatorWithVariancePercentage.calculateCentralTendencyValue(values2); assertEquals(Float.valueOf("4.5"), calculatorWithVariancePercentage.getCentralTendencyValue()); assertFalse(calculatorWithVariancePercentage.isHighVariance()); calculatorWithVariancePercentage = new CentralTendencyCalculator(CentralTendencyTypeEnum.MEDIAN, true, 44.0, HighVarianceCalculationTypeEnum.PERCENTAGE); calculatorWithVariancePercentage.calculateCentralTendencyValue(values2); assertTrue(calculatorWithVariancePercentage.isHighVariance()); values2 = ArrayUtils.add(values2, 4.5f); calculatorWithVariancePercentage.calculateCentralTendencyValue(values2); assertFalse(calculatorWithVariancePercentage.isHighVariance()); }
From source file:Composite.java
public void changeRule(String a, int rule) { alpha = Float.valueOf(a).floatValue(); ac = AlphaComposite.getInstance(getRule(rule), alpha); repaint(); }
From source file:com.eviware.loadui.impl.statistics.db.util.TypeConverter.java
public static Object stringToObject(String value, Class<? extends Object> type) throws IOException { if (value == null) { return null; } else if (type == Long.class) { return Long.valueOf(value); } else if (type == Integer.class) { return Integer.valueOf(value); } else if (type == Double.class) { return Double.valueOf(value); } else if (type == Float.class) { return Float.valueOf(value); } else if (type == Boolean.class) { return Boolean.valueOf(value); } else if (type == String.class) { return value; } else if (type == Date.class) { Date d = new Date(); d.setTime(Long.valueOf(value)); return d; } else if (type == BufferedImage.class) { return imageFromByteArray(Base64.decodeBase64(value)); } else {// www .j a v a 2 s . com try { type.asSubclass(Serializable.class); return base64ToObject(value); } catch (Exception e) { return value; } } }
From source file:com.workday.autoparse.xml.demo.XmlParserTest.java
@Test public void testParse() throws UnknownElementException, ParseException, UnexpectedChildException { XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser(); InputStream in = getInputStreamOf("input.xml"); DemoModel model = (DemoModel) parser.parseStream(in); assertTrue(model.myBoxedBoolean);// ww w. j av a 2 s . co m assertTrue(model.myPrimitiveBoolean); assertEquals(new BigDecimal(0.5), model.myBigDecimal); assertEquals(BigInteger.ONE, model.myBigInteger); assertEquals(2, model.myPrimitiveByte); assertEquals(Byte.valueOf((byte) 4), model.myBoxedByte); assertEquals('a', model.myPrimitiveChar); assertEquals(Character.valueOf('b'), model.myBoxedChar); assertEquals(5.5, model.myPrimitiveDouble, DOUBLE_E); assertEquals(Double.valueOf(6.5), model.myBoxedDouble); assertEquals(7.5f, model.myPrimitiveFloat, FLOAT_E); assertEquals(Float.valueOf(8.5f), model.myBoxedFloat); assertEquals(9, model.myPrimitiveInt); assertEquals(Integer.valueOf(10), model.myBoxedInt); assertEquals(11, model.myPrimitiveLong); assertEquals(Long.valueOf(12), model.myBoxedLong); assertEquals(13, model.myPrimitiveShort); assertEquals(Short.valueOf((short) 15), model.myBoxedShort); assertEquals("Bob", model.myString); assertTrue(model.myChildModel != null); assertEquals("My_String_Value", model.myChildModel.myString); assertEquals(5, model.myChildModel.myInt); assertEquals(3, model.repeatedChildModels.size()); assertEquals("a", model.repeatedChildModels.get(0).value); assertEquals("I am some text.", model.repeatedChildModels.get(0).textContent); assertEquals("b", model.repeatedChildModels.get(1).value); assertNull(model.repeatedChildModels.get(1).textContent); assertEquals("c", model.repeatedChildModels.get(2).value); }
From source file:com.bigdata.etl.util.DwUtil.java
public static void bulkInsert(String tableName, List<Map<String, String>> lst) { ResultSet rs = null;/* www. j a v a 2 s . co m*/ java.sql.Statement stmt = null; try (java.sql.Connection conn = DataSource.getConnection()) { stmt = conn.createStatement(); rs = stmt.executeQuery("select top 0 * from " + tableName); try (SQLServerBulkCopy bulk = new SQLServerBulkCopy(url + "user=" + user + ";password=" + password)) { SQLServerBulkCopyOptions sqlsbc = new SQLServerBulkCopyOptions(); sqlsbc.setBulkCopyTimeout(60 * 60 * 1000); bulk.setBulkCopyOptions(sqlsbc); bulk.setDestinationTableName(tableName); ResultSetMetaData rsmd = rs.getMetaData(); if (lst == null) { return; } // System.out.println(LocalTime.now() + " "+Thread.currentThread().getId()+" "+lst.size()); try (CachedRowSetImpl x = new CachedRowSetImpl()) { x.populate(rs); for (int k = 0; k < lst.size(); k++) { Map<String, String> map = lst.get(k); x.last(); x.moveToInsertRow(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { String name = rsmd.getColumnName(i).toUpperCase(); int type = rsmd.getColumnType(i);//package java.sql.Type? try { switch (type) { case Types.VARCHAR: case Types.NVARCHAR: int len = rsmd.getColumnDisplaySize(i); String v = map.get(name); if (map.containsKey(name)) { x.updateString(i, v.length() > len ? v.substring(0, len) : v); } else { x.updateNull(i); } break; case Types.BIGINT: if (map.containsKey(name) && map.get(name).matches("\\d{1,}")) { x.updateLong(i, Long.valueOf(map.get(name))); } else { // x.updateLong(i, 0); x.updateNull(i); } break; case Types.FLOAT: if (map.containsKey(name) && map.get(name).matches("([+-]?)\\d*\\.\\d+$")) { x.updateFloat(i, Float.valueOf(map.get(name))); } else { x.updateNull(i); } break; case Types.DOUBLE: if (map.containsKey(name) && map.get(name).trim().length() > 0 && StringUtils.isNumeric(map.get(name))) { x.updateDouble(i, Double.valueOf(map.get(name))); } else { x.updateNull(i); } break; case Types.INTEGER: if (map.containsKey(name) && map.get(name).matches("\\d{1,}")) { x.updateInt(i, Integer.valueOf(map.get(name))); } else { x.updateNull(i); } break; default: throw new RuntimeException("? " + type); } /* if(map.containsKey("SYS_TELECOM")) System.err.println(map.get("SYS_TELECOM")); */ } catch (RuntimeException | SQLException e) { Logger.getLogger(DwUtil.class.getName()).log(Level.SEVERE, "? name=" + name + " v=" + map.get(name), e); } } x.insertRow(); x.moveToCurrentRow(); //x.acceptChanges(); } long start = System.currentTimeMillis(); bulk.writeToServer(x); long end = System.currentTimeMillis(); System.out.println(LocalTime.now() + " " + Thread.currentThread().getId() + " " + (end - start) + "ms" + " " + x.size()); } } } catch (SQLException e) { Logger.getLogger(DwUtil.class.getName()).log(Level.SEVERE, null, e); } finally { try { if (rs != null) { rs.close(); } if (stmt != null) { stmt.close(); } } catch (SQLException ex) { Logger.getLogger(DwUtil.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:cz.babi.desktop.remoteme.common.Controller.java
/** * Move mouse./*from w ww.ja v a2 s .com*/ * @param addInfo String include offsetX and offsetY. */ public void mouseMove(String addInfo) { String[] offsets = addInfo.split(SimpleMessage.SEPARATOR); float offsetX = Float.valueOf(offsets[0]); float offsetY = Float.valueOf(offsets[1]); if (Common.DEBUG) LOGGER.debug("[mouseMove][" + offsetX * -1 + ";" + offsetY * -1 + "]"); Point currentLocation = MouseInfo.getPointerInfo().getLocation(); robot.mouseMove(currentLocation.x + (int) offsetX * -1, currentLocation.y + (int) offsetY * -1); }
From source file:com.ewcms.common.query.mongo.EasyQueryInit.java
private void insertCertificate() throws IOException { DataOperator<Certificate> operator = new DataOperator<Certificate>("certificate.csv"); operator.insert(new MapperCallback<Certificate>() { @Override/*from w w w . java 2s . c o m*/ public Certificate mapping(String line) { String[] array = line.split(","); Certificate c = new Certificate(); c.setCerId(array[0]); c.setName(array[1]); try { c.setLimitLogs(findLimitLog(array[0])); } catch (IOException e1) { e1.printStackTrace(); } try { c.setBrithdate(format.parse(array[3])); } catch (ParseException e) { new RuntimeException(e); } c.setLimit(Float.valueOf(array[4]).intValue()); if (array.length > 5 && StringUtils.hasText(array[5])) { c.setPhones(StringUtils.tokenizeToStringArray(array[5], "|")); } return c; } }, operations); }
From source file:org.ngrinder.monitor.service.MonitorService.java
/** * Get all{@link SystemDataModel} from monitor data file of one test and target. * @param testId/*from w w w .j a v a2 s . c o m*/ * test id * @param monitorIP * IP address of the monitor target * @return SystemDataModel list */ public List<SystemDataModel> getSystemMonitorData(long testId, String monitorIP) { LOG.debug("Get SystemMonitorData of test:{} ip:{}", testId, monitorIP); List<SystemDataModel> rtnList = new ArrayList<SystemDataModel>(); File monitorDataFile = new File(config.getHome().getPerfTestReportDirectory(String.valueOf(testId)), Config.MONITOR_FILE_PREFIX + monitorIP + ".data"); BufferedReader br = null; try { br = new BufferedReader(new FileReader(monitorDataFile)); br.readLine(); //skip the header. //header: "ip,system,collectTime,freeMemory,totalMemory,cpuUsedPercentage" String line = br.readLine(); while (StringUtils.isNotBlank(line)) { SystemDataModel model = new SystemDataModel(); String[] datalist = StringUtils.split(line, ","); model.setIp(datalist[0]); model.setSystem(datalist[1]); model.setCollectTime(Long.valueOf(datalist[2])); model.setFreeMemory(Long.valueOf(datalist[3])); model.setTotalMemory(Long.valueOf(datalist[4])); model.setCpuUsedPercentage(Float.valueOf(datalist[5])); rtnList.add(model); line = br.readLine(); } } catch (FileNotFoundException e) { LOG.error("Monitor data file not exist:{}", monitorDataFile); LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error("Error while getting monitor:{} data file:{}", monitorIP, monitorDataFile); LOG.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(br); } LOG.debug("Finish getSystemMonitorData of test:{} ip:{}", testId, monitorIP); return rtnList; }
From source file:au.org.ala.delta.dist.DISTTest.java
private void checkResults(String path, String resultFileName, boolean compareAsFloats) throws Exception { java.io.File expectedFile = new File(FilenameUtils.concat(path, "expected_results/" + resultFileName)); String expected = FileUtils.readFileToString(expectedFile, "cp1252"); System.out.println(expected); File actualFile = new File(FilenameUtils.concat(path, resultFileName)); String actual = FileUtils.readFileToString(actualFile, "cp1252"); System.out.print(actual);/* w w w .ja v a2 s . c o m*/ expected = replaceNewLines(expected); if (compareAsFloats) { String[] actualFloats = actual.trim().split("\\s+"); String[] expectedFloats = expected.trim().split("\\s+"); for (int i = 0; i < expectedFloats.length; i++) { float float1 = Float.valueOf(actualFloats[i]); float float2 = Float.valueOf(expectedFloats[i]); assertEquals("index " + i, float2, float1, 0.001f); } } assertEquals(expected, actual); }