From 23bf37045d96197ed43a02b48b9996103922593a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Jun 2012 22:06:51 +0400 Subject: Optimize strings --- src/org/traccar/protocol/Avl08ProtocolDecoder.java | 56 ++++++++++++++++------ .../traccar/protocol/MeiligaoProtocolDecoder.java | 12 +++-- .../traccar/protocol/Xexun2ProtocolDecoder.java | 24 +++++++--- 3 files changed, 66 insertions(+), 26 deletions(-) (limited to 'src/org/traccar') 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 = "avl08"; + StringBuilder extendedInfo = new StringBuilder("avl08"); Integer index = 1; @@ -91,7 +91,9 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Alarm type - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // 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 += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append(""); + extendedInfo.append(""); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append(""); + extendedInfo.append(""); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append(""); // Status - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Real time clock - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Voltage String voltage = parser.group(index++); position.setPower(Double.valueOf(voltage.substring(1, 4)) / 100); - extendedInfo += "" + voltage + ""; + extendedInfo.append(""); + extendedInfo.append(voltage); + extendedInfo.append(""); // ADC - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Cell - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Temperature - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Mileage - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Serial - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*", "") + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*", "")); + extendedInfo.append(""); // RFID String rfid = parser.group(index++); if (rfid != null) { - extendedInfo += "" + rfid + ""; + extendedInfo.append(""); + extendedInfo.append(rfid); + extendedInfo.append(""); } // 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 = "meiligao"; + StringBuilder extendedInfo = new StringBuilder("meiligao"); // 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 += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Altitude String altitude = parser.group(index++); @@ -195,10 +197,12 @@ public class MeiligaoProtocolDecoder extends GenericProtocolDecoder { } // State - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // 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 = "xexun2"; + StringBuilder extendedInfo = new StringBuilder("xexun2"); Integer index = 1; // Serial - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Number - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -133,17 +137,23 @@ public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { position.setTime(time.getTime()); // Signal - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Alarm - extendedInfo += "" + parser.group(index++) + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++)); + extendedInfo.append(""); // Get device by IMEI String imei = parser.group(index++); position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); // Satellites - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; + extendedInfo.append(""); + extendedInfo.append(parser.group(index++).replaceFirst ("^0*(?![\\.$])", "")); + extendedInfo.append(""); // 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; } -- cgit v1.2.3