aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/Context.java12
-rw-r--r--src/org/traccar/DetectorHandler.java18
-rw-r--r--src/org/traccar/FilterHandler.java25
-rw-r--r--src/org/traccar/database/DataManager.java6
-rw-r--r--src/org/traccar/database/QueryBuilder.java3
-rw-r--r--src/org/traccar/geocode/JsonReverseGeocoder.java7
-rw-r--r--src/org/traccar/helper/DistanceCalculator.java9
-rw-r--r--src/org/traccar/helper/Log.java31
-rw-r--r--src/org/traccar/model/MiscFormatter.java5
9 files changed, 67 insertions, 49 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index eb84b4ac5..113ed02ec 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -31,7 +31,10 @@ import org.traccar.geocode.ReverseGeocoder;
import org.traccar.helper.Log;
import org.traccar.web.WebServer;
-public class Context {
+public final class Context {
+
+ private Context() {
+ }
private static Config config;
@@ -87,10 +90,10 @@ public class Context {
return serverManager;
}
- private static final AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
+ private static final AsyncHttpClient ASYNC_HTTP_CLIENT = new AsyncHttpClient();
public static AsyncHttpClient getAsyncHttpClient() {
- return asyncHttpClient;
+ return ASYNC_HTTP_CLIENT;
}
public static void init(String[] arguments) throws Exception {
@@ -142,7 +145,8 @@ public class Context {
}
if (config.getBoolean("web.enable")) {
- if (config.getString("web.type", "new").equals("new") || config.getString("web.type", "new").equals("api")) {
+ if (config.getString("web.type", "new").equals("new")
+ || config.getString("web.type", "new").equals("api")) {
permissionsManager = new PermissionsManager(dataManager);
}
webServer = new WebServer(config, dataManager.getDataSource());
diff --git a/src/org/traccar/DetectorHandler.java b/src/org/traccar/DetectorHandler.java
index 8bc63fd1c..223985906 100644
--- a/src/org/traccar/DetectorHandler.java
+++ b/src/org/traccar/DetectorHandler.java
@@ -46,11 +46,13 @@ public class DetectorHandler extends SimpleChannelHandler {
FrameDecoder frameDecoder = (FrameDecoder) pipeline.get("frameDecoder");
if (frameDecoder != null) {
try {
- Method method = frameDecoder.getClass().getDeclaredMethod("decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
+ Method method = frameDecoder.getClass().getDeclaredMethod(
+ "decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
method.setAccessible(true);
tmp = method.invoke(frameDecoder, null, null, tmp);
} catch (NoSuchMethodException error) {
- Method method = frameDecoder.getClass().getSuperclass().getDeclaredMethod("decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
+ Method method = frameDecoder.getClass().getSuperclass().getDeclaredMethod(
+ "decode", ChannelHandlerContext.class, Channel.class, ChannelBuffer.class);
method.setAccessible(true);
tmp = method.invoke(frameDecoder, null, null, tmp);
}
@@ -61,11 +63,13 @@ public class DetectorHandler extends SimpleChannelHandler {
StringDecoder stringDecoder = new StringDecoder();
if (tmp != null) {
try {
- Method method = stringDecoder.getClass().getDeclaredMethod("decode", ChannelHandlerContext.class, Channel.class, Object.class);
+ Method method = stringDecoder.getClass().getDeclaredMethod(
+ "decode", ChannelHandlerContext.class, Channel.class, Object.class);
method.setAccessible(true);
tmp = method.invoke(stringDecoder, null, null, tmp);
} catch (NoSuchMethodException error) {
- Method method = stringDecoder.getClass().getSuperclass().getDeclaredMethod("decode", ChannelHandlerContext.class, Channel.class, Object.class);
+ Method method = stringDecoder.getClass().getSuperclass().getDeclaredMethod(
+ "decode", ChannelHandlerContext.class, Channel.class, Object.class);
method.setAccessible(true);
tmp = method.invoke(stringDecoder, null, null, tmp);
}
@@ -76,11 +80,13 @@ public class DetectorHandler extends SimpleChannelHandler {
BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) pipeline.get("objectDecoder");
if (tmp != null) {
try {
- Method method = protocolDecoder.getClass().getDeclaredMethod("decode", ChannelHandlerContext.class, Channel.class, SocketAddress.class, Object.class);
+ Method method = protocolDecoder.getClass().getDeclaredMethod(
+ "decode", ChannelHandlerContext.class, Channel.class, SocketAddress.class, Object.class);
method.setAccessible(true);
tmp = method.invoke(protocolDecoder, null, null, null, tmp);
} catch (NoSuchMethodException error) {
- Method method = protocolDecoder.getClass().getSuperclass().getDeclaredMethod("decode", ChannelHandlerContext.class, Channel.class, SocketAddress.class, Object.class);
+ Method method = protocolDecoder.getClass().getSuperclass().getDeclaredMethod(
+ "decode", ChannelHandlerContext.class, Channel.class, SocketAddress.class, Object.class);
method.setAccessible(true);
tmp = method.invoke(protocolDecoder, null, null, null, tmp);
}
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index 870132fe0..79f40c979 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -31,12 +31,8 @@ public class FilterHandler extends BaseDataHandler {
private final long filterLimit;
public FilterHandler(
- boolean filterInvalid,
- boolean filterZero,
- boolean filterDuplicate,
- boolean filterFuture,
- int filterDistance,
- long filterLimit) {
+ boolean filterInvalid, boolean filterZero, boolean filterDuplicate,
+ boolean filterFuture, int filterDistance, long filterLimit) {
this.filterInvalid = filterInvalid;
this.filterZero = filterZero;
@@ -69,9 +65,7 @@ public class FilterHandler extends BaseDataHandler {
}
private boolean filterZero(Position position) {
- return filterZero &&
- position.getLatitude() == 0.0 &&
- position.getLongitude() == 0.0;
+ return filterZero && position.getLatitude() == 0.0 && position.getLongitude() == 0.0;
}
private boolean filterDuplicate(Position position) {
@@ -122,12 +116,8 @@ public class FilterHandler extends BaseDataHandler {
private boolean filter(Position p) {
- boolean result =
- filterInvalid(p) ||
- filterZero(p) ||
- filterDuplicate(p) ||
- filterFuture(p) ||
- filterDistance(p);
+ boolean result = filterInvalid(p) || filterZero(p)
+ || filterDuplicate(p) || filterFuture(p) || filterDistance(p);
if (filterLimit(p)) {
result = false;
@@ -142,7 +132,10 @@ public class FilterHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
- return filter(position) ? null : position;
+ if (filter(position)) {
+ return null;
+ }
+ return position;
}
}
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 66134d51e..e249a7591 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -118,7 +118,8 @@ public class DataManager implements IdentityManager {
@Override
public Device getDeviceByUniqueId(String uniqueId) throws SQLException {
- if (System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay || !devicesByUniqueId.containsKey(uniqueId)) {
+ if (System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay
+ || !devicesByUniqueId.containsKey(uniqueId)) {
devicesById.clear();
devicesByUniqueId.clear();
@@ -163,7 +164,8 @@ public class DataManager implements IdentityManager {
String schemaVersionQuery = getQuery("database.selectSchemaVersion");
if (schemaVersionQuery != null) {
- Schema schema = QueryBuilder.create(dataSource, schemaVersionQuery).executeQuerySingle(new Schema());
+ Schema schema = QueryBuilder.create(dataSource, schemaVersionQuery)
+ .executeQuerySingle(new Schema());
int version = 0;
if (schema != null) {
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index 07a351c05..f50546129 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -132,7 +132,8 @@ public final class QueryBuilder {
return new QueryBuilder(dataSource, query, false);
}
- public static QueryBuilder create(DataSource dataSource, String query, boolean returnGeneratedKeys) throws SQLException {
+ public static QueryBuilder create(
+ DataSource dataSource, String query, boolean returnGeneratedKeys) throws SQLException {
return new QueryBuilder(dataSource, query, returnGeneratedKeys);
}
diff --git a/src/org/traccar/geocode/JsonReverseGeocoder.java b/src/org/traccar/geocode/JsonReverseGeocoder.java
index 6f4b5dcd2..e07419d55 100644
--- a/src/org/traccar/geocode/JsonReverseGeocoder.java
+++ b/src/org/traccar/geocode/JsonReverseGeocoder.java
@@ -45,7 +45,9 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder {
}
@Override
- public void getAddress(final AddressFormat format, final double latitude, final double longitude, final ReverseGeocoderCallback callback) {
+ public void getAddress(
+ final AddressFormat format, final double latitude,
+ final double longitude, final ReverseGeocoderCallback callback) {
if (cache != null) {
String cachedAddress = cache.get(new AbstractMap.SimpleImmutableEntry<>(latitude, longitude));
@@ -55,7 +57,8 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder {
}
}
- Context.getAsyncHttpClient().prepareGet(String.format(url, latitude, longitude)).execute(new AsyncCompletionHandler() {
+ Context.getAsyncHttpClient().prepareGet(String.format(url, latitude, longitude))
+ .execute(new AsyncCompletionHandler() {
@Override
public Object onCompleted(Response response) throws Exception {
try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
diff --git a/src/org/traccar/helper/DistanceCalculator.java b/src/org/traccar/helper/DistanceCalculator.java
index 7ba5044bc..d191a27af 100644
--- a/src/org/traccar/helper/DistanceCalculator.java
+++ b/src/org/traccar/helper/DistanceCalculator.java
@@ -15,7 +15,10 @@
*/
package org.traccar.helper;
-public class DistanceCalculator {
+public final class DistanceCalculator {
+
+ private DistanceCalculator() {
+ }
private static final double EQUATORIAL_EARTH_RADIUS = 6378.1370;
private static final double DEG_TO_RAD = Math.PI / 180;
@@ -23,8 +26,8 @@ public class DistanceCalculator {
public static double distance(double lat1, double lon1, double lat2, double lon2) {
double dlong = (lon2 - lon1) * DEG_TO_RAD;
double dlat = (lat2 - lat1) * DEG_TO_RAD;
- double a = Math.pow(Math.sin(dlat / 2), 2) +
- Math.cos(lat1 * DEG_TO_RAD) * Math.cos(lat2 * DEG_TO_RAD) * Math.pow(Math.sin(dlong / 2), 2);
+ double a = Math.pow(Math.sin(dlat / 2), 2)
+ + Math.cos(lat1 * DEG_TO_RAD) * Math.cos(lat2 * DEG_TO_RAD) * Math.pow(Math.sin(dlong / 2), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double d = EQUATORIAL_EARTH_RADIUS * c;
return d * 1000;
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index f344a4a93..0e55a5445 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -35,7 +35,10 @@ import org.jboss.netty.logging.InternalLogger;
import org.jboss.netty.logging.InternalLoggerFactory;
import org.traccar.Config;
-public class Log {
+public final class Log {
+
+ private Log() {
+ }
private static final String LOGGER_NAME = "traccar";
@@ -81,24 +84,24 @@ public class Log {
public static void logSystemInfo() {
try {
OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
- Log.info("Operating system" +
- " name: " + operatingSystemBean.getName() +
- " version: " + operatingSystemBean.getVersion() +
- " architecture: " + operatingSystemBean.getArch());
+ Log.info("Operating system"
+ + " name: " + operatingSystemBean.getName()
+ + " version: " + operatingSystemBean.getVersion()
+ + " architecture: " + operatingSystemBean.getArch());
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
- Log.info("Java runtime" +
- " name: " + runtimeBean.getVmName() +
- " vendor: " + runtimeBean.getVmVendor() +
- " version: " + runtimeBean.getVmVersion());
+ Log.info("Java runtime"
+ + " name: " + runtimeBean.getVmName()
+ + " vendor: " + runtimeBean.getVmVendor()
+ + " version: " + runtimeBean.getVmVersion());
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
- Log.info("Memory limit" +
- " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb" +
- " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");
+ Log.info("Memory limit"
+ + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb"
+ + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");
- Log.info("Character encoding: " +
- System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());
+ Log.info("Character encoding: "
+ + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());
} catch (Exception error) {
Log.warning("Failed to get system info");
diff --git a/src/org/traccar/model/MiscFormatter.java b/src/org/traccar/model/MiscFormatter.java
index 8f95f5c45..4f39c4013 100644
--- a/src/org/traccar/model/MiscFormatter.java
+++ b/src/org/traccar/model/MiscFormatter.java
@@ -30,7 +30,10 @@ import org.traccar.web.JsonConverter;
/**
* Format extended tracker status
*/
-public class MiscFormatter {
+public final class MiscFormatter {
+
+ private MiscFormatter() {
+ }
private static final String XML_ROOT_NODE = "info";