diff --git a/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java b/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java
index 15bc6d3..0c8bd06 100644
--- a/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java
+++ b/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java
@@ -54,7 +54,7 @@
* @return エレメントTRKPT。指定時刻に対応するノードがないときはnullを返す。
* @throws ParseException
*/
- public Element get(Date jptime) throws ParseException {
+ public Element getValue(Date jptime) throws ParseException {
Element imaE = getTrkpt(jptime);
if (imaE != null) {
Element maeE = getMaeTrkpt(new TagTrkpt(imaE));
@@ -72,10 +72,11 @@
if (Complementation.param_GpxOutputSpeed) {
comp.complementationSpeed();
}
- imaE = (Element)(comp.imaTag.trkpt.cloneNode(true));
+
+ return (Element)(comp.imaTag.trkpt.cloneNode(true));
}
}
- return imaE;
+ return null;
}
/**
@@ -101,7 +102,7 @@
if (Math.abs(jpt - t) < sa) {
sa = Math.abs(jpt - t);
- ret = super.get(time);
+ ret = this.get(time);
}
}
@@ -125,7 +126,7 @@
if (Math.abs(jpt - t) < diffTime) {
diffTime = Math.abs(jpt - t);
- ret = super.get(time);
+ ret = this.get(time);
}
}
diff --git a/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java b/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java
index e021131..89606f6 100644
--- a/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java
+++ b/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java
@@ -1,20 +1,29 @@
package osm.jp.gpx;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.*;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
@RunWith(Enclosed.class)
public class ElementMapTRKPTTest {
- public static class 時間順にプットされない場合 {
+
+ public static class Keyのみ {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
ElementMapTRKPT map = null;
long timeL;
@@ -67,5 +76,90 @@
}
}
+ public static class Keyとvalueのセット {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ ElementMapTRKPT map = null;
+ long timeL;
+
+ /*
+ *
+ *
+ *
+ *
+ */
+ static String[][] values = {
+ {"2017-05-29T01:23:18Z", "35.8812697884", "137.9952202085"},
+ {"2017-05-29T01:23:21Z", "35.8811769169", "137.9951928835"},
+ {"2017-05-29T01:23:24Z", "35.881112963", "137.9951796401"},
+ {"2017-05-29T01:23:27Z", "35.881072646", "137.9951728508"}
+ };
+
+ Element createElement(Document document, String[] values) {
+ Element trkpt = document.createElement("trkpt");
+ trkpt.setAttribute("lat", values[1]);
+ trkpt.setAttribute("lon", values[2]);
+ Element timeE = document.createElement("time");
+ timeE.appendChild(document.createTextNode(values[0]));
+ trkpt.appendChild(timeE);
+ return trkpt;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ DOMImplementation domImpl=builder.getDOMImplementation();
+ Document document = domImpl.createDocument("","trkpt",null);
+
+ map = new ElementMapTRKPT();
+ for (int cnt = 4; cnt > 0; cnt--) {
+ map.put(createElement(document, values[cnt - 1]));
+ }
+ }
+
+ @Test
+ public void コンテンツの数をチェック() {
+ assertThat(map.size(), is(4));
+ }
+ @Test
+ public void KEYが時間順に取り出せるか() {
+ int i = 0;
+ for (Date key : map.keySet()) {
+ assertThat(sdf.format(key), is(values[i++][0]));
+ }
+ }
+
+ @Test
+ public void get_一番先頭の1秒前() throws ParseException {
+ Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:17Z"));
+ assertThat(ret, is(nullValue()));
+ }
+
+ @Test
+ public void get_一番先頭のTRKPTと同時刻() throws ParseException {
+ Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:18Z"));
+ assertThat(ret, is(nullValue()));
+ }
+
+ @Test
+ public void get_一番から二番の間() throws ParseException {
+ Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:19Z"));
+ TagTrkpt tag = new TagTrkpt(ret);
+ assertThat(sdf.format(tag.time), is("2017-05-29T01:23:18Z"));
+ }
+
+ @Test
+ public void get_最後と同時刻() throws ParseException {
+ Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:27Z"));
+ TagTrkpt tag = new TagTrkpt(ret);
+ assertThat(sdf.format(tag.time), is("2017-05-29T01:23:27Z"));
+ }
+
+ @Test
+ public void get_最後の1秒後() throws ParseException {
+ Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:28Z"));
+ assertThat(ret, is(nullValue()));
+ }
+ }
}