Skip to content

Commit faec8b9

Browse files
committed
#66: Experimenting.
1 parent edd5b57 commit faec8b9

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

jpx/src/main/java/io/jenetics/jpx/Filter.java

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package io.jenetics.jpx;
2121

2222
import java.util.List;
23+
import java.util.function.BinaryOperator;
2324
import java.util.function.Function;
2425
import java.util.function.Predicate;
2526

@@ -85,4 +86,9 @@ public interface Filter<T, R> {
8586
*/
8687
public R build();
8788

89+
90+
public static <T> Function<List<T>, List<T>> listMaps(final BinaryOperator<T> op) {
91+
return null;
92+
}
93+
8894
}

jpx/src/test/java/io/jenetics/jpx/GPXTest.java

+35
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@
4545
import java.util.stream.Collectors;
4646
import java.util.stream.Stream;
4747

48+
import javax.xml.parsers.DocumentBuilder;
49+
import javax.xml.parsers.DocumentBuilderFactory;
50+
import javax.xml.parsers.ParserConfigurationException;
4851
import javax.xml.stream.XMLStreamException;
4952

5053
import org.testng.Assert;
5154
import org.testng.annotations.DataProvider;
5255
import org.testng.annotations.Test;
5356
import org.w3c.dom.Document;
57+
import org.w3c.dom.Element;
5458

5559
import io.jenetics.jpx.GPX.Reader.Mode;
5660
import io.jenetics.jpx.GPX.Version;
@@ -61,6 +65,37 @@
6165
*/
6266
public class GPXTest extends XMLStreamTestBase<GPX> {
6367

68+
@Test
69+
public void extensions() throws ParserConfigurationException {
70+
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
71+
final DocumentBuilder db = dbf.newDocumentBuilder();
72+
final Document doc = db.newDocument();
73+
74+
GPX gpx = GPX.builder()
75+
.extensions(doc)
76+
.build();
77+
}
78+
79+
@Test
80+
public void foo1() throws ParserConfigurationException, IOException {
81+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
82+
DocumentBuilder db = dbf.newDocumentBuilder();
83+
Document doc = db.newDocument();
84+
Element ext = doc.createElement("extesions");
85+
Element elem = doc.createElement( "property");
86+
elem.setAttribute("name", "my_attribute");
87+
elem.setTextContent("Some Attribute Value");
88+
89+
ext.appendChild(elem);
90+
doc.appendChild(ext);
91+
92+
GPX gpx = GPX.builder()
93+
.extensions(doc)
94+
.build();
95+
96+
GPX.writer(" ").write(gpx, System.out);
97+
}
98+
6499
@Override
65100
public Supplier<GPX> factory(Random random) {
66101
return () -> nextGPX(random);

jpx/src/test/java/io/jenetics/jpx/geom/GeoidTest.java

+41
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
*/
2020
package io.jenetics.jpx.geom;
2121

22+
import java.io.IOException;
23+
import java.io.InputStream;
2224
import java.util.List;
25+
import java.util.Optional;
2326
import java.util.Random;
2427
import java.util.stream.Collectors;
2528
import java.util.stream.Stream;
@@ -28,7 +31,13 @@
2831
import org.testng.annotations.DataProvider;
2932
import org.testng.annotations.Test;
3033

34+
import io.jenetics.jpx.GPX;
35+
import io.jenetics.jpx.GPX.Reader.Mode;
3136
import io.jenetics.jpx.Point;
37+
import io.jenetics.jpx.Speed;
38+
import io.jenetics.jpx.Speed.Unit;
39+
import io.jenetics.jpx.Track;
40+
import io.jenetics.jpx.TrackSegment;
3241
import io.jenetics.jpx.WayPoint;
3342
import io.jenetics.jpx.WayPointTest;
3443

@@ -134,4 +143,36 @@ public void parallelPointStream() {
134143
.collect(GEOID.toPathLength());
135144
}
136145

146+
@Test
147+
public void speed() throws IOException {
148+
final String resource = "/io/jenetics/jpx/geom/Track_1.gpx";
149+
150+
final GPX gpx;
151+
try (InputStream in = getClass().getResourceAsStream(resource)) {
152+
gpx = GPX.reader(Mode.LENIENT).read(in);
153+
}
154+
155+
GPX.writer(" ").write(gpx, System.out);
156+
157+
final List<WayPoint> points = gpx.tracks()
158+
.flatMap(Track::segments)
159+
.flatMap(TrackSegment::points)
160+
.collect(Collectors.toList());
161+
162+
/*
163+
Point p0 = points.get(0);
164+
for (int i = 1; i < points.size(); ++i) {
165+
final Point p1 = points.get(i);
166+
final Optional<Speed> speed = Geoid.DEFAULT.speed(p0, p1);
167+
speed
168+
.map(s -> s.to(Unit.KILOMETERS_PER_HOUR))
169+
.ifPresent(System.out::println);
170+
171+
p0 = p1;
172+
}
173+
174+
*/
175+
176+
}
177+
137178
}

0 commit comments

Comments
 (0)