Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/states/LocationDistanceSelect.java @ 9175:34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
author | gernotbelger |
---|---|
date | Mon, 25 Jun 2018 17:58:11 +0200 |
parents | 07df414d5d88 |
children |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/LocationDistanceSelect.java Mon Jun 25 16:07:41 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/LocationDistanceSelect.java Mon Jun 25 17:58:11 2018 +0200 @@ -9,23 +9,18 @@ package org.dive4elements.river.artifacts.states; import org.apache.log4j.Logger; - +import org.dive4elements.artifactdatabase.data.StateData; import org.dive4elements.artifacts.Artifact; - -import org.dive4elements.artifactdatabase.data.StateData; - +import org.dive4elements.artifacts.CallContext; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.WINFOArtifact; - import org.dive4elements.river.artifacts.access.RangeAccess; - +import org.dive4elements.river.artifacts.resources.Resources; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ -public class LocationDistanceSelect -extends ComputationRangeState -{ +public class LocationDistanceSelect extends ComputationRangeState { /** The log used in this class. */ private static Logger log = Logger.getLogger(LocationDistanceSelect.class); @@ -36,55 +31,46 @@ /** The name of the 'locations' field. */ public static final String LOCATIONS = "ld_locations"; - /** * The default constructor that initializes an empty State object. */ public LocationDistanceSelect() { } - @Override protected String getUIProvider() { return "location_distance_panel"; } - /** Validates the range (or location). */ @Override - public boolean validate(Artifact artifact) - throws IllegalArgumentException - { + public boolean validate(final Artifact artifact) throws IllegalArgumentException { log.debug("LocationDistanceSelect.validate"); - D4EArtifact flys = (D4EArtifact)artifact; - StateData mode = getData(flys, MODE); - String mValue = mode != null ? (String)mode.getValue() : null; + final D4EArtifact flys = (D4EArtifact) artifact; + final StateData mode = getData(flys, MODE); + final String mValue = mode != null ? (String) mode.getValue() : null; if (mValue != null) { if (mValue.equals("distance")) { return super.validate(flys); - } - else { + } else { return validateLocations(flys); } } return false; } - /** Validate selected locations. */ - protected boolean validateLocations(D4EArtifact flys) - throws IllegalArgumentException - { - StateData dValues = getData(flys, LOCATIONS); - String values = dValues != null ? (String)dValues.getValue() : null; + protected boolean validateLocations(final D4EArtifact flys) throws IllegalArgumentException { + final StateData dValues = getData(flys, LOCATIONS); + final String values = dValues != null ? (String) dValues.getValue() : null; if (values == null || values.length() == 0) { throw new IllegalArgumentException("error_empty_state"); } - double[] absMinMax = getMinMax(flys); - double[] relMinMax = getMinMaxFromString(values); + final double[] absMinMax = getMinMax(flys); + final double[] relMinMax = getMinMaxFromString(values); if (relMinMax[0] < absMinMax[0] || relMinMax[0] > absMinMax[1]) { throw new IllegalArgumentException("error_feed_from_out_of_range"); @@ -97,45 +83,46 @@ return true; } - /** * Extracts the min/max values from String <i>s</i>. An * IllegalArgumentException is thrown if there is a value that throws a * NumberFormatException. * - * @param s String that contains whitespace separated double values. + * @param s + * String that contains whitespace separated double values. * * @return a 2dmin array [min,max]. */ - public static double[] getMinMaxFromString(String s) - throws IllegalArgumentException - { - String[] values = s.split(" "); + public static double[] getMinMaxFromString(final String s) throws IllegalArgumentException { + final String[] values = s.split(" "); - double[] minmax = new double[] { - Double.MAX_VALUE, - -Double.MAX_VALUE }; + final double[] minmax = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; - for (String v: values) { + for (final String v : values) { try { - double value = Double.valueOf(v); + final double value = Double.valueOf(v); minmax[0] = minmax[0] < value ? minmax[0] : value; minmax[1] = minmax[1] > value ? minmax[1] : value; } - catch (NumberFormatException nfe) { - throw new IllegalArgumentException( - "error_invalid_double_value"); + catch (final NumberFormatException nfe) { + throw new IllegalArgumentException("error_invalid_double_value"); } } return minmax; } - - public static double[] getLocations(WINFOArtifact flys) { - RangeAccess ra = new RangeAccess(flys); + public static double[] getLocations(final WINFOArtifact flys) { + final RangeAccess ra = new RangeAccess(flys); return ra.getLocations(); } + + @Override + protected String getTitle(final CallContext context) { + // REMARK: that is how it should be: return Resources.getMsg(context.getMeta(), getID()); + return Resources.getMsg(context.getMeta(), "state.title.location_distance_state"); + } + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :