Prefer "str".equals(var) to var.equals("str") / Add proper null checks

This commit is contained in:
Trustin Lee 2012-11-12 08:59:54 +09:00
parent fa805c4c13
commit a07fb94fe7
15 changed files with 25 additions and 25 deletions

View File

@ -53,10 +53,10 @@ public class HttpVersion implements Comparable<HttpVersion> {
}
text = text.trim().toUpperCase();
if (text.equals("HTTP/1.1")) {
if ("HTTP/1.1".equals(text)) {
return HTTP_1_1;
}
if (text.equals("HTTP/1.0")) {
if ("HTTP/1.0".equals(text)) {
return HTTP_1_0;
}
return new HttpVersion(text, true);

View File

@ -40,7 +40,7 @@ public final class RtspVersions {
}
text = text.trim().toUpperCase();
if (text.equals("RTSP/1.0")) {
if ("RTSP/1.0".equals(text)) {
return RTSP_1_0;
}

View File

@ -109,11 +109,11 @@ public final class SystemPropertyUtil {
return true;
}
if (value.equals("true") || value.equals("yes") || value.equals("1")) {
if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) {
return true;
}
if (value.equals("false") || value.equals("no") || value.equals("0")) {
if ("false".equals(value) || "no".equals(value) || "0".equals(value)) {
return false;
}

View File

@ -47,19 +47,19 @@ public class HttpSnoopClient {
String host = uri.getHost() == null? "localhost" : uri.getHost();
int port = uri.getPort();
if (port == -1) {
if (scheme.equalsIgnoreCase("http")) {
if ("http".equalsIgnoreCase(scheme)) {
port = 80;
} else if (scheme.equalsIgnoreCase("https")) {
} else if ("https".equalsIgnoreCase(scheme)) {
port = 443;
}
}
if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) {
if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
System.err.println("Only HTTP(S) is supported.");
return;
}
boolean ssl = scheme.equalsIgnoreCase("https");
boolean ssl = "https".equalsIgnoreCase(scheme);
// Configure the client.
Bootstrap b = new Bootstrap();

View File

@ -83,19 +83,19 @@ public class HttpUploadClient {
String host = uriSimple.getHost() == null ? "localhost" : uriSimple.getHost();
int port = uriSimple.getPort();
if (port == -1) {
if (scheme.equalsIgnoreCase("http")) {
if ("http".equalsIgnoreCase(scheme)) {
port = 80;
} else if (scheme.equalsIgnoreCase("https")) {
} else if ("https".equalsIgnoreCase(scheme)) {
port = 443;
}
}
if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) {
if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
logger.error("Only HTTP(S) is supported.");
return;
}
boolean ssl = scheme.equalsIgnoreCase("https");
boolean ssl = "https".equalsIgnoreCase(scheme);
URI uriFile;
try {

View File

@ -68,7 +68,7 @@ public class WebSocketClient {
try {
String protocol = uri.getScheme();
if (!protocol.equals("ws")) {
if (!"ws".equals(protocol)) {
throw new IllegalArgumentException("Unsupported protocol: " + protocol);
}

View File

@ -73,7 +73,7 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
}
// Send the demo page and favicon.ico
if (req.getUri().equals("/")) {
if ("/".equals(req.getUri())) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, OK);
ByteBuf content = WebSocketServerIndexPage.getContent(getWebSocketLocation(req));
@ -84,7 +84,7 @@ public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<
res.setContent(content);
sendHttpResponse(ctx, req, res);
return;
} else if (req.getUri().equals("/favicon.ico")) {
} else if ("/favicon.ico".equals(req.getUri())) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
sendHttpResponse(ctx, req, res);
return;

View File

@ -74,7 +74,7 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
}
// Send the demo page and favicon.ico
if (req.getUri().equals("/")) {
if ("/".equals(req.getUri())) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, OK);
ByteBuf content = WebSocketServerIndexPage.getContent(getWebSocketLocation(req));
@ -85,7 +85,7 @@ public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapt
res.setContent(content);
sendHttpResponse(ctx, req, res);
return;
} else if (req.getUri().equals("/favicon.ico")) {
} else if ("/favicon.ico".equals(req.getUri())) {
HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
sendHttpResponse(ctx, req, res);
return;

View File

@ -47,7 +47,7 @@ public class QuoteOfTheMomentServerHandler extends ChannelInboundMessageHandlerA
public void messageReceived(
ChannelHandlerContext ctx, DatagramPacket msg)
throws Exception {
if (msg.data().toString(CharsetUtil.UTF_8).equals("QOTM?")) {
if ("QOTM?".equals(msg.data().toString(CharsetUtil.UTF_8))) {
ctx.write(new DatagramPacket(
Unpooled.copiedBuffer("QOTM: " + nextQuote(), CharsetUtil.UTF_8),
msg.remoteAddress()));

View File

@ -63,7 +63,7 @@ public class SecureChatClient {
// If user typed the 'bye' command, wait until the server closes
// the connection.
if (line.toLowerCase().equals("bye")) {
if ("bye".equals(line.toLowerCase())) {
ch.closeFuture().sync();
break;
}

View File

@ -71,7 +71,7 @@ public class SecureChatServerHandler extends ChannelInboundMessageHandlerAdapter
}
// Close the connection if the client has sent 'bye'.
if (request.toLowerCase().equals("bye")) {
if ("bye".equals(request.toLowerCase())) {
ctx.close();
}
}

View File

@ -62,7 +62,7 @@ public class TelnetClient {
// If user typed the 'bye' command, wait until the server closes
// the connection.
if (line.toLowerCase().equals("bye")) {
if ("bye".equals(line.toLowerCase())) {
ch.closeFuture().sync();
break;
}

View File

@ -50,7 +50,7 @@ public class TelnetServerHandler extends ChannelInboundMessageHandlerAdapter<Str
boolean close = false;
if (request.isEmpty()) {
response = "Please type something.\r\n";
} else if (request.toLowerCase().equals("bye")) {
} else if ("bye".equals(request.toLowerCase())) {
response = "Have a good day!\r\n";
close = true;
} else {

View File

@ -619,7 +619,7 @@ public class SslHandler
}
// check if the method name is read if not skip it
if (!methodname.equals("read")) {
if (!"read".equals(methodname)) {
continue;
}

View File

@ -82,7 +82,7 @@ public final class TestUtils {
*/
public static boolean isSctpSupported() {
String os = System.getProperty("os.name").toLowerCase(Locale.UK);
if (os.equals("unix") || os.equals("linux") || os.equals("sun") || os.equals("solaris")) {
if ("unix".equals(os) || "linux".equals(os) || "sun".equals(os) || "solaris".equals(os)) {
try {
// Try to open a SCTP Channel, by using reflection to make it compile also on
// operation systems that not support SCTP like OSX and Windows