bug fix: resources CLI command with -t(type) option didn't work for ContinuousResource.

Change-Id: Ib1443e2a5395c7f75ef3da583019978aab4a742a
diff --git a/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java b/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java
index c9a2ad6..d6e637f 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ResourcesCommand.java
@@ -36,6 +36,7 @@
 import org.onosproject.net.newresource.ContinuousResource;
 import org.onosproject.net.newresource.DiscreteResource;
 import org.onosproject.net.newresource.Resource;
+import org.onosproject.net.newresource.Resources;
 import org.onosproject.net.newresource.ResourceService;
 
 import com.google.common.base.Strings;
@@ -46,7 +47,6 @@
 import com.google.common.collect.Range;
 import com.google.common.collect.RangeSet;
 import com.google.common.collect.TreeRangeSet;
-import org.onosproject.net.newresource.Resources;
 
 /**
  * Lists available resources.
@@ -113,14 +113,6 @@
         if (resource.equals(Resource.ROOT)) {
             print("ROOT");
         } else {
-            String resourceName = resource.last().getClass().getSimpleName();
-
-            if (children.isEmpty() && !typesToPrint.isEmpty() && !typesToPrint.contains(resourceName)) {
-                // This resource is target of filtering
-                return;
-            }
-
-
             if (resource instanceof ContinuousResource) {
                 String s = ((String) resource.last());
                 String simpleName = s.substring(s.lastIndexOf('.') + 1);
@@ -133,6 +125,7 @@
                 // Continuous resource is terminal node, stop here
                 return;
             } else {
+                String resourceName = resource.last().getClass().getSimpleName();
 
                 String toString = String.valueOf(resource.last());
                 if (toString.startsWith(resourceName)) {
@@ -158,15 +151,17 @@
         List<Resource> nonAggregatable = new ArrayList<>();
 
         for (Resource r : children) {
+            if (!isPrintTarget(r)) {
+                continue;
+            }
+
             if (r instanceof ContinuousResource) {
                 // non-aggregatable terminal node
                 nonAggregatable.add(r);
             } else if (aggregatableTypes.contains(r.last().getClass())) {
                 // aggregatable & terminal node
                 String className = r.last().getClass().getSimpleName();
-                if (typesToPrint.isEmpty() || typesToPrint.contains(className)) {
-                    aggregatables.put(className, r);
-                }
+                aggregatables.put(className, r);
             } else {
                 nonAggregatable.add(r);
             }
@@ -213,4 +208,29 @@
             nonAggregatable.forEach(r -> printResource(r, level + 1));
         }
     }
+
+    private boolean isPrintTarget(Resource resource) {
+        if (typesToPrint.isEmpty()) {
+            return true;
+        }
+
+        String resourceName;
+        if (resource instanceof ContinuousResource) {
+            String s = (String) resource.last();
+            resourceName = s.substring(s.lastIndexOf('.') + 1);
+        } else if (resource instanceof DiscreteResource) {
+            // TODO This distributed store access incurs overhead.
+            //      This should be merged with the one in printResource()
+            if (!resourceService.getRegisteredResources(((DiscreteResource) resource).id()).isEmpty()) {
+                // resource which has children should be printed
+                return true;
+            }
+            resourceName = resource.last().getClass().getSimpleName();
+        } else {
+            log.warn("Unexpected resource class: {}", resource.getClass().getSimpleName());
+            return false;
+        }
+
+        return typesToPrint.contains(resourceName);
+    }
 }