diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-08-02 10:28:25 +0200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-08-02 10:28:25 +0200 |
commit | 53486c0fe1bad6adb2324bd596e7528dcec82d26 (patch) | |
tree | b1b1b38cf8ad81f10e9eaf0a6b133c854384ea23 /src/org/traccar | |
parent | e77e0e4de5c2c424df8aa6663f986e85e1190db1 (diff) | |
download | trackermap-server-53486c0fe1bad6adb2324bd596e7528dcec82d26.tar.gz trackermap-server-53486c0fe1bad6adb2324bd596e7528dcec82d26.tar.bz2 trackermap-server-53486c0fe1bad6adb2324bd596e7528dcec82d26.zip |
Improve extended formatter
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/model/ExtendedInfoFormatter.java | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/org/traccar/model/ExtendedInfoFormatter.java b/src/org/traccar/model/ExtendedInfoFormatter.java index 99966569e..31aac7672 100644 --- a/src/org/traccar/model/ExtendedInfoFormatter.java +++ b/src/org/traccar/model/ExtendedInfoFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,9 @@ */ package org.traccar.model; +import java.util.LinkedHashMap; +import java.util.Map; + /** * Format extended tracker status */ @@ -22,12 +25,11 @@ public class ExtendedInfoFormatter { private static final String rootNode = "info"; - private StringBuilder data; - + private final Map<String, Object> data; + public ExtendedInfoFormatter(String protocol) { - data = new StringBuilder(); - data.append("<").append(rootNode).append(">"); - data.append("<protocol>").append(protocol).append("</protocol>"); + data = new LinkedHashMap<String, Object>(); + data.put("protocol", protocol); } public void set(String key, Object value) { @@ -37,15 +39,26 @@ public class ExtendedInfoFormatter { return; } - data.append("<").append(key).append(">"); - data.append(value); - data.append("</").append(key).append(">"); + data.put(key, value); } } @Override public String toString() { - return data.toString() + "</" + rootNode + ">"; + StringBuilder result = new StringBuilder(); + + result.append("<").append(rootNode).append(">"); + + for (Map.Entry<String, Object> entry : data.entrySet()) { + + result.append("<").append(entry.getKey()).append(">"); + result.append(entry.getValue()); + result.append("</").append(entry.getKey()).append(">"); + } + + result.append("</").append(rootNode).append(">"); + + return result.toString(); } } |