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-io.git
commit 3bae4fa3db0657c5b7323d0f6e2b4bdd2a7feb32 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Jan 21 14:27:39 2025 -0500 Fix ParenPad --- .../commons/io/filefilter/FileFilterUtils.java | 2 +- .../org/apache/commons/io/EndianUtilsTest.java | 237 ++++++++++----------- .../commons/io/function/IOBiFunctionTest.java | 4 +- .../commons/io/function/IOSpliteratorTest.java | 6 +- 4 files changed, 124 insertions(+), 125 deletions(-) diff --git a/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java b/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java index 0fd7bd64d..2fe69c096 100644 --- a/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java +++ b/src/main/java/org/apache/commons/io/filefilter/FileFilterUtils.java @@ -669,7 +669,7 @@ public static IOFileFilter sizeFileFilter(final long threshold, final boolean ac * @see SizeFileFilter * @since 1.3 */ - public static IOFileFilter sizeRangeFileFilter(final long minSizeInclusive, final long maxSizeInclusive ) { + public static IOFileFilter sizeRangeFileFilter(final long minSizeInclusive, final long maxSizeInclusive) { final IOFileFilter minimumFilter = new SizeFileFilter(minSizeInclusive, true); final IOFileFilter maximumFilter = new SizeFileFilter(maxSizeInclusive + 1L, false); return minimumFilter.and(maximumFilter); diff --git a/src/test/java/org/apache/commons/io/EndianUtilsTest.java b/src/test/java/org/apache/commons/io/EndianUtilsTest.java index 54abb4142..6865cbf44 100644 --- a/src/test/java/org/apache/commons/io/EndianUtilsTest.java +++ b/src/test/java/org/apache/commons/io/EndianUtilsTest.java @@ -29,7 +29,7 @@ /** * Tests {@link EndianUtils}. */ -public class EndianUtilsTest { +public class EndianUtilsTest { @Test public void testCtor() { @@ -60,147 +60,146 @@ public void testInvalidOffset() throws IOException { @Test public void testReadSwappedDouble() throws IOException { final byte[] bytes = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); - final double d2 = EndianUtils.readSwappedDouble( bytes, 0 ); - assertEquals( d1, d2, 0.0 ); + final double d1 = Double.longBitsToDouble(0x0102030405060708L); + final double d2 = EndianUtils.readSwappedDouble(bytes, 0); + assertEquals(d1, d2, 0.0); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); - assertEquals( d1, EndianUtils.readSwappedDouble( input ), 0.0 ); + assertEquals(d1, EndianUtils.readSwappedDouble(input), 0.0); } @Test public void testReadSwappedFloat() throws IOException { final byte[] bytes = { 0x04, 0x03, 0x02, 0x01 }; - final float f1 = Float.intBitsToFloat( 0x01020304 ); - final float f2 = EndianUtils.readSwappedFloat( bytes, 0 ); - assertEquals( f1, f2, 0.0 ); + final float f1 = Float.intBitsToFloat(0x01020304); + final float f2 = EndianUtils.readSwappedFloat(bytes, 0); + assertEquals(f1, f2, 0.0); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); - assertEquals( f1, EndianUtils.readSwappedFloat( input ), 0.0 ); + assertEquals(f1, EndianUtils.readSwappedFloat(input), 0.0); } @Test public void testReadSwappedInteger() throws IOException { final byte[] bytes = { 0x04, 0x03, 0x02, 0x01 }; - assertEquals( 0x01020304, EndianUtils.readSwappedInteger( bytes, 0 ) ); + assertEquals(0x01020304, EndianUtils.readSwappedInteger(bytes, 0)); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); - assertEquals( 0x01020304, EndianUtils.readSwappedInteger( input ) ); + assertEquals(0x01020304, EndianUtils.readSwappedInteger(input)); } @Test public void testReadSwappedLong() throws IOException { final byte[] bytes = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; - assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( bytes, 0 ) ); + assertEquals(0x0102030405060708L, EndianUtils.readSwappedLong(bytes, 0)); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); - assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( input ) ); + assertEquals(0x0102030405060708L, EndianUtils.readSwappedLong(input)); } @Test public void testReadSwappedShort() throws IOException { final byte[] bytes = { 0x02, 0x01 }; - assertEquals( 0x0102, EndianUtils.readSwappedShort( bytes, 0 ) ); + assertEquals(0x0102, EndianUtils.readSwappedShort(bytes, 0)); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); - assertEquals( 0x0102, EndianUtils.readSwappedShort( input ) ); + assertEquals(0x0102, EndianUtils.readSwappedShort(input)); } @Test public void testReadSwappedUnsignedInteger() throws IOException { final byte[] bytes = { 0x04, 0x03, 0x02, 0x01 }; - assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( bytes, 0 ) ); + assertEquals(0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger(bytes, 0)); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); - assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( input ) ); + assertEquals(0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger(input)); } @Test public void testReadSwappedUnsignedShort() throws IOException { final byte[] bytes = { 0x02, 0x01 }; - assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( bytes, 0 ) ); + assertEquals(0x00000102, EndianUtils.readSwappedUnsignedShort(bytes, 0)); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); - assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( input ) ); + assertEquals(0x00000102, EndianUtils.readSwappedUnsignedShort(input)); } @Test public void testSwapDouble() { - assertEquals( 0.0, EndianUtils.swapDouble( 0.0 ), 0.0 ); - final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); - final double d2 = Double.longBitsToDouble( 0x0807060504030201L ); - assertEquals( d2, EndianUtils.swapDouble( d1 ), 0.0 ); + assertEquals(0.0, EndianUtils.swapDouble(0.0), 0.0); + final double d1 = Double.longBitsToDouble(0x0102030405060708L); + final double d2 = Double.longBitsToDouble(0x0807060504030201L); + assertEquals(d2, EndianUtils.swapDouble(d1), 0.0); } @Test public void testSwapFloat() { - assertEquals( 0.0f, EndianUtils.swapFloat( 0.0f ), 0.0 ); - final float f1 = Float.intBitsToFloat( 0x01020304 ); - final float f2 = Float.intBitsToFloat( 0x04030201 ); - assertEquals( f2, EndianUtils.swapFloat( f1 ), 0.0 ); + assertEquals(0.0f, EndianUtils.swapFloat(0.0f), 0.0); + final float f1 = Float.intBitsToFloat(0x01020304); + final float f2 = Float.intBitsToFloat(0x04030201); + assertEquals(f2, EndianUtils.swapFloat(f1), 0.0); } @Test public void testSwapInteger() { - assertEquals( 0, EndianUtils.swapInteger( 0 ) ); - assertEquals( 0x04030201, EndianUtils.swapInteger( 0x01020304 ) ); - assertEquals( 0x01000000, EndianUtils.swapInteger( 0x00000001 ) ); - assertEquals( 0x00000001, EndianUtils.swapInteger( 0x01000000 ) ); - assertEquals( 0x11111111, EndianUtils.swapInteger( 0x11111111 ) ); - assertEquals( 0xabcdef10, EndianUtils.swapInteger( 0x10efcdab ) ); - assertEquals( 0xab, EndianUtils.swapInteger( 0xab000000 ) ); + assertEquals(0, EndianUtils.swapInteger(0)); + assertEquals(0x04030201, EndianUtils.swapInteger(0x01020304)); + assertEquals(0x01000000, EndianUtils.swapInteger(0x00000001)); + assertEquals(0x00000001, EndianUtils.swapInteger(0x01000000)); + assertEquals(0x11111111, EndianUtils.swapInteger(0x11111111)); + assertEquals(0xabcdef10, EndianUtils.swapInteger(0x10efcdab)); + assertEquals(0xab, EndianUtils.swapInteger(0xab000000)); } @Test public void testSwapLong() { - assertEquals( 0, EndianUtils.swapLong( 0 ) ); - assertEquals( 0x0807060504030201L, EndianUtils.swapLong( 0x0102030405060708L ) ); - assertEquals( 0xffffffffffffffffL, EndianUtils.swapLong( 0xffffffffffffffffL ) ); - assertEquals( 0xab, EndianUtils.swapLong( 0xab00000000000000L ) ); + assertEquals(0, EndianUtils.swapLong(0)); + assertEquals(0x0807060504030201L, EndianUtils.swapLong(0x0102030405060708L)); + assertEquals(0xffffffffffffffffL, EndianUtils.swapLong(0xffffffffffffffffL)); + assertEquals(0xab, EndianUtils.swapLong(0xab00000000000000L)); } @Test public void testSwapShort() { - assertEquals( (short) 0, EndianUtils.swapShort( (short) 0 ) ); - assertEquals( (short) 0x0201, EndianUtils.swapShort( (short) 0x0102 ) ); - assertEquals( (short) 0xffff, EndianUtils.swapShort( (short) 0xffff ) ); - assertEquals( (short) 0x0102, EndianUtils.swapShort( (short) 0x0201 ) ); + assertEquals((short) 0, EndianUtils.swapShort((short) 0)); + assertEquals((short) 0x0201, EndianUtils.swapShort((short) 0x0102)); + assertEquals((short) 0xffff, EndianUtils.swapShort((short) 0xffff)); + assertEquals((short) 0x0102, EndianUtils.swapShort((short) 0x0201)); } /** - * Tests all swapXxxx methods for symmetry when going from one endian - * to another and back again. + * Tests all swapXxxx methods for symmetry when going from one endian to another and back again. */ @Test public void testSymmetry() { - assertEquals( (short) 0x0102, EndianUtils.swapShort( EndianUtils.swapShort( (short) 0x0102 ) ) ); - assertEquals( 0x01020304, EndianUtils.swapInteger( EndianUtils.swapInteger( 0x01020304 ) ) ); - assertEquals( 0x0102030405060708L, EndianUtils.swapLong( EndianUtils.swapLong( 0x0102030405060708L ) ) ); - final float f1 = Float.intBitsToFloat( 0x01020304 ); - assertEquals( f1, EndianUtils.swapFloat( EndianUtils.swapFloat( f1 ) ), 0.0 ); - final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); - assertEquals( d1, EndianUtils.swapDouble( EndianUtils.swapDouble( d1 ) ), 0.0 ); + assertEquals((short) 0x0102, EndianUtils.swapShort(EndianUtils.swapShort((short) 0x0102))); + assertEquals(0x01020304, EndianUtils.swapInteger(EndianUtils.swapInteger(0x01020304))); + assertEquals(0x0102030405060708L, EndianUtils.swapLong(EndianUtils.swapLong(0x0102030405060708L))); + final float f1 = Float.intBitsToFloat(0x01020304); + assertEquals(f1, EndianUtils.swapFloat(EndianUtils.swapFloat(f1)), 0.0); + final double d1 = Double.longBitsToDouble(0x0102030405060708L); + assertEquals(d1, EndianUtils.swapDouble(EndianUtils.swapDouble(d1)), 0.0); } // tests #IO-101 @Test public void testSymmetryOfLong() { - final double[] tests = {34.345, -345.5645, 545.12, 10.043, 7.123456789123}; + final double[] tests = { 34.345, -345.5645, 545.12, 10.043, 7.123456789123 }; for (final double test : tests) { // testing the real problem byte[] buffer = new byte[8]; - final long ln1 = Double.doubleToLongBits( test ); + final long ln1 = Double.doubleToLongBits(test); EndianUtils.writeSwappedLong(buffer, 0, ln1); final long ln2 = EndianUtils.readSwappedLong(buffer, 0); - assertEquals( ln1, ln2 ); + assertEquals(ln1, ln2); // testing the bug report buffer = new byte[8]; EndianUtils.writeSwappedDouble(buffer, 0, test); final double val = EndianUtils.readSwappedDouble(buffer, 0); - assertEquals( test, val, 0 ); + assertEquals(test, val, 0); } } @@ -221,105 +220,105 @@ public void testUnsignedOverrun() throws Exception { @Test public void testWriteSwappedDouble() throws IOException { byte[] bytes = new byte[8]; - final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); - EndianUtils.writeSwappedDouble( bytes, 0, d1 ); - assertEquals( 0x08, bytes[0] ); - assertEquals( 0x07, bytes[1] ); - assertEquals( 0x06, bytes[2] ); - assertEquals( 0x05, bytes[3] ); - assertEquals( 0x04, bytes[4] ); - assertEquals( 0x03, bytes[5] ); - assertEquals( 0x02, bytes[6] ); - assertEquals( 0x01, bytes[7] ); + final double d1 = Double.longBitsToDouble(0x0102030405060708L); + EndianUtils.writeSwappedDouble(bytes, 0, d1); + assertEquals(0x08, bytes[0]); + assertEquals(0x07, bytes[1]); + assertEquals(0x06, bytes[2]); + assertEquals(0x05, bytes[3]); + assertEquals(0x04, bytes[4]); + assertEquals(0x03, bytes[5]); + assertEquals(0x02, bytes[6]); + assertEquals(0x01, bytes[7]); final ByteArrayOutputStream baos = new ByteArrayOutputStream(8); - EndianUtils.writeSwappedDouble( baos, d1 ); + EndianUtils.writeSwappedDouble(baos, d1); bytes = baos.toByteArray(); - assertEquals( 0x08, bytes[0] ); - assertEquals( 0x07, bytes[1] ); - assertEquals( 0x06, bytes[2] ); - assertEquals( 0x05, bytes[3] ); - assertEquals( 0x04, bytes[4] ); - assertEquals( 0x03, bytes[5] ); - assertEquals( 0x02, bytes[6] ); - assertEquals( 0x01, bytes[7] ); + assertEquals(0x08, bytes[0]); + assertEquals(0x07, bytes[1]); + assertEquals(0x06, bytes[2]); + assertEquals(0x05, bytes[3]); + assertEquals(0x04, bytes[4]); + assertEquals(0x03, bytes[5]); + assertEquals(0x02, bytes[6]); + assertEquals(0x01, bytes[7]); } @Test public void testWriteSwappedFloat() throws IOException { byte[] bytes = new byte[4]; - final float f1 = Float.intBitsToFloat( 0x01020304 ); - EndianUtils.writeSwappedFloat( bytes, 0, f1 ); - assertEquals( 0x04, bytes[0] ); - assertEquals( 0x03, bytes[1] ); - assertEquals( 0x02, bytes[2] ); - assertEquals( 0x01, bytes[3] ); + final float f1 = Float.intBitsToFloat(0x01020304); + EndianUtils.writeSwappedFloat(bytes, 0, f1); + assertEquals(0x04, bytes[0]); + assertEquals(0x03, bytes[1]); + assertEquals(0x02, bytes[2]); + assertEquals(0x01, bytes[3]); final ByteArrayOutputStream baos = new ByteArrayOutputStream(4); - EndianUtils.writeSwappedFloat( baos, f1 ); + EndianUtils.writeSwappedFloat(baos, f1); bytes = baos.toByteArray(); - assertEquals( 0x04, bytes[0] ); - assertEquals( 0x03, bytes[1] ); - assertEquals( 0x02, bytes[2] ); - assertEquals( 0x01, bytes[3] ); + assertEquals(0x04, bytes[0]); + assertEquals(0x03, bytes[1]); + assertEquals(0x02, bytes[2]); + assertEquals(0x01, bytes[3]); } @Test public void testWriteSwappedInteger() throws IOException { byte[] bytes = new byte[4]; - EndianUtils.writeSwappedInteger( bytes, 0, 0x01020304 ); - assertEquals( 0x04, bytes[0] ); - assertEquals( 0x03, bytes[1] ); - assertEquals( 0x02, bytes[2] ); - assertEquals( 0x01, bytes[3] ); + EndianUtils.writeSwappedInteger(bytes, 0, 0x01020304); + assertEquals(0x04, bytes[0]); + assertEquals(0x03, bytes[1]); + assertEquals(0x02, bytes[2]); + assertEquals(0x01, bytes[3]); final ByteArrayOutputStream baos = new ByteArrayOutputStream(4); - EndianUtils.writeSwappedInteger( baos, 0x01020304 ); + EndianUtils.writeSwappedInteger(baos, 0x01020304); bytes = baos.toByteArray(); - assertEquals( 0x04, bytes[0] ); - assertEquals( 0x03, bytes[1] ); - assertEquals( 0x02, bytes[2] ); - assertEquals( 0x01, bytes[3] ); + assertEquals(0x04, bytes[0]); + assertEquals(0x03, bytes[1]); + assertEquals(0x02, bytes[2]); + assertEquals(0x01, bytes[3]); } @Test public void testWriteSwappedLong() throws IOException { byte[] bytes = new byte[8]; - EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L ); - assertEquals( 0x08, bytes[0] ); - assertEquals( 0x07, bytes[1] ); - assertEquals( 0x06, bytes[2] ); - assertEquals( 0x05, bytes[3] ); - assertEquals( 0x04, bytes[4] ); - assertEquals( 0x03, bytes[5] ); - assertEquals( 0x02, bytes[6] ); - assertEquals( 0x01, bytes[7] ); + EndianUtils.writeSwappedLong(bytes, 0, 0x0102030405060708L); + assertEquals(0x08, bytes[0]); + assertEquals(0x07, bytes[1]); + assertEquals(0x06, bytes[2]); + assertEquals(0x05, bytes[3]); + assertEquals(0x04, bytes[4]); + assertEquals(0x03, bytes[5]); + assertEquals(0x02, bytes[6]); + assertEquals(0x01, bytes[7]); final ByteArrayOutputStream baos = new ByteArrayOutputStream(8); - EndianUtils.writeSwappedLong( baos, 0x0102030405060708L ); + EndianUtils.writeSwappedLong(baos, 0x0102030405060708L); bytes = baos.toByteArray(); - assertEquals( 0x08, bytes[0] ); - assertEquals( 0x07, bytes[1] ); - assertEquals( 0x06, bytes[2] ); - assertEquals( 0x05, bytes[3] ); - assertEquals( 0x04, bytes[4] ); - assertEquals( 0x03, bytes[5] ); - assertEquals( 0x02, bytes[6] ); - assertEquals( 0x01, bytes[7] ); + assertEquals(0x08, bytes[0]); + assertEquals(0x07, bytes[1]); + assertEquals(0x06, bytes[2]); + assertEquals(0x05, bytes[3]); + assertEquals(0x04, bytes[4]); + assertEquals(0x03, bytes[5]); + assertEquals(0x02, bytes[6]); + assertEquals(0x01, bytes[7]); } @Test public void testWriteSwappedShort() throws IOException { byte[] bytes = new byte[2]; - EndianUtils.writeSwappedShort( bytes, 0, (short) 0x0102 ); - assertEquals( 0x02, bytes[0] ); - assertEquals( 0x01, bytes[1] ); + EndianUtils.writeSwappedShort(bytes, 0, (short) 0x0102); + assertEquals(0x02, bytes[0]); + assertEquals(0x01, bytes[1]); final ByteArrayOutputStream baos = new ByteArrayOutputStream(2); - EndianUtils.writeSwappedShort( baos, (short) 0x0102 ); + EndianUtils.writeSwappedShort(baos, (short) 0x0102); bytes = baos.toByteArray(); - assertEquals( 0x02, bytes[0] ); - assertEquals( 0x01, bytes[1] ); + assertEquals(0x02, bytes[0]); + assertEquals(0x01, bytes[1]); } } diff --git a/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java b/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java index 350a35100..f61f63065 100644 --- a/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java +++ b/src/test/java/org/apache/commons/io/function/IOBiFunctionTest.java @@ -51,7 +51,7 @@ private boolean not(final boolean value) throws IOException { public void testAndThenIOFunction() throws IOException { final IOBiFunction<Path, LinkOption[], Boolean> isDirectory = Files::isDirectory; final IOFunction<Boolean, Boolean> not = this::not; - assertTrue( isDirectory.apply(PathUtils.current(), PathUtils.EMPTY_LINK_OPTION_ARRAY)); + assertTrue(isDirectory.apply(PathUtils.current(), PathUtils.EMPTY_LINK_OPTION_ARRAY)); final IOBiFunction<Path, LinkOption[], Boolean> andThen = isDirectory.andThen(not); assertFalse(andThen.apply(PathUtils.current(), PathUtils.EMPTY_LINK_OPTION_ARRAY)); } @@ -64,7 +64,7 @@ public void testAndThenIOFunction() throws IOException { @Test public void testApply() throws IOException { final IOBiFunction<Path, LinkOption[], Boolean> isDirectory = Files::isDirectory; - assertTrue( isDirectory.apply(PathUtils.current(), PathUtils.EMPTY_LINK_OPTION_ARRAY)); + assertTrue(isDirectory.apply(PathUtils.current(), PathUtils.EMPTY_LINK_OPTION_ARRAY)); } /** diff --git a/src/test/java/org/apache/commons/io/function/IOSpliteratorTest.java b/src/test/java/org/apache/commons/io/function/IOSpliteratorTest.java index ba377b36f..02e612a9e 100644 --- a/src/test/java/org/apache/commons/io/function/IOSpliteratorTest.java +++ b/src/test/java/org/apache/commons/io/function/IOSpliteratorTest.java @@ -114,11 +114,11 @@ public void testGetExactSizeIfKnown() { @Test public void testHasCharacteristics() { - assertTrue( spliterator.hasCharacteristics(spliterator.characteristics())); + assertTrue(spliterator.hasCharacteristics(spliterator.characteristics())); assertEquals(spliterator.unwrap().hasCharacteristics(spliterator.unwrap().characteristics()), - spliterator.hasCharacteristics(spliterator.characteristics())); + spliterator.hasCharacteristics(spliterator.characteristics())); assertEquals(spliterator.unwrap().hasCharacteristics(spliterator.unwrap().characteristics()), - spliterator.asSpliterator().hasCharacteristics(spliterator.asSpliterator().characteristics())); + spliterator.asSpliterator().hasCharacteristics(spliterator.asSpliterator().characteristics())); } @Test