[PATCH] 2.3.4.1.10 Berechnung mit Start-km > End-km

Wald Commits scm-commit at wald.intevation.org
Mon May 28 13:22:53 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1527506565 -7200
# Node ID 850ce16034e96cb64951e9c486d2a24fa19cd4a0
# Parent  32dd7e761e4e6374a885064e3abae67c32316c29
2.3.4.1.10	Berechnung mit Start-km > End-km

diff -r 32dd7e761e4e -r 850ce16034e9 artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Mon May 28 10:56:57 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Mon May 28 13:22:45 2018 +0200
@@ -252,5 +252,13 @@
 
         return DoubleUtil.explode(getFrom(), getTo(), step);
     }
+
+    public final double getLowerKm() {
+        return Math.min(this.getFrom(), this.getTo());
+    }
+
+    public final double getUpperKm() {
+        return Math.max(this.getFrom(), this.getTo());
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
diff -r 32dd7e761e4e -r 850ce16034e9 artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java	Mon May 28 10:56:57 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/FixCalculation.java	Mon May 28 13:22:45 2018 +0200
@@ -8,30 +8,6 @@
 
 package org.dive4elements.river.artifacts.model.fixings;
 
-import org.dive4elements.artifacts.common.utils.StringUtils;
-
-import org.dive4elements.river.artifacts.access.FixAccess;
-
-import org.dive4elements.river.artifacts.math.fitting.Function;
-import org.dive4elements.river.artifacts.math.fitting.FunctionFactory;
-
-import org.dive4elements.river.artifacts.model.Calculation;
-import org.dive4elements.river.artifacts.model.CalculationResult;
-import org.dive4elements.river.artifacts.model.FixingsColumn;
-import org.dive4elements.river.artifacts.model.FixingsColumnFactory;
-
-import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing.Filter;
-
-import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing;
-import org.dive4elements.river.artifacts.model.FixingsOverview.IdsFilter;
-
-import org.dive4elements.river.artifacts.model.FixingsOverview;
-import org.dive4elements.river.artifacts.model.FixingsOverviewFactory;
-import org.dive4elements.river.artifacts.model.Parameters;
-
-import org.dive4elements.river.utils.DoubleUtil;
-import org.dive4elements.river.utils.KMIndex;
-
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -39,99 +15,104 @@
 import java.util.Map;
 
 import org.apache.log4j.Logger;
+import org.dive4elements.artifacts.common.utils.StringUtils;
+import org.dive4elements.river.artifacts.access.FixAccess;
+import org.dive4elements.river.artifacts.math.fitting.Function;
+import org.dive4elements.river.artifacts.math.fitting.FunctionFactory;
+import org.dive4elements.river.artifacts.model.Calculation;
+import org.dive4elements.river.artifacts.model.CalculationResult;
+import org.dive4elements.river.artifacts.model.FixingsColumn;
+import org.dive4elements.river.artifacts.model.FixingsColumnFactory;
+import org.dive4elements.river.artifacts.model.FixingsOverview;
+import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing;
+import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing.Filter;
+import org.dive4elements.river.artifacts.model.FixingsOverview.IdsFilter;
+import org.dive4elements.river.artifacts.model.FixingsOverviewFactory;
+import org.dive4elements.river.artifacts.model.Parameters;
+import org.dive4elements.river.utils.DoubleUtil;
+import org.dive4elements.river.utils.KMIndex;
 
 /** Calculation base class for fix. */
-public abstract class FixCalculation
-extends               Calculation
-{
+public abstract class FixCalculation extends Calculation {
     private static Logger log = Logger.getLogger(FixCalculation.class);
 
     public static final double EPSILON = 1e-4;
 
-    public static final String [] STANDARD_COLUMNS = {
-        "km", "chi_sqr", "max_q", "std-dev"
-    };
+    public static final String[] STANDARD_COLUMNS = { "km", "chi_sqr", "max_q", "std-dev" };
 
     protected static class FitResult {
 
-        protected Parameters      parameters;
-        protected KMIndex<QWD []> referenced;
-        protected KMIndex<QWI []> outliers;
+        protected Parameters parameters;
+        protected KMIndex<QWD[]> referenced;
+        protected KMIndex<QWI[]> outliers;
 
         public FitResult() {
         }
 
-        public FitResult(
-            Parameters      parameters,
-            KMIndex<QWD []> referenced,
-            KMIndex<QWI []> outliers
-        ) {
+        public FitResult(final Parameters parameters, final KMIndex<QWD[]> referenced, final KMIndex<QWI[]> outliers) {
             this.parameters = parameters;
             this.referenced = referenced;
-            this.outliers   = outliers;
+            this.outliers = outliers;
         }
 
         public Parameters getParameters() {
-            return parameters;
+            return this.parameters;
         }
 
-        public KMIndex<QWD []> getReferenced() {
-            return referenced;
+        public KMIndex<QWD[]> getReferenced() {
+            return this.referenced;
         }
 
-        public KMIndex<QWI []> getOutliers() {
-            return outliers;
+        public KMIndex<QWI[]> getOutliers() {
+            return this.outliers;
         }
     } // class FitResult
 
-    /** Helper class to bundle the meta information of a column
-     *  and the real data.
+    /**
+     * Helper class to bundle the meta information of a column
+     * and the real data.
      */
     protected static class Column {
 
         protected Fixing.Column meta;
         protected FixingsColumn data;
-        protected int           index;
+        protected int index;
 
         public Column() {
         }
 
-        public Column(Fixing.Column meta, FixingsColumn data, int index) {
-            this.meta  = meta;
-            this.data  = data;
+        public Column(final Fixing.Column meta, final FixingsColumn data, final int index) {
+            this.meta = meta;
+            this.data = data;
             this.index = index;
         }
 
         public Date getDate() {
-            return meta.getStartTime();
+            return this.meta.getStartTime();
         }
 
         public String getDescription() {
-            return meta.getDescription();
+            return this.meta.getDescription();
         }
 
         public int getIndex() {
-            return index;
+            return this.index;
         }
 
         public int getId() {
-            return meta.getId();
+            return this.meta.getId();
         }
 
-        public boolean getQW(
-            double    km,
-            double [] qs,
-            double [] ws,
-            int       index
-        ) {
-            qs[index] = data.getQ(km);
-            return data.getW(km, ws, index);
+        public boolean getQW(final double km, final double[] qs, final double[] ws, final int index) {
+            qs[index] = this.data.getQ(km);
+            return this.data.getW(km, ws, index);
         }
 
-        public boolean getQW(double km, double [] wq) {
-            data.getW(km, wq, 0);
-            if (Double.isNaN(wq[0])) return false;
-            wq[1] = data.getQ(km);
+        public boolean getQW(final double km, final double[] wq) {
+            this.data.getW(km, wq, 0);
+            if (Double.isNaN(wq[0]))
+                return false;
+            wq[1] = this.data.getQ(km);
             return !Double.isNaN(wq[1]);
         }
     } // class Column
@@ -144,49 +125,46 @@
         protected Map<Integer, Column> columns;
 
         public ColumnCache() {
-            columns = new HashMap<Integer, Column>();
+            this.columns = new HashMap<>();
         }
 
-        public Column getColumn(Fixing.Column meta) {
-            Integer key = meta.getId();
-            Column column = columns.get(key);
+        public Column getColumn(final Fixing.Column meta) {
+            final Integer key = meta.getId();
+            Column column = this.columns.get(key);
             if (column == null) {
-                FixingsColumn data = FixingsColumnFactory
-                    .getInstance()
-                    .getColumnData(meta);
+                final FixingsColumn data = FixingsColumnFactory.getInstance().getColumnData(meta);
                 if (data != null) {
-                    column = new Column(meta, data, columns.size());
-                    columns.put(key, column);
+                    column = new Column(meta, data, this.columns.size());
+                    this.columns.put(key, column);
                 }
             }
             return column;
         }
     } // class ColumnCache
 
-
-    protected String  river;
-    protected double  from;
-    protected double  to;
-    protected double  step;
+    protected String river;
+    protected double from;
+    protected double to;
+    protected double step;
     protected boolean preprocessing;
-    protected String  function;
-    protected int []  events;
-    protected int     qSectorStart;
-    protected int     qSectorEnd;
+    protected String function;
+    protected int[] events;
+    protected int qSectorStart;
+    protected int qSectorEnd;
 
     public FixCalculation() {
     }
 
-    public FixCalculation(FixAccess access) {
-        String  river         = access.getRiverName();
-        Double  from          = access.getFrom();
-        Double  to            = access.getTo();
-        Double  step          = access.getStep();
-        String  function      = access.getFunction();
-        int []  events        = access.getEvents();
-        Integer qSectorStart  = access.getQSectorStart();
-        Integer qSectorEnd    = access.getQSectorEnd();
-        Boolean preprocessing = access.getPreprocessing();
+    public FixCalculation(final FixAccess access) {
+        final String river = access.getRiverName();
+        final Double from = access.getLowerKm();
+        final Double to = access.getUpperKm();
+        final Double step = access.getStep();
+        final String function = access.getFunction();
+        final int[] events = access.getEvents();
+        final Integer qSectorStart = access.getQSectorStart();
+        final Integer qSectorEnd = access.getQSectorEnd();
+        final Boolean preprocessing = access.getPreprocessing();
 
         if (river == null) {
             addProblem("fix.missing.river");
@@ -225,57 +203,51 @@
         }
 
         if (!hasProblems()) {
-            this.river         = river;
-            this.from          = from;
-            this.to            = to;
-            this.step          = step;
-            this.function      = function;
-            this.events        = events;
-            this.qSectorStart  = qSectorStart;
-            this.qSectorEnd    = qSectorEnd;
+            this.river = river;
+            this.from = from;
+            this.to = to;
+            this.step = step;
+            this.function = function;
+            this.events = events;
+            this.qSectorStart = qSectorStart;
+            this.qSectorEnd = qSectorEnd;
             this.preprocessing = preprocessing;
         }
     }
 
-    protected static String toString(
-        String [] parameterNames,
-        double [] values
-    ) {
-        StringBuilder sb = new StringBuilder();
+    protected static String toString(final String[] parameterNames, final double[] values) {
+        final StringBuilder sb = new StringBuilder();
         for (int i = 0; i < parameterNames.length; ++i) {
-            if (i > 0) sb.append(", ");
+            if (i > 0)
+                sb.append(", ");
             sb.append(parameterNames[i]).append(": ").append(values[i]);
         }
         return sb.toString();
     }
 
-
-    /** Create filter to accept only the chosen events.
-     *  This factored out out to be overwritten.
+    /**
+     * Create filter to accept only the chosen events.
+     * This factored out out to be overwritten.
      */
     protected Filter createFilter() {
-        return new IdsFilter(events);
+        return new IdsFilter(this.events);
     }
 
-    protected List<Column> getEventColumns(
-        FixingsOverview overview,
-        ColumnCache     cc
-    ) {
-        FixingsColumnFactory fcf = FixingsColumnFactory.getInstance();
+    protected List<Column> getEventColumns(final FixingsOverview overview, final ColumnCache cc) {
+        final FixingsColumnFactory fcf = FixingsColumnFactory.getInstance();
 
-        Filter filter = createFilter();
+        final Filter filter = createFilter();
 
-        List<Fixing.Column> metas = overview.filter(null, filter);
+        final List<Fixing.Column> metas = overview.filter(null, filter);
 
-        List<Column> columns = new ArrayList<Column>(metas.size());
+        final List<Column> columns = new ArrayList<>(metas.size());
 
-        for (Fixing.Column meta: metas) {
+        for (final Fixing.Column meta : metas) {
 
-            Column data = cc.getColumn(meta);
+            final Column data = cc.getColumn(meta);
             if (data == null) {
                 addProblem("fix.cannot.load.data");
-            }
-            else {
+            } else {
                 columns.add(data);
             }
         }
@@ -284,12 +256,8 @@
     }
 
     // Fit a function to the given points from fixation.
-    protected FitResult doFitting(
-        FixingsOverview overview,
-        ColumnCache     cc,
-        Function        func
-    ) {
-        boolean debug = log.isDebugEnabled();
+    protected FitResult doFitting(final FixingsOverview overview, final ColumnCache cc, final Function func) {
+        final boolean debug = log.isDebugEnabled();
 
         final List<Column> eventColumns = getEventColumns(overview, cc);
 
@@ -298,26 +266,19 @@
             return null;
         }
 
-        final double  [] qs = new double[eventColumns.size()];
-        final double  [] ws = new double[qs.length];
-        final boolean [] interpolated = new boolean[ws.length];
+        final double[] qs = new double[eventColumns.size()];
+        final double[] ws = new double[qs.length];
+        final boolean[] interpolated = new boolean[ws.length];
 
-        Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() {
+        final Fitting.QWDFactory qwdFactory = new Fitting.QWDFactory() {
             @Override
-            public QWD create(double q, double w) {
+            public QWD create(final double q, final double w) {
                 // Check all the event columns for close match
                 // and take the description and the date from meta.
                 for (int i = 0; i < qs.length; ++i) {
-                    if (Math.abs(qs[i]-q) < EPSILON
-                    &&  Math.abs(ws[i]-w) < EPSILON) {
-                        Column column = eventColumns.get(i);
-                        return new QWD(
-                            qs[i], ws[i],
-                            column.getDescription(),
-                            column.getDate(),
-                            interpolated[i],
-                            0d,
-                            column.getId()); // Use database id here
+                    if (Math.abs(qs[i] - q) < EPSILON && Math.abs(ws[i] - w) < EPSILON) {
+                        final Column column = eventColumns.get(i);
+                        return new QWD(qs[i], ws[i], column.getDescription(), column.getDate(), interpolated[i], 0d, column.getId()); // Use database id here
                     }
                 }
                 log.warn("cannot find column for (" + q + ", " + w + ")");
@@ -325,35 +286,33 @@
             }
         };
 
-        Fitting fitting = new Fitting(func, qwdFactory, preprocessing);
+        final Fitting fitting = new Fitting(func, qwdFactory, this.preprocessing);
 
-        String [] parameterNames = func.getParameterNames();
+        final String[] parameterNames = func.getParameterNames();
 
-        Parameters results =
-            new Parameters(
-                StringUtils.join(STANDARD_COLUMNS, parameterNames));
+        final Parameters results = new Parameters(StringUtils.join(STANDARD_COLUMNS, parameterNames));
 
         boolean invalid = false;
 
-        double [] kms = DoubleUtil.explode(from, to, step / 1000.0);
+        final double[] kms = DoubleUtil.explode(this.from, this.to, this.step / 1000.0);
 
         if (debug) {
             log.debug("number of kms: " + kms.length);
         }
 
-        KMIndex<QWI []> outliers   = new KMIndex<QWI []>();
-        KMIndex<QWD []> referenced = new KMIndex<QWD []>(kms.length);
+        final KMIndex<QWI[]> outliers = new KMIndex<>();
+        final KMIndex<QWD[]> referenced = new KMIndex<>(kms.length);
 
-        int kmIndex             = results.columnIndex("km");
-        int chiSqrIndex         = results.columnIndex("chi_sqr");
-        int maxQIndex           = results.columnIndex("max_q");
-        int stdDevIndex         = results.columnIndex("std-dev");
-        int [] parameterIndices = results.columnIndices(parameterNames);
+        final int kmIndex = results.columnIndex("km");
+        final int chiSqrIndex = results.columnIndex("chi_sqr");
+        final int maxQIndex = results.columnIndex("max_q");
+        final int stdDevIndex = results.columnIndex("std-dev");
+        final int[] parameterIndices = results.columnIndices(parameterNames);
 
         int numFailed = 0;
 
-        for (int i = 0; i < kms.length; ++i) {
-            double km = kms[i];
+        for (final double km2 : kms) {
+            final double km = km2;
 
             // Fill Qs and Ws from event columns.
             for (int j = 0; j < ws.length; ++j) {
@@ -369,7 +328,7 @@
                 continue;
             }
 
-            QWD [] refs = fitting.referencedToArray();
+            final QWD[] refs = fitting.referencedToArray();
 
             referenced.add(km, refs);
 
@@ -377,17 +336,17 @@
                 outliers.add(km, fitting.outliersToArray());
             }
 
-            int row = results.newRow();
-            double [] values = fitting.getParameters();
+            final int row = results.newRow();
+            final double[] values = fitting.getParameters();
 
             results.set(row, kmIndex, km);
             results.set(row, chiSqrIndex, fitting.getChiSquare());
             results.set(row, stdDevIndex, fitting.getStandardDeviation());
-            results.set(row, maxQIndex,   fitting.getMaxQ());
+            results.set(row, maxQIndex, fitting.getMaxQ());
             invalid |= results.set(row, parameterIndices, values);
 
             if (debug) {
-                log.debug("km: "+km+" " + toString(parameterNames, values));
+                log.debug("km: " + km + " " + toString(parameterNames, values));
             }
         }
 
@@ -404,22 +363,17 @@
         outliers.sort();
         referenced.sort();
 
-        return new FitResult(
-            results,
-            referenced,
-            outliers);
+        return new FitResult(results, referenced, outliers);
     }
 
     public CalculationResult calculate() {
-        FixingsOverview overview =
-            FixingsOverviewFactory.getOverview(river);
+        final FixingsOverview overview = FixingsOverviewFactory.getOverview(this.river);
 
         if (overview == null) {
             addProblem("fix.no.overview.available");
         }
 
-        Function func = FunctionFactory.getInstance()
-            .getFunction(function);
+        final Function func = FunctionFactory.getInstance().getFunction(this.function);
 
         if (func == null) {
             addProblem("fix.invalid.function.name");
@@ -428,13 +382,13 @@
         if (hasProblems()) {
             return new CalculationResult(this);
         }
-        CalculationResult result = innerCalculate(overview, func);
+        final CalculationResult result = innerCalculate(overview, func);
 
         if (result != null) {
             // Workaraound to deal with same dates in data set
-            Object o = result.getData();
+            final Object o = result.getData();
             if (o instanceof FixResult) {
-                FixResult fr = (FixResult)o;
+                final FixResult fr = (FixResult) o;
                 fr.makeReferenceEventsDatesUnique();
                 fr.remapReferenceIndicesToRank();
             }
@@ -443,9 +397,6 @@
         return result;
     }
 
-    protected abstract CalculationResult innerCalculate(
-        FixingsOverview overview,
-        Function        function
-    );
+    protected abstract CalculationResult innerCalculate(FixingsOverview overview, Function function);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 32dd7e761e4e -r 850ce16034e9 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java	Mon May 28 10:56:57 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java	Mon May 28 13:22:45 2018 +0200
@@ -86,8 +86,8 @@
             catch (final NumberFormatException nfe) {
                 this.collectionView.setSteps(100d);
             }
-            fromKm = fixFilter.getFromKm();
-            toKm = fixFilter.getToKm();
+            fromKm = fixFilter.getLowerKm();
+            toKm = fixFilter.getUpperKm();
         } else {
             // Probably WINFOArtifact kind of artifact.
             final String ld_step = art.getArtifactDescription().getDataValueAsString("ld_step");
@@ -292,7 +292,7 @@
         if (this.collectionView.getArtifact() instanceof AbstractFixBunduArtifact) {
             if (this.collectionView.getCurrentKm() == -1) {
                 final AbstractFixBunduArtifact fix = (AbstractFixBunduArtifact) this.collectionView.getArtifact();
-                this.collectionView.setCurrentKm(fix.getFilter().getFromKm());
+                this.collectionView.setCurrentKm(fix.getFilter().getLowerKm());
             }
         } else if (this.collectionView.getCurrentKm() == -1) {
             this.collectionView.setCurrentKm(this.collectionView.getArtifact().getArtifactDescription().getKMRange()[0]);
diff -r 32dd7e761e4e -r 850ce16034e9 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixLocationPanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixLocationPanel.java	Mon May 28 10:56:57 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixLocationPanel.java	Mon May 28 13:22:45 2018 +0200
@@ -8,45 +8,39 @@
 
 package org.dive4elements.river.client.client.ui.fixation;
 
+import java.util.ArrayList;
 import java.util.List;
-import java.util.ArrayList;
-
-import com.google.gwt.core.client.GWT;
-
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.Label;
-
-import com.smartgwt.client.widgets.layout.HLayout;
-import com.smartgwt.client.widgets.layout.VLayout;
-
-import com.smartgwt.client.widgets.form.fields.FormItem;
-import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
-import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
 
 import org.dive4elements.river.client.client.FLYSConstants;
 import org.dive4elements.river.client.client.ui.DoubleRangePanel;
-
 import org.dive4elements.river.client.shared.model.Data;
 import org.dive4elements.river.client.shared.model.DataItem;
 import org.dive4elements.river.client.shared.model.DataList;
 import org.dive4elements.river.client.shared.model.DefaultData;
 import org.dive4elements.river.client.shared.model.DefaultDataItem;
+
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
+import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
 /**
  * This UIProvider creates a panel for location or distance input.
  *
  * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
  */
-public class FixLocationPanel
-extends      FixationPanel
-implements   BlurHandler
-{
+public class FixLocationPanel extends FixationPanel implements BlurHandler {
     /** The message class that provides i18n strings. */
     protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
 
-    /** The constant name of the input field to enter locations.*/
+    /** The constant name of the input field to enter locations. */
     public static final String FIELD_VALUE_LOCATION = "location";
 
-    /** The constant name of the input field to enter distance.*/
+    /** The constant name of the input field to enter distance. */
     public static final String FIELD_VALUE_DISTANCE = "distance";
 
     DoubleRangePanel inputPanel;
@@ -56,61 +50,54 @@
     double step;
 
     public FixLocationPanel() {
-        htmlOverview = "";
+        this.htmlOverview = "";
     }
 
-    public Canvas createWidget(DataList data) {
+    @Override
+    public Canvas createWidget(final DataList data) {
         instances.put(this.artifact.getUuid(), this);
 
-        VLayout layout = new VLayout();
+        final VLayout layout = new VLayout();
 
-        Canvas title = new Label(MESSAGES.distance());
+        final Canvas title = new Label(this.MESSAGES.distance());
         title.setHeight("25px");
 
-        inputPanel = new DoubleRangePanel(
-                MESSAGES.unitFrom(),
-                MESSAGES.unitTo(),
-                MESSAGES.unitWidth(),
-                0d,
-                0d,
-                0d,
-                240,
-                this);
+        this.inputPanel = new DoubleRangePanel(this.MESSAGES.unitFrom(), this.MESSAGES.unitTo(), this.MESSAGES.unitWidth(), 0d, 0d, 0d, 240, this);
 
         layout.addMember(title);
-        layout.addMember(inputPanel);
+        layout.addMember(this.inputPanel);
         return layout;
     }
 
     @Override
-    public Canvas createOld(DataList dataList) {
-        List<Data> items = dataList.getAll();
+    public Canvas createOld(final DataList dataList) {
+        final List<Data> items = dataList.getAll();
 
-        Data       f      = getData(items, "ld_from");
-        Data       t      = getData(items, "ld_to");
-        Data       s      = getData(items, "ld_step");
-        DataItem[] fItems = f.getItems();
-        DataItem[] tItems = t.getItems();
-        DataItem[] sItems = s.getItems();
+        final Data f = getData(items, "ld_from");
+        final Data t = getData(items, "ld_to");
+        final Data s = getData(items, "ld_step");
+        final DataItem[] fItems = f.getItems();
+        final DataItem[] tItems = t.getItems();
+        final DataItem[] sItems = s.getItems();
 
-        StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
         sb.append(fItems[0].getLabel());
-        sb.append(" " + MESSAGES.unitFrom() + " ");
+        sb.append(" " + this.MESSAGES.unitFrom() + " ");
         sb.append(tItems[0].getLabel());
-        sb.append(" " + MESSAGES.unitTo() + " ");
+        sb.append(" " + this.MESSAGES.unitTo() + " ");
         sb.append(sItems[0].getLabel());
-        sb.append(" " + MESSAGES.unitWidth());
+        sb.append(" " + this.MESSAGES.unitWidth());
 
-        Label old = new Label(sb.toString());
+        final Label old = new Label(sb.toString());
         old.setWidth(130);
 
-        HLayout layout = new HLayout();
+        final HLayout layout = new HLayout();
         layout.setWidth("400px");
 
-        Label   label  = new Label(dataList.getLabel());
+        final Label label = new Label(dataList.getLabel());
         label.setWidth("200px");
 
-        Canvas back = getBackButton(dataList.getState());
+        final Canvas back = getBackButton(dataList.getState());
 
         layout.addMember(label);
         layout.addMember(old);
@@ -119,40 +106,36 @@
         return layout;
     }
 
-
     /**
      * This method returns the selected data.
      *
      * @return the selected/inserted data.
      */
+    @Override
     public Data[] getData() {
-        List<Data> data = new ArrayList<Data>();
+        final List<Data> data = new ArrayList<Data>();
 
-        boolean valid = saveRangeValues(inputPanel);
+        final boolean valid = saveRangeValues(this.inputPanel);
         if (valid) {
-            String f = Double.valueOf(this.from).toString();
-            String t = Double.valueOf(this.to).toString();
-            String s = Double.valueOf(this.step).toString();
-            DataItem fi = new DefaultDataItem("ld_from", "ld_from", f);
-            DataItem ti = new DefaultDataItem("ld_to", "ld_to", t);
-            DataItem si = new DefaultDataItem("ld_step", "ld_step", s);
-            data.add(new DefaultData(
-                    "ld_from", null, null, new DataItem[]{ fi }));
-            data.add(new DefaultData(
-                    "ld_to", null, null, new DataItem[]{ ti }));
-            data.add(new DefaultData(
-                    "ld_step", null, null, new DataItem[]{ si }));
+            final String f = Double.valueOf(this.from).toString();
+            final String t = Double.valueOf(this.to).toString();
+            final String s = Double.valueOf(this.step).toString();
+            final DataItem fi = new DefaultDataItem("ld_from", "ld_from", f);
+            final DataItem ti = new DefaultDataItem("ld_to", "ld_to", t);
+            final DataItem si = new DefaultDataItem("ld_step", "ld_step", s);
+            data.add(new DefaultData("ld_from", null, null, new DataItem[] { fi }));
+            data.add(new DefaultData("ld_to", null, null, new DataItem[] { ti }));
+            data.add(new DefaultData("ld_step", null, null, new DataItem[] { si }));
         }
         // what else?
         return data.toArray(new Data[data.size()]);
     }
 
+    protected boolean saveRangeValues(final DoubleRangePanel p) {
+        final FormItem[] items = p.getFields();
+        final boolean valid = p.validateForm();
 
-    protected boolean saveRangeValues(DoubleRangePanel p) {
-        FormItem[] items = p.getFields();
-        boolean valid = p.validateForm();
-
-        if(valid) {
+        if (valid) {
             this.from = p.getFrom();
             this.to = p.getTo();
             this.step = p.getStep();
@@ -160,45 +143,45 @@
         return valid;
     }
 
-
     @Override
-    public void setValues(String cid, boolean checked) {
+    public void setValues(final String cid, final boolean checked) {
         // No user interaction, do nothing.
     }
 
-
     @Override
     public boolean renderCheckboxes() {
         // No selection, return false.
         return false;
     }
 
-
+    @Override
     public void success() {
-        inputPanel.setValues(fixInfo.getFrom(), fixInfo.getTo(), 100d);
+        this.inputPanel.setValues(this.fixInfo.getLowerKm(), // TODO: check if revert makes sense
+                this.fixInfo.getUpperKm(), 100d);
     }
 
     /**
      * This method is used to validate the inserted data in the form fields.
      *
-     * @param event The BlurEvent that gives information about the FormItem that
-     * has been modified and its value.
+     * @param event
+     *            The BlurEvent that gives information about the FormItem that
+     *            has been modified and its value.
      */
-    public void onBlur(BlurEvent event) {
-        FormItem item = event.getItem();
-        String  field = item.getFieldName();
+    @Override
+    public void onBlur(final BlurEvent event) {
+        final FormItem item = event.getItem();
+        final String field = item.getFieldName();
 
         if (field == null) {
             return;
         }
-        DoubleRangePanel p = (DoubleRangePanel) event.getForm();
+        final DoubleRangePanel p = (DoubleRangePanel) event.getForm();
     }
 
-
-    public void dumpGWT(String cid) {
+    public void dumpGWT(final String cid) {
         GWT.log("Setting values for cId: " + cid);
-        GWT.log("River: " + fixInfo.getRiver());
-        GWT.log("Date: " + fixInfo.getEventByCId(cid).getDate());
-        GWT.log("Name: " + fixInfo.getEventByCId(cid).getDescription());
+        GWT.log("River: " + this.fixInfo.getRiver());
+        GWT.log("Date: " + this.fixInfo.getEventByCId(cid).getDate());
+        GWT.log("Name: " + this.fixInfo.getEventByCId(cid).getDescription());
     }
 }
diff -r 32dd7e761e4e -r 850ce16034e9 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java	Mon May 28 10:56:57 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java	Mon May 28 13:22:45 2018 +0200
@@ -161,8 +161,8 @@
                         final FixFilter filter = art.getFilter();
                         filter.setRiver(info.getRiver());
                         if (filter.getCurrentKm() == -Double.MAX_VALUE || filter.getCurrentKm() == -1d) {
-                            filter.setCurrentKm(info.getFrom());
-                            filter.setToKm(info.getTo());
+                            filter.setCurrentKm(filter.getLowerKm());
+                            filter.setToKm(filter.getUpperKm());
                         }
                         if (FixationPanel.this.kmText != null) {
                             final NumberFormat nf = NumberFormat.getDecimalFormat();
@@ -175,7 +175,7 @@
                             }
                         }
                         eventPane.setContents(FixationPanel.this.htmlOverview);
-                        updateChartTab(FixationPanel.this.fixInfo.getFrom());
+                        updateChartTab(FixationPanel.this.fixInfo.getLowerKm());
                         FixationPanel.this.events.setPane(eventPane);
                         success();
                     }
@@ -261,19 +261,20 @@
 
         final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact;
 
+        // was soll das all
         if (this.fixInfo != null) {
-            if (km < this.fixInfo.getFrom())
-                km = this.fixInfo.getFrom();
-            if (km > this.fixInfo.getTo())
-                km = this.fixInfo.getTo();
+            if (km < this.fixInfo.getLowerKm())
+                km = this.fixInfo.getLowerKm();
+            // if (km > this.fixInfo.getTo())
+            // km = this.fixInfo.getTo();
         }
 
         final FixFilter filter = art.getFilter();
 
-        if (km < filter.getFromKm())
-            km = filter.getFromKm();
-        if (km > filter.getToKm())
-            km = filter.getToKm();
+        if (km < filter.getLowerKm())
+            km = filter.getLowerKm();
+        if (km > filter.getUpperKm())
+            km = filter.getUpperKm();
 
         filter.setCurrentKm(km);
 
@@ -307,7 +308,7 @@
         final FixFilter filter = art.getFilter();
 
         final double curr = filter.getCurrentKm();
-        if (curr > filter.getFromKm()) {
+        if (curr > filter.getLowerKm()) {
             final double newVal = (curr - 0.1) * 10;
             final long round = Math.round(newVal);
             updateChartTab(((double) round) / 10);
@@ -321,7 +322,7 @@
         final FixFilter filter = art.getFilter();
 
         final double curr = filter.getCurrentKm();
-        if (curr < filter.getToKm()) {
+        if (curr < filter.getUpperKm()) {
             final double newVal = (curr + 0.1) * 10;
             final long round = Math.round(newVal);
             updateChartTab(((double) round) / 10);
@@ -383,8 +384,8 @@
     public String getChartFilter(final FixFilter filter, final int width, final int height) {
         final String river = filter.getRiver();
         final double currentKm = filter.getCurrentKm();
-        final double fromKm = filter.getFromKm();
-        final double toKm = filter.getToKm();
+        final double fromKm = filter.getLowerKm();
+        final double toKm = filter.getUpperKm();
 
         if (river != null && river.length() > 0 && currentKm >= fromKm && currentKm <= toKm) {
             final JSONObject jfix = new JSONObject();
@@ -411,8 +412,8 @@
     }
 
     protected static JSONObject createFilter(final FixFilter filter, final JSONObject root) {
-        final double fromKm = filter.getFromKm();
-        final double toKm = filter.getToKm();
+        final double fromKm = filter.getLowerKm();
+        final double toKm = filter.getUpperKm();
         final boolean hasDate = filter.hasDate();
 
         if (fromKm >= 0 && toKm >= 0 && fromKm <= toKm) {
diff -r 32dd7e761e4e -r 850ce16034e9 gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixFilter.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixFilter.java	Mon May 28 10:56:57 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixFilter.java	Mon May 28 13:22:45 2018 +0200
@@ -11,7 +11,7 @@
 import java.io.Serializable;
 
 /** Probably something like *Access, but from client side. */
-public class FixFilter implements Serializable{
+public class FixFilter implements Serializable {
 
     protected String river;
     protected double fromKm;
@@ -37,41 +37,41 @@
         this.events = new int[0];
     }
 
-    public void setRiver(String river) {
+    public void setRiver(final String river) {
         this.river = river;
     }
 
-    public void setFromKm(double from) {
+    public void setFromKm(final double from) {
         this.fromKm = from;
     }
 
-    public void setToKm(double to) {
+    public void setToKm(final double to) {
         this.toKm = to;
     }
 
-    public void setCurrentKm(double km) {
+    public void setCurrentKm(final double km) {
         this.currentKm = km;
     }
 
-    public void setFromClass(int from) {
+    public void setFromClass(final int from) {
         this.fromClass = from;
     }
 
-    public void setToClass(int to) {
+    public void setToClass(final int to) {
         this.toClass = to;
     }
 
-    public void setFromDate(long from) {
+    public void setFromDate(final long from) {
         this.hasDate = true;
         this.fromDate = from;
     }
 
-    public void setToDate(long to) {
+    public void setToDate(final long to) {
         this.hasDate = true;
         this.toDate = to;
     }
 
-    public void setEvents(int[] ev) {
+    public void setEvents(final int[] ev) {
         this.events = ev;
     }
 
@@ -79,14 +79,22 @@
         return this.river;
     }
 
-    public double getFromKm() {
-        return this.fromKm;
+    public double getLowerKm() {
+        return Math.min(this.fromKm, this.toKm);
     }
 
-    public double getToKm() {
-        return this.toKm;
+    public double getUpperKm() {
+        return Math.max(this.fromKm, this.toKm);
     }
 
+    // public double getFromKm() {
+    // return this.fromKm;
+    // }
+    //
+    // public double getToKm() {
+    // return this.toKm;
+    // }
+
     public double getCurrentKm() {
         return this.currentKm;
     }
@@ -112,7 +120,7 @@
     }
 
     public boolean hasDate() {
-        return fromDate != Long.MIN_VALUE && toDate != Long.MIN_VALUE;
+        return this.fromDate != Long.MIN_VALUE && this.toDate != Long.MIN_VALUE;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 32dd7e761e4e -r 850ce16034e9 gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java	Mon May 28 10:56:57 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/FixingsOverviewInfo.java	Mon May 28 13:22:45 2018 +0200
@@ -9,9 +9,8 @@
 package org.dive4elements.river.client.shared.model;
 
 import java.io.Serializable;
-
+import java.util.ArrayList;
 import java.util.List;
-import java.util.ArrayList;
 
 public class FixingsOverviewInfo implements Serializable {
 
@@ -22,16 +21,10 @@
     protected int rid;
     protected String html;
 
-    protected FixingsOverviewInfo() {}
+    private FixingsOverviewInfo() {
+    }
 
-    public FixingsOverviewInfo(
-        int rid,
-        String river,
-        double from,
-        double to,
-        List<FixEvent> events,
-        String html
-    ) {
+    public FixingsOverviewInfo(final int rid, final String river, final double from, final double to, final List<FixEvent> events, final String html) {
         this.rid = rid;
         this.river = river;
         this.from = from;
@@ -48,20 +41,29 @@
         return this.river;
     }
 
-    public double getFrom() {
-        return this.from;
+    public double getLowerKm() {
+        return Math.min(this.from, this.to);
     }
 
-    public double getTo() {
-        return this.to;
+    public double getUpperKm() {
+        return Math.max(this.from, this.to);
     }
 
+    // public double getFrom() {
+    // return this.from < this.to ? this.from : this.to; // TODO: prüfung wieder rausnehmen, hat glaube ich keinen
+    // sinnvollen effekt.
+    // }
+    //
+    // public double getTo() {
+    // return this.to > this.from ? this.to : this.from;
+    // }
+
     public List<FixEvent> getEvents() {
         return this.events;
     }
 
-    public FixEvent getEventByCId(String cid) {
-        for (FixEvent event: events) {
+    public FixEvent getEventByCId(final String cid) {
+        for (final FixEvent event : this.events) {
             if (event.getCId().equals(cid)) {
                 return event;
             }
@@ -73,21 +75,16 @@
         return this.html;
     }
 
-
     public static class FixEvent implements Serializable {
         protected String cid;
         protected String date;
         protected String description;
         protected List<Sector> sectors;
 
-        protected FixEvent () {}
+        protected FixEvent() {
+        }
 
-        public FixEvent(
-            String cid,
-            String date,
-            String description,
-            List<Sector> sectors
-        ) {
+        public FixEvent(final String cid, final String date, final String description, final List<Sector> sectors) {
             this.cid = cid;
             this.date = date;
             this.description = description;
@@ -116,13 +113,10 @@
         protected double from;
         protected double to;
 
-        protected Sector () {}
+        protected Sector() {
+        }
 
-        public Sector(
-            int cls,
-            double from,
-            double to
-        ) {
+        public Sector(final int cls, final double from, final double to) {
             this.cls = cls;
             this.from = from;
             this.to = to;


More information about the Dive4Elements-commits mailing list