Skip to content

Commit

Permalink
#66: Experimenting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Aug 1, 2019
1 parent edd5b57 commit faec8b9
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jpx/src/main/java/io/jenetics/jpx/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.jenetics.jpx;

import java.util.List;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;

Expand Down Expand Up @@ -85,4 +86,9 @@ public interface Filter<T, R> {
*/
public R build();


public static <T> Function<List<T>, List<T>> listMaps(final BinaryOperator<T> op) {
return null;
}

}
35 changes: 35 additions & 0 deletions jpx/src/test/java/io/jenetics/jpx/GPXTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;

import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

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

@Test
public void extensions() throws ParserConfigurationException {
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
final DocumentBuilder db = dbf.newDocumentBuilder();
final Document doc = db.newDocument();

GPX gpx = GPX.builder()
.extensions(doc)
.build();
}

@Test
public void foo1() throws ParserConfigurationException, IOException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element ext = doc.createElement("extesions");
Element elem = doc.createElement( "property");
elem.setAttribute("name", "my_attribute");
elem.setTextContent("Some Attribute Value");

ext.appendChild(elem);
doc.appendChild(ext);

GPX gpx = GPX.builder()
.extensions(doc)
.build();

GPX.writer(" ").write(gpx, System.out);
}

@Override
public Supplier<GPX> factory(Random random) {
return () -> nextGPX(random);
Expand Down
41 changes: 41 additions & 0 deletions jpx/src/test/java/io/jenetics/jpx/geom/GeoidTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
*/
package io.jenetics.jpx.geom;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -28,7 +31,13 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import io.jenetics.jpx.GPX;
import io.jenetics.jpx.GPX.Reader.Mode;
import io.jenetics.jpx.Point;
import io.jenetics.jpx.Speed;
import io.jenetics.jpx.Speed.Unit;
import io.jenetics.jpx.Track;
import io.jenetics.jpx.TrackSegment;
import io.jenetics.jpx.WayPoint;
import io.jenetics.jpx.WayPointTest;

Expand Down Expand Up @@ -134,4 +143,36 @@ public void parallelPointStream() {
.collect(GEOID.toPathLength());
}

@Test
public void speed() throws IOException {
final String resource = "/io/jenetics/jpx/geom/Track_1.gpx";

final GPX gpx;
try (InputStream in = getClass().getResourceAsStream(resource)) {
gpx = GPX.reader(Mode.LENIENT).read(in);
}

GPX.writer(" ").write(gpx, System.out);

final List<WayPoint> points = gpx.tracks()
.flatMap(Track::segments)
.flatMap(TrackSegment::points)
.collect(Collectors.toList());

/*
Point p0 = points.get(0);
for (int i = 1; i < points.size(); ++i) {
final Point p1 = points.get(i);
final Optional<Speed> speed = Geoid.DEFAULT.speed(p0, p1);
speed
.map(s -> s.to(Unit.KILOMETERS_PER_HOUR))
.ifPresent(System.out::println);
p0 = p1;
}
*/

}

}

0 comments on commit faec8b9

Please sign in to comment.