This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-codec.git
The following commit(s) were added to refs/heads/master by this push: new 30e5768 Use final. 30e5768 is described below commit 30e5768186f73552b5f1634a76cf2c12bf26b5bb Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Fri Jul 12 15:56:10 2019 -0400 Use final. --- .../org/apache/commons/codec/binary/Base32.java | 2 +- .../org/apache/commons/codec/binary/Base64.java | 2 +- .../apache/commons/codec/digest/MurmurHash2.java | 16 ++--- .../apache/commons/codec/digest/MurmurHash3.java | 68 ++++++++++---------- .../org/apache/commons/codec/digest/Sha2Crypt.java | 2 +- .../commons/codec/language/ColognePhonetic.java | 4 +- .../org/apache/commons/codec/net/PercentCodec.java | 10 +-- .../apache/commons/codec/binary/Base32Test.java | 6 +- .../apache/commons/codec/binary/Base64Test.java | 6 +- .../apache/commons/codec/digest/Apr1CryptTest.java | 2 +- .../apache/commons/codec/digest/Md5CryptTest.java | 2 +- .../commons/codec/digest/MurmurHash2Test.java | 16 ++--- .../commons/codec/digest/MurmurHash3Test.java | 74 +++++++++++----------- .../commons/codec/digest/Sha256CryptTest.java | 2 +- .../commons/codec/digest/Sha512CryptTest.java | 2 +- .../codec/language/ColognePhoneticTest.java | 16 ++--- .../org/apache/commons/codec/net/BCodecTest.java | 6 +- .../apache/commons/codec/net/PercentCodecTest.java | 52 +++++++-------- 18 files changed, 144 insertions(+), 144 deletions(-) diff --git a/src/main/java/org/apache/commons/codec/binary/Base32.java b/src/main/java/org/apache/commons/codec/binary/Base32.java index d9da1fd..a8ede4e 100644 --- a/src/main/java/org/apache/commons/codec/binary/Base32.java +++ b/src/main/java/org/apache/commons/codec/binary/Base32.java @@ -557,7 +557,7 @@ public class Base32 extends BaseNCodec { * * @throws IllegalArgumentException if the bits being checked contain any non-zero value */ - private void validateCharacter(int numBits, Context context) { + private void validateCharacter(final int numBits, final Context context) { if ((context.lbitWorkArea & numBits) != 0) { throw new IllegalArgumentException( "Last encoded character (before the paddings if any) is a valid base 32 alphabet but not a possible value"); diff --git a/src/main/java/org/apache/commons/codec/binary/Base64.java b/src/main/java/org/apache/commons/codec/binary/Base64.java index 56744aa..f515b51 100644 --- a/src/main/java/org/apache/commons/codec/binary/Base64.java +++ b/src/main/java/org/apache/commons/codec/binary/Base64.java @@ -793,7 +793,7 @@ public class Base64 extends BaseNCodec { * * @throws IllegalArgumentException if the bits being checked contain any non-zero value */ - private long validateCharacter(int numBitsToDrop, Context context) { + private long validateCharacter(final int numBitsToDrop, final Context context) { if ((context.ibitWorkArea & numBitsToDrop) != 0) { throw new IllegalArgumentException( "Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible value"); diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java b/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java index a980196..45c8b61 100644 --- a/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java +++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java @@ -48,7 +48,7 @@ public final class MurmurHash2 { * @param seed initial seed value * @return 32 bit hash of the given array */ - public static int hash32(final byte[] data, int length, int seed) { + public static int hash32(final byte[] data, final int length, final int seed) { // 'm' and 'r' are mixing constants generated offline. // They're not really 'magic', they just happen to work well. final int m = 0x5bd1e995; @@ -56,7 +56,7 @@ public final class MurmurHash2 { // Initialize the hash to a random value int h = seed ^ length; - int length4 = length / 4; + final int length4 = length / 4; for (int i = 0; i < length4; i++) { final int i4 = i * 4; @@ -94,7 +94,7 @@ public final class MurmurHash2 { * @param length length of the array to hash * @return 32 bit hash of the given array */ - public static int hash32(final byte[] data, int length) { + public static int hash32(final byte[] data, final int length) { return hash32(data, length, 0x9747b28c); } @@ -117,7 +117,7 @@ public final class MurmurHash2 { * @param length length of the substring to hash * @return 32 bit hash of the given string */ - public static int hash32(final String text, int from, int length) { + public static int hash32(final String text, final int from, final int length) { return hash32(text.substring(from, from + length)); } @@ -129,13 +129,13 @@ public final class MurmurHash2 { * @param seed initial seed value * @return 64 bit hash of the given array */ - public static long hash64(final byte[] data, int length, int seed) { + public static long hash64(final byte[] data, final int length, final int seed) { final long m = 0xc6a4a7935bd1e995L; final int r = 47; long h = (seed & 0xffffffffl) ^ (length * m); - int length8 = length / 8; + final int length8 = length / 8; for (int i = 0; i < length8; i++) { final int i8 = i * 8; @@ -184,7 +184,7 @@ public final class MurmurHash2 { * @param length length of the array to hash * @return 64 bit hash of the given string */ - public static long hash64(final byte[] data, int length) { + public static long hash64(final byte[] data, final int length) { return hash64(data, length, 0xe17a1465); } @@ -207,7 +207,7 @@ public final class MurmurHash2 { * @param length length of the substring to hash * @return 64 bit hash of the given array */ - public static long hash64(final String text, int from, int length) { + public static long hash64(final String text, final int from, final int length) { return hash64(text.substring(from, from + length)); } } diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java index 1a1c312..7c543ad 100644 --- a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java +++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java @@ -86,7 +86,7 @@ public final class MurmurHash3 { * @param l1 long to hash * @return 32 bit hash */ - public static int hash32(long l0, long l1) { + public static int hash32(final long l0, final long l1) { return hash32(l0, l1, DEFAULT_SEED); } @@ -96,7 +96,7 @@ public final class MurmurHash3 { * @param l0 long to hash * @return 32 bit hash */ - public static int hash32(long l0) { + public static int hash32(final long l0) { return hash32(l0, DEFAULT_SEED); } @@ -107,7 +107,7 @@ public final class MurmurHash3 { * @param seed initial seed value * @return 32 bit hash */ - public static int hash32(long l0, int seed) { + public static int hash32(final long l0, final int seed) { int hash = seed; final long r0 = Long.reverseBytes(l0); @@ -125,7 +125,7 @@ public final class MurmurHash3 { * @param seed initial seed value * @return 32 bit hash */ - public static int hash32(long l0, long l1, int seed) { + public static int hash32(final long l0, final long l1, final int seed) { int hash = seed; final long r0 = Long.reverseBytes(l0); final long r1 = Long.reverseBytes(l1); @@ -144,7 +144,7 @@ public final class MurmurHash3 { * @param data - input byte array * @return 32 bit hash */ - public static int hash32(byte[] data) { + public static int hash32(final byte[] data) { return hash32(data, 0, data.length, DEFAULT_SEED); } @@ -154,8 +154,8 @@ public final class MurmurHash3 { * @param data - input string * @return 32 bit hash */ - public static int hash32(String data) { - byte[] origin = data.getBytes(); + public static int hash32(final String data) { + final byte[] origin = data.getBytes(); return hash32(origin, 0, origin.length, DEFAULT_SEED); } @@ -166,7 +166,7 @@ public final class MurmurHash3 { * @param length - length of array * @return 32 bit hash */ - public static int hash32(byte[] data, int length) { + public static int hash32(final byte[] data, final int length) { return hash32(data, length, DEFAULT_SEED); } @@ -178,7 +178,7 @@ public final class MurmurHash3 { * @param seed - seed. (default 0) * @return 32 bit hash */ - public static int hash32(byte[] data, int length, int seed) { + public static int hash32(final byte[] data, final int length, final int seed) { return hash32(data, 0, length, seed); } @@ -191,21 +191,21 @@ public final class MurmurHash3 { * @param seed - seed. (default 0) * @return 32 bit hash */ - public static int hash32(byte[] data, int offset, int length, int seed) { + public static int hash32(final byte[] data, final int offset, final int length, final int seed) { int hash = seed; final int nblocks = length >> 2; // body for (int i = 0; i < nblocks; i++) { - int i_4 = i << 2; - int k = (data[offset + i_4] & 0xff) | ((data[offset + i_4 + 1] & 0xff) << 8) + final int i_4 = i << 2; + final int k = (data[offset + i_4] & 0xff) | ((data[offset + i_4 + 1] & 0xff) << 8) | ((data[offset + i_4 + 2] & 0xff) << 16) | ((data[offset + i_4 + 3] & 0xff) << 24); hash = mix32(k, hash); } // tail - int idx = nblocks << 2; + final int idx = nblocks << 2; int k1 = 0; switch (length - idx) { case 3: @@ -232,7 +232,7 @@ public final class MurmurHash3 { * @param data - input byte array * @return 64 bit hash */ - public static long hash64(byte[] data) { + public static long hash64(final byte[] data) { return hash64(data, 0, data.length, DEFAULT_SEED); } @@ -243,10 +243,10 @@ public final class MurmurHash3 { * @param data - input long * @return 64 bit hash */ - public static long hash64(long data) { + public static long hash64(final long data) { long hash = DEFAULT_SEED; long k = Long.reverseBytes(data); - int length = LONG_BYTES; + final int length = LONG_BYTES; // mix functions k *= C1; k = Long.rotateLeft(k, R1); @@ -266,9 +266,9 @@ public final class MurmurHash3 { * @param data - input int * @return 64 bit hash */ - public static long hash64(int data) { + public static long hash64(final int data) { long k1 = Integer.reverseBytes(data) & (-1L >>> 32); - int length = INTEGER_BYTES; + final int length = INTEGER_BYTES; long hash = DEFAULT_SEED; k1 *= C1; k1 = Long.rotateLeft(k1, R1); @@ -287,7 +287,7 @@ public final class MurmurHash3 { * @param data - input short * @return 64 bit hash */ - public static long hash64(short data) { + public static long hash64(final short data) { long hash = DEFAULT_SEED; long k1 = 0; k1 ^= ((long) data & 0xff) << 8; @@ -312,7 +312,7 @@ public final class MurmurHash3 { * @param length - length of array * @return 64 bit hash */ - public static long hash64(byte[] data, int offset, int length) { + public static long hash64(final byte[] data, final int offset, final int length) { return hash64(data, offset, length, DEFAULT_SEED); } @@ -325,7 +325,7 @@ public final class MurmurHash3 { * @param seed - seed. (default 0) * @return 64 bit hash */ - public static long hash64(byte[] data, int offset, int length, int seed) { + public static long hash64(final byte[] data, final int offset, final int length, final int seed) { long hash = seed; final int nblocks = length >> 3; @@ -347,7 +347,7 @@ public final class MurmurHash3 { // tail long k1 = 0; - int tailStart = nblocks << 3; + final int tailStart = nblocks << 3; switch (length - tailStart) { case 7: k1 ^= ((long) data[offset + tailStart + 6] & 0xff) << 48; @@ -382,7 +382,7 @@ public final class MurmurHash3 { * @param data - input byte array * @return - 128 bit hash (2 longs) */ - public static long[] hash128(byte[] data) { + public static long[] hash128(final byte[] data) { return hash128(data, 0, data.length, DEFAULT_SEED); } @@ -392,8 +392,8 @@ public final class MurmurHash3 { * @param data - input String * @return - 128 bit hash (2 longs) */ - public static long[] hash128(String data) { - byte[] origin = data.getBytes(); + public static long[] hash128(final String data) { + final byte[] origin = data.getBytes(); return hash128(origin, 0, origin.length, DEFAULT_SEED); } @@ -406,7 +406,7 @@ public final class MurmurHash3 { * @param seed - seed. (default is 0) * @return - 128 bit hash (2 longs) */ - public static long[] hash128(byte[] data, int offset, int length, int seed) { + public static long[] hash128(final byte[] data, final int offset, final int length, final int seed) { long h1 = seed; long h2 = seed; final int nblocks = length >> 4; @@ -446,7 +446,7 @@ public final class MurmurHash3 { // tail long k1 = 0; long k2 = 0; - int tailStart = nblocks << 4; + final int tailStart = nblocks << 4; switch (length - tailStart) { case 15: k2 ^= (long) (data[offset + tailStart + 14] & 0xff) << 48; @@ -513,7 +513,7 @@ public final class MurmurHash3 { return Integer.rotateLeft(hash, R2_32) * M_32 + N_32; } - private static int fmix32(int length, int hash) { + private static int fmix32(final int length, int hash) { hash ^= length; hash ^= (hash >>> 16); hash *= 0x85ebca6b; @@ -539,12 +539,12 @@ public final class MurmurHash3 { int totalLen; int hash; - public final void start(int hash) { + public final void start(final int hash) { tailLen = totalLen = 0; this.hash = hash; } - public final void add(byte[] data, int offset, int length) { + public final void add(final byte[] data, int offset, final int length) { if (length == 0) { return; } @@ -578,12 +578,12 @@ public final class MurmurHash3 { hash ^= k; hash = Integer.rotateLeft(hash, R2_32) * M_32 + N_32; } - int length2 = length - offset2; + final int length2 = length - offset2; offset += offset2; final int nblocks = length2 >> 2; for (int i = 0; i < nblocks; i++) { - int i_4 = (i << 2) + offset; + final int i_4 = (i << 2) + offset; int k = orBytes(data[i_4], data[i_4 + 1], data[i_4 + 2], data[i_4 + 3]); // mix functions @@ -594,7 +594,7 @@ public final class MurmurHash3 { hash = Integer.rotateLeft(hash, R2_32) * M_32 + N_32; } - int consumed = (nblocks << 2); + final int consumed = (nblocks << 2); tailLen = length2 - consumed; if (consumed == length2) { return; @@ -630,7 +630,7 @@ public final class MurmurHash3 { } } - private static int orBytes(byte b1, byte b2, byte b3, byte b4) { + private static int orBytes(final byte b1, final byte b2, final byte b3, final byte b4) { return (b1 & 0xff) | ((b2 & 0xff) << 8) | ((b3 & 0xff) << 16) | ((b4 & 0xff) << 24); } } diff --git a/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java b/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java index 877249f..f49505a 100644 --- a/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java +++ b/src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java @@ -133,7 +133,7 @@ public class Sha2Crypt { * when a {@link java.security.NoSuchAlgorithmException} is caught. * @since 1.12 */ - public static String sha256Crypt(final byte[] keyBytes, String salt, Random random) { + public static String sha256Crypt(final byte[] keyBytes, String salt, final Random random) { if (salt == null) { salt = SHA256_PREFIX + B64.getRandomSalt(8, random); } diff --git a/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java b/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java index 329d9bb..2ce2e51 100644 --- a/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java +++ b/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java @@ -309,7 +309,7 @@ public class ColognePhonetic implements StringEncoder { * @param text The source text to encode * @return the corresponding encoding according to the <i>Kölner Phonetik</i> algorithm */ - public String colognePhonetic(String text) { + public String colognePhonetic(final String text) { if (text == null) { return null; } @@ -414,7 +414,7 @@ public class ColognePhonetic implements StringEncoder { * <li>small sharp s, German</li> * </ul> */ - private char[] preprocess(String text) { + private char[] preprocess(final String text) { // This converts German small sharp s (Eszett) to SS final char[] chrs = text.toUpperCase(Locale.GERMAN).toCharArray(); diff --git a/src/main/java/org/apache/commons/codec/net/PercentCodec.java b/src/main/java/org/apache/commons/codec/net/PercentCodec.java index a93c6f9..2c0ca4c 100644 --- a/src/main/java/org/apache/commons/codec/net/PercentCodec.java +++ b/src/main/java/org/apache/commons/codec/net/PercentCodec.java @@ -89,7 +89,7 @@ public class PercentCodec implements BinaryEncoder, BinaryDecoder { */ private void insertAlwaysEncodeChars(final byte[] alwaysEncodeCharsArray) { if (alwaysEncodeCharsArray != null) { - for (byte b : alwaysEncodeCharsArray) { + for (final byte b : alwaysEncodeCharsArray) { insertAlwaysEncodeChar(b); } } @@ -122,15 +122,15 @@ public class PercentCodec implements BinaryEncoder, BinaryDecoder { return null; } - int expectedEncodingBytes = expectedEncodingBytes(bytes); - boolean willEncode = expectedEncodingBytes != bytes.length; + final int expectedEncodingBytes = expectedEncodingBytes(bytes); + final boolean willEncode = expectedEncodingBytes != bytes.length; if (willEncode || (plusForSpace && containsSpace(bytes))) { return doEncode(bytes, expectedEncodingBytes, willEncode); } return bytes; } - private byte[] doEncode(final byte[] bytes, int expectedLength, boolean willEncode) { + private byte[] doEncode(final byte[] bytes, final int expectedLength, final boolean willEncode) { final ByteBuffer buffer = ByteBuffer.allocate(expectedLength); for (final byte b : bytes) { if (willEncode && canEncode(b)) { @@ -218,7 +218,7 @@ public class PercentCodec implements BinaryEncoder, BinaryDecoder { private int expectedDecodingBytes(final byte[] bytes) { int byteCount = 0; for (int i = 0; i < bytes.length; ) { - byte b = bytes[i]; + final byte b = bytes[i]; i += b == ESCAPE_CHAR ? 3: 1; byteCount++; } diff --git a/src/test/java/org/apache/commons/codec/binary/Base32Test.java b/src/test/java/org/apache/commons/codec/binary/Base32Test.java index 547c241..d7d2d34 100644 --- a/src/test/java/org/apache/commons/codec/binary/Base32Test.java +++ b/src/test/java/org/apache/commons/codec/binary/Base32Test.java @@ -287,12 +287,12 @@ public class Base32Test { testImpossibleCases(new Base32(true), BASE32HEX_IMPOSSIBLE_CASES); } - private void testImpossibleCases(Base32 codec, String[] impossible_cases) { - for (String impossible : impossible_cases) { + private void testImpossibleCases(final Base32 codec, final String[] impossible_cases) { + for (final String impossible : impossible_cases) { try { codec.decode(impossible); fail(); - } catch (IllegalArgumentException ex) { + } catch (final IllegalArgumentException ex) { // expected } } diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Test.java b/src/test/java/org/apache/commons/codec/binary/Base64Test.java index 233372b..a9b9867 100644 --- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java +++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java @@ -1306,12 +1306,12 @@ public class Base64Test { @Test public void testBase64ImpossibleSamples() { - Base64 codec = new Base64(); - for (String s : BASE64_IMPOSSIBLE_CASES) { + final Base64 codec = new Base64(); + for (final String s : BASE64_IMPOSSIBLE_CASES) { try { codec.decode(s); fail(); - } catch (IllegalArgumentException ex) { + } catch (final IllegalArgumentException ex) { // expected } } diff --git a/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java index 0a14013..80016ab 100644 --- a/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java +++ b/src/test/java/org/apache/commons/codec/digest/Apr1CryptTest.java @@ -61,7 +61,7 @@ public class Apr1CryptTest { public void testApr1CryptBytesWithThreadLocalRandom() { // random salt final byte[] keyBytes = new byte[] { '!', 'b', 'c', '.' }; - ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); + final ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); final String hash = Md5Crypt.apr1Crypt(keyBytes, threadLocalRandom); assertEquals(hash, Md5Crypt.apr1Crypt("!bc.", hash)); diff --git a/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java index 6a2e6a2..6b7dfee 100644 --- a/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java +++ b/src/test/java/org/apache/commons/codec/digest/Md5CryptTest.java @@ -63,7 +63,7 @@ public class Md5CryptTest { @Test public void testMd5CryptExplicitCallWithThreadLocalRandom() { - ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); + final ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); assertTrue(Md5Crypt.md5Crypt("secret".getBytes(), threadLocalRandom).matches("^\\$1\\$[a-zA-Z0-9./]{0,8}\\$.{1,}$")); assertTrue(Md5Crypt.md5Crypt("secret".getBytes(), (String) null).matches("^\\$1\\$[a-zA-Z0-9./]{0,8}\\$.{1,}$")); } diff --git a/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java b/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java index 1682870..884bee6 100644 --- a/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java +++ b/src/test/java/org/apache/commons/codec/digest/MurmurHash2Test.java @@ -83,7 +83,7 @@ public class MurmurHash2Test { @Test public void testHash32ByteArrayIntInt() { for (int i = 0; i < input.length; i++) { - int hash = MurmurHash2.hash32(input[i], input[i].length, 0x71b4954d); + final int hash = MurmurHash2.hash32(input[i], input[i].length, 0x71b4954d); if (hash != results32_seed[i]) { fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash, results32_seed[i])); @@ -94,7 +94,7 @@ public class MurmurHash2Test { @Test public void testHash32ByteArrayInt() { for (int i = 0; i < input.length; i++) { - int hash = MurmurHash2.hash32(input[i], input[i].length); + final int hash = MurmurHash2.hash32(input[i], input[i].length); if (hash != results32_standard[i]) { fail(String.format("Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash, results32_standard[i])); @@ -104,20 +104,20 @@ public class MurmurHash2Test { @Test public void testHash32String() { - int hash = MurmurHash2.hash32(text); + final int hash = MurmurHash2.hash32(text); assertTrue(hash == 0xb3bf597e); } @Test public void testHash32StringIntInt() { - int hash = MurmurHash2.hash32(text, 2, text.length() - 4); + final int hash = MurmurHash2.hash32(text, 2, text.length() - 4); assertTrue(hash == 0x4d666d90); } @Test public void testHash64ByteArrayIntInt() { for (int i = 0; i < input.length; i++) { - long hash = MurmurHash2.hash64(input[i], input[i].length, 0x344d1f5c); + final long hash = MurmurHash2.hash64(input[i], input[i].length, 0x344d1f5c); assertTrue(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash, results64_seed[i]), hash == results64_seed[i]); } @@ -126,7 +126,7 @@ public class MurmurHash2Test { @Test public void testHash64ByteArrayInt() { for (int i = 0; i < input.length; i++) { - long hash = MurmurHash2.hash64(input[i], input[i].length); + final long hash = MurmurHash2.hash64(input[i], input[i].length); assertTrue(String.format("Unexpected hash64 result for example %d: 0x%016x instead of 0x%016x", i, hash, results64_standard[i]), hash == results64_standard[i]); } @@ -134,13 +134,13 @@ public class MurmurHash2Test { @Test public void testHash64String() { - long hash = MurmurHash2.hash64(text); + final long hash = MurmurHash2.hash64(text); assertTrue(hash == 0x0920e0c1b7eeb261l); } @Test public void testHash64StringIntInt() { - long hash = MurmurHash2.hash64(text, 2, text.length() - 4); + final long hash = MurmurHash2.hash64(text, 2, text.length() - 4); assertTrue(hash == 0xa8b33145194985a2l); } diff --git a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java index 674f077..d239c16 100644 --- a/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java +++ b/src/test/java/org/apache/commons/codec/digest/MurmurHash3Test.java @@ -33,10 +33,10 @@ public class MurmurHash3Test { @Test public void test32_String() { // Arrange - String origin = TEST; + final String origin = TEST; // Act - int result = MurmurHash3.hash32(origin); + final int result = MurmurHash3.hash32(origin); // Assert assertEquals(-436507231, result); @@ -44,11 +44,11 @@ public class MurmurHash3Test { @Test public void testHashCodeM3_64() { - byte[] origin =TEST.getBytes(); + final byte[] origin =TEST.getBytes(); long hash = MurmurHash3.hash64(origin, 0, origin.length); assertEquals(5785358552565094607L, hash); - byte[] originOffset = new byte[origin.length + 150]; + final byte[] originOffset = new byte[origin.length + 150]; Arrays.fill(originOffset, (byte) 123); System.arraycopy(origin, 0, originOffset, 150, origin.length); hash = MurmurHash3.hash64(originOffset, 150, origin.length); @@ -58,16 +58,16 @@ public class MurmurHash3Test { @Test public void test64() { final int seed = 123, iters = 1000000; - ByteBuffer SHORT_BUFFER = ByteBuffer.allocate(MurmurHash3.SHORT_BYTES); - ByteBuffer INT_BUFFER = ByteBuffer.allocate(MurmurHash3.INTEGER_BYTES); - ByteBuffer LONG_BUFFER = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); - Random rdm = new Random(seed); + final ByteBuffer SHORT_BUFFER = ByteBuffer.allocate(MurmurHash3.SHORT_BYTES); + final ByteBuffer INT_BUFFER = ByteBuffer.allocate(MurmurHash3.INTEGER_BYTES); + final ByteBuffer LONG_BUFFER = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); + final Random rdm = new Random(seed); for (int i = 0; i < iters; ++i) { - long ln = rdm.nextLong(); - int in = rdm.nextInt(); - short sn = (short) (rdm.nextInt(2 * Short.MAX_VALUE - 1) - Short.MAX_VALUE); - float fn = rdm.nextFloat(); - double dn = rdm.nextDouble(); + final long ln = rdm.nextLong(); + final int in = rdm.nextInt(); + final short sn = (short) (rdm.nextInt(2 * Short.MAX_VALUE - 1) - Short.MAX_VALUE); + final float fn = rdm.nextFloat(); + final double dn = rdm.nextDouble(); SHORT_BUFFER.putShort(0, sn); assertEquals(MurmurHash3.hash64(SHORT_BUFFER.array()), MurmurHash3.hash64(sn)); INT_BUFFER.putInt(0, in); @@ -84,11 +84,11 @@ public class MurmurHash3Test { @Test public void test128_Short() { // Arrange - ByteBuffer BUFFER = ByteBuffer.allocate(MurmurHash3.SHORT_BYTES); + final ByteBuffer BUFFER = ByteBuffer.allocate(MurmurHash3.SHORT_BYTES); BUFFER.putShort(0, (short) 2); // Act - long[] result = MurmurHash3.hash128(BUFFER.array()); + final long[] result = MurmurHash3.hash128(BUFFER.array()); // Assert assertEquals(result.length, 2); @@ -99,11 +99,11 @@ public class MurmurHash3Test { @Test public void test128_Int() { // Arrange - ByteBuffer BUFFER = ByteBuffer.allocate(MurmurHash3.INTEGER_BYTES); + final ByteBuffer BUFFER = ByteBuffer.allocate(MurmurHash3.INTEGER_BYTES); BUFFER.putInt(0, 3); // Act - long[] result = MurmurHash3.hash128(BUFFER.array()); + final long[] result = MurmurHash3.hash128(BUFFER.array()); // Assert assertEquals(result.length, 2); @@ -114,11 +114,11 @@ public class MurmurHash3Test { @Test public void test128_Long() { // Arrange - ByteBuffer BUFFER = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); + final ByteBuffer BUFFER = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); BUFFER.putLong(0, 8675309L); // Act - long[] result = MurmurHash3.hash128(BUFFER.array()); + final long[] result = MurmurHash3.hash128(BUFFER.array()); // Assert assertEquals(result.length, 2); @@ -129,11 +129,11 @@ public class MurmurHash3Test { @Test public void test128_Double() { // Arrange - ByteBuffer BUFFER = ByteBuffer.allocate(Double.SIZE / Byte.SIZE); + final ByteBuffer BUFFER = ByteBuffer.allocate(Double.SIZE / Byte.SIZE); BUFFER.putDouble(0, 456.987); // Act - long[] result = MurmurHash3.hash128(BUFFER.array()); + final long[] result = MurmurHash3.hash128(BUFFER.array()); // Assert assertEquals(result.length, 2); @@ -144,10 +144,10 @@ public class MurmurHash3Test { @Test public void test128_String() { // Arrange - String origin = TEST; + final String origin = TEST; // Act - long[] result = MurmurHash3.hash128(origin); + final long[] result = MurmurHash3.hash128(origin); // Assert assertEquals(result.length, 2); @@ -158,16 +158,16 @@ public class MurmurHash3Test { @Test public void testIncremental() { final int seed = 123, arraySize = 1023; - byte[] bytes = new byte[arraySize]; + final byte[] bytes = new byte[arraySize]; new Random(seed).nextBytes(bytes); - int expected = MurmurHash3.hash32(bytes, arraySize); - MurmurHash3.IncrementalHash32 same = new IncrementalHash32(), diff = new IncrementalHash32(); + final int expected = MurmurHash3.hash32(bytes, arraySize); + final MurmurHash3.IncrementalHash32 same = new IncrementalHash32(), diff = new IncrementalHash32(); for (int blockSize = 1; blockSize <= arraySize; ++blockSize) { - byte[] block = new byte[blockSize]; + final byte[] block = new byte[blockSize]; same.start(MurmurHash3.DEFAULT_SEED); diff.start(MurmurHash3.DEFAULT_SEED); for (int offset = 0; offset < arraySize; offset += blockSize) { - int length = Math.min(arraySize - offset, blockSize); + final int length = Math.min(arraySize - offset, blockSize); same.add(bytes, offset, length); System.arraycopy(bytes, offset, block, 0, length); diff.add(block, 0, length); @@ -179,7 +179,7 @@ public class MurmurHash3Test { @Test public void testTwoLongOrdered() { - ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES * 2); + final ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES * 2); for (long i = 0; i < 1000; i++) { for (long j = 0; j < 1000; j++) { buffer.putLong(0, i); @@ -191,12 +191,12 @@ public class MurmurHash3Test { @Test public void testTwoLongRandom() { - ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES * 2); - Random random = new Random(); + final ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES * 2); + final Random random = new Random(); for (long i = 0; i < 1000; i++) { for (long j = 0; j < 1000; j++) { - long x = random.nextLong(); - long y = random.nextLong(); + final long x = random.nextLong(); + final long y = random.nextLong(); buffer.putLong(0, x); buffer.putLong(MurmurHash3.LONG_BYTES, y); assertEquals(MurmurHash3.hash32(buffer.array()), MurmurHash3.hash32(x, y)); @@ -206,7 +206,7 @@ public class MurmurHash3Test { @Test public void testSingleLongOrdered() { - ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); + final ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); for (long i = 0; i < 1000; i++) { buffer.putLong(0, i); assertEquals(MurmurHash3.hash32(buffer.array()), MurmurHash3.hash32(i)); @@ -215,10 +215,10 @@ public class MurmurHash3Test { @Test public void testSingleLongRandom() { - ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); - Random random = new Random(); + final ByteBuffer buffer = ByteBuffer.allocate(MurmurHash3.LONG_BYTES); + final Random random = new Random(); for (long i = 0; i < 1000; i++) { - long x = random.nextLong(); + final long x = random.nextLong(); buffer.putLong(0, x); assertEquals(MurmurHash3.hash32(buffer.array()), MurmurHash3.hash32(x)); } diff --git a/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java index 0d12a38..1bea725 100644 --- a/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java +++ b/src/test/java/org/apache/commons/codec/digest/Sha256CryptTest.java @@ -60,7 +60,7 @@ public class Sha256CryptTest { @Test public void testSha2CryptRoundsThreadLocalRandom() { - ThreadLocalRandom random = ThreadLocalRandom.current(); + final ThreadLocalRandom random = ThreadLocalRandom.current(); // minimum rounds? assertEquals("$5$rounds=1000$abcd$b8MCU4GEeZIekOy5ahQ8EWfT330hvYGVeDYkBxXBva.", Sha2Crypt.sha256Crypt("secret".getBytes(Charsets.UTF_8), "$5$rounds=50$abcd$", random)); assertEquals("$5$rounds=1001$abcd$SQsJZs7KXKdd2DtklI3TY3tkD7UYA99RD0FBLm4Sk48", Sha2Crypt.sha256Crypt("secret".getBytes(Charsets.UTF_8), "$5$rounds=1001$abcd$", random)); diff --git a/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java b/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java index e013ea4..4db1f62 100644 --- a/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java +++ b/src/test/java/org/apache/commons/codec/digest/Sha512CryptTest.java @@ -59,7 +59,7 @@ public class Sha512CryptTest { @Test public void testSha512CryptExplicitCallThreadLocalRandom() { - ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); + final ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); assertTrue(Sha2Crypt.sha512Crypt("secret".getBytes(), null, threadLocalRandom).matches("^\\$6\\$[a-zA-Z0-9./]{0,16}\\$.{1,}$")); } diff --git a/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java b/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java index e6f8777..95e3bb1 100644 --- a/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java +++ b/src/test/java/org/apache/commons/codec/language/ColognePhoneticTest.java @@ -37,8 +37,8 @@ public class ColognePhoneticTest extends StringEncoderAbstractTest<ColognePhonet private static final Set<String> TESTSET = new HashSet<>(); - private static boolean hasTestCase(String re) { - for(String s : TESTSET) { + private static boolean hasTestCase(final String re) { + for(final String s : TESTSET) { if (s.matches(re)) { return true; } @@ -74,7 +74,7 @@ public class ColognePhoneticTest extends StringEncoderAbstractTest<ColognePhonet // Check that all possible input sequence conditions are represented public static void finishTests() { int errors = 0; - for(String m : MATCHES) { + for(final String m : MATCHES) { if (!hasTestCase(m)) { System.out.println(m + " has no test case"); errors++; @@ -85,7 +85,7 @@ public class ColognePhoneticTest extends StringEncoderAbstractTest<ColognePhonet @Override // Capture test strings for later checking - public void checkEncoding(String expected, String source) throws EncoderException { + public void checkEncoding(final String expected, final String source) throws EncoderException { // Note that the German letter Eszett is converted to SS by toUpperCase, so we don't need to replace it TESTSET.add(source.toUpperCase(Locale.GERMAN).replace('Ä', 'A').replace('Ö', 'O').replace('Ü', 'U')); super.checkEncoding(expected, source); @@ -244,10 +244,10 @@ public class ColognePhoneticTest extends StringEncoderAbstractTest<ColognePhonet } // Allow command-line testing - public static void main(String args[]) { - ColognePhonetic coder = new ColognePhonetic(); - for(String arg : args) { - String code = coder.encode(arg); + public static void main(final String args[]) { + final ColognePhonetic coder = new ColognePhonetic(); + for(final String arg : args) { + final String code = coder.encode(arg); System.out.println("'" + arg + "' = '" + code + "'"); } } diff --git a/src/test/java/org/apache/commons/codec/net/BCodecTest.java b/src/test/java/org/apache/commons/codec/net/BCodecTest.java index c44b20a..5a90629 100644 --- a/src/test/java/org/apache/commons/codec/net/BCodecTest.java +++ b/src/test/java/org/apache/commons/codec/net/BCodecTest.java @@ -156,12 +156,12 @@ public class BCodecTest { @Test public void testBase64ImpossibleSamples() { - BCodec codec = new BCodec(); - for (String s : BASE64_IMPOSSIBLE_CASES) { + final BCodec codec = new BCodec(); + for (final String s : BASE64_IMPOSSIBLE_CASES) { try { codec.decode(s); fail(); - } catch (DecoderException ex) { + } catch (final DecoderException ex) { // expected } } diff --git a/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java b/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java index 48fd66e..5ea9634 100644 --- a/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java +++ b/src/test/java/org/apache/commons/codec/net/PercentCodecTest.java @@ -36,11 +36,11 @@ public class PercentCodecTest { @Test public void testBasicEncodeDecode() throws Exception { - PercentCodec percentCodec = new PercentCodec(); + final PercentCodec percentCodec = new PercentCodec(); final String input = "abcdABCD"; - byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); + final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); final String encodedS = new String(encoded, "UTF-8"); - byte[] decoded = percentCodec.decode(encoded); + final byte[] decoded = percentCodec.decode(encoded); final String decodedS = new String(decoded, "UTF-8"); assertEquals("Basic PercentCodec encoding test", input, encodedS); assertEquals("Basic PercentCodec decoding test", input, decodedS); @@ -49,17 +49,17 @@ public class PercentCodecTest { @Test @Ignore public void testBasicSpace() throws Exception { - PercentCodec percentCodec = new PercentCodec(); + final PercentCodec percentCodec = new PercentCodec(); final String input = " "; - byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); + final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); Assert.assertArrayEquals("%20".getBytes(StandardCharsets.UTF_8), encoded); } @Test public void testConfigurablePercentEncoder() throws Exception { final String input = "abc123_-.*\u03B1\u03B2"; - PercentCodec percentCodec = new PercentCodec("abcdef".getBytes("UTF-8"), false); - byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); + final PercentCodec percentCodec = new PercentCodec("abcdef".getBytes("UTF-8"), false); + final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); final String encodedS = new String(encoded, "UTF-8"); assertEquals("Configurable PercentCodec encoding test", "%61%62%63123_-.*%CE%B1%CE%B2", encodedS); final byte[] decoded = percentCodec.decode(encoded); @@ -68,12 +68,12 @@ public class PercentCodecTest { @Test public void testDecodeInvalidEncodedResultDecoding() throws Exception { - String inputS = "\u03B1\u03B2"; - PercentCodec percentCodec = new PercentCodec(); - byte[] encoded = percentCodec.encode(inputS.getBytes("UTF-8")); + final String inputS = "\u03B1\u03B2"; + final PercentCodec percentCodec = new PercentCodec(); + final byte[] encoded = percentCodec.encode(inputS.getBytes("UTF-8")); try { percentCodec.decode(Arrays.copyOf(encoded, encoded.length-1)); //exclude one byte - } catch (Exception e) { + } catch (final Exception e) { assertTrue(DecoderException.class.isInstance(e) && ArrayIndexOutOfBoundsException.class.isInstance(e.getCause())); } @@ -81,34 +81,34 @@ public class PercentCodecTest { @Test public void testDecodeNullObject() throws Exception { - PercentCodec percentCodec = new PercentCodec(); + final PercentCodec percentCodec = new PercentCodec(); assertEquals(percentCodec.decode((Object) null), null); } @Test(expected = DecoderException.class) public void testDecodeUnsupportedObject() throws Exception { - PercentCodec percentCodec = new PercentCodec(); + final PercentCodec percentCodec = new PercentCodec(); percentCodec.decode("test"); } @Test public void testEncodeNullObject() throws Exception { - PercentCodec percentCodec = new PercentCodec(); + final PercentCodec percentCodec = new PercentCodec(); assertEquals(percentCodec.encode((Object) null), null); } @Test(expected = EncoderException.class) public void testEncodeUnsupportedObject() throws Exception { - PercentCodec percentCodec = new PercentCodec(); + final PercentCodec percentCodec = new PercentCodec(); percentCodec.encode("test"); } @Test public void testPercentEncoderDecoderWithNullOrEmptyInput() throws Exception { - PercentCodec percentCodec = new PercentCodec(null, true); + final PercentCodec percentCodec = new PercentCodec(null, true); assertEquals("Null input value encoding test", percentCodec.encode(null), null); assertEquals("Null input value decoding test", percentCodec.decode(null), null); - byte[] emptyInput = "".getBytes("UTF-8"); + final byte[] emptyInput = "".getBytes("UTF-8"); assertEquals("Empty input value encoding test", percentCodec.encode(emptyInput), emptyInput); assertTrue("Empty input value decoding test", Arrays.equals(percentCodec.decode(emptyInput), emptyInput)); } @@ -116,21 +116,21 @@ public class PercentCodecTest { @Test public void testPercentEncoderDecoderWithPlusForSpace() throws Exception { final String input = "a b c d"; - PercentCodec percentCodec = new PercentCodec(null, true); - byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); + final PercentCodec percentCodec = new PercentCodec(null, true); + final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); final String encodedS = new String(encoded, "UTF-8"); assertEquals("PercentCodec plus for space encoding test", "a+b+c+d", encodedS); - byte[] decode = percentCodec.decode(encoded); + final byte[] decode = percentCodec.decode(encoded); assertEquals("PercentCodec plus for space decoding test", new String(decode, "UTF-8"), input); } @Test public void testSafeCharEncodeDecodeObject() throws Exception { - PercentCodec percentCodec = new PercentCodec(null, true); + final PercentCodec percentCodec = new PercentCodec(null, true); final String input = "abc123_-.*"; - Object encoded = percentCodec.encode((Object) input.getBytes(StandardCharsets.UTF_8)); + final Object encoded = percentCodec.encode((Object) input.getBytes(StandardCharsets.UTF_8)); final String encodedS = new String((byte[]) encoded, "UTF-8"); - Object decoded = percentCodec.decode(encoded); + final Object decoded = percentCodec.decode(encoded); final String decodedS = new String((byte[]) decoded, "UTF-8"); assertEquals("Basic PercentCodec safe char encoding test", input, encodedS); assertEquals("Basic PercentCodec safe char decoding test", input, decodedS); @@ -138,11 +138,11 @@ public class PercentCodecTest { @Test public void testUnsafeCharEncodeDecode() throws Exception { - PercentCodec percentCodec = new PercentCodec(); + final PercentCodec percentCodec = new PercentCodec(); final String input = "\u03B1\u03B2\u03B3\u03B4\u03B5\u03B6% "; - byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); + final byte[] encoded = percentCodec.encode(input.getBytes(StandardCharsets.UTF_8)); final String encodedS = new String(encoded, "UTF-8"); - byte[] decoded = percentCodec.decode(encoded); + final byte[] decoded = percentCodec.decode(encoded); final String decodedS = new String(decoded, "UTF-8"); assertEquals("Basic PercentCodec unsafe char encoding test", "%CE%B1%CE%B2%CE%B3%CE%B4%CE%B5%CE%B6%25 ", encodedS); assertEquals("Basic PercentCodec unsafe char decoding test", input, decodedS);