3 import java.text.ParseException;
5 import java.util.TreeMap;
7 import org.w3c.dom.DOMException;
8 import org.w3c.dom.Element;
9 import org.w3c.dom.Node;
10 import org.w3c.dom.NodeList;
12 @SuppressWarnings("serial")
13 public class ElementMapTRKPT extends TreeMap<Date, Element> {
14 public static final long DIFF_MAE_TIME = 3000L; // before 3 secound
16 public ElementMapTRKPT() {
17 super(new TimeComparator());
21 * 拡張put value:ElementをputするとElement内のtimeを読み取ってkeyとしてthis.put(key,value)する。
23 * @return keyとして登録したtime:Date
24 * @throws ParseException
25 * @throws DOMException
27 public Date put(Element value) throws DOMException, ParseException {
28 NodeList nodes3 = value.getChildNodes();
29 for (int i3=0; i3 < nodes3.getLength(); i3++) {
30 Node node4 = nodes3.item(i3);
31 if (node4.getNodeName().equals("time")) {
32 NodeList nodes4 = node4.getChildNodes(); // 子ノードを取得
33 for (int i4=0; i4< nodes4.getLength(); i4++) {
34 Node node5 = nodes4.item(i4);
36 if (node5.getNodeType() == Node.TEXT_NODE) {
37 Date time = ImportPicture.dfuk.parse(node5.getNodeValue());
38 this.put(time, value);
49 * 指定時刻(jptime)のTRKPTエレメントを取り出す。
51 * @param jptime 指定する日時
52 * @return エレメントTRKPT。指定時刻に対応するノードがないときはnullを返す。
53 * @throws ParseException
55 public Element getValue(Date jptime) throws ParseException {
56 Element imaE = getTrkpt(jptime);
58 Element maeE = getMaeTrkpt((new TagTrkpt(imaE)).time);
60 Complementation comp = new Complementation(imaE, maeE);
63 // 直前の位置と、現在地から進行方向を求める
64 // 経度(longitude)と経度から進行方向を求める
65 if (Complementation.param_GpxOverwriteMagvar) {
66 comp.complementationMagvar();
69 // 緯度・経度と時間差から速度(km/h)を求める
70 if (Complementation.param_GpxOutputSpeed) {
71 comp.complementationSpeed();
74 return (Element)(comp.imaTag.trkpt.cloneNode(true));
82 * [map]から指定した時刻の<trkpt>エレメントを取り出す。
83 * 取り出すエレメントは、指定した時刻と同一時刻、もしくは、直近・直前の時刻のエレメントとする。
84 * 指定した時刻以前のエレメントが存在しない場合は null を返す。
85 * 指定した時刻と直近・直前のエレメントの時刻との乖離が プロパティ[OVER_TIME_LIMIT=3000(ミリ秒)]より大きい場合には null を返す。
88 * @return <trkpt>エレメント。対象のエレメントが存在しなかった場合には null。
89 * @throws ParseException
91 private Element getTrkpt(Date jptime) throws ParseException {
93 for (Date key : this.keySet()) {
94 int flag = jptime.compareTo(key);
96 if (keyTime != null) {
97 return this.get(keyTime);
101 else if (flag == 0) {
102 return this.get(key);
105 keyTime = new Date(key.getTime());
108 if (keyTime != null) {
109 if (Math.abs(keyTime.getTime() - jptime.getTime()) <= OVER_TIME_LIMIT) {
110 return this.get(keyTime);
117 * ロガーの最終取得時刻を超えた場合、どこまでを有効とするかを設定する。
118 * この設定がないと、最終取得時刻を超えたものは全て有効になってしまう。
119 * OVER_TIME_LIMITは、GPSロガーの位置取得間隔()よりも長くする必要がある。長すぎても良くない。
121 public static long OVER_TIME_LIMIT = 3000; // ミリ秒(msec)
123 private Element getMaeTrkpt(Date time) throws ParseException {
125 for (Date key : this.keySet()) {
126 int flag = time.compareTo(key);
128 maeTime = new Date(key.getTime());
130 else if (flag == 0) {
131 if (maeTime == null) {
134 return this.get(maeTime);
137 if (maeTime == null) {
140 if (Math.abs(maeTime.getTime() - time.getTime()) > OVER_TIME_LIMIT) {
143 return this.get(maeTime);
149 public void printinfo() {
150 Date firstTime = null;
151 Date lastTime = null;
152 for (Date key : this.keySet()) {
153 if (firstTime == null) {
154 firstTime = new Date(key.getTime());
156 lastTime = new Date(key.getTime());
158 System.out.println(String.format("| <trkpt/> |%20s|%20s|", ImportPicture.dfuk.format(firstTime), ImportPicture.dfuk.format(lastTime)));