changeset 690:3481cd37e609 facets-slt

Use enums to dispatch computeFeed() and computeAdvance(). flys-artifacts/branches/facets-slt@2130 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 16 Jun 2011 08:57:05 +0000
parents f8ac04b2dbd0
children 2600aa2c7319
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java
diffstat 3 files changed, 31 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 08:43:58 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 08:57:05 2011 +0000
@@ -46,6 +46,7 @@
 import de.intevation.flys.artifacts.cache.CacheFactory;
 
 import de.intevation.flys.artifacts.model.ComputeCallback;
+import de.intevation.flys.artifacts.model.ComputeCallback.ComputeType;
 import de.intevation.flys.artifacts.model.DischargeTables;
 import de.intevation.flys.artifacts.model.RiverFactory;
 import de.intevation.flys.artifacts.model.Segment;
@@ -196,7 +197,7 @@
         try {
             saveData(target, XPATH_FEED_INPUT, context);
 
-            compute(context);
+            compute(context, ComputeType.FEED);
 
             return describe(target, context);
         }
@@ -261,7 +262,7 @@
 
             setCurrentStateId(targetState);
 
-            compute(context);
+            compute(context, ComputeType.ADVANCE);
 
             return describe(target, context);
         }
@@ -1051,8 +1052,8 @@
      *
      * @param context The CallContext.
      */
-    public Object compute(CallContext context) {
-        return compute(context, hash());
+    public Object compute(CallContext context, ComputeType type) {
+        return compute(context, hash(), type);
     }
 
 
@@ -1067,7 +1068,7 @@
      *
      * @return the computed data.
      */
-    public Object compute(CallContext context, String hash) {
+    public Object compute(CallContext context, String hash, ComputeType type) {
         String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue();
 
         DefaultState current = (DefaultState) getCurrentState(context);
@@ -1079,15 +1080,25 @@
             return null;
         }
 
-        return compute(hash, callback);
+        return compute(hash, callback, type);
     }
 
 
-    public Object compute(String key, ComputeCallback callback) {
+    public Object compute(
+        String          key,
+        ComputeCallback callback,
+        ComputeType     type)
+    {
         Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
 
         if (cache == null) {
-            return callback.compute(facets);
+            switch (type) {
+                case FEED:
+                    return callback.computeFeed(facets);
+
+                case ADVANCE:
+                    return callback.computeAdvance(facets);
+            }
         }
 
         net.sf.ehcache.Element element = cache.get(key);
@@ -1096,7 +1107,15 @@
             return element.getValue();
         }
 
-        Object result = callback.compute(facets);
+        Object result = null;
+        switch (type) {
+            case FEED:
+                result = callback.computeFeed(facets);
+                break;
+
+            case ADVANCE:
+                result = callback.computeAdvance(facets);
+        }
 
         if (result != null) {
             cache.put(new net.sf.ehcache.Element(key, result));
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java	Thu Jun 16 08:43:58 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java	Thu Jun 16 08:57:05 2011 +0000
@@ -7,7 +7,9 @@
 
 public interface ComputeCallback {
 
-    Object compute(List<Facet> facets);
+    public enum ComputeType {
+        FEED, ADVANCE
+    }
 
     Object computeAdvance(List<Facet> facets);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java	Thu Jun 16 08:43:58 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java	Thu Jun 16 08:57:05 2011 +0000
@@ -8,18 +8,6 @@
 public class ComputeCallbackAdapter implements ComputeCallback {
 
     @Override
-    public Object compute(List<Facet> facets) {
-        Object obj = computeAdvance(facets);
-
-        if (obj == null) {
-            obj = computeFeed(facets);
-        }
-
-        return obj;
-    }
-
-
-    @Override
     public Object computeAdvance(List<Facet> facets) {
         return null;
     }

http://dive4elements.wald.intevation.org