← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1973: Added utility method

 

------------------------------------------------------------
revno: 1973
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2010-10-29 17:58:05 +0200
message:
  Added utility method
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java	2010-10-29 15:58:05 +0000
@@ -35,6 +35,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @author Lars Helge Overland
@@ -245,4 +247,25 @@
         
         return array;
     }
+    
+    /**
+     * Strips the number of decimals to a maximum of 4. The string must be on the
+     * form <number>.<decimals>,<number>.<decimals>
+     * 
+     * @param coordinates the coordinates string.
+     * @return the stripped coordinates string.
+     */
+    public static String stripCoordinates( String coordinates )
+    {
+        final int decimals = 4;
+        
+        if ( coordinates != null )
+        {
+            Matcher matcher = Pattern.compile( "\\d+\\.\\d{0," + decimals + "}" ).matcher( coordinates );
+            matcher.find();
+            return matcher.group() + "," + matcher.group();
+        }
+        
+        return null;
+    }
 }