From 3ac43300fca643cd5d08684e73a23778139613e2 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Wed, 12 Dec 2012 14:10:29 -0600 Subject: [PATCH] Issue #1415 fix or level node time matching Change-Id: If4d05a6d181856dacc14a103fb51f2755dcf706a Former-commit-id: 7ad0749d76328eafcd2f02137c099f7a302e0387 --- .../uf/viz/derivparam/tree/OrLevelNode.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java index 1e0dffec58..09b39f10a1 100644 --- a/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java +++ b/cave/com.raytheon.uf.viz.derivparam/src/com/raytheon/uf/viz/derivparam/tree/OrLevelNode.java @@ -20,6 +20,7 @@ package com.raytheon.uf.viz.derivparam.tree; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -27,18 +28,23 @@ import java.util.Map; import java.util.Set; import com.raytheon.uf.common.dataplugin.level.Level; +import com.raytheon.uf.common.geospatial.ISpatialObject; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.derivparam.data.AbstractRequestableData; import com.raytheon.uf.viz.derivparam.inv.AvailabilityContainer; import com.raytheon.uf.viz.derivparam.inv.TimeAndSpace; +import com.raytheon.uf.viz.derivparam.inv.TimeAndSpaceMatcher; +import com.raytheon.uf.viz.derivparam.inv.TimeAndSpaceMatcher.MatchResult; import com.raytheon.uf.viz.derivparam.library.DerivParamDesc; import com.raytheon.uf.viz.derivparam.library.DerivParamMethod; /** * * Or LevelNodes will return data for each requested time for the first node - * which has data. For time queries it simply returns all times available for - * any node that it has. + * which has data. For availability queries it simply returns all unique + * TimeAndSpaces for any node that it has. TimeAndSpaces that only differ by + * time range are not considered unique, in such cases only the TimeAndSpace + * from the first node will be returned. * *
  * 
@@ -192,9 +198,31 @@ public class OrLevelNode extends AbstractDerivedDataNode {
     public Set getAvailability(
             Map> availability)
             throws VizException {
+        // Do not return two identical TimeAndSpaces that are different only by
+        // time range. For cases where two nodes have times that only differ by
+        // range then only the first time should be returned.
+        TimeAndSpaceMatcher matcher = new TimeAndSpaceMatcher();
+        matcher.setIgnoreRange(true);
         Set myAvailability = new HashSet();
         for (AbstractRequestableNode node : nodes) {
-            myAvailability.addAll(availability.get(node));
+            HashSet nodeAvail = new HashSet(
+                    availability.get(node));
+
+            // find the times that match ignoring range.
+            Collection matches = matcher.match(myAvailability,
+                    nodeAvail).values();
+            for (MatchResult match : matches) {
+                ISpatialObject space1 = match.get1().getSpace();
+                ISpatialObject space2 = match.get2().getSpace();
+                // if the spaces are equal then remove the new time so it is not
+                // added. This will remove identical times and times that match
+                // ignoring range.
+                if (space1.equals(space2)) {
+                    nodeAvail.remove(match.get2());
+                }
+            }
+            // Add the TimeAndSpace objects that are new.
+            myAvailability.addAll(nodeAvail);
         }
         return myAvailability;
     }