Skip to content

Commit e910218

Browse files
committed
Use final
- Don't nest in else unless you have to
1 parent 8080c7c commit e910218

File tree

7 files changed

+28
-29
lines changed

7 files changed

+28
-29
lines changed

src/main/java/org/apache/commons/io/build/AbstractOrigin.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public Writer getWriter(final Charset charset, final OpenOption... options) thro
398398
}
399399

400400
@Override
401-
protected Channel getChannel(OpenOption... options) throws IOException {
401+
protected Channel getChannel(final OpenOption... options) throws IOException {
402402
return getRandomAccessFile(options).getChannel();
403403
}
404404

@@ -445,7 +445,7 @@ public Reader getReader(final Charset charset) throws IOException {
445445
}
446446

447447
@Override
448-
protected Channel getChannel(OpenOption... options) throws IOException {
448+
protected Channel getChannel(final OpenOption... options) throws IOException {
449449
for (final OpenOption option : options) {
450450
if (option == StandardOpenOption.WRITE) {
451451
throw new UnsupportedOperationException(
@@ -518,7 +518,7 @@ public Reader getReader(final Charset charset) throws IOException {
518518
}
519519

520520
@Override
521-
protected Channel getChannel(OpenOption... options) throws IOException {
521+
protected Channel getChannel(final OpenOption... options) throws IOException {
522522
for (final OpenOption option : options) {
523523
if (option == StandardOpenOption.WRITE) {
524524
throw new UnsupportedOperationException(
@@ -571,7 +571,7 @@ public Path getPath() {
571571
}
572572

573573
@Override
574-
protected Channel getChannel(OpenOption... options) throws IOException {
574+
protected Channel getChannel(final OpenOption... options) throws IOException {
575575
return Files.newByteChannel(getPath(), options);
576576
}
577577
}
@@ -616,7 +616,7 @@ public Reader getReader(final Charset charset) throws IOException {
616616
}
617617

618618
@Override
619-
protected Channel getChannel(OpenOption... options) throws IOException {
619+
protected Channel getChannel(final OpenOption... options) throws IOException {
620620
return Channels.newChannel(getInputStream(options));
621621
}
622622

@@ -700,7 +700,7 @@ public Writer getWriter(final Charset charset, final OpenOption... options) thro
700700
}
701701

702702
@Override
703-
protected Channel getChannel(OpenOption... options) throws IOException {
703+
protected Channel getChannel(final OpenOption... options) throws IOException {
704704
return Channels.newChannel(getOutputStream(options));
705705
}
706706
}
@@ -739,7 +739,7 @@ public Path getPath() {
739739
}
740740

741741
@Override
742-
protected Channel getChannel(OpenOption... options) throws IOException {
742+
protected Channel getChannel(final OpenOption... options) throws IOException {
743743
return Files.newByteChannel(getPath(), options);
744744
}
745745
}
@@ -826,7 +826,7 @@ public Reader getReader(final Charset charset) throws IOException {
826826
}
827827

828828
@Override
829-
protected Channel getChannel(OpenOption... options) throws IOException {
829+
protected Channel getChannel(final OpenOption... options) throws IOException {
830830
return Channels.newChannel(getInputStream());
831831
}
832832
}
@@ -869,7 +869,7 @@ public Path getPath() {
869869
}
870870

871871
@Override
872-
protected Channel getChannel(OpenOption... options) throws IOException {
872+
protected Channel getChannel(final OpenOption... options) throws IOException {
873873
final URI uri = get();
874874
final String scheme = uri.getScheme();
875875
if (SCHEME_HTTP.equalsIgnoreCase(scheme) || SCHEME_HTTPS.equalsIgnoreCase(scheme)) {
@@ -924,7 +924,7 @@ public Writer getWriter(final Charset charset, final OpenOption... options) thro
924924
}
925925

926926
@Override
927-
protected Channel getChannel(OpenOption... options) throws IOException {
927+
protected Channel getChannel(final OpenOption... options) throws IOException {
928928
return Channels.newChannel(getOutputStream());
929929
}
930930
}
@@ -956,7 +956,7 @@ public InputStream getInputStream(final OpenOption... options) throws IOExceptio
956956
}
957957

958958
@Override
959-
public Reader getReader(Charset charset) throws IOException {
959+
public Reader getReader(final Charset charset) throws IOException {
960960
return Channels.newReader(
961961
getChannel(ReadableByteChannel.class),
962962
Charsets.toCharset(charset).newDecoder(),
@@ -969,15 +969,15 @@ public OutputStream getOutputStream(final OpenOption... options) throws IOExcept
969969
}
970970

971971
@Override
972-
public Writer getWriter(Charset charset, OpenOption... options) throws IOException {
972+
public Writer getWriter(final Charset charset, final OpenOption... options) throws IOException {
973973
return Channels.newWriter(
974974
getChannel(WritableByteChannel.class, options),
975975
Charsets.toCharset(charset).newEncoder(),
976976
-1);
977977
}
978978

979979
@Override
980-
protected Channel getChannel(OpenOption... options) throws IOException {
980+
protected Channel getChannel(final OpenOption... options) throws IOException {
981981
// No conversion
982982
return get();
983983
}
@@ -1155,7 +1155,7 @@ public Writer getWriter(final Charset charset, final OpenOption... options) thro
11551155
* @throws UnsupportedOperationException If this origin cannot be converted to a channel of the given type.
11561156
* @since 2.21.0
11571157
*/
1158-
public final <C extends Channel> C getChannel(Class<C> channelType, OpenOption... options) throws IOException {
1158+
public final <C extends Channel> C getChannel(final Class<C> channelType, final OpenOption... options) throws IOException {
11591159
Objects.requireNonNull(channelType, "channelType");
11601160
final Channel channel = getChannel(options);
11611161
if (channelType.isInstance(channel)) {
@@ -1173,7 +1173,7 @@ public final <C extends Channel> C getChannel(Class<C> channelType, OpenOption..
11731173
* @throws UnsupportedOperationException If this origin cannot be converted to a channel.
11741174
* @since 2.21.0
11751175
*/
1176-
protected Channel getChannel(OpenOption... options) throws IOException {
1176+
protected Channel getChannel(final OpenOption... options) throws IOException {
11771177
throw unsupportedOperation("getChannel");
11781178
}
11791179

@@ -1193,13 +1193,13 @@ public String toString() {
11931193
return getSimpleClassName() + "[" + origin.toString() + "]";
11941194
}
11951195

1196-
UnsupportedOperationException unsupportedOperation(String method) {
1196+
UnsupportedOperationException unsupportedOperation(final String method) {
11971197
return new UnsupportedOperationException(String.format(
11981198
"%s#%s() for %s origin %s",
11991199
getSimpleClassName(), method, origin.getClass().getSimpleName(), origin));
12001200
}
12011201

1202-
UnsupportedOperationException unsupportedChannelType(Class<? extends Channel> channelType) {
1202+
UnsupportedOperationException unsupportedChannelType(final Class<? extends Channel> channelType) {
12031203
return new UnsupportedOperationException(String.format(
12041204
"%s#getChannel(%s) for %s origin %s",
12051205
getSimpleClassName(),

src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public Writer getWriter() throws IOException {
273273
* @see #getOpenOptions()
274274
* @since 2.21.0
275275
*/
276-
public <C extends Channel> C getChannel(Class<C> channelType) throws IOException {
276+
public <C extends Channel> C getChannel(final Class<C> channelType) throws IOException {
277277
return checkOrigin().getChannel(channelType, getOpenOptions());
278278
}
279279

src/main/java/org/apache/commons/io/channels/ByteArraySeekableByteChannel.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class ByteArraySeekableByteChannel implements SeekableByteChannel {
6161
* @see #array()
6262
* @see ByteArrayInputStream#ByteArrayInputStream(byte[])
6363
*/
64-
public static ByteArraySeekableByteChannel wrap(byte[] bytes) {
64+
public static ByteArraySeekableByteChannel wrap(final byte[] bytes) {
6565
Objects.requireNonNull(bytes, "bytes");
6666
return new ByteArraySeekableByteChannel(bytes);
6767
}
@@ -102,7 +102,7 @@ public ByteArraySeekableByteChannel(final int size) {
102102
this.size = 0;
103103
}
104104

105-
private ByteArraySeekableByteChannel(byte[] data) {
105+
private ByteArraySeekableByteChannel(final byte[] data) {
106106
this.data = data;
107107
this.position = 0;
108108
this.size = data.length;
@@ -264,9 +264,8 @@ public int write(final ByteBuffer b) throws IOException {
264264
final int newSize = position + wanted;
265265
if (newSize < 0 || newSize > IOUtils.SOFT_MAX_ARRAY_LENGTH) { // overflow
266266
throw new OutOfMemoryError("required array size " + Integer.toUnsignedString(newSize) + " too large");
267-
} else {
268-
resize(newSize);
269267
}
268+
resize(newSize);
270269
}
271270
b.get(data, position, wanted);
272271
position += wanted;

src/test/java/org/apache/commons/io/build/AbstractOriginTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void testGetReadableByteChannel() throws IOException {
304304
}
305305
}
306306

307-
private void checkRead(ReadableByteChannel channel) throws IOException {
307+
private void checkRead(final ReadableByteChannel channel) throws IOException {
308308
final ByteBuffer buffer = ByteBuffer.allocate(RO_LENGTH);
309309
int read = channel.read(buffer);
310310
assertEquals(RO_LENGTH, read);
@@ -367,7 +367,7 @@ void testGetWritableByteChannel() throws IOException {
367367
}
368368
}
369369

370-
private void checkWrite(WritableByteChannel channel) throws IOException {
370+
private void checkWrite(final WritableByteChannel channel) throws IOException {
371371
final ByteBuffer buffer = ByteBuffer.wrap(getFixtureByteArray());
372372
final int written = channel.write(buffer);
373373
assertEquals(RO_LENGTH, written);

src/test/java/org/apache/commons/io/build/AbstractStreamBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private static Stream<IOConsumer<Builder>> fileBasedConfigurers() throws URISynt
109109
*/
110110
@ParameterizedTest
111111
@MethodSource("fileBasedConfigurers")
112-
void testGetInputStream(IOConsumer<Builder> configurer) throws Exception {
112+
void testGetInputStream(final IOConsumer<Builder> configurer) throws Exception {
113113
final Builder builder = builder();
114114
configurer.accept(builder);
115115
assertNotNull(builder.getInputStream());
@@ -122,7 +122,7 @@ void testGetInputStream(IOConsumer<Builder> configurer) throws Exception {
122122
*/
123123
@ParameterizedTest
124124
@MethodSource("fileBasedConfigurers")
125-
void getGetSeekableByteChannel(IOConsumer<Builder> configurer) throws Exception {
125+
void getGetSeekableByteChannel(final IOConsumer<Builder> configurer) throws Exception {
126126
final Builder builder = builder();
127127
configurer.accept(builder);
128128
try (ReadableByteChannel channel = assertDoesNotThrow(() -> builder.getChannel(SeekableByteChannel.class))) {

src/test/java/org/apache/commons/io/build/ChannelOriginTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void testGetRandomAccessFile() {
8383
@Override
8484
@ParameterizedTest
8585
@EnumSource(StandardOpenOption.class)
86-
void testGetRandomAccessFile(OpenOption openOption) {
86+
void testGetRandomAccessFile(final OpenOption openOption) {
8787
// A FileByteChannel cannot be converted into a RandomAccessFile.
8888
assertThrows(UnsupportedOperationException.class, () -> super.testGetRandomAccessFile(openOption));
8989
}

src/test/java/org/apache/commons/io/channels/ByteArraySeekableByteChannelTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static Stream<Arguments> testConstructor() {
7676

7777
@ParameterizedTest
7878
@MethodSource
79-
void testConstructor(IOSupplier<ByteArraySeekableByteChannel> supplier, byte[] expected, int capacity) throws IOException {
79+
void testConstructor(final IOSupplier<ByteArraySeekableByteChannel> supplier, final byte[] expected, final int capacity) throws IOException {
8080
try (ByteArraySeekableByteChannel channel = supplier.get()) {
8181
assertEquals(0, channel.position());
8282
assertEquals(expected.length, channel.size());
@@ -103,7 +103,7 @@ static Stream<Arguments> testShouldResizeWhenWritingMoreDataThanCapacity() {
103103

104104
@ParameterizedTest
105105
@MethodSource
106-
void testShouldResizeWhenWritingMoreDataThanCapacity(byte[] data, int wanted) throws IOException {
106+
void testShouldResizeWhenWritingMoreDataThanCapacity(final byte[] data, final int wanted) throws IOException {
107107
try (ByteArraySeekableByteChannel c = ByteArraySeekableByteChannel.wrap(data)) {
108108
c.position(data.length);
109109
final ByteBuffer inData = ByteBuffer.wrap(new byte[wanted]);

0 commit comments

Comments
 (0)