changeset 5840:07fb247caeb1

Ensemble8: Fix for RT-33822 Ensemble8: Category should not show up if there are no samples for that category
author Alexander Kouznetsov
date Wed, 27 Nov 2013 18:15:52 -0800
parents 47021dd0546e
children 7bf5df173491
files apps/samples/Ensemble8/src/app/java/ensemble/SampleCategory.java apps/samples/Ensemble8/src/app/java/ensemble/util/FeatureChecker.java
diffstat 2 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/app/java/ensemble/SampleCategory.java	Wed Nov 27 17:51:17 2013 -0800
+++ b/apps/samples/Ensemble8/src/app/java/ensemble/SampleCategory.java	Wed Nov 27 18:15:52 2013 -0800
@@ -50,7 +50,7 @@
         this.name = name;
         this.samples = FeatureChecker.filterSamples(samples);
         this.samplesAll = FeatureChecker.filterSamples(samplesAll);
-        this.subCategories = subCategories;
+        this.subCategories = FeatureChecker.filterEmptyCategories(subCategories);
     }
     
     public SampleInfo sampleForPath(String path) {
--- a/apps/samples/Ensemble8/src/app/java/ensemble/util/FeatureChecker.java	Wed Nov 27 17:51:17 2013 -0800
+++ b/apps/samples/Ensemble8/src/app/java/ensemble/util/FeatureChecker.java	Wed Nov 27 18:15:52 2013 -0800
@@ -32,6 +32,7 @@
 package ensemble.util;
 
 import ensemble.PlatformFeatures;
+import ensemble.SampleCategory;
 import ensemble.SampleInfo;
 import java.util.ArrayList;
 import java.util.List;
@@ -56,13 +57,29 @@
 
     public static SampleInfo[] filterSamples(SampleInfo[] samples) {
         if (samples != null) {
-            List filteredSampleInfos = new ArrayList<>();
+            List<SampleInfo> filteredSampleInfos = new ArrayList<>();
             for (SampleInfo oneSampleInfo : samples) {
                 if (isSampleSupported(oneSampleInfo)) {
                     filteredSampleInfos.add(oneSampleInfo);
                 }
             }
-            return (SampleInfo[]) filteredSampleInfos.toArray(new SampleInfo[0]);
+            return filteredSampleInfos.toArray(new SampleInfo[filteredSampleInfos.size()]);
+        } else {
+            return null;
+        }
+    }
+
+    public static SampleCategory[] filterEmptyCategories(SampleCategory[] subCategories) {
+        if (subCategories != null) {
+            List<SampleCategory> filteredSubcategories = new ArrayList<>();
+            for (SampleCategory subCategory : subCategories) {
+                if (subCategory.samples != null && subCategory.samples.length > 0 
+                        || subCategory.samplesAll != null && subCategory.samplesAll.length > 0) {
+                    filteredSubcategories.add(subCategory);
+                }
+                
+            }
+            return filteredSubcategories.toArray(new SampleCategory[filteredSubcategories.size()]);
         } else {
             return null;
         }