← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3300: Added method OrganisationUnit.getSortedChildren

 

------------------------------------------------------------
revno: 3300
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-04-06 16:47:13 +0200
message:
  Added method OrganisationUnit.getSortedChildren
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.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/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-03-31 16:28:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-04-06 14:47:13 +0000
@@ -28,6 +28,8 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
@@ -36,6 +38,7 @@
 import java.util.regex.Pattern;
 
 import org.apache.commons.lang.StringUtils;
+import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.user.User;
 
@@ -51,6 +54,7 @@
     public static final String FEATURETYPE_POLYGON = "Polygon";
     public static final String FEATURETYPE_POINT = "Point";
         
+    private static final Comparator<OrganisationUnit> COMPARATOR = new OrganisationUnitNameComparator();
     private static final Pattern JSON_COORDINATE_PATTERN = Pattern.compile( "(\\[{3}.*?\\]{3})" );
     private static final Pattern COORDINATE_PATTERN = Pattern.compile("([\\-0-9.]+,[\\-0-9.]+)");
     
@@ -159,6 +163,13 @@
     // Logic
     // -------------------------------------------------------------------------
     
+    public List<OrganisationUnit> getSortedChildren()
+    {
+        List<OrganisationUnit> sortedChildren = new ArrayList<OrganisationUnit>( children );
+        Collections.sort( sortedChildren, COMPARATOR );
+        return sortedChildren;
+    }
+    
     public Set<OrganisationUnit> getGrandChildren()
     {
         Set<OrganisationUnit> grandChildren = new HashSet<OrganisationUnit>();