PMD: Remove unnecessary parentheses
MODIFY
src/main/java/org/apache/commons/io/EndianUtils.java
src/main/java/org/apache/commons/io/EndianUtils.java
@@ -109,10 +109,10 @@ public static float readSwappedFloat(final InputStream input) throws IOException
* @return the value read
*/
public static int readSwappedInteger(final byte[] data, final int offset) {
- return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
+ return ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
( ( data[ offset + 2 ] & 0xff ) << 16 ) +
- ( ( data[ offset + 3 ] & 0xff ) << 24 ) );
+ ( ( data[ offset + 3 ] & 0xff ) << 24 );
}
// ========================================== Swapping read/write routines
@@ -193,9 +193,9 @@ public static short readSwappedShort(final InputStream input) throws IOException
* @return the value read
*/
public static long readSwappedUnsignedInteger(final byte[] data, final int offset) {
- final long low = ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
+ final long low = ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
( ( data[ offset + 1 ] & 0xff ) << 8 ) +
- ( ( data[ offset + 2 ] & 0xff ) << 16 ) );
+ ( ( data[ offset + 2 ] & 0xff ) << 16 );
final long high = data[ offset + 3 ] & 0xff;
@@ -215,7 +215,7 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO
final int value3 = read(input);
final int value4 = read(input);
- final long low = (((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16));
+ final long low = ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8) + ((value3 & 0xff) << 16);
final long high = value4 & 0xff;
@@ -231,8 +231,8 @@ public static long readSwappedUnsignedInteger(final InputStream input) throws IO
* @return the value read
*/
public static int readSwappedUnsignedShort(final byte[] data, final int offset) {
- return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
- ( ( data[ offset + 1 ] & 0xff ) << 8 ) );
+ return ( ( data[ offset + 0 ] & 0xff ) << 0 ) +
+ ( ( data[ offset + 1 ] & 0xff ) << 8 );
}
/**
@@ -246,7 +246,7 @@ public static int readSwappedUnsignedShort(final InputStream input) throws IOExc
final int value1 = read(input);
final int value2 = read(input);
- return (((value1 & 0xff) << 0) + ((value2 & 0xff) << 8));
+ return ((value1 & 0xff) << 0) + ((value2 & 0xff) << 8);
}
/**
@@ -274,10 +274,10 @@ public static float swapFloat(final float value) {
*/
public static int swapInteger(final int value) {
return
- ( ( ( value >> 0 ) & 0xff ) << 24 ) +
- ( ( ( value >> 8 ) & 0xff ) << 16 ) +
- ( ( ( value >> 16 ) & 0xff ) << 8 ) +
- ( ( ( value >> 24 ) & 0xff ) << 0 );
+ ( ( value >> 0 & 0xff ) << 24 ) +
+ ( ( value >> 8 & 0xff ) << 16 ) +
+ ( ( value >> 16 & 0xff ) << 8 ) +
+ ( ( value >> 24 & 0xff ) << 0 );
}
/**
@@ -287,14 +287,14 @@ public static int swapInteger(final int value) {
*/
public static long swapLong(final long value) {
return
- ( ( ( value >> 0 ) & 0xff ) << 56 ) +
- ( ( ( value >> 8 ) & 0xff ) << 48 ) +
- ( ( ( value >> 16 ) & 0xff ) << 40 ) +
- ( ( ( value >> 24 ) & 0xff ) << 32 ) +
- ( ( ( value >> 32 ) & 0xff ) << 24 ) +
- ( ( ( value >> 40 ) & 0xff ) << 16 ) +
- ( ( ( value >> 48 ) & 0xff ) << 8 ) +
- ( ( ( value >> 56 ) & 0xff ) << 0 );
+ ( ( value >> 0 & 0xff ) << 56 ) +
+ ( ( value >> 8 & 0xff ) << 48 ) +
+ ( ( value >> 16 & 0xff ) << 40 ) +
+ ( ( value >> 24 & 0xff ) << 32 ) +
+ ( ( value >> 32 & 0xff ) << 24 ) +
+ ( ( value >> 40 & 0xff ) << 16 ) +
+ ( ( value >> 48 & 0xff ) << 8 ) +
+ ( ( value >> 56 & 0xff ) << 0 );
}
/**
@@ -303,8 +303,8 @@ public static long swapLong(final long value) {
* @return the converted value
*/
public static short swapShort(final short value) {
- return (short) ( ( ( ( value >> 0 ) & 0xff ) << 8 ) +
- ( ( ( value >> 8 ) & 0xff ) << 0 ) );
+ return (short) ( ( ( value >> 0 & 0xff ) << 8 ) +
+ ( ( value >> 8 & 0xff ) << 0 ) );
}
/**
@@ -359,10 +359,10 @@ public static void writeSwappedFloat(final OutputStream output, final float valu
* @param value value to write
*/
public static void writeSwappedInteger(final byte[] data, final int offset, final int value) {
- data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
- data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
- data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
- data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
+ data[ offset + 0 ] = (byte)( value >> 0 & 0xff );
+ data[ offset + 1 ] = (byte)( value >> 8 & 0xff );
+ data[ offset + 2 ] = (byte)( value >> 16 & 0xff );
+ data[ offset + 3 ] = (byte)( value >> 24 & 0xff );
}
/**
@@ -373,10 +373,10 @@ public static void writeSwappedInteger(final byte[] data, final int offset, fina
* @throws IOException in case of an I/O problem
*/
public static void writeSwappedInteger(final OutputStream output, final int value) throws IOException {
- output.write((byte) ((value >> 0) & 0xff));
- output.write((byte) ((value >> 8) & 0xff));
- output.write((byte) ((value >> 16) & 0xff));
- output.write((byte) ((value >> 24) & 0xff));
+ output.write((byte) (value >> 0 & 0xff));
+ output.write((byte) (value >> 8 & 0xff));
+ output.write((byte) (value >> 16 & 0xff));
+ output.write((byte) (value >> 24 & 0xff));
}
/**
@@ -387,14 +387,14 @@ public static void writeSwappedInteger(final OutputStream output, final int valu
* @param value value to write
*/
public static void writeSwappedLong(final byte[] data, final int offset, final long value) {
- data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
- data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
- data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff );
- data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff );
- data[ offset + 4 ] = (byte)( ( value >> 32 ) & 0xff );
- data[ offset + 5 ] = (byte)( ( value >> 40 ) & 0xff );
- data[ offset + 6 ] = (byte)( ( value >> 48 ) & 0xff );
- data[ offset + 7 ] = (byte)( ( value >> 56 ) & 0xff );
+ data[ offset + 0 ] = (byte)( value >> 0 & 0xff );
+ data[ offset + 1 ] = (byte)( value >> 8 & 0xff );
+ data[ offset + 2 ] = (byte)( value >> 16 & 0xff );
+ data[ offset + 3 ] = (byte)( value >> 24 & 0xff );
+ data[ offset + 4 ] = (byte)( value >> 32 & 0xff );
+ data[ offset + 5 ] = (byte)( value >> 40 & 0xff );
+ data[ offset + 6 ] = (byte)( value >> 48 & 0xff );
+ data[ offset + 7 ] = (byte)( value >> 56 & 0xff );
}
/**
@@ -405,14 +405,14 @@ public static void writeSwappedLong(final byte[] data, final int offset, final l
* @throws IOException in case of an I/O problem
*/
public static void writeSwappedLong(final OutputStream output, final long value) throws IOException {
- output.write((byte) ((value >> 0) & 0xff));
- output.write((byte) ((value >> 8) & 0xff));
- output.write((byte) ((value >> 16) & 0xff));
- output.write((byte) ((value >> 24) & 0xff));
- output.write((byte) ((value >> 32) & 0xff));
- output.write((byte) ((value >> 40) & 0xff));
- output.write((byte) ((value >> 48) & 0xff));
- output.write((byte) ((value >> 56) & 0xff));
+ output.write((byte) (value >> 0 & 0xff));
+ output.write((byte) (value >> 8 & 0xff));
+ output.write((byte) (value >> 16 & 0xff));
+ output.write((byte) (value >> 24 & 0xff));
+ output.write((byte) (value >> 32 & 0xff));
+ output.write((byte) (value >> 40 & 0xff));
+ output.write((byte) (value >> 48 & 0xff));
+ output.write((byte) (value >> 56 & 0xff));
}
/**
@@ -423,8 +423,8 @@ public static void writeSwappedLong(final OutputStream output, final long value)
* @param value value to write
*/
public static void writeSwappedShort(final byte[] data, final int offset, final short value) {
- data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff );
- data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff );
+ data[ offset + 0 ] = (byte)( value >> 0 & 0xff );
+ data[ offset + 1 ] = (byte)( value >> 8 & 0xff );
}
/**
@@ -435,8 +435,8 @@ public static void writeSwappedShort(final byte[] data, final int offset, final
* @throws IOException in case of an I/O problem
*/
public static void writeSwappedShort(final OutputStream output, final short value) throws IOException {
- output.write((byte) ((value >> 0) & 0xff));
- output.write((byte) ((value >> 8) & 0xff));
+ output.write((byte) (value >> 0 & 0xff));
+ output.write((byte) (value >> 8 & 0xff));
}
/**

MODIFY
src/main/java/org/apache/commons/io/FilenameUtils.java
src/main/java/org/apache/commons/io/FilenameUtils.java
@@ -358,7 +358,7 @@ private static String doNormalize(final String fileName, final char separator, f
// adjoining slashes
// If we get here, prefix can only be 0 or greater, size 1 or greater
// If prefix is 0, set loop start to 1 to prevent index errors
- for (int i = (prefix != 0) ? prefix : 1; i < size; i++) {
+ for (int i = prefix != 0 ? prefix : 1; i < size; i++) {
if (array[i] == separator && array[i - 1] == separator) {
System.arraycopy(array, i, array, i - 1, size - i);
size--;
@@ -1107,11 +1107,11 @@ private static boolean isIPv4Address(final String name) {
*/
private static boolean isIPv6Address(final String inet6Address) {
final boolean containsCompressedZeroes = inet6Address.contains("::");
- if (containsCompressedZeroes && (inet6Address.indexOf("::") != inet6Address.lastIndexOf("::"))) {
+ if (containsCompressedZeroes && inet6Address.indexOf("::") != inet6Address.lastIndexOf("::")) {
return false;
}
- if ((inet6Address.startsWith(":") && !inet6Address.startsWith("::"))
- || (inet6Address.endsWith(":") && !inet6Address.endsWith("::"))) {
+ if (inet6Address.startsWith(":") && !inet6Address.startsWith("::")
+ || inet6Address.endsWith(":") && !inet6Address.endsWith("::")) {
return false;
}
String[] octets = inet6Address.split(":");

MODIFY
src/main/java/org/apache/commons/io/file/attribute/FileTimes.java
src/main/java/org/apache/commons/io/file/attribute/FileTimes.java
@@ -216,7 +216,7 @@ public static long toNtfsTime(final Date date) {
*/
public static long toNtfsTime(final FileTime fileTime) {
final Instant instant = fileTime.toInstant();
- final long javaHundredNanos = (instant.getEpochSecond() * HUNDRED_NANOS_PER_SECOND) + (instant.getNano() / 100);
+ final long javaHundredNanos = instant.getEpochSecond() * HUNDRED_NANOS_PER_SECOND + instant.getNano() / 100;
return Math.subtractExact(javaHundredNanos, WINDOWS_EPOCH_OFFSET);
}

MODIFY
src/main/java/org/apache/commons/io/input/BoundedReader.java
src/main/java/org/apache/commons/io/input/BoundedReader.java
@@ -102,7 +102,7 @@ public int read() throws IOException {
return EOF;
}
- if (markedAt >= 0 && (charsRead - markedAt) >= readAheadLimit) {
+ if (markedAt >= 0 && charsRead - markedAt >= readAheadLimit) {
return EOF;
}
charsRead++;

MODIFY
src/main/java/org/apache/commons/io/input/ReaderInputStream.java
src/main/java/org/apache/commons/io/input/ReaderInputStream.java
@@ -328,7 +328,7 @@ public int read(final byte[] b) throws IOException {
@Override
public int read(final byte[] array, int off, int len) throws IOException {
Objects.requireNonNull(array, "array");
- if (len < 0 || off < 0 || (off + len) > array.length) {
+ if (len < 0 || off < 0 || off + len > array.length) {
throw new IndexOutOfBoundsException("Array size=" + array.length + ", offset=" + off + ", length=" + len);
}
int read = 0;

MODIFY
src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
@@ -123,7 +123,7 @@ public InputStream toInputStream() {
@Override
public void write(final byte[] b, final int off, final int len) {
- if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) {
+ if (off < 0 || off > b.length || len < 0 || off + len > b.length || off + len < 0) {
throw new IndexOutOfBoundsException(String.format("offset=%,d, length=%,d", off, len));
}
if (len == 0) {

PMD: Remove unnecessary parentheses