optimize some code (#9289)

Motivation:

There is some manual coping of elements of Collections which can be replaced by Collections.addAll(...) and also some unnecessary semicolons.

Modifications:

- Simplify branches
- Use Collections.addAll
- Code cleanup

Result:

Code cleanup
This commit is contained in:
jimin 2019-06-28 19:48:23 +08:00 committed by Norman Maurer
parent 6b6475fb56
commit ee8206cb26
6 changed files with 17 additions and 24 deletions

View File

@ -225,7 +225,7 @@ public class Http2Exception extends Exception {
/**
* Close the channel immediately after a {@code GOAWAY} is sent.
*/
HARD_SHUTDOWN;
HARD_SHUTDOWN
}
/**

View File

@ -20,6 +20,7 @@ import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.UnstableApi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -94,9 +95,7 @@ public final class SmtpRequests {
} else {
List<CharSequence> params = new ArrayList<CharSequence>(mailParameters.length + 1);
params.add(sender != null? "FROM:<" + sender + '>' : FROM_NULL_SENDER);
for (CharSequence param : mailParameters) {
params.add(param);
}
Collections.addAll(params, mailParameters);
return new DefaultSmtpRequest(SmtpCommand.MAIL, params);
}
}
@ -111,9 +110,7 @@ public final class SmtpRequests {
} else {
List<CharSequence> params = new ArrayList<CharSequence>(rcptParameters.length + 1);
params.add("TO:<" + recipient + '>');
for (CharSequence param : rcptParameters) {
params.add(param);
}
Collections.addAll(params, rcptParameters);
return new DefaultSmtpRequest(SmtpCommand.RCPT, params);
}
}

View File

@ -15,14 +15,6 @@
*/
package io.netty.handler.codec;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.SwappedByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.ByteProcessor;
import io.netty.util.Signal;
import io.netty.util.internal.StringUtil;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
@ -32,6 +24,14 @@ import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.SwappedByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.ByteProcessor;
import io.netty.util.Signal;
import io.netty.util.internal.StringUtil;
/**
* Special {@link ByteBuf} implementation which is used by the {@link ReplayingDecoder}
*/
@ -488,12 +488,12 @@ final class ReplayingDecoderByteBuf extends ByteBuf {
@Override
public boolean isReadable() {
return terminated? buffer.isReadable() : true;
return !terminated || buffer.isReadable();
}
@Override
public boolean isReadable(int size) {
return terminated? buffer.isReadable(size) : true;
return !terminated || buffer.isReadable(size);
}
@Override

View File

@ -50,7 +50,7 @@ public class Log4J2LoggerTest extends AbstractInternalLoggerTest<Logger> {
result.put("level", level.name());
result.put("t", t);
super.logMessage(fqcn, level, marker, message, t);
};
}
};
}

View File

@ -102,9 +102,7 @@ public class JdkSslContext extends SslContext {
// Choose the sensible default list of protocols.
final String[] supportedProtocols = engine.getSupportedProtocols();
Set<String> supportedProtocolsSet = new HashSet<String>(supportedProtocols.length);
for (int i = 0; i < supportedProtocols.length; ++i) {
supportedProtocolsSet.add(supportedProtocols[i]);
}
Collections.addAll(supportedProtocolsSet, supportedProtocols);
List<String> protocols = new ArrayList<String>();
addIfSupported(
supportedProtocolsSet, protocols,

View File

@ -123,9 +123,7 @@ final class SslUtils {
// AES256 requires JCE unlimited strength jurisdiction policy files.
defaultCiphers.add("TLS_RSA_WITH_AES_256_CBC_SHA");
for (String tlsv13Cipher: DEFAULT_TLSV13_CIPHER_SUITES) {
defaultCiphers.add(tlsv13Cipher);
}
Collections.addAll(defaultCiphers, DEFAULT_TLSV13_CIPHER_SUITES);
DEFAULT_CIPHER_SUITES = defaultCiphers.toArray(new String[0]);
}