Skip to content

Commit bbcb035

Browse files
committed
Prefer isEmpty() over size() == 0 or length() == 0
1 parent 02a4380 commit bbcb035

16 files changed

Lines changed: 28 additions & 28 deletions

File tree

codec-http/src/main/java/io/netty/handler/codec/http/DefaultCookie.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public DefaultCookie(String name, String value) {
4848
throw new NullPointerException("name");
4949
}
5050
name = name.trim();
51-
if (name.length() == 0) {
51+
if (name.isEmpty()) {
5252
throw new IllegalArgumentException("empty name");
5353
}
5454

@@ -343,7 +343,7 @@ private static String validateValue(String name, String value) {
343343
return null;
344344
}
345345
value = value.trim();
346-
if (value.length() == 0) {
346+
if (value.isEmpty()) {
347347
return null;
348348
}
349349
for (int i = 0; i < value.length(); i ++) {

codec-http/src/main/java/io/netty/handler/codec/http/HttpMessageDecoder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ private State readHeaders(ByteBuf buffer) throws TooLongFrameException {
537537
String line = readHeader(buffer);
538538
String name = null;
539539
String value = null;
540-
if (line.length() != 0) {
540+
if (line.isEmpty()) {
541541
message.clearHeaders();
542542
do {
543543
char firstChar = line.charAt(0);
@@ -553,7 +553,7 @@ private State readHeaders(ByteBuf buffer) throws TooLongFrameException {
553553
}
554554

555555
line = readHeader(buffer);
556-
} while (line.length() != 0);
556+
} while (!line.isEmpty());
557557

558558
// Add the last header.
559559
if (name != null) {
@@ -581,13 +581,13 @@ private HttpChunkTrailer readTrailingHeaders(ByteBuf buffer) throws TooLongFrame
581581
headerSize = 0;
582582
String line = readHeader(buffer);
583583
String lastHeader = null;
584-
if (line.length() != 0) {
584+
if (!line.isEmpty()) {
585585
HttpChunkTrailer trailer = new DefaultHttpChunkTrailer();
586586
do {
587587
char firstChar = line.charAt(0);
588588
if (lastHeader != null && (firstChar == ' ' || firstChar == '\t')) {
589589
List<String> current = trailer.getHeaders(lastHeader);
590-
if (current.size() != 0) {
590+
if (!current.isEmpty()) {
591591
int lastPos = current.size() - 1;
592592
String newString = current.get(lastPos) + line.trim();
593593
current.set(lastPos, newString);
@@ -606,7 +606,7 @@ private HttpChunkTrailer readTrailingHeaders(ByteBuf buffer) throws TooLongFrame
606606
}
607607

608608
line = readHeader(buffer);
609-
} while (line.length() != 0);
609+
} while (!line.isEmpty());
610610

611611
return trailer;
612612
}

codec-http/src/main/java/io/netty/handler/codec/http/HttpMethod.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static HttpMethod valueOf(String name) {
110110
}
111111

112112
name = name.trim();
113-
if (name.length() == 0) {
113+
if (name.isEmpty()) {
114114
throw new IllegalArgumentException("empty name");
115115
}
116116

@@ -137,7 +137,7 @@ public HttpMethod(String name) {
137137
}
138138

139139
name = name.trim();
140-
if (name.length() == 0) {
140+
if (name.isEmpty()) {
141141
throw new IllegalArgumentException("empty name");
142142
}
143143

codec-http/src/main/java/io/netty/handler/codec/http/HttpVersion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public HttpVersion(String text, boolean keepAliveDefault) {
8585
}
8686

8787
text = text.trim().toUpperCase();
88-
if (text.length() == 0) {
88+
if (text.isEmpty()) {
8989
throw new IllegalArgumentException("empty text");
9090
}
9191

@@ -120,7 +120,7 @@ public HttpVersion(
120120
}
121121

122122
protocolName = protocolName.trim().toUpperCase();
123-
if (protocolName.length() == 0) {
123+
if (protocolName.isEmpty()) {
124124
throw new IllegalArgumentException("empty protocolName");
125125
}
126126

codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractHttpData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package io.netty.handler.codec.http.multipart;
1717

18-
import java.nio.charset.Charset;
19-
2018
import io.netty.handler.codec.http.HttpConstants;
2119

20+
import java.nio.charset.Charset;
21+
2222
/**
2323
* Abstract HttpData implementation
2424
*/
@@ -35,7 +35,7 @@ public AbstractHttpData(String name, Charset charset, long size) {
3535
throw new NullPointerException("name");
3636
}
3737
name = name.trim();
38-
if (name.length() == 0) {
38+
if (name.isEmpty()) {
3939
throw new IllegalArgumentException("empty name");
4040
}
4141

codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public boolean hasNext() throws EndOfDataDecoderException {
379379
throw new EndOfDataDecoderException();
380380
}
381381
}
382-
return bodyListHttpData.size() > 0 && bodyListHttpDataRank < bodyListHttpData.size();
382+
return !bodyListHttpData.isEmpty() && bodyListHttpDataRank < bodyListHttpData.size();
383383
}
384384

385385
/**

codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
442442
duringMixedMode = false;
443443
}
444444
InternalAttribute internal = new InternalAttribute();
445-
if (multipartHttpDatas.size() > 0) {
445+
if (!multipartHttpDatas.isEmpty()) {
446446
// previously a data field so CRLF
447447
internal.addValue("\r\n");
448448
}
@@ -465,7 +465,7 @@ public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderExcep
465465
} else if (data instanceof FileUpload) {
466466
FileUpload fileUpload = (FileUpload) data;
467467
InternalAttribute internal = new InternalAttribute();
468-
if (multipartHttpDatas.size() > 0) {
468+
if (!multipartHttpDatas.isEmpty()) {
469469
// previously a data field so CRLF
470470
internal.addValue("\r\n");
471471
}

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public ChannelFuture handshake(Channel channel) {
133133
// Get path
134134
URI wsURL = getWebSocketUrl();
135135
String path = wsURL.getPath();
136-
if (wsURL.getQuery() != null && wsURL.getQuery().length() > 0) {
136+
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
137137
path = wsURL.getPath() + "?" + wsURL.getQuery();
138138
}
139139

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public ChannelFuture handshake(Channel channel) {
101101
// Get path
102102
URI wsURL = getWebSocketUrl();
103103
String path = wsURL.getPath();
104-
if (wsURL.getQuery() != null && wsURL.getQuery().length() > 0) {
104+
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
105105
path = wsURL.getPath() + "?" + wsURL.getQuery();
106106
}
107107

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public ChannelFuture handshake(Channel channel) {
101101
// Get path
102102
URI wsURL = getWebSocketUrl();
103103
String path = wsURL.getPath();
104-
if (wsURL.getQuery() != null && wsURL.getQuery().length() > 0) {
104+
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
105105
path = wsURL.getPath() + "?" + wsURL.getQuery();
106106
}
107107

0 commit comments

Comments
 (0)