Remove unnecessary code (#9303)

Motivation:

There are is some unnecessary code (like toString() calls) which can be cleaned up.

Modifications:

- Remove not needed toString() calls
- Simplify subString(...) calls
- Remove some explicit casts when not needed.

Result:

Cleaner code
This commit is contained in:
jimin 2019-07-04 14:51:47 +08:00 committed by Norman Maurer
parent d951140c56
commit d54678d645
6 changed files with 13 additions and 13 deletions

View File

@ -55,7 +55,7 @@ public class CombinedHttpHeadersTest {
otherHeaders.add(HEADER_NAME, "a"); otherHeaders.add(HEADER_NAME, "a");
otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "b");
headers.add(otherHeaders); headers.add(otherHeaders);
assertEquals("a,b", headers.get(HEADER_NAME).toString()); assertEquals("a,b", headers.get(HEADER_NAME));
} }
@Test @Test
@ -66,7 +66,7 @@ public class CombinedHttpHeadersTest {
otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c"); otherHeaders.add(HEADER_NAME, "c");
headers.add(otherHeaders); headers.add(otherHeaders);
assertEquals("a,b,c", headers.get(HEADER_NAME).toString()); assertEquals("a,b,c", headers.get(HEADER_NAME));
} }
@Test @Test
@ -99,7 +99,7 @@ public class CombinedHttpHeadersTest {
otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c"); otherHeaders.add(HEADER_NAME, "c");
headers.set(otherHeaders); headers.set(otherHeaders);
assertEquals("b,c", headers.get(HEADER_NAME).toString()); assertEquals("b,c", headers.get(HEADER_NAME));
} }
@Test @Test
@ -110,7 +110,7 @@ public class CombinedHttpHeadersTest {
otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c"); otherHeaders.add(HEADER_NAME, "c");
headers.add(otherHeaders); headers.add(otherHeaders);
assertEquals("a,b,c", headers.get(HEADER_NAME).toString()); assertEquals("a,b,c", headers.get(HEADER_NAME));
} }
@Test @Test
@ -121,7 +121,7 @@ public class CombinedHttpHeadersTest {
otherHeaders.add(HEADER_NAME, "b"); otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c"); otherHeaders.add(HEADER_NAME, "c");
headers.set(otherHeaders); headers.set(otherHeaders);
assertEquals("b,c", headers.get(HEADER_NAME).toString()); assertEquals("b,c", headers.get(HEADER_NAME));
} }
@Test @Test

View File

@ -272,7 +272,7 @@ public class HttpContentCompressorTest {
assertEncodedResponse(ch); assertEncodedResponse(ch);
ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT); ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
HttpContent chunk = (HttpContent) ch.readOutbound(); HttpContent chunk = ch.readOutbound();
assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b080000000000000003000000000000000000")); assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b080000000000000003000000000000000000"));
assertThat(chunk, is(instanceOf(HttpContent.class))); assertThat(chunk, is(instanceOf(HttpContent.class)));
chunk.release(); chunk.release();
@ -423,7 +423,7 @@ public class HttpContentCompressorTest {
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.IDENTITY); res.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.IDENTITY);
assertTrue(ch.writeOutbound(res)); assertTrue(ch.writeOutbound(res));
FullHttpResponse response = (FullHttpResponse) ch.readOutbound(); FullHttpResponse response = ch.readOutbound();
assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH)); assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
assertEquals(HttpHeaderValues.IDENTITY.toString(), response.headers().get(HttpHeaderNames.CONTENT_ENCODING)); assertEquals(HttpHeaderValues.IDENTITY.toString(), response.headers().get(HttpHeaderNames.CONTENT_ENCODING));
assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII)); assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII));
@ -445,7 +445,7 @@ public class HttpContentCompressorTest {
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, "ascii"); res.headers().set(HttpHeaderNames.CONTENT_ENCODING, "ascii");
assertTrue(ch.writeOutbound(res)); assertTrue(ch.writeOutbound(res));
FullHttpResponse response = (FullHttpResponse) ch.readOutbound(); FullHttpResponse response = ch.readOutbound();
assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH)); assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
assertEquals("ascii", response.headers().get(HttpHeaderNames.CONTENT_ENCODING)); assertEquals("ascii", response.headers().get(HttpHeaderNames.CONTENT_ENCODING));
assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII)); assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII));

View File

@ -39,7 +39,7 @@ public class XmlDecoder extends ByteToMessageDecoder {
private static final XmlDocumentEnd XML_DOCUMENT_END = XmlDocumentEnd.INSTANCE; private static final XmlDocumentEnd XML_DOCUMENT_END = XmlDocumentEnd.INSTANCE;
private final AsyncXMLStreamReader<AsyncByteArrayFeeder> streamReader = XML_INPUT_FACTORY.createAsyncForByteArray(); private final AsyncXMLStreamReader<AsyncByteArrayFeeder> streamReader = XML_INPUT_FACTORY.createAsyncForByteArray();
private final AsyncByteArrayFeeder streamFeeder = (AsyncByteArrayFeeder) streamReader.getInputFeeder(); private final AsyncByteArrayFeeder streamFeeder = streamReader.getInputFeeder();
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

View File

@ -64,7 +64,7 @@ public class ByteToMessageCodecTest {
assertTrue(ch.finish()); assertTrue(ch.finish());
assertEquals(1, (int) ch.readInbound()); assertEquals(1, (int) ch.readInbound());
ByteBuf buf = (ByteBuf) ch.readInbound(); ByteBuf buf = ch.readInbound();
assertEquals(Unpooled.wrappedBuffer(new byte[]{'0'}), buf); assertEquals(Unpooled.wrappedBuffer(new byte[]{'0'}), buf);
buf.release(); buf.release();
assertNull(ch.readInbound()); assertNull(ch.readInbound());

View File

@ -319,7 +319,7 @@ public final class NetUtil {
if (line.startsWith(sysctlKey)) { if (line.startsWith(sysctlKey)) {
for (int i = line.length() - 1; i > sysctlKey.length(); --i) { for (int i = line.length() - 1; i > sysctlKey.length(); --i) {
if (!Character.isDigit(line.charAt(i))) { if (!Character.isDigit(line.charAt(i))) {
return Integer.valueOf(line.substring(i + 1, line.length())); return Integer.valueOf(line.substring(i + 1));
} }
} }
} }

View File

@ -1102,8 +1102,8 @@ public final class PlatformDependent {
// Last resort: guess from VM name and then fall back to most common 64-bit mode. // Last resort: guess from VM name and then fall back to most common 64-bit mode.
String vm = SystemPropertyUtil.get("java.vm.name", "").toLowerCase(Locale.US); String vm = SystemPropertyUtil.get("java.vm.name", "").toLowerCase(Locale.US);
Pattern BIT_PATTERN = Pattern.compile("([1-9][0-9]+)-?bit"); Pattern bitPattern = Pattern.compile("([1-9][0-9]+)-?bit");
Matcher m = BIT_PATTERN.matcher(vm); Matcher m = bitPattern.matcher(vm);
if (m.find()) { if (m.find()) {
return Integer.parseInt(m.group(1)); return Integer.parseInt(m.group(1));
} else { } else {