diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-13 23:11:23 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-13 23:11:23 +1300 |
commit | 398b705820109c1103d915a2fec81fcf70b032cf (patch) | |
tree | 659a0483eda19f9c91855197b70fd2a0bfb82a60 /src/org | |
parent | 2da5669f8bd3f734fa37626c892aebdff7268613 (diff) | |
download | trackermap-server-398b705820109c1103d915a2fec81fcf70b032cf.tar.gz trackermap-server-398b705820109c1103d915a2fec81fcf70b032cf.tar.bz2 trackermap-server-398b705820109c1103d915a2fec81fcf70b032cf.zip |
Fix some check style issues
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/helper/BitUtil.java | 8 | ||||
-rw-r--r-- | src/org/traccar/helper/Checksum.java | 8 | ||||
-rw-r--r-- | src/org/traccar/helper/Hashing.java | 14 | ||||
-rw-r--r-- | src/org/traccar/helper/PatternBuilder.java | 12 | ||||
-rw-r--r-- | src/org/traccar/model/MiscFormatter.java | 15 | ||||
-rw-r--r-- | src/org/traccar/protocol/Avl301ProtocolDecoder.java | 15 | ||||
-rw-r--r-- | src/org/traccar/protocol/BceProtocolDecoder.java | 16 | ||||
-rw-r--r-- | src/org/traccar/protocol/BlackKiteProtocolDecoder.java | 8 | ||||
-rw-r--r-- | src/org/traccar/protocol/CityeasyProtocolEncoder.java | 10 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolEncoder.java | 1 | ||||
-rw-r--r-- | src/org/traccar/protocol/GpsGateProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/NavisProtocolDecoder.java | 4 | ||||
-rw-r--r-- | src/org/traccar/protocol/Tk102ProtocolDecoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/TrackboxProtocolDecoder.java | 2 |
14 files changed, 79 insertions, 38 deletions
diff --git a/src/org/traccar/helper/BitUtil.java b/src/org/traccar/helper/BitUtil.java index e13df8f7e..81c638a68 100644 --- a/src/org/traccar/helper/BitUtil.java +++ b/src/org/traccar/helper/BitUtil.java @@ -15,10 +15,10 @@ */ package org.traccar.helper; -/** - * Useful functions to work with bits - */ -public class BitUtil { +public final class BitUtil { + + private BitUtil() { + } public static boolean check(long number, int index) { return (number & (1 << index)) != 0; diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java index 6801e81d6..e6b6cd2c8 100644 --- a/src/org/traccar/helper/Checksum.java +++ b/src/org/traccar/helper/Checksum.java @@ -19,7 +19,10 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.zip.CRC32; -public class Checksum { +public final class Checksum { + + private Checksum() { + } private static final int[] CRC16_CCITT_TABLE_REVERSE = { 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, @@ -132,8 +135,9 @@ public class Checksum { return crc16Unreflected(buf, 0xFFFF, CRC16_CCITT_TABLE) ^ 0xFFFF; case CRC16_MCRF4XX: return crc16Reflected(buf, 0xFFFF, CRC16_CCITT_TABLE_REVERSE); + default: + throw new UnsupportedOperationException(type); } - throw new UnsupportedOperationException(); } public static int crc32(ByteBuffer buf) { diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java index beb674b00..1f01d9102 100644 --- a/src/org/traccar/helper/Hashing.java +++ b/src/org/traccar/helper/Hashing.java @@ -15,12 +15,12 @@ */ package org.traccar.helper; -import javax.crypto.SecretKeyFactory; -import javax.crypto.spec.PBEKeySpec; import java.security.GeneralSecurityException; import java.security.SecureRandom; +import javax.crypto.SecretKeyFactory; +import javax.crypto.spec.PBEKeySpec; -public class Hashing { +public final class Hashing { public static final int ITERATIONS = 1000; public static final int SALT_SIZE = 24; @@ -45,6 +45,9 @@ public class Hashing { } } + private Hashing() { + } + private static byte[] function(char[] password, byte[] salt) { try { PBEKeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, HASH_SIZE * Byte.SIZE); @@ -55,10 +58,11 @@ public class Hashing { } } - private static final SecureRandom random = new SecureRandom(); + private static final SecureRandom RANDOM = new SecureRandom(); public static HashingResult createHash(String password) { - byte[] salt = new byte[SALT_SIZE]; random.nextBytes(salt); + byte[] salt = new byte[SALT_SIZE]; + RANDOM.nextBytes(salt); byte[] hash = function(password.toCharArray(), salt); return new HashingResult( ChannelBufferTools.convertByteArray(hash), diff --git a/src/org/traccar/helper/PatternBuilder.java b/src/org/traccar/helper/PatternBuilder.java index 0105bf7a6..fbef144e6 100644 --- a/src/org/traccar/helper/PatternBuilder.java +++ b/src/org/traccar/helper/PatternBuilder.java @@ -25,20 +25,24 @@ public class PatternBuilder { void build(PatternBuilder builder); } + // eXPRession public PatternBuilder xpr(String s) { pattern.append(s); return this; } + // OPtional eXpression public PatternBuilder opx(String s) { return xpr("(?:").xpr(s).xpr(")?"); } + // TeXT public PatternBuilder txt(String s) { pattern.append(s.replaceAll("([\\\\\\.\\[\\{\\(\\*\\+\\?\\^\\$\\|])", "\\\\$1")); return this; } + // NUMber public PatternBuilder num(String s) { s = s.replace("dddd", "d{4}").replace("ddd", "d{3}").replace("dd", "d{2}"); s = s.replace("xxxx", "x{4}").replace("xxx", "x{3}").replace("xx", "x{2}"); @@ -47,6 +51,7 @@ public class PatternBuilder { return this; } + // OPtional Number public PatternBuilder opn(String s) { return xpr("(?:").num(s).xpr(")?"); } @@ -60,6 +65,7 @@ public class PatternBuilder { return xpr("[^").txt(s).xpr("]*"); } + // NeXT public PatternBuilder nxt(String s) { return not(s).txt(s); } @@ -69,7 +75,11 @@ public class PatternBuilder { } public PatternBuilder groupEnd(boolean optional) { - return xpr(optional ? ")?" : ")"); + if (optional) { + return xpr(")?"); + } else { + return xpr(")"); + } } public Pattern compile() { diff --git a/src/org/traccar/model/MiscFormatter.java b/src/org/traccar/model/MiscFormatter.java index 2bc6207fb..8f95f5c45 100644 --- a/src/org/traccar/model/MiscFormatter.java +++ b/src/org/traccar/model/MiscFormatter.java @@ -15,9 +15,6 @@ */ package org.traccar.model; -import org.traccar.helper.Log; -import org.traccar.web.JsonConverter; - import java.text.DecimalFormat; import java.util.LinkedHashMap; import java.util.Map; @@ -27,19 +24,21 @@ import javax.json.JsonObject; import javax.json.JsonObjectBuilder; import javax.json.JsonString; import javax.json.JsonValue; +import org.traccar.helper.Log; +import org.traccar.web.JsonConverter; /** * Format extended tracker status */ public class MiscFormatter { - private static final String xmlRootNode = "info"; + private static final String XML_ROOT_NODE = "info"; - private static final DecimalFormat decimalFormat = new DecimalFormat("#.##"); + private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##"); private static String format(Object value) { if (value instanceof Double || value instanceof Float) { - return decimalFormat.format(value); + return DECIMAL_FORMAT.format(value); } else { return value.toString(); } @@ -48,7 +47,7 @@ public class MiscFormatter { public static String toXmlString(Map<String, Object> attributes) { StringBuilder result = new StringBuilder(); - result.append("<").append(xmlRootNode).append(">"); + result.append("<").append(XML_ROOT_NODE).append(">"); for (Map.Entry<String, Object> entry : attributes.entrySet()) { @@ -57,7 +56,7 @@ public class MiscFormatter { result.append("</").append(entry.getKey()).append(">"); } - result.append("</").append(xmlRootNode).append(">"); + result.append("</").append(XML_ROOT_NODE).append(">"); return result.toString(); } diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index 1f1fdd6f8..f0ad97bf8 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -15,6 +15,9 @@ */ package org.traccar.protocol; +import java.net.SocketAddress; +import java.util.Calendar; +import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; @@ -22,10 +25,6 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.model.Event; import org.traccar.model.Position; -import java.net.SocketAddress; -import java.util.Calendar; -import java.util.TimeZone; - public class Avl301ProtocolDecoder extends BaseProtocolDecoder { public Avl301ProtocolDecoder(Avl301Protocol protocol) { @@ -114,8 +113,12 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { 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; + if ((union & 0x0400) != 0) { + latitude = -latitude; + } + if ((union & 0x0800) != 0) { + longitude = -longitude; + } position.setLatitude(latitude); position.setLongitude(longitude); diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java index c6f928aef..31e0868fd 100644 --- a/src/org/traccar/protocol/BceProtocolDecoder.java +++ b/src/org/traccar/protocol/BceProtocolDecoder.java @@ -113,10 +113,18 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { } } - if (BitUtil.check(mask, 10)) buf.skipBytes(4); - if (BitUtil.check(mask, 11)) buf.skipBytes(4); - if (BitUtil.check(mask, 12)) buf.skipBytes(2); - if (BitUtil.check(mask, 13)) buf.skipBytes(2); + if (BitUtil.check(mask, 10)) { + buf.skipBytes(4); + } + if (BitUtil.check(mask, 11)) { + buf.skipBytes(4); + } + if (BitUtil.check(mask, 12)) { + buf.skipBytes(2); + } + if (BitUtil.check(mask, 13)) { + buf.skipBytes(2); + } if (BitUtil.check(mask, 14)) { position.set(Event.KEY_MCC, buf.readUnsignedShort()); diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java index 21c7c5b33..6b7a8a971 100644 --- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java +++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java @@ -28,8 +28,8 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.helper.Log; import org.traccar.helper.BitUtil; +import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Position; @@ -131,14 +131,16 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { case TAG_DIGITAL_INPUTS: int input = buf.readUnsignedShort(); - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) { position.set(Event.PREFIX_IO + (i + 1), BitUtil.check(input, i)); + } break; case TAG_DIGITAL_OUTPUTS: int output = buf.readUnsignedShort(); - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; i++) { position.set(Event.PREFIX_IO + (i + 17), BitUtil.check(output, i)); + } break; case TAG_INPUT_VOLTAGE1: diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java index 76c4199e1..9c5695001 100644 --- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolEncoder.java @@ -19,6 +19,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; +import org.traccar.helper.Log; import org.traccar.model.Command; public class CityeasyProtocolEncoder extends BaseProtocolEncoder { @@ -56,9 +57,16 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder { return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content); case Command.TYPE_SET_TIMEZONE: int timezone = ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).intValue(); - content.writeByte(timezone < 0 ? 1 : 0); + if (timezone < 0) { + content.writeByte(1); + } else { + content.writeByte(0); + } content.writeShort(Math.abs(timezone) / 60); return encodeContent(CityeasyProtocolDecoder.MSG_TIMEZONE, content); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + break; } return null; diff --git a/src/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/org/traccar/protocol/Gps103ProtocolEncoder.java index cb1050be3..9f0df8761 100644 --- a/src/org/traccar/protocol/Gps103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolEncoder.java @@ -60,7 +60,6 @@ public class Gps103ProtocolEncoder extends StringProtocolEncoder implements Stri default: Log.warning(new UnsupportedOperationException(command.getType())); break; - } return null; diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index cdd3f5bb6..5e97a66f8 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -81,7 +81,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { } } else if (sentence.startsWith("$FRVER,")) { - + // Version check send(channel, "$FRVER,1,0,GpsGate Server 1.0"); diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 39912e420..0af74d70e 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -26,6 +26,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Position; @@ -308,6 +309,9 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { return processArray(channel, buf); case "*>S": return processHandshake(channel, buf); + default: + Log.warning(new UnsupportedOperationException(type)); + break; } return null; diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java index c052f09ed..613513f89 100644 --- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java @@ -62,7 +62,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { } else if (sentence.startsWith("[#")) { // TODO: EXIT Send response - + } else if (hasDeviceId()) { Matcher parser = PATTERN.matcher(sentence); diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java index 58795d4d3..39b1662ea 100644 --- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java +++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java @@ -63,7 +63,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder { if (identify(id, channel)) { sendResponse(channel); } - + } else { Matcher parser = PATTERN.matcher(sentence); |