File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed
main/java/io/jenetics/jpx
test/java/io/jenetics/jpx Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -1490,6 +1490,7 @@ public void write(final GPX gpx, final Result result)
14901490 try (output ) {
14911491 final var format = NumberFormat .getNumberInstance (ENGLISH );
14921492 format .setMaximumFractionDigits (_maximumFractionDigits );
1493+ format .setGroupingUsed (false );
14931494 final Function <Number , String > formatter = value ->
14941495 value != null ? format .format (value ) : null ;
14951496
Original file line number Diff line number Diff line change 2020package io .jenetics .jpx ;
2121
2222import static java .lang .String .format ;
23+ import static java .util .Locale .ENGLISH ;
2324import static java .util .Objects .requireNonNull ;
2425
2526import java .io .DataInput ;
2930import java .io .ObjectInputStream ;
3031import java .io .Serial ;
3132import java .io .Serializable ;
33+ import java .text .NumberFormat ;
34+ import java .text .ParseException ;
3235
3336/**
3437 * Extent of something along its greatest dimension or the extent of space
@@ -220,11 +223,17 @@ public static Length of(final double length, final Unit unit) {
220223 }
221224
222225 static Length parse (final String value ) {
223- final String length = Strings .trim (value );
226+ final Double length = parseDouble (value );
227+ return Length .of (length , Unit .METER );
228+ }
224229
225- return length != null
226- ? Length .of (Double .parseDouble (length ), Unit .METER )
227- : null ;
230+ private static Double parseDouble (final String value ) {
231+ NumberFormat formatter = NumberFormat .getNumberInstance (ENGLISH );
232+ try {
233+ return formatter .parse (Strings .trim (value )).doubleValue ();
234+ } catch (ParseException e ) {
235+ throw new NumberFormatException ("Unable to parse " + value );
236+ }
228237 }
229238
230239 /* *************************************************************************
Original file line number Diff line number Diff line change 2323import static java .util .Arrays .asList ;
2424import static org .assertj .core .api .Assertions .assertThat ;
2525import static io .jenetics .jpx .ListsTest .revert ;
26+ import static org .assertj .core .api .Assertions .assertThatNoException ;
2627
2728import nl .jqno .equalsverifier .EqualsVerifier ;
2829
@@ -154,6 +155,19 @@ public void readFromDocument() throws Exception {
154155 assertThat (gpx2 ).isEqualTo (gpx );
155156 }
156157
158+ @ Test
159+ public void writeThenReadDocument () {
160+ GPX gpx = GPX .builder ()
161+ .addWayPoint (wp ->
162+ wp .ele (1234.5 ).build (1.2 , 3.4 )
163+ )
164+ .build ();
165+ String gpxString = GPX .Writer .DEFAULT .toString (gpx );
166+ assertThatNoException ().isThrownBy (() -> {
167+ GPX .Reader .DEFAULT .fromString (gpxString );
168+ });
169+ }
170+
157171 //@Test
158172 public void print () throws IOException {
159173 final GPX gpx = nextGPX (new Random (6123 )).toBuilder ()
You can’t perform that action at this time.
0 commit comments