Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernPropertiesHelper.java @ 9194:c373909fb7ca
Fixed: used java 7 feature although java 6 comliance level is configured
author | gernotbelger |
---|---|
date | Fri, 29 Jun 2018 13:09:29 +0200 |
parents | 0633f963c5be |
children | fb5272746c74 |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.uinfo.inundationduration; import java.io.IOException; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; import org.apache.commons.lang.text.StrSubstitutor; import org.dive4elements.artifacts.CallMeta; import org.dive4elements.artifacts.common.utils.Config; import org.dive4elements.river.artifacts.resources.Resources; /** * @author Domenico Nardi Tironi * */ public class UedauernPropertiesHelper { private static UedauernPropertiesHelper instance; private final String CONFIG_FILE; private final String rivername; private Integer[] mittelStartEnde = null; private String[] einzeljahre = null; private String mittelUrl = null; private Properties properties = null; public UedauernPropertiesHelper(final String rivername) { this.rivername = rivername; this.CONFIG_FILE = makeFileName(rivername); } public static synchronized UedauernPropertiesHelper getInstance(final String rivername) { if (UedauernPropertiesHelper.instance == null || !UedauernPropertiesHelper.instance.getRivername().equals(rivername)) { UedauernPropertiesHelper.instance = new UedauernPropertiesHelper(rivername); } return UedauernPropertiesHelper.instance; } private String getRivername() { return this.rivername; } private static final String makeFileName(final String river) { return "uinfo_uedauern_aue_" + river + ".properties"; } public LinkedHashMap<String, String> getExtraLayers(final CallMeta meta) { final LinkedHashMap<String, String> entries = new LinkedHashMap<>(); final Integer[] totalEpoch = getMittelStartEnd(); final Object[] args = new Object[] { String.valueOf(totalEpoch[0]), String.valueOf(totalEpoch[1]) }; entries.put("state.uinfo.totalepoch", Resources.getMsg(meta, "state.uinfo.totalepoch", args)); // // String.valueOf: avoid formatting // (3.333,00 return entries; } private Properties getProperties() { if (this.properties == null) { try { this.properties = Config.loadProperties(this.CONFIG_FILE); } catch (final IOException e) { e.printStackTrace(); } } return this.properties; } final Integer[] getMittelStartEnd() { if (this.mittelStartEnde == null) { final Integer mittel_start = Integer.valueOf(getProperties().get("mittel_start").toString()); final Integer mittel_ende = Integer.valueOf(getProperties().get("mittel_ende").toString()); this.mittelStartEnde = new Integer[] { mittel_start, mittel_ende }; // lazy } return this.mittelStartEnde; } public String[] getEinzeljahre() { if (this.einzeljahre == null) { // lazy final Object years = getProperties().get("jahre"); if (years != null) { this.einzeljahre = years.toString().split(","); } } return this.einzeljahre; } public final String getMittelUrl() { if (this.mittelUrl == null) { // lazy this.mittelUrl = getProperties().get("mittel_url").toString(); } return this.mittelUrl; } public final String urlFromYear(final int year) { // besser kein lazy-loading, da der user nochmal zurück gehen und das Jahr ändern könnte... final String templateUrl = getProperties().get("url").toString(); final Map<String, String> tokens = new HashMap<>(); tokens.put("jahr", String.valueOf(year)); final StrSubstitutor subst = new StrSubstitutor(tokens); final String yearUrl = subst.replace(templateUrl); return yearUrl; } public static boolean fileExistsForRiver(final String river) { try { Config.loadProperties(makeFileName(river)); return true; } catch (final IOException e) { e.printStackTrace(); return false; } } public String getScenarioUrlFromYear(final Integer year, final Integer dMwspl) { // besser kein lazy-loading, da der user nochmal zurück gehen und das Jahr ändern könnte... final String templateUrl = getProperties().get("scenario_url").toString(); final Map<String, String> tokens = new HashMap<>(); tokens.put("jahr", String.valueOf(year)); tokens.put("scenario", String.valueOf(dMwspl)); final StrSubstitutor subst = new StrSubstitutor(tokens); final String yearUrl = subst.replace(templateUrl); return yearUrl; } public String getMittelScenarioUrl(final Integer dMwspl) { final Map<String, String> tokens = new HashMap<>(); tokens.put("scenario", String.valueOf(dMwspl)); final String templateUrl = getProperties().get("mittel_scenario_url").toString(); final StrSubstitutor subst = new StrSubstitutor(tokens); final String url = subst.replace(templateUrl); return url; } }