changeset 6388:3eff8efb4354

New Facet for sediment load fraction 'unknown'.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 21 Jun 2013 15:29:41 +0200
parents ef08c4f57ede
children 7b67b952b517
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadUnknownFacet.java
diffstat 1 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadUnknownFacet.java	Fri Jun 21 15:29:41 2013 +0200
@@ -0,0 +1,66 @@
+package org.dive4elements.river.artifacts.model.minfo;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.access.SedimentLoadAccess;
+import org.dive4elements.river.artifacts.model.DataFacet;
+import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
+
+
+public class SedimentLoadUnknownFacet
+extends DataFacet
+{
+    /** Very own logger. */
+    private static Logger logger = Logger.getLogger(SedimentLoadFacet.class);
+
+    public SedimentLoadUnknownFacet() {
+    }
+
+    public SedimentLoadUnknownFacet(int idx, String name, String description,
+        ComputeType type, String stateId, String hash) {
+        super(idx, name, description, type, hash, stateId);
+    }
+
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("Get data for sediment load at index: " + index);
+
+        D4EArtifact flys = (D4EArtifact) artifact;
+
+        SedimentLoadAccess access = new SedimentLoadAccess(flys);
+        String river = access.getRiver();
+        SedimentLoad[] unknown =
+            SedimentLoadFactory.getSedimentLoadUnknown(river);
+
+        SedimentLoad load = SedimentLoadFactory.getLoadUnknown(
+            river, unknown[index].getDescription());
+        if (access.getUnit().equals("t/a") && load.getUnit().equals("m3/a")) {
+            for (Double km: load.getKms()) {
+                SedimentLoadFraction fraction = load.getFraction(km);
+                fraction.setUnknown(fraction.getUnknown() / 1.8);
+                load.addKm(km, fraction);
+            }
+        }
+        else if (access.getUnit().equals("m3/a") && load.getUnit().equals("t/a")) {
+            for (Double km: load.getKms()) {
+                SedimentLoadFraction fraction = load.getFraction(km);
+                fraction.setUnknown(fraction.getUnknown() * 1.8);
+                load.addKm(km, fraction);
+            }
+        }
+        return load;
+    }
+
+    /** Copy deeply. */
+    @Override
+    public Facet deepCopy() {
+        SedimentLoadUnknownFacet copy = new SedimentLoadUnknownFacet();
+        copy.set(this);
+        copy.hash = hash;
+        copy.stateId = stateId;
+        return copy;
+    }
+}

http://dive4elements.wald.intevation.org