本文整理汇总了Java中org.apache.commons.lang3.math.NumberUtils.toFloat方法的典型用法代码示例。如果您正苦于以下问题:Java NumberUtils.toFloat方法的具体用法?Java NumberUtils.toFloat怎么用?Java NumberUtils.toFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.math.NumberUtils
的用法示例。
在下文中一共展示了NumberUtils.toFloat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: QuakeInfo
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public QuakeInfo(final Document doc) {
this.url = "https://typhoon.yahoo.co.jp"+Optional.ofNullable(doc.getElementById("history")).map(history -> history.getElementsByTag("tr").get(1).getElementsByTag("td").first().getElementsByTag("a").first().attr("href")).orElse("");
this.imageUrl = Optional.ofNullable(doc.getElementById("yjw_keihou").getElementsByTag("img").first()).map(image -> StringUtils.substringBefore(image.attr("src"), "?"));
final Element info = doc.getElementById("eqinfdtl");
final Map<String, String> data = info.getElementsByTag("table").get(0).getElementsByTag("tr").stream()
.map(tr -> tr.getElementsByTag("td")).collect(Collectors.toMap(td -> td.get(0).text(), td -> td.get(1).text()));
try {
this.announceTime = FORMAT.parse(data.get("情報発表時刻"));
final String quakeTime = data.get("発生時刻");
this.quakeTime = FORMAT.parse(StringUtils.substring(quakeTime, 0, quakeTime.length()-2));
this.epicenter = data.get("震源地");
this.lat = data.get("緯度");
this.lon = data.get("経度");
this.depth = data.get("深さ");
this.magnitude = NumberUtils.toFloat(data.get("マグニチュード"), -1f);
this.info = data.get("情報");
} catch (final ParseException e) {
throw new RuntimeException("Parse Error", e);
}
final Element yjw = info.getElementsByTag("table").get(1);
if (yjw.childNodeSize()<=1)
this.maxIntensity = Optional.empty();
else
this.maxIntensity = SeismicIntensity.get(yjw.getElementsByTag("td").first().getElementsByTag("td").first().text());
final Map<String, PrefectureDetail> details = new HashMap<>();
yjw.getElementsByTag("tr").stream().filter(tr -> tr.attr("valign").equals("middle")).forEach(tr -> {
final Optional<SeismicIntensity> intensity = SeismicIntensity.get(tr.getElementsByTag("td").first().getElementsByTag("td").first().text());
tr.getElementsByTag("table").first().getElementsByTag("tr").stream().map(line -> line.getElementsByTag("td")).collect(Collectors.toMap(td -> td.get(0).text(), td -> td.get(1).text())).entrySet().forEach(entry -> {
final String prefecture = entry.getKey();
final PrefectureDetail detail = details.computeIfAbsent(prefecture, key -> new PrefectureDetail(prefecture));
intensity.ifPresent(line -> Stream.of(StringUtils.split(entry.getValue(), " ")).forEach(str -> detail.addCity(line, str)));
});
});
this.details = new ArrayList<>(details.values());
Collections.sort(this.details, Comparator.reverseOrder());
}
示例2: getFloat
import org.apache.commons.lang3.math.NumberUtils; //导入方法依赖的package包/类
public Float getFloat() {
String value = super.get();
return value == null ? null : NumberUtils.toFloat(value);
}