Java Code Examples for org.apache.commons.lang3.math.NumberUtils.toFloat()

The following are Jave code examples for showing how to use toFloat() of the org.apache.commons.lang3.math.NumberUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: EEWBot   File: QuakeInfo.java   View Source Code Vote up 5 votes
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());
}
 
Example 2
Project: azeroth   File: RedisNumber.java   View Source Code Vote up 4 votes
public Float getFloat() {
    String value = super.get();
    return value == null ? null : NumberUtils.toFloat(value);
}