OSDN Git Service

green: magvar, speed.
[importpicture/importpicture.git] / importPicture / src / osm / jp / gpx / ElementMapTRKPT.java
index 8bb015e..ab25615 100644 (file)
@@ -5,12 +5,9 @@ import java.util.Date;
 import java.util.TreeMap;
 
 import org.w3c.dom.DOMException;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 @SuppressWarnings("serial")
-public class ElementMapTRKPT extends TreeMap<Date, Element> {
+public class ElementMapTRKPT extends TreeMap<Date, TagTrkpt> {
        public static final long DIFF_MAE_TIME = 3000L; // before 3 secound
 
        public ElementMapTRKPT() {
@@ -18,31 +15,20 @@ public class ElementMapTRKPT extends TreeMap<Date, Element> {
        }
 
        /**
-        * 拡張put value:ElementをputするとElement内のtimeを読み取ってkeyとしてsuper.put(key,value)する。
+        * 拡張put value:ElementをputするとElement内のtimeを読み取ってkeyとしてthis.put(key,value)する。
+        * <trkpt lat="36.4260153752" lon="138.0117778201">
+     *   <ele>614.90</ele>
+     *   <time>2017-05-21T23:02:16Z</time>
+     *   <hdop>0.5</hdop>
+     * </trkpt>
         * @param value
         * @return      keyとして登録したtime:Date
         * @throws ParseException 
         * @throws DOMException 
         */
-       public Date put(Element value) throws DOMException, ParseException {
-        NodeList nodes3 = value.getChildNodes();
-        for (int i3=0; i3 < nodes3.getLength(); i3++) {
-            Node node4 = nodes3.item(i3);
-            if (node4.getNodeName().equals("time")) {
-                NodeList nodes4 = node4.getChildNodes();      // 子ノードを取得
-                for (int i4=0; i4< nodes4.getLength(); i4++) {
-                    Node node5 = nodes4.item(i4);
-                    if (node5 != null) {
-                        if (node5.getNodeType() == Node.TEXT_NODE) {
-                            Date time = ImportPicture.dfuk.parse(node5.getNodeValue());
-                            this.put(time, value);
-                               return time;
-                        }
-                    }
-                }
-            }
-        }
-        return null;
+       public Date put(TagTrkpt tag) throws DOMException, ParseException {
+        this.put(tag.time, tag);
+       return tag.time;
        }
        
        /**
@@ -52,10 +38,10 @@ public class ElementMapTRKPT extends TreeMap<Date, Element> {
      * @return エレメントTRKPT。指定時刻に対応するノードがないときはnullを返す。
      * @throws ParseException
      */
-    public Element getValue(Date jptime) throws ParseException {
-       Element imaE = getTrkpt(jptime);
+    public TagTrkpt getValue(Date jptime) throws ParseException {
+       TagTrkpt imaE = getTrkpt(jptime);
         if (imaE != null) {
-               Element maeE = getMaeTrkpt((new TagTrkpt(imaE)).time);
+               TagTrkpt maeE = getMaeTrkpt(imaE.time);
             if (maeE != null) {
                Complementation comp = new Complementation(imaE, maeE);
 
@@ -70,8 +56,8 @@ public class ElementMapTRKPT extends TreeMap<Date, Element> {
                 if (Complementation.param_GpxOutputSpeed) {
                        comp.complementationSpeed();
                 }
-                
-                return (Element)(comp.imaTag.trkpt.cloneNode(true));
+                //return (TagTrkpt)(comp.imaTag.trkpt.cloneNode(true));
+                return (TagTrkpt)(comp.imaTag);
             }
             return imaE;
         }
@@ -88,7 +74,7 @@ public class ElementMapTRKPT extends TreeMap<Date, Element> {
      * @return <trkpt>エレメント。対象のエレメントが存在しなかった場合には null。
      * @throws ParseException
      */
-    private Element getTrkpt(Date jptime) throws ParseException {
+    private TagTrkpt getTrkpt(Date jptime) throws ParseException {
        Date keyTime = null;
        for (Date key : this.keySet()) {
                        int flag = jptime.compareTo(key);
@@ -120,11 +106,11 @@ public class ElementMapTRKPT extends TreeMap<Date, Element> {
      */
     public static long OVER_TIME_LIMIT = 3000; // ミリ秒(msec)
     
-    private Element getMaeTrkpt(Date time) throws ParseException {
+    private TagTrkpt getMaeTrkpt(Date time) throws ParseException {
        Date maeTime = null;
                for (Date key : this.keySet()) {
                        int flag = time.compareTo(key);
-                       if (flag < 0) {
+                       if (flag > 0) {
                                maeTime = new Date(key.getTime());
                        }
                        else if (flag == 0) {
@@ -134,6 +120,7 @@ public class ElementMapTRKPT extends TreeMap<Date, Element> {
                                return this.get(maeTime);
                        }
                        else {
+                               // time は key より古い
                                if (maeTime == null) {
                                        return null;
                                }
@@ -145,4 +132,16 @@ public class ElementMapTRKPT extends TreeMap<Date, Element> {
                }
         return null;
     }
+    
+    public void printinfo() {
+       Date firstTime = null;
+       Date lastTime = null;
+               for (Date key : this.keySet()) {
+                       if (firstTime == null) {
+                               firstTime = new Date(key.getTime());
+                       }
+                       lastTime = new Date(key.getTime());
+               }
+               System.out.println(String.format("|                      <trkseg/> |%20s|%20s|", ImportPicture.toUTCString(firstTime), ImportPicture.toUTCString(lastTime)));
+    }
 }