[PATCH 2 of 2] Refactored BedDifferenceYearGenerator to use new BedDiffYearProcessor
Wald Commits
scm-commit at wald.intevation.org
Mon Jul 15 14:36:39 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1373892129 -7200
# Node ID 6435b3d7fb5213f95a163bbc9095eb1dd5986f39
# Parent 28ab77bf7ecef9a65e10edfba482efbdfb7f2300
Refactored BedDifferenceYearGenerator to use new BedDiffYearProcessor.
diff -r 28ab77bf7ece -r 6435b3d7fb52 artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java Mon Jul 15 14:41:03 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceYearGenerator.java Mon Jul 15 14:42:09 2013 +0200
@@ -22,6 +22,8 @@
import org.dive4elements.river.artifacts.model.minfo.MorphologicWidth;
import org.dive4elements.river.exports.StyledSeriesBuilder;
import org.dive4elements.river.exports.fixings.FixChartGenerator;
+import org.dive4elements.river.exports.process.BedDiffYearProcessor;
+import org.dive4elements.river.exports.process.BedDiffHeightYearProcessor;
import org.dive4elements.river.exports.process.KMIndexProcessor;
import org.dive4elements.river.exports.process.Processor;
import org.dive4elements.river.exports.process.WOutProcessor;
@@ -110,41 +112,13 @@
Processor processor = new KMIndexProcessor();
Processor woutp = new WOutProcessor();
- if (name.equals(BED_DIFFERENCE_YEAR)) {
- doBedDifferenceYearOut(
- (BedDiffYearResult) bundle.getData(context),
- bundle, attr, visible);
- }
- else if (name.equals(BED_DIFFERENCE_MORPH_WIDTH)) {
+ Processor bdhyProcessor = new BedDiffHeightYearProcessor();
+ Processor bdyProcessor = new BedDiffYearProcessor();
+ if (name.equals(BED_DIFFERENCE_MORPH_WIDTH)) {
doBedDifferenceMorphWidthOut(
(BedDiffYearResult) bundle.getData(context),
bundle, attr, visible);
}
- else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT1)) {
- doBedDifferenceHeightsOut(
- (BedDiffYearResult)bundle.getData(context),
- bundle, attr, visible, 0);
- }
- else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT2)) {
- doBedDifferenceHeightsOut(
- (BedDiffYearResult)bundle.getData(context),
- bundle, attr, visible, 1);
- }
- else if (name.equals(BED_DIFFERENCE_YEAR_FILTERED)) {
- doBedDifferenceYearOut(
- (BedDiffYearResult) bundle.getData(context),
- bundle, attr, visible);
- }
- else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED)) {
- doBedDifferenceHeightsOut(
- (BedDiffYearResult)bundle.getData(context),
- bundle, attr, visible, 0);
- }
- else if (name.equals(BED_DIFFERENCE_YEAR_HEIGHT2_FILTERED)) {
- doBedDifferenceHeightsOut(
- (BedDiffYearResult)bundle.getData(context),
- bundle, attr, visible, 1);
- }
else if (name.equals(MORPHOLOGIC_WIDTH)) {
doMorphologicWidthOut(
(MorphologicWidth)bundle.getData(context),
@@ -163,6 +137,12 @@
attr,
visible);
}
+ else if (bdyProcessor.canHandle(name)) {
+ bdyProcessor.doOut(this, bundle, attr, visible, YAXIS.D.idx);
+ }
+ else if (bdhyProcessor.canHandle(name)) {
+ bdhyProcessor.doOut(this, bundle, attr, visible, YAXIS.D.idx);
+ }
else if (woutp.canHandle(name)) {
woutp.doOut(this, bundle, attr, visible, YAXIS.W.idx);
}
@@ -249,15 +229,6 @@
return label;
}
- protected void doBedDifferenceYearOut(BedDiffYearResult data,
- ArtifactAndFacet aandf, Document theme, boolean visible) {
- logger.debug("doBedDifferenceYearOut()");
-
- XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
- StyledSeriesBuilder.addPoints(series, data.getDifferencesData(), true);
-
- addAxisSeries(series, YAXIS.D.idx, visible);
- }
protected void doBedDifferenceMorphWidthOut(BedDiffYearResult data,
ArtifactAndFacet aandf, Document theme, boolean visible) {
diff -r 28ab77bf7ece -r 6435b3d7fb52 artifacts/src/main/java/org/dive4elements/river/exports/process/BedDiffYearProcessor.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/BedDiffYearProcessor.java Mon Jul 15 14:42:09 2013 +0200
@@ -0,0 +1,87 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * 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.exports.process;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+import org.w3c.dom.Document;
+
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.model.FacetTypes;
+import org.dive4elements.river.artifacts.model.minfo.BedHeightSingle;
+import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult;
+import org.dive4elements.river.exports.StyledSeriesBuilder;
+import org.dive4elements.river.exports.XYChartGenerator;
+import org.dive4elements.river.jfree.StyledXYSeries;
+import org.dive4elements.river.model.BedHeightSingleValue;
+
+
+public class BedDiffYearProcessor implements Processor, FacetTypes {
+
+ private final static Logger logger =
+ Logger.getLogger(BedDiffYearProcessor.class);
+
+ @Override
+ public void doOut(
+ XYChartGenerator generator,
+ ArtifactAndFacet aandf,
+ Document theme,
+ boolean visible,
+ int axidx
+ ) {
+ CallContext context = generator.getCallContext();
+ Object data = aandf.getData(context);
+ if (data instanceof BedDiffYearResult) {
+ String facetType = aandf.getFacetName();
+ int index =
+ (BED_DIFFERENCE_YEAR_HEIGHT1.equals(facetType)
+ || BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED.equals(facetType))?0:1;
+ doBedDifferenceHeightsOut(
+ generator,
+ (BedDiffYearResult) data,
+ aandf, theme, visible, index, axidx);
+ return;
+ }
+ logger.error("Can't process " + data.getClass().getName() + " objects");
+ }
+
+ @Override
+ public boolean canHandle(String facetType) {
+ return
+ BED_DIFFERENCE_YEAR_HEIGHT1.equals(facetType)
+ || BED_DIFFERENCE_YEAR_HEIGHT2.equals(facetType)
+ || BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED.equals(facetType)
+ || BED_DIFFERENCE_YEAR_HEIGHT2_FILTERED.equals(facetType);
+ }
+
+ private void doBedDifferenceHeightsOut(
+ XYChartGenerator generator,
+ BedDiffYearResult data,
+ ArtifactAndFacet bundle,
+ Document attr,
+ boolean visible,
+ int idx,
+ int axidx) {
+ logger.debug("doBedDifferenceHeightsOut()");
+
+ XYSeries series = new StyledXYSeries(bundle.getFacetDescription(), attr);
+ if (idx == 0) {
+ StyledSeriesBuilder.addPoints(series, data.getHeights1Data(), true);
+ }
+ else {
+ StyledSeriesBuilder.addPoints(series, data.getHeights2Data(), true);
+ }
+
+ generator.addAxisSeries(series, axidx, visible);
+ }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4elements-commits
mailing list