diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2012-06-20 22:06:51 +0400 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2012-06-20 22:06:51 +0400 |
commit | 23bf37045d96197ed43a02b48b9996103922593a (patch) | |
tree | de71e359adb9d4a521266237ba64cc33cef0e83c /src/org/traccar/protocol | |
parent | 15d13a99d3215a3208b2c44a07a29a7af9c13de3 (diff) | |
download | trackermap-server-23bf37045d96197ed43a02b48b9996103922593a.tar.gz trackermap-server-23bf37045d96197ed43a02b48b9996103922593a.tar.bz2 trackermap-server-23bf37045d96197ed43a02b48b9996103922593a.zip |
Optimize strings
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/Avl08ProtocolDecoder.java | 56 | ||||
-rw-r--r-- | src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 12 | ||||
-rw-r--r-- | src/org/traccar/protocol/Xexun2ProtocolDecoder.java | 24 |
3 files changed, 66 insertions, 26 deletions
diff --git a/src/org/traccar/protocol/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/Avl08ProtocolDecoder.java index 0ca976d26..2dc711cd7 100644 --- a/src/org/traccar/protocol/Avl08ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl08ProtocolDecoder.java @@ -82,7 +82,7 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { // Create new position Position position = new Position(); - String extendedInfo = "<protocol>avl08</protocol>"; + StringBuilder extendedInfo = new StringBuilder("<protocol>avl08</protocol>"); Integer index = 1; @@ -91,7 +91,9 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Alarm type - extendedInfo += "<alarm>" + parser.group(index++) + "</alarm>"; + extendedInfo.append("<alarm>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</alarm>"); // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -137,44 +139,68 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { position.setTime(time.getTime()); // Dilution of precision - extendedInfo += "<pdop>" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + "</pdop>"; - extendedInfo += "<hdop>" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + "</hdop>"; - extendedInfo += "<vdop>" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + "</vdop>"; + extendedInfo.append("<pdop>"); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append("</pdop>"); + extendedInfo.append("<hdop>"); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append("</hdop>"); + extendedInfo.append("<vdop>"); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append("</vdop>"); // Status - extendedInfo += "<status>" + parser.group(index++) + "</status>"; + extendedInfo.append("<status>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</status>"); // Real time clock - extendedInfo += "<clock>" + parser.group(index++) + "</clock>"; + extendedInfo.append("<clock>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</clock>"); // Voltage String voltage = parser.group(index++); position.setPower(Double.valueOf(voltage.substring(1, 4)) / 100); - extendedInfo += "<voltage>" + voltage + "</voltage>"; + extendedInfo.append("<voltage>"); + extendedInfo.append(voltage); + extendedInfo.append("</voltage>"); // ADC - extendedInfo += "<adc>" + parser.group(index++) + "</adc>"; + extendedInfo.append("<adc>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</adc>"); // Cell - extendedInfo += "<cell>" + parser.group(index++) + "</cell>"; + extendedInfo.append("<cell>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</cell>"); // Temperature - extendedInfo += "<temperature>" + parser.group(index++) + "</temperature>"; + extendedInfo.append("<temperature>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</temperature>"); // Mileage - extendedInfo += "<mileage>" + parser.group(index++) + "</mileage>"; + extendedInfo.append("<mileage>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</mileage>"); // Serial - extendedInfo += "<serial>" + parser.group(index++).replaceFirst ("^0*", "") + "</serial>"; + extendedInfo.append("<serial>"); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*", "")); + extendedInfo.append("</serial>"); // RFID String rfid = parser.group(index++); if (rfid != null) { - extendedInfo += "<rfid>" + rfid + "</rfid>"; + extendedInfo.append("<rfid>"); + extendedInfo.append(rfid); + extendedInfo.append("</rfid>"); } // Extended info - position.setExtendedInfo(extendedInfo); + position.setExtendedInfo(extendedInfo.toString()); return position; } diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index c3b376c65..db007f936 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -128,7 +128,7 @@ public class MeiligaoProtocolDecoder extends GenericProtocolDecoder { // Create new position Position position = new Position(); - String extendedInfo = "<protocol>meiligao</protocol>"; + StringBuilder extendedInfo = new StringBuilder("<protocol>meiligao</protocol>"); // Get device by id // TODO: change imei to unique id @@ -184,7 +184,9 @@ public class MeiligaoProtocolDecoder extends GenericProtocolDecoder { position.setTime(time.getTime()); // Dilution of precision - extendedInfo += "<hdop>" + parser.group(index++) + "</hdop>"; + extendedInfo.append("<hdop>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</hdop>"); // Altitude String altitude = parser.group(index++); @@ -195,10 +197,12 @@ public class MeiligaoProtocolDecoder extends GenericProtocolDecoder { } // State - extendedInfo += "<state>" + parser.group(index++) + "</state>"; + extendedInfo.append("<state>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</state>"); // Extended info - position.setExtendedInfo(extendedInfo); + position.setExtendedInfo(extendedInfo.toString()); return position; } diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java index 2449a60a6..1ee2737d1 100644 --- a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java @@ -82,15 +82,19 @@ public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { // Create new position Position position = new Position(); - String extendedInfo = "<protocol>xexun2</protocol>"; + StringBuilder extendedInfo = new StringBuilder("<protocol>xexun2</protocol>"); Integer index = 1; // Serial - extendedInfo += "<serial>" + parser.group(index++) + "</serial>"; + extendedInfo.append("<serial>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</serial>"); // Number - extendedInfo += "<number>" + parser.group(index++) + "</number>"; + extendedInfo.append("<number>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</number>"); // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -133,17 +137,23 @@ public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { position.setTime(time.getTime()); // Signal - extendedInfo += "<signal>" + parser.group(index++) + "</signal>"; + extendedInfo.append("<signal>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</signal>"); // Alarm - extendedInfo += "<alarm>" + parser.group(index++) + "</alarm>"; + extendedInfo.append("<alarm>"); + extendedInfo.append(parser.group(index++)); + extendedInfo.append("</alarm>"); // Get device by IMEI String imei = parser.group(index++); position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Satellites - extendedInfo += "<satellites>" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + "</satellites>"; + extendedInfo.append("<satellites>"); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append("</satellites>"); // Altitude position.setAltitude(Double.valueOf(parser.group(index++))); @@ -152,7 +162,7 @@ public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { position.setPower(Double.valueOf(parser.group(index++))); // Extended info - position.setExtendedInfo(extendedInfo); + position.setExtendedInfo(extendedInfo.toString()); return position; } |