From 346c6befe177c6cffe99e6ac9cc6083000a2981c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 25 Jan 2018 20:31:32 +1300 Subject: Some more code cleanup --- src/org/traccar/database/DataManager.java | 16 ++++++---- .../protocol/MiniFinderProtocolEncoder.java | 36 +++++++++++----------- .../traccar/protocol/TrakMateProtocolDecoder.java | 7 +---- src/org/traccar/reports/Stops.java | 4 +-- src/org/traccar/reports/Trips.java | 4 +-- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 1f6315d92..a997a89f6 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -242,12 +242,16 @@ public class DataManager { public String getQuery(String action, Class owner, Class property) { String queryName; - if (action.equals(ACTION_SELECT_ALL)) { - queryName = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s"; - } else if (action.equals(ACTION_INSERT)) { - queryName = "database.link" + owner.getSimpleName() + property.getSimpleName(); - } else { - queryName = "database.unlink" + owner.getSimpleName() + property.getSimpleName(); + switch (action) { + case ACTION_SELECT_ALL: + queryName = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s"; + break; + case ACTION_INSERT: + queryName = "database.link" + owner.getSimpleName() + property.getSimpleName(); + break; + default: + queryName = "database.unlink" + owner.getSimpleName() + property.getSimpleName(); + break; } String query = config.getString(queryName); if (query == null) { diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java index 486f406a5..d3f49b4e4 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java @@ -25,25 +25,25 @@ public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements @Override public String formatValue(String key, Object value) { - - if (key.equals(Command.KEY_ENABLE)) { - return (Boolean) value ? "1" : "0"; - } else if (key.equals(Command.KEY_TIMEZONE)) { - return String.format("%+03d", TimeZone.getTimeZone((String) value).getRawOffset() / 3600000); - } else if (key.equals(Command.KEY_INDEX)) { - switch (((Number) value).intValue()) { - case 0: - return "A"; - case 1: - return "B"; - case 2: - return "C"; - default: - return null; - } + switch (key) { + case Command.KEY_ENABLE: + return (Boolean) value ? "1" : "0"; + case Command.KEY_TIMEZONE: + return String.format("%+03d", TimeZone.getTimeZone((String) value).getRawOffset() / 3600000); + case Command.KEY_INDEX: + switch (((Number) value).intValue()) { + case 0: + return "A"; + case 1: + return "B"; + case 2: + return "C"; + default: + return null; + } + default: + return null; } - - return null; } @Override diff --git a/src/org/traccar/protocol/TrakMateProtocolDecoder.java b/src/org/traccar/protocol/TrakMateProtocolDecoder.java index 28fd1c64d..293c13fad 100644 --- a/src/org/traccar/protocol/TrakMateProtocolDecoder.java +++ b/src/org/traccar/protocol/TrakMateProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,23 +17,18 @@ package org.traccar.protocol; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; import java.net.SocketAddress; -import java.util.TimeZone; import java.util.regex.Pattern; public class TrakMateProtocolDecoder extends BaseProtocolDecoder { - private final TimeZone timeZone = TimeZone.getTimeZone("UTC"); - public TrakMateProtocolDecoder(TrakMateProtocol protocol) { super(protocol); - timeZone.setRawOffset(Context.getConfig().getInteger(getProtocolName() + ".timezone") * 1000); } private static final Pattern PATTERN_SRT = new PatternBuilder() diff --git a/src/org/traccar/reports/Stops.java b/src/org/traccar/reports/Stops.java index 14b3a2437..aa7a1ef20 100644 --- a/src/org/traccar/reports/Stops.java +++ b/src/org/traccar/reports/Stops.java @@ -42,11 +42,9 @@ public final class Stops { boolean ignoreOdometer = Context.getDeviceManager() .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true); - Collection result = ReportUtils.detectTripsAndStops( + return ReportUtils.detectTripsAndStops( Context.getDataManager().getPositions(deviceId, from, to), Context.getTripsConfig(), ignoreOdometer, StopReport.class); - - return result; } public static Collection getObjects( diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java index 696defa94..792833c27 100644 --- a/src/org/traccar/reports/Trips.java +++ b/src/org/traccar/reports/Trips.java @@ -41,11 +41,9 @@ public final class Trips { boolean ignoreOdometer = Context.getDeviceManager() .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true); - Collection result = ReportUtils.detectTripsAndStops( + return ReportUtils.detectTripsAndStops( Context.getDataManager().getPositions(deviceId, from, to), Context.getTripsConfig(), ignoreOdometer, TripReport.class); - - return result; } public static Collection getObjects(long userId, Collection deviceIds, Collection groupIds, -- cgit v1.2.3