Skip to content

Commit 20807fa

Browse files
committed
Use final
Remove extra parens
1 parent 70055e3 commit 20807fa

23 files changed

Lines changed: 161 additions & 161 deletions

src/main/java/org/apache/commons/codec/binary/Base16.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void decode(final byte[] data, int offset, final int length, final Context conte
176176
int result;
177177
if (dataLen < availableChars) {
178178
// we have 1/2 byte from previous invocation to decode
179-
result = (context.ibitWorkArea - 1) << BITS_PER_ENCODED_BYTE;
179+
result = context.ibitWorkArea - 1 << BITS_PER_ENCODED_BYTE;
180180
result |= decodeOctet(data[offset++]);
181181

182182
buffer[context.pos++] = (byte)result;
@@ -233,7 +233,7 @@ void encode(final byte[] data, final int offset, final int length, final Context
233233
final int end = offset + length;
234234
for (int i = offset; i < end; i++) {
235235
final int value = data[i];
236-
final int high = (value >> BITS_PER_ENCODED_BYTE) & MASK_4BITS;
236+
final int high = value >> BITS_PER_ENCODED_BYTE & MASK_4BITS;
237237
final int low = value & MASK_4BITS;
238238
buffer[context.pos++] = encodeTable[high];
239239
buffer[context.pos++] = encodeTable[low];

src/main/java/org/apache/commons/codec/binary/Base32.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ void decode(final byte[] input, int inPos, final int inAvail, final Context cont
386386
// collect decoded bytes
387387
context.lbitWorkArea = (context.lbitWorkArea << BITS_PER_ENCODED_BYTE) + result;
388388
if (context.modulus == 0) { // we can output the 5 bytes
389-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 32) & MASK_8BITS);
390-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
391-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
392-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
389+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 32 & MASK_8BITS);
390+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 24 & MASK_8BITS);
391+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 16 & MASK_8BITS);
392+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 8 & MASK_8BITS);
393393
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
394394
}
395395
}
@@ -414,41 +414,41 @@ void decode(final byte[] input, int inPos, final int inAvail, final Context cont
414414
validateTrailingCharacters();
415415
case 2 : // 10 bits, drop 2 and output one byte
416416
validateCharacter(MASK_2BITS, context);
417-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 2) & MASK_8BITS);
417+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 2 & MASK_8BITS);
418418
break;
419419
case 3 : // 15 bits, drop 7 and output 1 byte, or raise an exception
420420
validateTrailingCharacters();
421421
// Not possible from a valid encoding but decode anyway
422-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 7) & MASK_8BITS);
422+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 7 & MASK_8BITS);
423423
break;
424424
case 4 : // 20 bits = 2*8 + 4
425425
validateCharacter(MASK_4BITS, context);
426426
context.lbitWorkArea = context.lbitWorkArea >> 4; // drop 4 bits
427-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
428-
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
427+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 8 & MASK_8BITS);
428+
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
429429
break;
430430
case 5 : // 25 bits = 3*8 + 1
431431
validateCharacter(MASK_1BITS, context);
432432
context.lbitWorkArea = context.lbitWorkArea >> 1;
433-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
434-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
435-
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
433+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 16 & MASK_8BITS);
434+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 8 & MASK_8BITS);
435+
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
436436
break;
437437
case 6 : // 30 bits = 3*8 + 6, or raise an exception
438438
validateTrailingCharacters();
439439
// Not possible from a valid encoding but decode anyway
440440
context.lbitWorkArea = context.lbitWorkArea >> 6;
441-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
442-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
443-
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
441+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 16 & MASK_8BITS);
442+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 8 & MASK_8BITS);
443+
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
444444
break;
445445
case 7 : // 35 bits = 4*8 +3
446446
validateCharacter(MASK_3BITS, context);
447447
context.lbitWorkArea = context.lbitWorkArea >> 3;
448-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
449-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
450-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
451-
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
448+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 24 & MASK_8BITS);
449+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 16 & MASK_8BITS);
450+
buffer[context.pos++] = (byte) (context.lbitWorkArea >> 8 & MASK_8BITS);
451+
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
452452
break;
453453
default:
454454
// modulus can be 0-7, and we excluded 0,1 already

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public static boolean isArrayByteBase64(final byte[] arrayOctet) {
374374
* @since 1.4
375375
*/
376376
public static boolean isBase64(final byte octet) {
377-
return octet == PAD_DEFAULT || (octet >= 0 && octet < DECODE_TABLE.length && DECODE_TABLE[octet] != -1);
377+
return octet == PAD_DEFAULT || octet >= 0 && octet < DECODE_TABLE.length && DECODE_TABLE[octet] != -1;
378378
}
379379

380380
/**
@@ -420,18 +420,18 @@ public static boolean isBase64(final String base64) {
420420
static byte[] toIntegerBytes(final BigInteger bigInt) {
421421
int bitlen = bigInt.bitLength();
422422
// round bitlen
423-
bitlen = ((bitlen + 7) >> 3) << 3;
423+
bitlen = bitlen + 7 >> 3 << 3;
424424
final byte[] bigBytes = bigInt.toByteArray();
425425

426-
if (((bigInt.bitLength() % 8) != 0) && (((bigInt.bitLength() / 8) + 1) == (bitlen / 8))) {
426+
if (bigInt.bitLength() % 8 != 0 && bigInt.bitLength() / 8 + 1 == bitlen / 8) {
427427
return bigBytes;
428428
}
429429
// set up params for copying everything but sign bit
430430
int startSrc = 0;
431431
int len = bigBytes.length;
432432

433433
// if bigInt is exactly byte-aligned, just skip signbit in copy
434-
if ((bigInt.bitLength() % 8) == 0) {
434+
if (bigInt.bitLength() % 8 == 0) {
435435
startSrc = 1;
436436
len--;
437437
}
@@ -661,8 +661,8 @@ void decode(final byte[] input, int inPos, final int inAvail, final Context cont
661661
context.modulus = (context.modulus+1) % BYTES_PER_ENCODED_BLOCK;
662662
context.ibitWorkArea = (context.ibitWorkArea << BITS_PER_ENCODED_BYTE) + result;
663663
if (context.modulus == 0) {
664-
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS);
665-
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
664+
buffer[context.pos++] = (byte) (context.ibitWorkArea >> 16 & MASK_8BITS);
665+
buffer[context.pos++] = (byte) (context.ibitWorkArea >> 8 & MASK_8BITS);
666666
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
667667
}
668668
}
@@ -685,13 +685,13 @@ void decode(final byte[] input, int inPos, final int inAvail, final Context cont
685685
case 2 : // 12 bits = 8 + 4
686686
validateCharacter(MASK_4BITS, context);
687687
context.ibitWorkArea = context.ibitWorkArea >> 4; // dump the extra 4 bits
688-
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
688+
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
689689
break;
690690
case 3 : // 18 bits = 8 + 8 + 2
691691
validateCharacter(MASK_2BITS, context);
692692
context.ibitWorkArea = context.ibitWorkArea >> 2; // dump 2 bits
693-
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
694-
buffer[context.pos++] = (byte) ((context.ibitWorkArea) & MASK_8BITS);
693+
buffer[context.pos++] = (byte) (context.ibitWorkArea >> 8 & MASK_8BITS);
694+
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
695695
break;
696696
default:
697697
throw new IllegalStateException("Impossible modulus " + context.modulus);
@@ -739,9 +739,9 @@ void encode(final byte[] in, int inPos, final int inAvail, final Context context
739739
break;
740740
case 1 : // 8 bits = 6 + 2
741741
// top 6 bits:
742-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 2) & MASK_6BITS];
742+
buffer[context.pos++] = encodeTable[context.ibitWorkArea >> 2 & MASK_6BITS];
743743
// remaining 2:
744-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 4) & MASK_6BITS];
744+
buffer[context.pos++] = encodeTable[context.ibitWorkArea << 4 & MASK_6BITS];
745745
// URL-SAFE skips the padding to further reduce size.
746746
if (encodeTable == STANDARD_ENCODE_TABLE) {
747747
buffer[context.pos++] = pad;
@@ -750,9 +750,9 @@ void encode(final byte[] in, int inPos, final int inAvail, final Context context
750750
break;
751751

752752
case 2 : // 16 bits = 6 + 6 + 4
753-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 10) & MASK_6BITS];
754-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 4) & MASK_6BITS];
755-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea << 2) & MASK_6BITS];
753+
buffer[context.pos++] = encodeTable[context.ibitWorkArea >> 10 & MASK_6BITS];
754+
buffer[context.pos++] = encodeTable[context.ibitWorkArea >> 4 & MASK_6BITS];
755+
buffer[context.pos++] = encodeTable[context.ibitWorkArea << 2 & MASK_6BITS];
756756
// URL-SAFE skips the padding to further reduce size.
757757
if (encodeTable == STANDARD_ENCODE_TABLE) {
758758
buffer[context.pos++] = pad;
@@ -777,9 +777,9 @@ void encode(final byte[] in, int inPos, final int inAvail, final Context context
777777
}
778778
context.ibitWorkArea = (context.ibitWorkArea << 8) + b; // BITS_PER_BYTE
779779
if (0 == context.modulus) { // 3 bytes = 24 bits = 4 * 6 bits to extract
780-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 18) & MASK_6BITS];
781-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 12) & MASK_6BITS];
782-
buffer[context.pos++] = encodeTable[(context.ibitWorkArea >> 6) & MASK_6BITS];
780+
buffer[context.pos++] = encodeTable[context.ibitWorkArea >> 18 & MASK_6BITS];
781+
buffer[context.pos++] = encodeTable[context.ibitWorkArea >> 12 & MASK_6BITS];
782+
buffer[context.pos++] = encodeTable[context.ibitWorkArea >> 6 & MASK_6BITS];
783783
buffer[context.pos++] = encodeTable[context.ibitWorkArea & MASK_6BITS];
784784
context.currentLinePos += BYTES_PER_ENCODED_BLOCK;
785785
if (lineLength > 0 && lineLength <= context.currentLinePos) {

src/main/java/org/apache/commons/codec/binary/BaseNCodec.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ protected BaseNCodec(final int unencodedBlockSize, final int encodedBlockSize,
358358
this.unencodedBlockSize = unencodedBlockSize;
359359
this.encodedBlockSize = encodedBlockSize;
360360
final boolean useChunking = lineLength > 0 && chunkSeparatorLength > 0;
361-
this.lineLength = useChunking ? (lineLength / encodedBlockSize) * encodedBlockSize : 0;
361+
this.lineLength = useChunking ? lineLength / encodedBlockSize * encodedBlockSize : 0;
362362
this.chunkSeparatorLength = chunkSeparatorLength;
363363
this.pad = pad;
364364
this.decodingPolicy = Objects.requireNonNull(decodingPolicy, "codecPolicy");
@@ -594,10 +594,10 @@ protected int getDefaultBufferSize() {
594594
public long getEncodedLength(final byte[] pArray) {
595595
// Calculate non-chunked size - rounded up to allow for padding
596596
// cast to long is needed to avoid possibility of overflow
597-
long len = ((pArray.length + unencodedBlockSize-1) / unencodedBlockSize) * (long) encodedBlockSize;
597+
long len = (pArray.length + unencodedBlockSize-1) / unencodedBlockSize * (long) encodedBlockSize;
598598
if (lineLength > 0) { // We're using chunking
599599
// Round up to nearest multiple
600-
len += ((len + lineLength-1) / lineLength) * chunkSeparatorLength;
600+
len += (len + lineLength-1) / lineLength * chunkSeparatorLength;
601601
}
602602
return len;
603603
}
@@ -635,7 +635,7 @@ boolean hasData(final Context context) { // package protected for access from I
635635
public boolean isInAlphabet(final byte[] arrayOctet, final boolean allowWSPad) {
636636
for (final byte octet : arrayOctet) {
637637
if (!isInAlphabet(octet) &&
638-
(!allowWSPad || (octet != pad) && !Character.isWhitespace(octet))) {
638+
(!allowWSPad || octet != pad && !Character.isWhitespace(octet))) {
639639
return false;
640640
}
641641
}

src/main/java/org/apache/commons/codec/digest/B64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class B64 {
5757
static void b64from24bit(final byte b2, final byte b1, final byte b0, final int outLen,
5858
final StringBuilder buffer) {
5959
// The bit masking is necessary because the JVM byte type is signed!
60-
int w = ((b2 << 16) & 0x00ffffff) | ((b1 << 8) & 0x00ffff) | (b0 & 0xff);
60+
int w = b2 << 16 & 0x00ffffff | b1 << 8 & 0x00ffff | b0 & 0xff;
6161
// It's effectively a "for" loop but kept to resemble the original C code.
6262
int n = outLen;
6363
while (n-- > 0) {

src/main/java/org/apache/commons/codec/digest/MurmurHash2.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static int hash32(final byte[] data, final int length, final int seed) {
7979

8080
// body
8181
for (int i = 0; i < nblocks; i++) {
82-
final int index = (i << 2);
82+
final int index = i << 2;
8383
int k = getLittleEndianInt(data, index);
8484
k *= M32;
8585
k ^= k >>> R32;
@@ -89,14 +89,14 @@ public static int hash32(final byte[] data, final int length, final int seed) {
8989
}
9090

9191
// Handle the last few bytes of the input array
92-
final int index = (nblocks << 2);
92+
final int index = nblocks << 2;
9393
switch (length - index) {
9494
case 3:
9595
h ^= (data[index + 2] & 0xff) << 16;
9696
case 2:
9797
h ^= (data[index + 1] & 0xff) << 8;
9898
case 1:
99-
h ^= (data[index] & 0xff);
99+
h ^= data[index] & 0xff;
100100
h *= M32;
101101
}
102102

@@ -180,13 +180,13 @@ public static int hash32(final String text, final int from, final int length) {
180180
* @return The 64-bit hash of the given array
181181
*/
182182
public static long hash64(final byte[] data, final int length, final int seed) {
183-
long h = (seed & 0xffffffffL) ^ (length * M64);
183+
long h = seed & 0xffffffffL ^ length * M64;
184184

185185
final int nblocks = length >> 3;
186186

187187
// body
188188
for (int i = 0; i < nblocks; i++) {
189-
final int index = (i << 3);
189+
final int index = i << 3;
190190
long k = getLittleEndianLong(data, index);
191191

192192
k *= M64;
@@ -197,7 +197,7 @@ public static long hash64(final byte[] data, final int length, final int seed) {
197197
h *= M64;
198198
}
199199

200-
final int index = (nblocks << 3);
200+
final int index = nblocks << 3;
201201
switch (length - index) {
202202
case 7:
203203
h ^= ((long) data[index + 6] & 0xff) << 48;
@@ -212,7 +212,7 @@ public static long hash64(final byte[] data, final int length, final int seed) {
212212
case 2:
213213
h ^= ((long) data[index + 1] & 0xff) << 8;
214214
case 1:
215-
h ^= ((long) data[index] & 0xff);
215+
h ^= (long) data[index] & 0xff;
216216
h *= M64;
217217
}
218218

@@ -295,10 +295,10 @@ public static long hash64(final String text, final int from, final int length) {
295295
* @return The little-endian int
296296
*/
297297
private static int getLittleEndianInt(final byte[] data, final int index) {
298-
return ((data[index ] & 0xff) ) |
299-
((data[index + 1] & 0xff) << 8) |
300-
((data[index + 2] & 0xff) << 16) |
301-
((data[index + 3] & 0xff) << 24);
298+
return data[index ] & 0xff |
299+
(data[index + 1] & 0xff) << 8 |
300+
(data[index + 2] & 0xff) << 16 |
301+
(data[index + 3] & 0xff) << 24;
302302
}
303303

304304
/**
@@ -309,13 +309,13 @@ private static int getLittleEndianInt(final byte[] data, final int index) {
309309
* @return The little-endian long
310310
*/
311311
private static long getLittleEndianLong(final byte[] data, final int index) {
312-
return (((long) data[index ] & 0xff) ) |
313-
(((long) data[index + 1] & 0xff) << 8) |
314-
(((long) data[index + 2] & 0xff) << 16) |
315-
(((long) data[index + 3] & 0xff) << 24) |
316-
(((long) data[index + 4] & 0xff) << 32) |
317-
(((long) data[index + 5] & 0xff) << 40) |
318-
(((long) data[index + 6] & 0xff) << 48) |
319-
(((long) data[index + 7] & 0xff) << 56);
312+
return (long) data[index ] & 0xff |
313+
((long) data[index + 1] & 0xff) << 8 |
314+
((long) data[index + 2] & 0xff) << 16 |
315+
((long) data[index + 3] & 0xff) << 24 |
316+
((long) data[index + 4] & 0xff) << 32 |
317+
((long) data[index + 5] & 0xff) << 40 |
318+
((long) data[index + 6] & 0xff) << 48 |
319+
((long) data[index + 7] & 0xff) << 56;
320320
}
321321
}

0 commit comments

Comments
 (0)