← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20306: Reimplemented getName() on category option combo to respect the order of categories in category c...

 

------------------------------------------------------------
revno: 20306
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-23 11:36:43 +0200
message:
  Reimplemented getName() on category option combo to respect the order of categories in category combo.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2015-09-18 18:07:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2015-09-23 09:36:43 +0000
@@ -32,6 +32,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -295,34 +296,29 @@
         {
             return name;
         }
-
-        StringBuilder name = new StringBuilder();
-
-        if ( categoryOptions != null && categoryOptions.size() > 0 )
+        
+        StringBuilder builder = new StringBuilder();
+        
+        List<DataElementCategory> categories = this.categoryCombo.getCategories();
+        
+        for ( DataElementCategory category : categories )
         {
-            name.append( "(" );
-
-            Iterator<DataElementCategoryOption> iterator = categoryOptions.iterator();
-
-            if ( iterator.hasNext() )
-            {
-                name.append( iterator.next().getDisplayName() );
-            }
-
-            while ( iterator.hasNext() )
-            {
-                DataElementCategoryOption categoryOption = iterator.next();
-
-                if ( categoryOption != null )
+            builder.append( "(" );
+            
+            List<DataElementCategoryOption> options = category.getCategoryOptions();
+            
+            for ( DataElementCategoryOption option : this.categoryOptions )
+            {
+                if ( options.contains( option ) )
                 {
-                    name.append( ", " ).append( categoryOption.getDisplayName() );
+                    builder.append( option.getDisplayName() ).append( ", " );
                 }
             }
-
-            name.append( ")" );
+            
+            builder.delete( Math.max( builder.length() - 2, 0 ), builder.length() ).append( ")" );
         }
-
-        return name.toString();
+        
+        return  builder.toString();
     }
 
     @Override