[PATCH] S/Q relation: Added forgotten class

Wald Commits scm-commit at wald.intevation.org
Wed Aug 14 11:01:20 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1376470876 -7200
# Node ID 1c3b2f7dc9a44277c3a3a4f9226673d66217fa2c
# Parent  f48d45e760d083fcfc3a98efd2e3d900db385448
S/Q relation: Added forgotten class.

diff -r f48d45e760d0 -r 1c3b2f7dc9a4 artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/LogSQ.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/LogSQ.java	Wed Aug 14 11:01:16 2013 +0200
@@ -0,0 +1,68 @@
+/* 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.artifacts.model.sq;
+
+public class LogSQ extends SQ {
+
+    public static final View LOG_SQ_VIEW = new View() {
+        @Override
+        public double getS(SQ sq) {
+            return ((LogSQ)sq).getLogS();
+        }
+
+        @Override
+        public double getQ(SQ sq) {
+            return ((LogSQ)sq).getLogQ();
+        }
+    };
+
+    public static final Factory LOG_SQ_FACTORY = new Factory() {
+        @Override
+        public SQ createSQ(double s, double q) {
+            return new LogSQ(s, q);
+        }
+    };
+
+    protected double logS;
+    protected double logQ;
+
+    protected boolean logTrans;
+
+    public LogSQ() {
+    }
+
+    public LogSQ(double s, double q) {
+        super(s, q);
+    }
+
+    /** important: We cannot process negative s/q. */
+    @Override
+    public boolean isValid() {
+        return super.isValid() && s > 0d && q > 0d;
+    }
+
+    protected void ensureLogTrans() {
+        if (!logTrans) {
+            logTrans = true;
+            logS = Math.log(s);
+            logQ = Math.log(q);
+        }
+    }
+
+    public double getLogS() {
+        ensureLogTrans();
+        return logS;
+    }
+
+    public double getLogQ() {
+        ensureLogTrans();
+        return logQ;
+    }
+}
+


More information about the Dive4elements-commits mailing list