dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23469
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11426: GML import util, made impl locale ignorant
------------------------------------------------------------
revno: 11426
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-07-17 23:21:33 +0200
message:
GML import util, made impl locale ignorant
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java
dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/xml/UtilTest.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-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java 2012-03-23 16:01:51 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/Util.java 2013-07-17 21:21:33 +0000
@@ -1,11 +1,5 @@
package org.hisp.dhis.importexport.xml;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-
/*
* Copyright (c) 2004-2005, University of Oslo
* All rights reserved.
@@ -33,18 +27,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+
+import org.apache.commons.math.util.MathUtils;
+
/**
*
* @author bobj
- *
- * Some static helper functions
- *
*/
public class Util
{
/**
* Compensating for Excel wonky storage for dates
- *
+ *
* @param xltimestr the number of days since 1/1/1900 as undertood by excel
* @return
*/
@@ -69,28 +68,30 @@
}
/**
- * Tokenizer to convert coordinates in GML to a sequence of <coord>nnn,nnn</coord>
+ * Tokenizer to convert coordinates in GML to a sequence of
+ * <coord>nnn,nnn</coord>
+ *
* @param coordinates
* @return
*/
- public static String gmlToCoords(String coordinates, String decimalPlacesAsString)
- throws ParseException
+ public static String gmlToCoords( String coordinates, String decimalPlacesAsString )
+ throws ParseException
{
- NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
+ NumberFormat nf = NumberFormat.getInstance( Locale.ENGLISH );
+
+ int decimals = Integer.parseInt( decimalPlacesAsString );
- int decimalPlaces = Integer.parseInt( decimalPlacesAsString);
- String formatString = "%."+decimalPlaces+"f,%."+decimalPlaces+"f";
StringBuilder sb = new StringBuilder();
- String[] coords = coordinates.split( "\\s");
+ String[] coords = coordinates.split( "\\s" );
- for (String coordAsString : coords)
+ for ( String coordAsString : coords )
{
- String[] latlon = coordAsString.split( ",");
+ String[] latlon = coordAsString.split( "," );
double lat = nf.parse( latlon[0] ).doubleValue();
double lon = nf.parse( latlon[1] ).doubleValue();
- sb.append( "<coord>");
- sb.append( String.format(formatString, lat, lon));
- sb.append( "</coord>");
+ sb.append( "<coord>" );
+ sb.append( MathUtils.round( lat, decimals ) + "," + MathUtils.round( lon, decimals ) );
+ sb.append( "</coord>" );
}
return sb.toString();
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/xml/UtilTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/xml/UtilTest.java 2013-07-17 20:56:02 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/xml/UtilTest.java 2013-07-17 21:21:33 +0000
@@ -27,31 +27,24 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.text.ParseException;
import org.junit.Assert;
import org.junit.Test;
/**
- *
* @author bobj
*/
-public class UtilTest {
-
+public class UtilTest
+{
@Test
public void testCoords()
+ throws Exception
{
- String src = "34.5,65,7 1234.67890,0.0056";
+ String src = "34.5,65,7 1234.67890,0.0056 451.23,-0.232561";
String decimals = "4";
-
- String expected = "<coord>34.5000,65.0000</coord><coord>1234.6789,0.0056</coord>";
-
- try
- {
- String result = Util.gmlToCoords( src, decimals );
- Assert.assertEquals( expected, result );
- } catch ( ParseException ex )
- {
- Assert.fail( ex.getMessage() );
- }
+
+ String expected = "<coord>34.5,65.0</coord><coord>1234.6789,0.0056</coord><coord>451.23,-0.2326</coord>";
+
+ String result = Util.gmlToCoords( src, decimals );
+ Assert.assertEquals( expected, result );
}
}