aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BaseProtocol.java2
-rw-r--r--src/org/traccar/Context.java18
-rw-r--r--src/org/traccar/ServerManager.java2
-rw-r--r--src/org/traccar/command/CommandType.java9
-rw-r--r--src/org/traccar/command/FixPositioningCommand.java2
-rw-r--r--src/org/traccar/command/NoParameterCommand.java2
-rw-r--r--src/org/traccar/command/StringCommandTemplate.java2
-rw-r--r--src/org/traccar/database/ConnectionManager.java8
-rw-r--r--src/org/traccar/database/DataManager.java6
-rw-r--r--src/org/traccar/database/PermissionsManager.java4
-rw-r--r--src/org/traccar/database/QueryBuilder.java36
-rw-r--r--src/org/traccar/geocode/GoogleReverseGeocoder.java53
-rw-r--r--src/org/traccar/geocode/JsonReverseGeocoder.java5
-rw-r--r--src/org/traccar/http/AsyncServlet.java6
-rw-r--r--src/org/traccar/http/CommandsServlet.java28
-rw-r--r--src/org/traccar/http/DeviceServlet.java26
-rw-r--r--src/org/traccar/http/JsonConverter.java8
-rw-r--r--src/org/traccar/http/MainServlet.java28
-rw-r--r--src/org/traccar/http/PositionServlet.java11
-rw-r--r--src/org/traccar/http/ServerServlet.java18
-rw-r--r--src/org/traccar/http/UserServlet.java28
-rw-r--r--src/org/traccar/model/Event.java2
-rw-r--r--src/org/traccar/protocol/ApelProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/BceProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java22
-rw-r--r--src/org/traccar/protocol/OrionProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/PiligrimProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java2
40 files changed, 191 insertions, 185 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index b345d3658..86bebacc7 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -26,7 +26,7 @@ import java.util.Map;
public abstract class BaseProtocol implements Protocol {
private final String name;
- private Map<CommandType, CommandTemplate> commandTemplates = new HashMap<CommandType, CommandTemplate>();
+ private Map<CommandType, CommandTemplate> commandTemplates = new HashMap<>();
public BaseProtocol(String name) {
this.name = name;
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 0b74eacd0..707e6edb6 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -103,14 +103,18 @@ public class Context {
}
if (config.getBoolean("geocoder.enable")) {
- String type = config.getString("geocoder.type");
+ String type = config.getString("geocoder.type", "google");
String url = config.getString("geocoder.url");
- if (type != null && type.equals("nominatim")) {
- reverseGeocoder = new NominatimReverseGeocoder(url);
- } else if (type != null && type.equals("gisgraphy")) {
- reverseGeocoder = new GisgraphyReverseGeocoder(url);
- } else {
- reverseGeocoder = new GoogleReverseGeocoder();
+ switch (type) {
+ case "google":
+ reverseGeocoder = new GoogleReverseGeocoder();
+ break;
+ case "nominatim":
+ reverseGeocoder = new NominatimReverseGeocoder(url);
+ break;
+ case "gisgraphy":
+ reverseGeocoder = new GisgraphyReverseGeocoder(url);
+ break;
}
}
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 04a3fc317..7fbefc94e 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -31,7 +31,7 @@ import org.jboss.netty.channel.ChannelPipeline;
public class ServerManager {
- private final List<TrackerServer> serverList = new LinkedList<TrackerServer>();
+ private final List<TrackerServer> serverList = new LinkedList<>();
public void init() throws Exception {
diff --git a/src/org/traccar/command/CommandType.java b/src/org/traccar/command/CommandType.java
index b5f6393b6..56596fa41 100644
--- a/src/org/traccar/command/CommandType.java
+++ b/src/org/traccar/command/CommandType.java
@@ -8,8 +8,7 @@ public enum CommandType implements Factory {
STOP_ENGINE(NoParameterCommand.class),
RESUME_ENGINE(NoParameterCommand.class);
-
- private Class<? extends GpsCommand> commandClass;
+ private final Class<? extends GpsCommand> commandClass;
CommandType(Class<? extends GpsCommand> commandClass) {
this.commandClass = commandClass;
@@ -19,10 +18,8 @@ public enum CommandType implements Factory {
public Object create() {
try {
return commandClass.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
+ } catch (InstantiationException | IllegalAccessException error) {
+ throw new RuntimeException(error);
}
}
}
diff --git a/src/org/traccar/command/FixPositioningCommand.java b/src/org/traccar/command/FixPositioningCommand.java
index 1304e1f3f..18d5f32fb 100644
--- a/src/org/traccar/command/FixPositioningCommand.java
+++ b/src/org/traccar/command/FixPositioningCommand.java
@@ -10,7 +10,7 @@ public class FixPositioningCommand extends GpsCommand {
@Override
public Map<String, Object> getReplacements() {
- Map<String, Object> replacements = new HashMap<String, Object>();
+ Map<String, Object> replacements = new HashMap<>();
replacements.put(FREQUENCY, data);
return replacements;
}
diff --git a/src/org/traccar/command/NoParameterCommand.java b/src/org/traccar/command/NoParameterCommand.java
index afb0f3aee..f4e139b7b 100644
--- a/src/org/traccar/command/NoParameterCommand.java
+++ b/src/org/traccar/command/NoParameterCommand.java
@@ -6,6 +6,6 @@ import java.util.Map;
public class NoParameterCommand extends GpsCommand {
@Override
public Map<String, Object> getReplacements() {
- return new HashMap<String, Object>();
+ return new HashMap<>();
}
}
diff --git a/src/org/traccar/command/StringCommandTemplate.java b/src/org/traccar/command/StringCommandTemplate.java
index 12470d441..3f326e534 100644
--- a/src/org/traccar/command/StringCommandTemplate.java
+++ b/src/org/traccar/command/StringCommandTemplate.java
@@ -8,7 +8,7 @@ import java.util.Map;
public class StringCommandTemplate<T extends GpsCommand> implements CommandTemplate<T> {
private String messageTemplate;
- private Map<Class<?>, CommandValueConversion> converters = new HashMap<Class<?>, CommandValueConversion>();
+ private Map<Class<?>, CommandValueConversion> converters = new HashMap<>();
public StringCommandTemplate(String template, Object... replacements) {
this.messageTemplate = String.format(template, replacements);
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index eb22379da..0d357a41c 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -31,9 +31,9 @@ import org.traccar.model.Position;
public class ConnectionManager {
- private Map<String, ActiveDevice> activeDevices = new HashMap<String, ActiveDevice>();
- private final Map<Long, Position> positions = new HashMap<Long, Position>();
- private final Map<Long, Set<DataCacheListener>> listeners = new HashMap<Long, Set<DataCacheListener>>();
+ private Map<String, ActiveDevice> activeDevices = new HashMap<>();
+ private final Map<Long, Position> positions = new HashMap<>();
+ private final Map<Long, Set<DataCacheListener>> listeners = new HashMap<>();
public void init(DataManager dataManager) {
try {
@@ -70,7 +70,7 @@ public class ConnectionManager {
public synchronized Collection<Position> getInitialState(Collection<Long> devices) {
- List<Position> result = new LinkedList<Position>();
+ List<Position> result = new LinkedList<>();
for (long device : devices) {
if (positions.containsKey(device)) {
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 959602512..48f3228ce 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -50,7 +50,7 @@ public class DataManager implements IdentityManager {
private DataSource dataSource;
- private final Map<String, Device> devices = new HashMap<String, Device>();
+ private final Map<String, Device> devices = new HashMap<>();
private long devicesLastUpdate;
private final long devicesRefreshDelay;
@@ -200,9 +200,7 @@ public class DataManager implements IdentityManager {
updateLatestPosition(position);
- } catch (SQLException error) {
- Log.warning(error);
- } catch (ParseException error) {
+ } catch (SQLException | ParseException error) {
Log.warning(error);
}
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 683f54cb4..40783ad98 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -28,9 +28,9 @@ import org.traccar.model.User;
public class PermissionsManager {
- private final Map<Long, User> users = new HashMap<Long, User>();
+ private final Map<Long, User> users = new HashMap<>();
- private final Map<Long, Set<Long>> permissions = new HashMap<Long, Set<Long>>();
+ private final Map<Long, Set<Long>> permissions = new HashMap<>();
private Set<Long> getNotNull(long userId) {
if (!permissions.containsKey(userId)) {
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index 88183f525..17165db82 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -36,7 +36,7 @@ import org.traccar.model.Factory;
public class QueryBuilder {
- private final Map<String, List<Integer>> indexMap = new HashMap<String, List<Integer>>();
+ private final Map<String, List<Integer>> indexMap = new HashMap<>();
private Connection connection;
private PreparedStatement statement;
private final String query;
@@ -106,7 +106,7 @@ public class QueryBuilder {
// Add to list
List<Integer> indexList = paramMap.get(name);
if (indexList == null) {
- indexList = new LinkedList<Integer>();
+ indexList = new LinkedList<>();
paramMap.put(name, indexList);
}
indexList.add(index);
@@ -133,7 +133,7 @@ public class QueryBuilder {
name = name.toLowerCase();
List<Integer> result = indexMap.get(name);
if (result == null) {
- result = new LinkedList<Integer>();
+ result = new LinkedList<>();
}
return result;
}
@@ -264,8 +264,7 @@ public class QueryBuilder {
} else if (method.getReturnType().equals(byte[].class)) {
setBytes(name, (byte[]) method.invoke(object));
}
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
}
@@ -293,13 +292,11 @@ public class QueryBuilder {
try {
- ResultSet resultSet = statement.executeQuery();
-
- try {
+ try (ResultSet resultSet = statement.executeQuery()) {
ResultSetMetaData resultMetaData = resultSet.getMetaData();
- List<ResultSetProcessor<T>> processors = new LinkedList<ResultSetProcessor<T>>();
+ List<ResultSetProcessor<T>> processors = new LinkedList<>();
Method[] methods = prototype.getClass().getMethods();
@@ -328,8 +325,7 @@ public class QueryBuilder {
public void process(T object, ResultSet resultSet) throws SQLException {
try {
method.invoke(object, resultSet.getBoolean(name));
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
});
@@ -339,8 +335,7 @@ public class QueryBuilder {
public void process(T object, ResultSet resultSet) throws SQLException {
try {
method.invoke(object, resultSet.getInt(name));
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
});
@@ -350,8 +345,7 @@ public class QueryBuilder {
public void process(T object, ResultSet resultSet) throws SQLException {
try {
method.invoke(object, resultSet.getLong(name));
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
});
@@ -361,8 +355,7 @@ public class QueryBuilder {
public void process(T object, ResultSet resultSet) throws SQLException {
try {
method.invoke(object, resultSet.getDouble(name));
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
});
@@ -372,8 +365,7 @@ public class QueryBuilder {
public void process(T object, ResultSet resultSet) throws SQLException {
try {
method.invoke(object, resultSet.getString(name));
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
});
@@ -383,8 +375,7 @@ public class QueryBuilder {
public void process(T object, ResultSet resultSet) throws SQLException {
try {
method.invoke(object, new Date(resultSet.getTimestamp(name).getTime()));
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
});
@@ -399,9 +390,6 @@ public class QueryBuilder {
}
result.add(object);
}
-
- } finally {
- resultSet.close();
}
} finally {
diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java
index df8d99545..c37d4188f 100644
--- a/src/org/traccar/geocode/GoogleReverseGeocoder.java
+++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java
@@ -15,14 +15,9 @@
*/
package org.traccar.geocode;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.net.URLConnection;
-import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonString;
-import org.traccar.helper.Log;
public class GoogleReverseGeocoder extends JsonReverseGeocoder {
@@ -45,28 +40,34 @@ public class GoogleReverseGeocoder extends JsonReverseGeocoder {
String value = component.getString("short_name");
for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) {
- if (type.getString().equals("street_number")) {
- address.setHouse(value);
- break;
- } else if (type.getString().equals("route")) {
- address.setStreet(value);
- break;
- } else if (type.getString().equals("locality")) {
- address.setSettlement(value);
- break;
- } else if (type.getString().equals("administrative_area_level_2")) {
- address.setDistrict(value);
- break;
- } else if (type.getString().equals("administrative_area_level_1")) {
- address.setState(value);
- break;
- } else if (type.getString().equals("country")) {
- address.setCountry(value);
- break;
- } else if (type.getString().equals("postal_code")) {
- address.setPostcode(value);
- break;
+
+ switch (type.getString()) {
+ case "street_number":
+ address.setHouse(value);
+ break;
+ case "route":
+ address.setStreet(value);
+ break;
+ case "locality":
+ address.setSettlement(value);
+ break;
+ case "administrative_area_level_2":
+ address.setDistrict(value);
+ break;
+ case "administrative_area_level_1":
+ address.setState(value);
+ break;
+ case "country":
+ address.setCountry(value);
+ break;
+ case "postal_code":
+ address.setPostcode(value);
+ break;
+ default:
+ continue;
}
+
+ break;
}
}
diff --git a/src/org/traccar/geocode/JsonReverseGeocoder.java b/src/org/traccar/geocode/JsonReverseGeocoder.java
index feaaaa0ed..c43641245 100644
--- a/src/org/traccar/geocode/JsonReverseGeocoder.java
+++ b/src/org/traccar/geocode/JsonReverseGeocoder.java
@@ -42,15 +42,12 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder {
conn.setRequestProperty("Connection", "close"); // don't keep-alive connections
try {
InputStreamReader streamReader = new InputStreamReader(conn.getInputStream());
- JsonReader reader = Json.createReader(streamReader);
- try {
+ try (JsonReader reader = Json.createReader(streamReader)) {
Address address = parseAddress(reader.readObject());
while (streamReader.read() > 0); // make sure we reached the end
if (address != null) {
return format.format(address);
}
- } finally {
- reader.close();
}
} finally {
conn.disconnect();
diff --git a/src/org/traccar/http/AsyncServlet.java b/src/org/traccar/http/AsyncServlet.java
index 47ffda3ad..0fc1cd2fb 100644
--- a/src/org/traccar/http/AsyncServlet.java
+++ b/src/org/traccar/http/AsyncServlet.java
@@ -57,10 +57,10 @@ public class AsyncServlet extends BaseServlet {
private boolean destroyed;
private final long userId;
- private final Set<Long> devices = new HashSet<Long>();
+ private final Set<Long> devices = new HashSet<>();
private Timeout sessionTimeout;
private Timeout requestTimeout;
- private final Map<Long, Position> positions = new HashMap<Long, Position>();
+ private final Map<Long, Position> positions = new HashMap<>();
private AsyncContext activeContext;
private void logEvent(String message) {
@@ -177,7 +177,7 @@ public class AsyncServlet extends BaseServlet {
}
- private static final Map<Long, AsyncSession> asyncSessions = new HashMap<Long, AsyncSession>();
+ private static final Map<Long, AsyncSession> asyncSessions = new HashMap<>();
public static void sessionRefreshUser(long userId) {
asyncSessions.remove(userId);
diff --git a/src/org/traccar/http/CommandsServlet.java b/src/org/traccar/http/CommandsServlet.java
index bf40b79e6..8b3d43fe7 100644
--- a/src/org/traccar/http/CommandsServlet.java
+++ b/src/org/traccar/http/CommandsServlet.java
@@ -1,29 +1,29 @@
package org.traccar.http;
-import org.traccar.Context;
-import org.traccar.database.ActiveDevice;
-import org.traccar.command.CommandType;
-import org.traccar.command.GpsCommand;
-
import javax.json.Json;
import javax.json.JsonObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.traccar.Context;
+import org.traccar.command.CommandType;
+import org.traccar.command.GpsCommand;
+import org.traccar.database.ActiveDevice;
public class CommandsServlet extends BaseServlet {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- if (command.equals("/send")) {
- send(req, resp);
- }
- else if (command.equals("/raw")) {
- sendRawCommand(req, resp);
- }
- else {
- return false;
+
+ switch (command) {
+ case "/send":
+ send(req, resp);
+ return true;
+ case "/raw":
+ sendRawCommand(req, resp);
+ return true;
+ default:
+ return false;
}
- return true;
}
private void send(HttpServletRequest req, HttpServletResponse resp) throws Exception {
diff --git a/src/org/traccar/http/DeviceServlet.java b/src/org/traccar/http/DeviceServlet.java
index 2a3e15a80..d1af1c106 100644
--- a/src/org/traccar/http/DeviceServlet.java
+++ b/src/org/traccar/http/DeviceServlet.java
@@ -24,16 +24,22 @@ public class DeviceServlet extends BaseServlet {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- if (command.equals("/get")) {
- get(req, resp);
- } else if (command.equals("/add")) {
- add(req, resp);
- } else if (command.equals("/update")) {
- update(req, resp);
- } else if (command.equals("/remove")) {
- remove(req, resp);
- } else {
- return false;
+
+ switch (command) {
+ case "/get":
+ get(req, resp);
+ break;
+ case "/add":
+ add(req, resp);
+ break;
+ case "/update":
+ update(req, resp);
+ break;
+ case "/remove":
+ remove(req, resp);
+ break;
+ default:
+ return false;
}
return true;
}
diff --git a/src/org/traccar/http/JsonConverter.java b/src/org/traccar/http/JsonConverter.java
index d658ef7d6..d8773ec1f 100644
--- a/src/org/traccar/http/JsonConverter.java
+++ b/src/org/traccar/http/JsonConverter.java
@@ -30,7 +30,6 @@ import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
-
import org.traccar.model.Factory;
public class JsonConverter {
@@ -89,9 +88,7 @@ public class JsonConverter {
populateObject(json.getJsonObject(name), nestedObject);
method.invoke(object, nestedObject);
}
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
- } catch (InstantiationException e) {
+ } catch (IllegalAccessException | InvocationTargetException | InstantiationException error) {
}
}
}
@@ -130,8 +127,7 @@ public class JsonConverter {
json.add(name, dateFormat.format(value));
}
}
- } catch (IllegalAccessException error) {
- } catch (InvocationTargetException error) {
+ } catch (IllegalAccessException | InvocationTargetException error) {
}
}
}
diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java
index 18430f0c3..29eaaec33 100644
--- a/src/org/traccar/http/MainServlet.java
+++ b/src/org/traccar/http/MainServlet.java
@@ -26,18 +26,24 @@ public class MainServlet extends BaseServlet {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- if (command.equals("/session")) {
- session(req, resp);
- } else if (command.equals("/login")) {
- login(req, resp);
- } else if (command.equals("/logout")) {
- logout(req, resp);
- } else if (command.equals("/register")) {
- register(req, resp);
- } else {
- return false;
+
+ switch (command) {
+ case "/session":
+ session(req, resp);
+ break;
+ case "/login":
+ login(req, resp);
+ break;
+ case "/logout":
+ logout(req, resp);
+ break;
+ case "/register":
+ register(req, resp);
+ break;
+ default:
+ return false;
}
- return true;
+ return true;
}
private void session(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
diff --git a/src/org/traccar/http/PositionServlet.java b/src/org/traccar/http/PositionServlet.java
index 57b411a79..6f973be3c 100644
--- a/src/org/traccar/http/PositionServlet.java
+++ b/src/org/traccar/http/PositionServlet.java
@@ -23,10 +23,15 @@ public class PositionServlet extends BaseServlet {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- if (command.equals("/get")) {
- get(req, resp);
+
+ switch (command) {
+ case "/get":
+ get(req, resp);
+ break;
+ default:
+ return false;
}
- return true;
+ return true;
}
private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception {
diff --git a/src/org/traccar/http/ServerServlet.java b/src/org/traccar/http/ServerServlet.java
index d814769a8..836a109fc 100644
--- a/src/org/traccar/http/ServerServlet.java
+++ b/src/org/traccar/http/ServerServlet.java
@@ -24,14 +24,18 @@ public class ServerServlet extends BaseServlet {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- if (command.equals("/get")) {
- get(req, resp);
- } else if (command.equals("/update")) {
- update(req, resp);
- } else {
- return false;
+
+ switch (command) {
+ case "/get":
+ get(req, resp);
+ break;
+ case "/update":
+ update(req, resp);
+ break;
+ default:
+ return false;
}
- return true;
+ return true;
}
private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception {
diff --git a/src/org/traccar/http/UserServlet.java b/src/org/traccar/http/UserServlet.java
index 71af74485..976a62890 100644
--- a/src/org/traccar/http/UserServlet.java
+++ b/src/org/traccar/http/UserServlet.java
@@ -24,18 +24,24 @@ public class UserServlet extends BaseServlet {
@Override
protected boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- if (command.equals("/get")) {
- get(req, resp);
- } else if (command.equals("/add")) {
- add(req, resp);
- } else if (command.equals("/update")) {
- update(req, resp);
- } else if (command.equals("/remove")) {
- remove(req, resp);
- } else {
- return false;
+
+ switch (command) {
+ case "/get":
+ get(req, resp);
+ break;
+ case "/add":
+ add(req, resp);
+ break;
+ case "/update":
+ update(req, resp);
+ break;
+ case "/remove":
+ remove(req, resp);
+ break;
+ default:
+ return false;
}
- return true;
+ return true;
}
private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception {
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 8f5678dff..71348ef8b 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -41,7 +41,7 @@ public abstract class Event {
public Date getDeviceTime() { return deviceTime; }
public void setDeviceTime(Date deviceTime) { this.deviceTime = deviceTime; }
- private final Map<String, Object> other = new LinkedHashMap<String, Object>();
+ private final Map<String, Object> other = new LinkedHashMap<>();
public void set(String key, Object value) {
if (value != null && (!(value instanceof String) || !((String) value).isEmpty())) {
other.put(key, value);
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java
index 9a25a4fff..6ce823a29 100644
--- a/src/org/traccar/protocol/ApelProtocolDecoder.java
+++ b/src/org/traccar/protocol/ApelProtocolDecoder.java
@@ -131,7 +131,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
// Position
else if (hasDeviceId() && (type == MSG_TYPE_CURRENT_GPS_DATA || type == MSG_TYPE_STATE_FULL_INFO_T104 || type == MSG_TYPE_LOG_RECORDS)) {
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
int recordCount = 1;
if (type == MSG_TYPE_LOG_RECORDS) {
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 1f8ec9a1f..1f777b12a 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -91,7 +91,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
// Send acknowledgement
sendResponse(channel, remoteAddress, id, index);
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
while (buf.readableBytes() >= MIN_DATA_LENGTH) {
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index 810d666dd..afc9a2d79 100644
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
@@ -140,7 +140,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
int count = buf.readUnsignedByte() & 0x0f;
buf.readUnsignedShort(); // total count
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
for (int i = 0; i < count; i++) {
positions.add(decodePosition(buf, true));
diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java
index 4255ebde2..4d4f262e8 100644
--- a/src/org/traccar/protocol/BceProtocolDecoder.java
+++ b/src/org/traccar/protocol/BceProtocolDecoder.java
@@ -54,7 +54,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
while (buf.readableBytes() > 1) {
@@ -79,7 +79,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
// Read masks
int mask;
- List<Integer> masks = new LinkedList<Integer>();
+ List<Integer> masks = new LinkedList<>();
do {
mask = buf.readUnsignedShort();
masks.add(mask);
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index 3a09822b3..358f6bb1d 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -150,7 +150,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
int count = buf.readUnsignedByte();
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
for (int i = 0; i < count; i++) {
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
index 66eb1f2cc..b9a4eef44 100644
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java
@@ -51,7 +51,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
private static final int TAG_REFRIGERATOR = 0x5b;
private static final int TAG_PRESSURE = 0x5c;
- private static final Map<Integer, Integer> tagLengthMap = new HashMap<Integer, Integer>();
+ private static final Map<Integer, Integer> tagLengthMap = new HashMap<>();
static {
int[] l1 = {0x01,0x02,0x35,0x43,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd5,0x88,0x8a,0x8b,0x8c,0xa0,0xaf,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae};
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index 06c3985dc..3bbe87e36 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -156,7 +156,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
// GPS length and Satellites count
int gpsLength = buf.readUnsignedByte();
- position.set(Event.KEY_SATELLITES, gpsLength & 0xf);
+ position.set(Event.KEY_SATELLITES, gpsLength & 0b0000_1111);
gpsLength >>= 4;
// Latitude
@@ -170,16 +170,16 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
// Course and flags
int union = buf.readUnsignedShort();
- position.setCourse(union & 0x03FF);
- position.setValid((union & 0x1000) != 0);
- if ((union & 0x0400) == 0) latitude = -latitude;
- if ((union & 0x0800) != 0) longitude = -longitude;
+ position.setCourse(union & 0b0000_0011_1111_1111);
+ position.setValid((union & 0b0001_0000_0000_0000) != 0);
+ if ((union & 0b0000_0100_0000_0000) == 0) latitude = -latitude;
+ if ((union & 0b0000_1000_0000_0000) != 0) longitude = -longitude;
position.setLatitude(latitude);
position.setLongitude(longitude);
- if ((union & 0x4000) != 0) {
- position.set("acc", (union & 0x8000) != 0);
+ if ((union & 0b0100_0000_0000_0000) != 0) {
+ position.set("acc", (union & 0b1000_0000_0000_0000) != 0);
}
buf.skipBytes(gpsLength - 12); // skip reserved
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index adbaa6e58..2cdf75106 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -178,7 +178,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
private List<Position> decodeBinaryMessage(Channel channel, ChannelBuffer buf) {
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
String flag = buf.toString(2, 1, Charset.defaultCharset());
int index = ChannelBufferTools.find(buf, 0, buf.readableBytes(), ",");
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
index e83c84583..e751c8b7a 100644
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
@@ -115,7 +115,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
}
private List<Position> parseFormatA(ChannelBuffer buf) {
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
FloatReader latitudeReader = new FloatReader();
FloatReader longitudeReader = new FloatReader();
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
index 02d408575..4f3e6a1a4 100644
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavisProtocolDecoder.java
@@ -15,19 +15,16 @@
*/
package org.traccar.protocol;
+import java.net.SocketAddress;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
-import java.net.SocketAddress;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
-
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-
import org.traccar.BaseProtocolDecoder;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -228,7 +225,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
}
private Object processArray(Channel channel, ChannelBuffer buf) {
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
@@ -303,13 +300,14 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
// Read message type
String type = buf.toString(buf.readerIndex(), 3, charset);
buf.skipBytes(type.length());
-
- if (type.equals("*>T")) {
- return processSingle(channel, buf);
- } else if (type.equals("*>A")) {
- return processArray(channel, buf);
- } else if (type.equals("*>S")) {
- return processHandshake(channel, buf);
+
+ switch (type) {
+ case "*>T":
+ return processSingle(channel, buf);
+ case "*>A":
+ return processArray(channel, buf);
+ case "*>S":
+ return processHandshake(channel, buf);
}
return null;
diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java
index daf52750b..388178dad 100644
--- a/src/org/traccar/protocol/OrionProtocolDecoder.java
+++ b/src/org/traccar/protocol/OrionProtocolDecoder.java
@@ -77,7 +77,7 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
for (int i = 0; i < (header & 0x0f); i++) {
diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
index 7f6d9463e..fad9bc703 100644
--- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java
+++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
@@ -88,7 +88,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
ChannelBuffer buf = request.getContent();
while (buf.readableBytes() > 2) {
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index bb29532bf..8b57f52d0 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -87,7 +87,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
// Position
else if (hasDeviceId() && (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG)) {
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
int recordCount = 1;
if (type == MSG_LOGMSG) {
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
index b81b5b248..0064798f3 100644
--- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -53,7 +53,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
int type = buf.readUnsignedByte();
if (type == COMMAND_RECORDS) {
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
buf.readUnsignedByte(); // records left
int count = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index eff04f7cf..e57723ddb 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -53,7 +53,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
private static final int CODEC_12 = 0x0C;
private List<Position> parseLocation(Channel channel, ChannelBuffer buf) {
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
buf.skipBytes(4); // marker
buf.readUnsignedInt(); // data length
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
index b242a2232..3cdb9199a 100644
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -81,7 +81,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
String status = parser.group(2);
String[] messages = sentence.substring(sentence.indexOf('\n') + 1).split("\r\n");
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
for (String message : messages) {
parser = patternPosition.matcher(message);
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index 432fa213e..558664e2d 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -58,7 +58,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
while (buf.readable()) {
@@ -137,7 +137,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
break;
case 24:
{
- Set<Integer> temps = new LinkedHashSet<Integer>();
+ Set<Integer> temps = new LinkedHashSet<>();
int temp = buf.readUnsignedByte();
for (int i = 3; i >= 0; i--) {
int n = (temp >> (2 * i)) & 0x03;
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 5cf6cdab5..e79a7e9ee 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -200,7 +200,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
else if (sentence.startsWith("#B#")) {
String[] messages = sentence.substring(sentence.indexOf('#', 1) + 1).split("\\|");
- List<Position> positions = new LinkedList<Position>();
+ List<Position> positions = new LinkedList<>();
for (String message : messages) {
Position position = decodePosition(message);