Prefer isEmpty() over size() == 0 or length() == 0

This commit is contained in:
Trustin Lee 2012-11-10 01:24:04 +09:00
parent 02a43804d4
commit bbcb035246
16 changed files with 28 additions and 28 deletions

View File

@ -48,7 +48,7 @@ public class DefaultCookie implements Cookie {
throw new NullPointerException("name");
}
name = name.trim();
if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("empty name");
}
@ -343,7 +343,7 @@ public class DefaultCookie implements Cookie {
return null;
}
value = value.trim();
if (value.length() == 0) {
if (value.isEmpty()) {
return null;
}
for (int i = 0; i < value.length(); i ++) {

View File

@ -537,7 +537,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
String line = readHeader(buffer);
String name = null;
String value = null;
if (line.length() != 0) {
if (line.isEmpty()) {
message.clearHeaders();
do {
char firstChar = line.charAt(0);
@ -553,7 +553,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
}
line = readHeader(buffer);
} while (line.length() != 0);
} while (!line.isEmpty());
// Add the last header.
if (name != null) {
@ -581,13 +581,13 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
headerSize = 0;
String line = readHeader(buffer);
String lastHeader = null;
if (line.length() != 0) {
if (!line.isEmpty()) {
HttpChunkTrailer trailer = new DefaultHttpChunkTrailer();
do {
char firstChar = line.charAt(0);
if (lastHeader != null && (firstChar == ' ' || firstChar == '\t')) {
List<String> current = trailer.getHeaders(lastHeader);
if (current.size() != 0) {
if (!current.isEmpty()) {
int lastPos = current.size() - 1;
String newString = current.get(lastPos) + line.trim();
current.set(lastPos, newString);
@ -606,7 +606,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<Object, HttpMe
}
line = readHeader(buffer);
} while (line.length() != 0);
} while (!line.isEmpty());
return trailer;
}

View File

@ -110,7 +110,7 @@ public class HttpMethod implements Comparable<HttpMethod> {
}
name = name.trim();
if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("empty name");
}
@ -137,7 +137,7 @@ public class HttpMethod implements Comparable<HttpMethod> {
}
name = name.trim();
if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("empty name");
}

View File

@ -85,7 +85,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
}
text = text.trim().toUpperCase();
if (text.length() == 0) {
if (text.isEmpty()) {
throw new IllegalArgumentException("empty text");
}
@ -120,7 +120,7 @@ public class HttpVersion implements Comparable<HttpVersion> {
}
protocolName = protocolName.trim().toUpperCase();
if (protocolName.length() == 0) {
if (protocolName.isEmpty()) {
throw new IllegalArgumentException("empty protocolName");
}

View File

@ -15,10 +15,10 @@
*/
package io.netty.handler.codec.http.multipart;
import java.nio.charset.Charset;
import io.netty.handler.codec.http.HttpConstants;
import java.nio.charset.Charset;
/**
* Abstract HttpData implementation
*/
@ -35,7 +35,7 @@ public abstract class AbstractHttpData implements HttpData {
throw new NullPointerException("name");
}
name = name.trim();
if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("empty name");
}

View File

@ -379,7 +379,7 @@ public class HttpPostRequestDecoder {
throw new EndOfDataDecoderException();
}
}
return bodyListHttpData.size() > 0 && bodyListHttpDataRank < bodyListHttpData.size();
return !bodyListHttpData.isEmpty() && bodyListHttpDataRank < bodyListHttpData.size();
}
/**

View File

@ -442,7 +442,7 @@ public class HttpPostRequestEncoder implements ChunkedMessageInput<HttpChunk> {
duringMixedMode = false;
}
InternalAttribute internal = new InternalAttribute();
if (multipartHttpDatas.size() > 0) {
if (!multipartHttpDatas.isEmpty()) {
// previously a data field so CRLF
internal.addValue("\r\n");
}
@ -465,7 +465,7 @@ public class HttpPostRequestEncoder implements ChunkedMessageInput<HttpChunk> {
} else if (data instanceof FileUpload) {
FileUpload fileUpload = (FileUpload) data;
InternalAttribute internal = new InternalAttribute();
if (multipartHttpDatas.size() > 0) {
if (!multipartHttpDatas.isEmpty()) {
// previously a data field so CRLF
internal.addValue("\r\n");
}

View File

@ -133,7 +133,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
// Get path
URI wsURL = getWebSocketUrl();
String path = wsURL.getPath();
if (wsURL.getQuery() != null && wsURL.getQuery().length() > 0) {
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
path = wsURL.getPath() + "?" + wsURL.getQuery();
}

View File

@ -101,7 +101,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
// Get path
URI wsURL = getWebSocketUrl();
String path = wsURL.getPath();
if (wsURL.getQuery() != null && wsURL.getQuery().length() > 0) {
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
path = wsURL.getPath() + "?" + wsURL.getQuery();
}

View File

@ -101,7 +101,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
// Get path
URI wsURL = getWebSocketUrl();
String path = wsURL.getPath();
if (wsURL.getQuery() != null && wsURL.getQuery().length() > 0) {
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
path = wsURL.getPath() + "?" + wsURL.getQuery();
}

View File

@ -123,7 +123,7 @@ public final class RtspMethods {
}
name = name.trim().toUpperCase();
if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("empty name");
}

View File

@ -319,7 +319,7 @@ final class SpdyCodecUtil {
if (name == null) {
throw new NullPointerException("name");
}
if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException(
"name cannot be length zero");
}
@ -349,7 +349,7 @@ final class SpdyCodecUtil {
if (value == null) {
throw new NullPointerException("value");
}
if (value.length() == 0) {
if (value.isEmpty()) {
throw new IllegalArgumentException(
"value cannot be length zero");
}

View File

@ -74,7 +74,7 @@ public final class StringUtil {
} else {
// Truncate trailing empty elements.
for (int i = res.size() - 1; i >= 0; i --) {
if (res.get(i).length() == 0) {
if (res.get(i).isEmpty()) {
res.remove(i);
} else {
break;

View File

@ -67,7 +67,7 @@ public final class SystemPropertyUtil {
if (key == null) {
throw new NullPointerException("key");
}
if (key.length() == 0) {
if (key.isEmpty()) {
throw new IllegalArgumentException("key must not be empty.");
}
@ -104,7 +104,7 @@ public final class SystemPropertyUtil {
}
value = value.trim().toLowerCase();
if (value.length() == 0) {
if (value.isEmpty()) {
return true;
}

View File

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

View File

@ -56,7 +56,7 @@ public final class LocalAddress extends SocketAddress implements Comparable<Loca
throw new NullPointerException("id");
}
id = id.trim().toLowerCase();
if (id.length() == 0) {
if (id.isEmpty()) {
throw new IllegalArgumentException("empty id");
}
this.id = id;