Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 4187:21f4e4b79121
Refactor GaugeDischargeCurveFacet to be able to set a facet name
For adding another output of the GaugeDischargeCurveArtifact it is necessary to
provide to facet instances with different names. Therefore the
GaugeDischargeCurveFacet is extended to set the facet name in the constructor.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 19 Oct 2012 13:25:49 +0200 |
parents | 022f62c75878 |
children | 1358d0c8481c |
line wrap: on
line source
package de.intevation.flys.artifacts.states; import org.apache.log4j.Logger; import de.intevation.artifacts.Artifact; import de.intevation.artifactdatabase.data.StateData; import de.intevation.flys.artifacts.FLYSArtifact; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public abstract class RangeState extends DefaultState { /** The logger that is used in this class. */ private Logger logger = Logger.getLogger(RangeState.class); public RangeState() { } protected abstract String getLowerField(); protected abstract String getUpperField(); protected abstract String getStepField(); protected abstract double[] getMinMax(Artifact artifact); protected boolean validateBounds( double fromValid, double toValid, double from, double to) throws IllegalArgumentException { if (from < fromValid) { logger.error( "Invalid 'from'. " + from + " is smaller than " + fromValid); throw new IllegalArgumentException("error_feed_from_out_of_range"); } else if (to > toValid) { logger.error( "Invalid 'to'. " + to + " is bigger than " + toValid); throw new IllegalArgumentException("error_feed_to_out_of_range"); } return true; } /** * Validates a given range with a given valid range. * * @param fromValid Valid lower value of the range. * @param toValid Valid upper value of the range. * @param from The lower value. * @param to The upper value. * @param step The step width. * * @return true, if everything was fine, otherwise an exception is thrown. */ protected boolean validateBounds( double fromValid, double toValid, double from, double to, double step) throws IllegalArgumentException { logger.debug("RangeState.validateRange"); // XXX The step width is not validated at the moment! return validateBounds(fromValid, toValid, from, to); } @Override public boolean validate(Artifact artifact) throws IllegalArgumentException { FLYSArtifact flys = (FLYSArtifact) artifact; StateData dFrom = getData(flys, getLowerField()); StateData dTo = getData(flys, getUpperField()); StateData dStep = getData(flys, getStepField()); String fromStr = dFrom != null ? (String) dFrom.getValue() : null; String toStr = dTo != null ? (String) dTo.getValue() : null; String stepStr = dStep != null ? (String) dStep.getValue() : null; if (fromStr == null || toStr == null || stepStr == null) { throw new IllegalArgumentException("error_empty_state"); } try { double from = Double.parseDouble(fromStr); double to = Double.parseDouble(toStr); double step = Double.parseDouble(stepStr); double[] minmax = getMinMax(flys); return validateBounds(minmax[0], minmax[1], from, to, step); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("error_invalid_double_value"); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :