aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-13 23:11:23 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-13 23:11:23 +1300
commit398b705820109c1103d915a2fec81fcf70b032cf (patch)
tree659a0483eda19f9c91855197b70fd2a0bfb82a60 /src/org/traccar/helper
parent2da5669f8bd3f734fa37626c892aebdff7268613 (diff)
downloadtraccar-server-398b705820109c1103d915a2fec81fcf70b032cf.tar.gz
traccar-server-398b705820109c1103d915a2fec81fcf70b032cf.tar.bz2
traccar-server-398b705820109c1103d915a2fec81fcf70b032cf.zip
Fix some check style issues
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/BitUtil.java8
-rw-r--r--src/org/traccar/helper/Checksum.java8
-rw-r--r--src/org/traccar/helper/Hashing.java14
-rw-r--r--src/org/traccar/helper/PatternBuilder.java12
4 files changed, 30 insertions, 12 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() {