List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:org.crazydog.util.spring.NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the corresponding {@code decode} / {@code valueOf} methods. * <p>Trims the input {@code String} before attempting to parse the number. * Supports numbers in hex format (with leading "0x", "0X" or "#") as well. * * @param text the text to convert * @param targetClass the target class to parse into * @return the parsed number/*from ww w .j ava 2 s. co m*/ * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see Byte#decode * @see Short#decode * @see Integer#decode * @see Long#decode * @see #decodeBigInteger(String) * @see Float#valueOf * @see Double#valueOf * @see BigDecimal#BigDecimal(String) */ @SuppressWarnings("unchecked") public static <T extends Number> T parseNumber(String text, Class<T> targetClass) { org.springframework.util.Assert.notNull(text, "Text must not be null"); org.springframework.util.Assert.notNull(targetClass, "Target class must not be null"); String trimmed = StringUtils.trimAllWhitespace(text); if (Byte.class == targetClass) { return (T) (isHexNumber(trimmed) ? Byte.decode(trimmed) : Byte.valueOf(trimmed)); } else if (Short.class == targetClass) { return (T) (isHexNumber(trimmed) ? Short.decode(trimmed) : Short.valueOf(trimmed)); } else if (Integer.class == targetClass) { return (T) (isHexNumber(trimmed) ? Integer.decode(trimmed) : Integer.valueOf(trimmed)); } else if (Long.class == targetClass) { return (T) (isHexNumber(trimmed) ? Long.decode(trimmed) : Long.valueOf(trimmed)); } else if (BigInteger.class == targetClass) { return (T) (isHexNumber(trimmed) ? decodeBigInteger(trimmed) : new BigInteger(trimmed)); } else if (Float.class == targetClass) { return (T) Float.valueOf(trimmed); } else if (Double.class == targetClass) { return (T) Double.valueOf(trimmed); } else if (BigDecimal.class == targetClass || Number.class == targetClass) { return (T) new BigDecimal(trimmed); } else { throw new IllegalArgumentException( "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]"); } }
From source file:mobi.shad.s3lib.gui.ui.FxEffect.java
@Override public void setValues(String changeKey, ArrayMap<String, String> values) { inSetValues = true;/* ww w .j a va2 s . c o m*/ if (changeKey.equals("effect")) { if (needSwapEffect == false) { needSwapEffect = true; newEffectName = values.get("effect"); } } if (Integer.valueOf(values.get("zindex")) < 0) { values.put("zindex", "0"); } if (abstractEffect != null) { try { abstractEffect.setValues(changeKey, values); } catch (Exception ex) { ex.printStackTrace(); } } setName(values.get("name")); setX(Float.valueOf(values.get("x"))); setY(Float.valueOf(values.get("y"))); setWidth(Float.valueOf(values.get("width"))); setHeight(Float.valueOf(values.get("height"))); setOriginX(Float.valueOf(values.get("originX"))); setOriginY(Float.valueOf(values.get("originY"))); setRotation(Float.valueOf(values.get("rotation"))); setColor(Color.valueOf(values.get("color"))); setTouchable(Touchable.valueOf(values.get("touchable"))); setVisible(Boolean.valueOf(values.get("visible"))); setZIndex((int) (float) (Integer.valueOf(values.get("zindex")))); inSetValues = false; }
From source file:com.marvelution.jira.plugins.hudson.utils.DateFormatUtils.java
/** * Format a given timestamp to a {@link String} * // w ww.j av a 2 s. c o m * @param duration the timestamp in milliseconds * @return the formatted time {@link String} */ public String getTimeSpanString(final long duration) { final long years = duration / YEAR_MILLIS; long remDuration = duration % YEAR_MILLIS; final long months = remDuration / MONTH_MILLIS; remDuration %= MONTH_MILLIS; final long days = remDuration / DAY_MILLIS; remDuration %= DAY_MILLIS; final long hours = remDuration / HOUR_MILLIS; remDuration %= HOUR_MILLIS; final long minutes = remDuration / MINUTE_MILLIS; remDuration %= MINUTE_MILLIS; final long seconds = remDuration / SECOND_MILLIS; remDuration %= SECOND_MILLIS; final long millisecs = remDuration; if (years > 0L) { return makeTimeSpanString(years, i18nHelper.getText("hudson.time.year", Long.valueOf(years)), months, i18nHelper.getText("hudson.time.month", Long.valueOf(months))); } else if (months > 0L && days == 1L) { return makeTimeSpanString(months, i18nHelper.getText("hudson.time.month", Long.valueOf(months)), days, i18nHelper.getText("hudson.time.day", Long.valueOf(days))); } else if (months > 0L) { return makeTimeSpanString(months, i18nHelper.getText("hudson.time.month", Long.valueOf(months)), days, i18nHelper.getText("hudson.time.days", Long.valueOf(days))); } else if (days == 1L) { return makeTimeSpanString(days, i18nHelper.getText("hudson.time.day", Long.valueOf(days)), hours, i18nHelper.getText("hudson.time.hour", Long.valueOf(hours))); } else if (days > 0L) { return makeTimeSpanString(days, i18nHelper.getText("hudson.time.days", Long.valueOf(days)), hours, i18nHelper.getText("hudson.time.hour", Long.valueOf(hours))); } else if (hours > 0L) { return makeTimeSpanString(hours, i18nHelper.getText("hudson.time.hour", Long.valueOf(hours)), minutes, i18nHelper.getText("hudson.time.minute", Long.valueOf(minutes))); } else if (minutes > 0L) { return makeTimeSpanString(minutes, i18nHelper.getText("hudson.time.minute", Long.valueOf(minutes)), seconds, i18nHelper.getText("hudson.time.second", Long.valueOf(seconds))); } else if (seconds >= 10L) { return i18nHelper.getText("hudson.time.second", Long.valueOf(seconds)); } else if (seconds >= 1L) { return i18nHelper.getText("hudson.time.second", Float.valueOf((float) seconds + (float) (millisecs / 100L) / 10.0F)); } else if (millisecs >= 100L) { return i18nHelper.getText("hudson.time.second", Float.valueOf((float) (millisecs / 10L) / 100.0F)); } return i18nHelper.getText("hudson.time.millisecond", Long.valueOf(millisecs)); }
From source file:com.silverpeas.projectManager.model.TaskDetail.java
public void setConsomme(String f) { if (f != null && f.length() > 0) { consomme = Float.valueOf(f); } else {/*from www . ja v a 2 s. c o m*/ consomme = 0; } }
From source file:com.kircherelectronics.accelerationexplorer.activity.NoiseActivity.java
private float getPrefLpfSmoothingTimeConstant() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); return Float.valueOf(prefs.getString(NoiseConfigActivity.LPF_SMOOTHING_TIME_CONSTANT_KEY, "1")); }
From source file:burstcoin.observer.service.NodeService.java
public void startCheckNodesTask() { timer.schedule(new TimerTask() { @Override/*from ww w.j a v a2s. c om*/ public void run() { try { while (networkBeans == null || networkBeans.isEmpty()) { Thread.sleep(1000 * 60); // wait another minute } Map<String, Peer> peerLookup = new HashMap<>(); for (NetworkBean networkBean : networkBeans) { if ("Wallet".equals(networkBean.getType())) { addMissingPeers(networkBean.getUrl(), peerLookup); } } for (String ip : peerLookup.keySet()) { if (!peerInfoLookup.containsKey(ip)) { PeerInfo peerInfo = getPeerInfo(ip); if (peerInfo != null) { peerInfoLookup.put(ip, peerInfo); } // max 150 requests per minute Thread.sleep(1000 * 60 / 155); } } BlockchainStatus blockchainStatus = getBlockchainStatus(); long blockChainTimeInMs = blockchainStatus.getTime() * 1000; long blockZeroTime = new Date().getTime() - blockChainTimeInMs; Map<String, Integer> nodesByCountry = new HashMap<>(); List<NodeListBean> nodeBeans = new ArrayList<>(); List<List> mapData = new ArrayList<>(); mapData.add(Arrays.asList("Lat", "Long", "Name")); for (Map.Entry<String, PeerInfo> entry : peerInfoLookup.entrySet()) { String ip = entry.getKey(); PeerInfo peerInfo = entry.getValue(); Peer peer = peerLookup.get(ip); if (peer != null) { // todo lastUpdate is not accurate, as it reflects the lastUpdate form first found wallet Date lastUpdate = new Date(blockZeroTime + peer.getLastUpdated() * 1000); long minLastActivity = new Date().getTime() - (1000 * 60 * 60); // min last updated 1h ago // only add peers that were updated in last 12h if (minLastActivity <= lastUpdate.getTime()) { if (!nodesByCountry.containsKey(peerInfo.getCountry())) { nodesByCountry.put(peerInfo.getCountry(), 0); } nodesByCountry.put(peerInfo.getCountry(), nodesByCountry.get(peerInfo.getCountry()) + 1); nodeBeans.add(new NodeListBean(lastUpdate, peer.getAnnouncedAddress(), ip, peer.getVersion() != null ? peer.getVersion() : "N/A", peer.getPlatform(), peerInfo.getCountry() != null ? peerInfo.getCountry() : "N/A", peerInfo.getRegionName(), peerInfo.getCity(), peerInfo.getIsp() != null ? peerInfo.getIsp() : "N/A")); mapData.add(Arrays.asList(Float.valueOf(peerInfo.getLat()), Float.valueOf(peerInfo.getLon()), peer.getAnnouncedAddress())); } } } Collections.sort(nodeBeans, new Comparator<NodeListBean>() { @Override public int compare(NodeListBean o1, NodeListBean o2) { return o2.getIsp().compareTo(o1.getIsp()); } }); Collections.sort(nodeBeans, new Comparator<NodeListBean>() { @Override public int compare(NodeListBean o1, NodeListBean o2) { return o1.getCountry().compareTo(o2.getCountry()); } }); Collections.sort(nodeBeans, new Comparator<NodeListBean>() { @Override public int compare(NodeListBean o1, NodeListBean o2) { return o2.getVersion().compareTo(o1.getVersion()); } }); // quickfix to put N/A at the end List<NodeListBean> atTheEnd = new ArrayList<>(); for (NodeListBean nodeBean : nodeBeans) { if (nodeBean.getVersion().equals("N/A")) { atTheEnd.add(nodeBean); } } nodeBeans.removeAll(atTheEnd); nodeBeans.addAll(atTheEnd); // google geo chart data List<List> geoData = new ArrayList<>(); geoData.add(Arrays.asList("Country", "Nodes")); for (Map.Entry<String, Integer> entry : nodesByCountry.entrySet()) { geoData.add(Arrays.asList(entry.getKey(), entry.getValue())); } // create wellKnownsPeers string String wellKnownPeers = "nxt.wellKnownPeers="; Set<String> nodeNames = new HashSet<>(); for (NodeListBean nodeBean : nodeBeans) { nodeNames.add(nodeBean.getIp()); } for (String name : nodeNames) { wellKnownPeers += name + "; "; } NodeStats nodeStats = new NodeStats(peerInfoLookup.size(), nodeBeans.size(), wellKnownPeers); Date now = new Date(); DecimalFormat f = new DecimalFormat("00"); for (NodeListBean nodeBean : nodeBeans) { long diff = now.getTime() - nodeBean.getLastUpdate().getTime(); long diffSeconds = diff / 1000 % 60; long diffMinutes = diff / (1000 * 60) % 60; long diffHours = diff / (1000 * 60 * 60) % 60; // not 100% accurate nodeBean.setUpdated(f.format(diffHours < 0 ? diffHours * -1 : diffHours) + ":" + f.format(diffMinutes < 0 ? diffMinutes * -1 : diffMinutes) + ":" + f.format(diffSeconds < 0 ? diffSeconds * -1 : diffSeconds)); } publisher.publishEvent(new NodeUpdateEvent(nodeBeans, nodeStats, geoData, mapData)); } catch (Exception e) { LOG.error("Failed update nodes!", e); } } }, ObserverProperties.getNetworkRefreshInterval(), ObserverProperties.getNodeRefreshInterval()); }
From source file:gov.nih.nci.caintegrator.web.action.query.form.ExpressionLevelCriterionWrapper.java
private TextFieldParameter createGreaterOrEqualParameter() { String possibleLabel = "Expression level >="; if (RangeTypeEnum.INSIDE_RANGE.equals(criterion.getRangeType())) { possibleLabel = "Expression level between"; } else if (RangeTypeEnum.OUTSIDE_RANGE.equals(criterion.getRangeType())) { possibleLabel = "Expression level outside of"; }/*from w w w.j a v a2 s .c o m*/ final String label = possibleLabel; TextFieldParameter rangeParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(), criterion.getLowerLimit().toString()); rangeParameter.setLabel(label); ValueHandler expressionHandler = new ValueHandlerAdapter() { @Override public boolean isValid(String value) { return NumberUtils.isNumber(value); } @Override public void validate(String formFieldName, String value, ValidationAware action) { if (!isValid(value)) { action.addActionError("Numeric value required for " + label); } } @Override public void valueChanged(String value) { criterion.setLowerLimit(Float.valueOf(value)); } }; rangeParameter.setValueHandler(expressionHandler); return rangeParameter; }
From source file:edu.osu.netmotifs.warswap.ui.GenerateMotifImages.java
public void createHtm(float zScoreCutoff, float pvalueCutoff, int recPerPage) throws Exception { InputStream inputStream;//from w w w. j a v a 2s . co m try { inputStream = new FileInputStream(new File(motifsFile)); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line = null; colPerGraphHash = new HashMap<Integer, Color>(); String headStr = "<head><style>\ntable, th, td {\nborder: 1px solid black;\nborder-collapse: collapse;\ntext-align: center;}\n</style></head>"; String tableStr = "<table style=\"width:50%\"><tr bgcolor=\"#F1F1F1\"><th>Image</th><th>Z-score</th><th>P-Value</th><th>std-dev</th><th>Adj-Matrix</th></tr>"; String seperator = "\t"; if (motifsFile.endsWith("csv")) seperator = ","; line = bufferedReader.readLine(); while ((line = bufferedReader.readLine()) != null) { // Thread.sleep(1000); // System.out.println(line); String[] parts = line.split(seperator); String adjMtx = parts[0]; //String graphPart = parts[0].split("_")[1]; Graph<Integer, String> g = new DirectedSparseGraph(); int s = 0; colPerGraphHash.clear(); for (int i = 0; i < motifSize; i++) { int vCode = Character.getNumericValue(adjMtx.charAt(i * (motifSize + 1))); colPerGraphHash.put(i, colorsHash.get(vCode)); g.addVertex(i); for (int j = 0; j < motifSize; j++) { int d = Character.getNumericValue(adjMtx.charAt(i * motifSize + j)); if (d == 1 && (i * motifSize + j) % (motifSize + 1) > 0) g.addEdge("E" + s++, i, j); } } graphList.add(g); if (!parts[1].equalsIgnoreCase(CONF.INFINIT) && !parts[2].equalsIgnoreCase(CONF.INFINIT) && !parts[3].equalsIgnoreCase(CONF.INFINIT)) { float zscore = Float.valueOf(parts[1]); float pValue = Float.valueOf(parts[2]); float stddev = Float.valueOf(parts[3]); // float std = Float.valueOf(parts[3]); if (zScoreCutoff != -1 || pvalueCutoff != -1) { if (zScoreCutoff != -1) { if (zscore < zScoreCutoff) continue; } if (pvalueCutoff != -1) { if (pValue > pvalueCutoff) continue; } } generateImagesSize3(g, parts[0]); File file = new File(imageOutFile); tableStr += "<tr>" + "<td><img src=\"" + relativePathToImage + "\" width=\"80\" height=\"80\" >" + "</td>" + "<td>" + parts[1] + "</td>" + "<td>" + parts[2] + "</td>" + "<td>" + parts[3] + "</td>" + "<td>" + adjMtx + "</td>" + "</tr>"; // tableStr += "<tr>" + "<td><img src=\"" + imageOutFile + "\" width=\"80\" height=\"80\" >" + "</td>" // + "<td>" + parts[1] + "</td>" + "<td>" + parts[2] + "</td>" + "<td>" + parts[3] + "</td>" + "<td>" + adjMtx + "</td>" + "</tr>"; } } Utils.printStrToFile(headStr + tableStr, htmOutFile); inputStream.close(); bufferedReader.close(); runstatus = 1; } catch (Exception e) { e.printStackTrace(); runstatus = 1; throw e; } }
From source file:net.librec.conf.Configuration.java
public Float getFloat(String name, Float defaultValue) { String value = get(name);//from w w w . j a v a2 s . com if (StringUtils.isNotBlank(value)) { return Float.valueOf(value); } else { return defaultValue; } }
From source file:business.security.control.OwmClient.java
/** * Find current city weather within a bounding box * * @param northLat is the latitude of the geographic top left point of the * bounding box//w w w. jav a 2s . c om * @param westLon is the longitude of the geographic top left point of the * bounding box * @param southLat is the latitude of the geographic bottom right point of * the bounding box * @param eastLon is the longitude of the geographic bottom right point of * the bounding box * @throws JSONException if the response from the OWM server can't be parsed * @throws IOException if there's some network error or the OWM server * replies with a error. */ public WeatherStatusResponse currentWeatherAtCityBoundingBox(float northLat, float westLon, float southLat, float eastLon) throws IOException, JSONException { //, boolean cluster, OwmClient.Lang lang) { String subUrl = String.format(Locale.ROOT, "find/city?bbox=%f,%f,%f,%f&cluster=yes", Float.valueOf(northLat), Float.valueOf(westLon), Float.valueOf(southLat), Float.valueOf(eastLon)); JSONObject response = doQuery(subUrl); return new WeatherStatusResponse(response); }