Remove redundant 'else' branches.

This commit is contained in:
Trustin Lee 2012-11-12 09:31:40 +09:00
parent 361703b319
commit aa7cd691df
22 changed files with 129 additions and 101 deletions

View File

@ -172,7 +172,8 @@ public final class ByteBufUtil {
long vb = bufferB.getUnsignedInt(bIndex);
if (va > vb) {
return 1;
} else if (va < vb) {
}
if (va < vb) {
return -1;
}
aIndex += 4;
@ -184,7 +185,8 @@ public final class ByteBufUtil {
long vb = swapInt(bufferB.getInt(bIndex)) & 0xFFFFFFFFL;
if (va > vb) {
return 1;
} else if (va < vb) {
}
if (va < vb) {
return -1;
}
aIndex += 4;
@ -197,7 +199,8 @@ public final class ByteBufUtil {
short vb = bufferB.getUnsignedByte(bIndex);
if (va > vb) {
return 1;
} else if (va < vb) {
}
if (va < vb) {
return -1;
}
aIndex ++;

View File

@ -56,7 +56,8 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<Object,
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
// 100-continue response must be passed through.
return msg;
} else if (msg instanceof HttpMessage) {
}
if (msg instanceof HttpMessage) {
HttpMessage m = (HttpMessage) msg;
cleanup();

View File

@ -29,7 +29,8 @@ public class HttpContentDecompressor extends HttpContentDecoder {
protected EmbeddedByteChannel newContentDecoder(String contentEncoding) throws Exception {
if ("gzip".equalsIgnoreCase(contentEncoding) || "x-gzip".equalsIgnoreCase(contentEncoding)) {
return new EmbeddedByteChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
} else if ("deflate".equalsIgnoreCase(contentEncoding) || "x-deflate".equalsIgnoreCase(contentEncoding)) {
}
if ("deflate".equalsIgnoreCase(contentEncoding) || "x-deflate".equalsIgnoreCase(contentEncoding)) {
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
return new EmbeddedByteChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.ZLIB_OR_NONE));
}

View File

@ -78,7 +78,8 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().getCode() == 100) {
// 100-continue response must be passed through.
return msg;
} else if (msg instanceof HttpMessage) {
}
if (msg instanceof HttpMessage) {
HttpMessage m = (HttpMessage) msg;
cleanup();

View File

@ -197,39 +197,39 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
if (nextState == State.READ_CHUNK_SIZE) {
// Chunked encoding - generate HttpMessage first. HttpChunks will follow.
return message;
} else if (nextState == State.SKIP_CONTROL_CHARS) {
}
if (nextState == State.SKIP_CONTROL_CHARS) {
// No content is expected.
return reset();
} else {
long contentLength = HttpHeaders.getContentLength(message, -1);
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
content = Unpooled.EMPTY_BUFFER;
return reset();
}
}
long contentLength = HttpHeaders.getContentLength(message, -1);
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
content = Unpooled.EMPTY_BUFFER;
return reset();
}
switch (nextState) {
case READ_FIXED_LENGTH_CONTENT:
if (contentLength > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
// Generate HttpMessage first. HttpChunks will follow.
checkpoint(State.READ_FIXED_LENGTH_CONTENT_AS_CHUNKS);
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
// chunkSize will be decreased as the READ_FIXED_LENGTH_CONTENT_AS_CHUNKS
// state reads data chunk by chunk.
chunkSize = HttpHeaders.getContentLength(message, -1);
return message;
}
break;
case READ_VARIABLE_LENGTH_CONTENT:
if (buffer.readableBytes() > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
// Generate HttpMessage first. HttpChunks will follow.
checkpoint(State.READ_VARIABLE_LENGTH_CONTENT_AS_CHUNKS);
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
return message;
}
break;
default:
throw new IllegalStateException("Unexpected state: " + nextState);
switch (nextState) {
case READ_FIXED_LENGTH_CONTENT:
if (contentLength > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
// Generate HttpMessage first. HttpChunks will follow.
checkpoint(State.READ_FIXED_LENGTH_CONTENT_AS_CHUNKS);
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
// chunkSize will be decreased as the READ_FIXED_LENGTH_CONTENT_AS_CHUNKS
// state reads data chunk by chunk.
chunkSize = HttpHeaders.getContentLength(message, -1);
return message;
}
break;
case READ_VARIABLE_LENGTH_CONTENT:
if (buffer.readableBytes() > maxChunkSize || HttpHeaders.is100ContinueExpected(message)) {
// Generate HttpMessage first. HttpChunks will follow.
checkpoint(State.READ_VARIABLE_LENGTH_CONTENT_AS_CHUNKS);
message.setTransferEncoding(HttpTransferEncoding.STREAMED);
return message;
}
break;
default:
throw new IllegalStateException("Unexpected state: " + nextState);
}
// We return null here, this forces decode to be called again where we will decode the content
return null;

View File

@ -346,7 +346,8 @@ public class QueryStringDecoder {
if (c == '%') {
buf[pos++] = '%'; // "%%" -> "%"
break;
} else if (i == size - 1) {
}
if (i == size - 1) {
throw new IllegalArgumentException("partial escape"
+ " sequence at end of string: " + s);
}

View File

@ -99,7 +99,8 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
List<HttpData> fileToDelete = getList(request);
fileToDelete.add(attribute);
return attribute;
} else if (checkSize) {
}
if (checkSize) {
Attribute attribute = new MixedAttribute(name, minSize);
List<HttpData> fileToDelete = getList(request);
fileToDelete.add(attribute);
@ -121,7 +122,8 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
List<HttpData> fileToDelete = getList(request);
fileToDelete.add(attribute);
return attribute;
} else if (checkSize) {
}
if (checkSize) {
Attribute attribute = new MixedAttribute(name, value, minSize);
List<HttpData> fileToDelete = getList(request);
fileToDelete.add(attribute);
@ -144,7 +146,8 @@ public class DefaultHttpDataFactory implements HttpDataFactory {
List<HttpData> fileToDelete = getList(request);
fileToDelete.add(fileUpload);
return fileUpload;
} else if (checkSize) {
}
if (checkSize) {
FileUpload fileUpload = new MixedFileUpload(name, filename, contentType,
contentTransferEncoding, charset, size, minSize);
List<HttpData> fileToDelete = getList(request);

View File

@ -909,7 +909,8 @@ public class HttpPostRequestDecoder {
if (newline.equals(delimiter)) {
currentStatus = dispositionStatus;
return decodeMultipart(dispositionStatus);
} else if (newline.equals(delimiter + "--")) {
}
if (newline.equals(delimiter + "--")) {
// CLOSEDELIMITER or MIXED CLOSEDELIMITER found
currentStatus = closeDelimiterStatus;
if (currentStatus == MultiPartStatus.HEADERDELIMITER) {
@ -1926,7 +1927,8 @@ public class HttpPostRequestDecoder {
}
undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 2);
return false;
} else if (nextByte == HttpConstants.LF) {
}
if (nextByte == HttpConstants.LF) {
return true;
}
undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1);

View File

@ -290,9 +290,11 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocketFrame, We
// fragmented
if (frameOpcode == OPCODE_PING) {
return new PingWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_PONG) {
}
if (frameOpcode == OPCODE_PONG) {
return new PongWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
} else if (frameOpcode == OPCODE_CLOSE) {
}
if (frameOpcode == OPCODE_CLOSE) {
checkCloseFrameBody(ctx, framePayload);
receivedClosingHandshake = true;
return new CloseWebSocketFrame(frameFinalFlag, frameRsv, framePayload);

View File

@ -15,7 +15,6 @@
*/
package io.netty.handler.codec.http.websocketx;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
@ -26,6 +25,8 @@ import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.AttributeKey;
import static io.netty.handler.codec.http.HttpVersion.*;
/**
* Handles WebSocket control frames (Close, Ping, Pong) and data frames (Text and Binary) are passed
* to the next handler in the pipeline.
@ -69,7 +70,8 @@ public class WebSocketServerProtocolHandler extends ChannelInboundMessageHandler
WebSocketServerHandshaker handshaker = getHandshaker(ctx);
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
return;
} else if (frame instanceof PingWebSocketFrame) {
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
return;
}

View File

@ -52,9 +52,11 @@ public enum WebSocketVersion {
public String toHttpHeaderValue() {
if (this == V00) {
return "0";
} else if (this == V08) {
}
if (this == V08) {
return "8";
} else if (this == V13) {
}
if (this == V13) {
return "13";
}
throw new IllegalStateException("Unknown web socket version: " + this);

View File

@ -80,11 +80,10 @@ public abstract class ByteToMessageDecoder<O>
} else {
continue;
}
} else {
if (oldInputLength == in.readableBytes()) {
throw new IllegalStateException(
"decode() did not read anything but decoded a message.");
}
}
if (oldInputLength == in.readableBytes()) {
throw new IllegalStateException(
"decode() did not read anything but decoded a message.");
}
if (ChannelHandlerUtil.unfoldAndAdd(ctx, o, true)) {

View File

@ -364,7 +364,8 @@ final class Deflate {
nextlen = tree[(n + 1) * 2 + 1];
if (++ count < max_count && curlen == nextlen) {
continue;
} else if (count < min_count) {
}
if (count < min_count) {
bl_tree[curlen * 2] += count;
} else if (curlen != 0) {
if (curlen != prevlen) {
@ -458,7 +459,8 @@ final class Deflate {
nextlen = tree[(n + 1) * 2 + 1];
if (++ count < max_count && curlen == nextlen) {
continue;
} else if (count < min_count) {
}
if (count < min_count) {
do {
send_code(curlen, bl_tree);
} while (-- count != 0);

View File

@ -303,7 +303,8 @@ final class Inflate {
if (z.istate.wrapperType == WrapperType.NONE) {
z.istate.mode = DONE;
break;
} else if (z.istate.wrapperType == WrapperType.ZLIB) {
}
if (z.istate.wrapperType == WrapperType.ZLIB) {
z.istate.mode = CHECK4;
} else if (z.istate.wrapperType == WrapperType.GZIP) {
gzipCRC32 = 0;
@ -317,7 +318,7 @@ final class Inflate {
z.istate.marker = 0;
break;
}
case CHECK4:
case CHECK4:
if (z.avail_in == 0) {
return r;
}

View File

@ -15,11 +15,6 @@
*/
package io.netty.example.http.websocketx.server;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
@ -40,6 +35,12 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
/**
* Handles handshakes and messages
*/
@ -84,7 +85,8 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
res.setContent(content);
sendHttpResponse(ctx, req, res);
return;
} else if ("/favicon.ico".equals(req.getUri())) {
}
if ("/favicon.ico".equals(req.getUri())) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
sendHttpResponse(ctx, req, res);
return;
@ -107,10 +109,12 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
return;
} else if (frame instanceof PingWebSocketFrame) {
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
return;
} else if (!(frame instanceof TextWebSocketFrame)) {
}
if (!(frame instanceof TextWebSocketFrame)) {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
.getName()));
}

View File

@ -15,11 +15,6 @@
*/
package io.netty.example.http.websocketx.sslserver;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
@ -41,6 +36,12 @@ import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*;
/**
* Handles handshakes and messages
*/
@ -85,7 +86,9 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
res.setContent(content);
sendHttpResponse(ctx, req, res);
return;
} else if ("/favicon.ico".equals(req.getUri())) {
}
if ("/favicon.ico".equals(req.getUri())) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
sendHttpResponse(ctx, req, res);
return;
@ -108,10 +111,12 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
return;
} else if (frame instanceof PingWebSocketFrame) {
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().write(new PongWebSocketFrame(frame.getBinaryData()));
return;
} else if (!(frame instanceof TextWebSocketFrame)) {
}
if (!(frame instanceof TextWebSocketFrame)) {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
.getName()));
}

View File

@ -15,13 +15,14 @@
*/
package io.netty.channel;
import static io.netty.channel.ChannelOption.*;
import io.netty.channel.socket.SocketChannelConfig;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Map.Entry;
import static io.netty.channel.ChannelOption.*;
/**
* The default {@link SocketChannelConfig} implementation.
*/
@ -74,7 +75,8 @@ public class DefaultChannelConfig implements ChannelConfig {
if (option == CONNECT_TIMEOUT_MILLIS) {
return (T) Integer.valueOf(getConnectTimeoutMillis());
} else if (option == WRITE_SPIN_COUNT) {
}
if (option == WRITE_SPIN_COUNT) {
return (T) Integer.valueOf(getWriteSpinCount());
}

View File

@ -311,9 +311,7 @@ public class DefaultChannelFuture extends FlushCheckpoint implements ChannelFutu
try {
synchronized (this) {
if (done) {
return done;
} else if (waitTime <= 0) {
if (done || waitTime <= 0) {
return done;
}

View File

@ -1351,15 +1351,15 @@ public class DefaultChannelPipeline implements ChannelPipeline {
}
flush0(ctx, future);
return future;
} else {
final DefaultChannelHandlerContext ctx0 = ctx;
executor.execute(new Runnable() {
@Override
public void run() {
write(ctx0, message, future);
}
});
}
final DefaultChannelHandlerContext ctx0 = ctx;
executor.execute(new Runnable() {
@Override
public void run() {
write(ctx0, message, future);
}
});
return future;
}

View File

@ -15,7 +15,6 @@
*/
package io.netty.channel.group;
import static java.util.concurrent.TimeUnit.*;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
@ -31,6 +30,8 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.*;
/**
* The default {@link ChannelGroupFuture} implementation.
*/
@ -289,9 +290,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
try {
synchronized (this) {
if (done) {
return done;
} else if (waitTime <= 0) {
if (done || waitTime <= 0) {
return done;
}

View File

@ -271,9 +271,7 @@ public final class NioDatagramChannel
public ChannelFuture joinGroup(
InetAddress multicastAddress, NetworkInterface networkInterface,
InetAddress source, ChannelFuture future) {
if (DetectionUtil.javaVersion() < 7) {
throw new UnsupportedOperationException();
} else {
if (DetectionUtil.javaVersion() >= 7) {
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
@ -303,6 +301,8 @@ public final class NioDatagramChannel
} catch (Throwable e) {
future.setFailure(e);
}
} else {
throw new UnsupportedOperationException();
}
return future;
}

View File

@ -15,7 +15,6 @@
*/
package io.netty.channel.local;
import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.MessageBuf;
@ -24,11 +23,12 @@ import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import org.junit.Test;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import static org.junit.Assert.*;
public class LocalTransportThreadModelTest2 {
@ -100,15 +100,15 @@ public class LocalTransportThreadModelTest2 {
localChannel.close();
return;
} else {
localChannel.eventLoop().execute(new Runnable() {
@Override
public void run() {
close(localChannel, localRegistrationHandler);
}
});
}
localChannel.eventLoop().execute(new Runnable() {
@Override
public void run() {
close(localChannel, localRegistrationHandler);
}
});
// Wait until the connection is closed or the connection attempt fails.
localChannel.closeFuture().awaitUninterruptibly();