com.frightanic.smn.api.SmnData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of open-data-smn Show documentation
Show all versions of open-data-smn Show documentation
An API to serve publicly available data from the SwissMetNet.
package com.frightanic.smn.api;
import com.google.common.base.Splitter;
import com.wordnik.swagger.annotations.ApiModel;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Represents the entire data set for a point in time.
*/
@ApiModel(value = "A container for SMN data records")
public class SmnData {
private final Map smnRecords;
public SmnData(String sourceData) {
List records = Splitter.on("\n").trimResults().omitEmptyStrings().splitToList(sourceData);
smnRecords = new HashMap<>(records.size() - 2);
// omit first three lines (the empty one was already removed be the Splitter, omitEmptyStrings)
/*
* MeteoSchweiz / MeteoSuisse / MeteoSvizzera / MeteoSwiss
*
* stn|time|tre200s0|sre000z0|rre150z0|dkl010z0|fu3010z0|pp0qnhs0|fu3010z1|ure200s0|prestas0|pp0qffs0
*/
for (int i = 2; i < records.size(); i++) {
SmnRecord smnRecord = new SmnRecord(records.get(i));
smnRecords.put(smnRecord.getCode(), smnRecord);
}
}
public Collection getAllRecords() {
return smnRecords.values();
}
public SmnRecord getRecordFor(String code) {
return smnRecords.get(code);
}
}