Remove 'get' prefix

This commit is contained in:
Trustin Lee 2013-01-17 14:48:03 +09:00
parent 5a82dccbc5
commit eacc474cda
10 changed files with 71 additions and 72 deletions

View File

@ -52,7 +52,7 @@ public abstract class DefaultHttpMessage extends DefaultHttpObject implements Ht
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append(getClass().getSimpleName()); buf.append(getClass().getSimpleName());
buf.append("(version: "); buf.append("(version: ");
buf.append(protocolVersion().getText()); buf.append(protocolVersion().text());
buf.append(", keepAlive: "); buf.append(", keepAlive: ");
buf.append(HttpHeaders.isKeepAlive(this)); buf.append(HttpHeaders.isKeepAlive(this));
buf.append(')'); buf.append(')');

View File

@ -66,7 +66,7 @@ public class DefaultHttpRequest extends DefaultHttpMessage implements HttpReques
buf.append(' '); buf.append(' ');
buf.append(uri()); buf.append(uri());
buf.append(' '); buf.append(' ');
buf.append(protocolVersion().getText()); buf.append(protocolVersion().text());
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);
appendHeaders(buf); appendHeaders(buf);

View File

@ -51,7 +51,7 @@ public class DefaultHttpResponse extends DefaultHttpMessage implements HttpRespo
buf.append(decoderResult()); buf.append(decoderResult());
buf.append(')'); buf.append(')');
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);
buf.append(protocolVersion().getText()); buf.append(protocolVersion().text());
buf.append(' '); buf.append(' ');
buf.append(status().toString()); buf.append(status().toString());
buf.append(StringUtil.NEWLINE); buf.append(StringUtil.NEWLINE);

View File

@ -131,13 +131,13 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
} }
} }
encoder = result.getContentEncoder(); encoder = result.contentEncoder();
// Encode the content and remove or replace the existing headers // Encode the content and remove or replace the existing headers
// so that the message looks like a decoded message. // so that the message looks like a decoded message.
headers.set( headers.set(
HttpHeaders.Names.CONTENT_ENCODING, HttpHeaders.Names.CONTENT_ENCODING,
result.getTargetContentEncoding()); result.targetContentEncoding());
Object[] encoded = encodeContent(message, c); Object[] encoded = encodeContent(message, c);
@ -264,11 +264,11 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpMessa
this.contentEncoder = contentEncoder; this.contentEncoder = contentEncoder;
} }
public String getTargetContentEncoding() { public String targetContentEncoding() {
return targetContentEncoding; return targetContentEncoding;
} }
public EmbeddedByteChannel getContentEncoder() { public EmbeddedByteChannel contentEncoder() {
return contentEncoder; return contentEncoder;
} }
} }

View File

@ -148,28 +148,28 @@ public class HttpVersion implements Comparable<HttpVersion> {
/** /**
* Returns the name of the protocol such as {@code "HTTP"} in {@code "HTTP/1.0"}. * Returns the name of the protocol such as {@code "HTTP"} in {@code "HTTP/1.0"}.
*/ */
public String getProtocolName() { public String protocolName() {
return protocolName; return protocolName;
} }
/** /**
* Returns the name of the protocol such as {@code 1} in {@code "HTTP/1.0"}. * Returns the name of the protocol such as {@code 1} in {@code "HTTP/1.0"}.
*/ */
public int getMajorVersion() { public int majorVersion() {
return majorVersion; return majorVersion;
} }
/** /**
* Returns the name of the protocol such as {@code 0} in {@code "HTTP/1.0"}. * Returns the name of the protocol such as {@code 0} in {@code "HTTP/1.0"}.
*/ */
public int getMinorVersion() { public int minorVersion() {
return minorVersion; return minorVersion;
} }
/** /**
* Returns the full protocol version text such as {@code "HTTP/1.0"}. * Returns the full protocol version text such as {@code "HTTP/1.0"}.
*/ */
public String getText() { public String text() {
return text; return text;
} }
@ -186,13 +186,13 @@ public class HttpVersion implements Comparable<HttpVersion> {
*/ */
@Override @Override
public String toString() { public String toString() {
return getText(); return text();
} }
@Override @Override
public int hashCode() { public int hashCode() {
return (getProtocolName().hashCode() * 31 + getMajorVersion()) * 31 + return (protocolName().hashCode() * 31 + majorVersion()) * 31 +
getMinorVersion(); minorVersion();
} }
@Override @Override
@ -202,23 +202,23 @@ public class HttpVersion implements Comparable<HttpVersion> {
} }
HttpVersion that = (HttpVersion) o; HttpVersion that = (HttpVersion) o;
return getMinorVersion() == that.getMinorVersion() && return minorVersion() == that.minorVersion() &&
getMajorVersion() == that.getMajorVersion() && majorVersion() == that.majorVersion() &&
getProtocolName().equals(that.getProtocolName()); protocolName().equals(that.protocolName());
} }
@Override @Override
public int compareTo(HttpVersion o) { public int compareTo(HttpVersion o) {
int v = getProtocolName().compareTo(o.getProtocolName()); int v = protocolName().compareTo(o.protocolName());
if (v != 0) { if (v != 0) {
return v; return v;
} }
v = getMajorVersion() - o.getMajorVersion(); v = majorVersion() - o.majorVersion();
if (v != 0) { if (v != 0) {
return v; return v;
} }
return getMinorVersion() - o.getMinorVersion(); return minorVersion() - o.minorVersion();
} }
} }

View File

@ -174,7 +174,7 @@ public class QueryStringDecoder {
/** /**
* Returns the decoded path string of the URI. * Returns the decoded path string of the URI.
*/ */
public String getPath() { public String path() {
if (path == null) { if (path == null) {
if (!hasPath) { if (!hasPath) {
return path = ""; return path = "";
@ -193,10 +193,10 @@ public class QueryStringDecoder {
/** /**
* Returns the decoded key-value parameter pairs of the URI. * Returns the decoded key-value parameter pairs of the URI.
*/ */
public Map<String, List<String>> getParameters() { public Map<String, List<String>> parameters() {
if (params == null) { if (params == null) {
if (hasPath) { if (hasPath) {
int pathLength = getPath().length(); int pathLength = path().length();
if (uri.length() == pathLength) { if (uri.length() == pathLength) {
return Collections.emptyMap(); return Collections.emptyMap();
} }

View File

@ -350,9 +350,9 @@ public class SpdyHeaders {
*/ */
public static void setVersion(int spdyVersion, SpdyHeaderBlock block, HttpVersion httpVersion) { public static void setVersion(int spdyVersion, SpdyHeaderBlock block, HttpVersion httpVersion) {
if (spdyVersion < 3) { if (spdyVersion < 3) {
block.setHeader(Spdy2HttpNames.VERSION, httpVersion.getText()); block.setHeader(Spdy2HttpNames.VERSION, httpVersion.text());
} else { } else {
block.setHeader(HttpNames.VERSION, httpVersion.getText()); block.setHeader(HttpNames.VERSION, httpVersion.text());
} }
} }

View File

@ -16,6 +16,8 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
import java.net.URI; import java.net.URI;
import java.util.Iterator; import java.util.Iterator;
@ -23,9 +25,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.junit.Assert;
import org.junit.Test;
public class QueryStringDecoderTest { public class QueryStringDecoderTest {
@Test @Test
@ -33,46 +32,46 @@ public class QueryStringDecoderTest {
QueryStringDecoder d; QueryStringDecoder d;
d = new QueryStringDecoder("/foo?a=b=c"); d = new QueryStringDecoder("/foo?a=b=c");
Assert.assertEquals("/foo", d.getPath()); Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.getParameters().size()); Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(1, d.getParameters().get("a").size()); Assert.assertEquals(1, d.parameters().get("a").size());
Assert.assertEquals("b=c", d.getParameters().get("a").get(0)); Assert.assertEquals("b=c", d.parameters().get("a").get(0));
d = new QueryStringDecoder("/foo?a=1&a=2"); d = new QueryStringDecoder("/foo?a=1&a=2");
Assert.assertEquals("/foo", d.getPath()); Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.getParameters().size()); Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.getParameters().get("a").size()); Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("1", d.getParameters().get("a").get(0)); Assert.assertEquals("1", d.parameters().get("a").get(0));
Assert.assertEquals("2", d.getParameters().get("a").get(1)); Assert.assertEquals("2", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo?a=&a=2"); d = new QueryStringDecoder("/foo?a=&a=2");
Assert.assertEquals("/foo", d.getPath()); Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.getParameters().size()); Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.getParameters().get("a").size()); Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("", d.getParameters().get("a").get(0)); Assert.assertEquals("", d.parameters().get("a").get(0));
Assert.assertEquals("2", d.getParameters().get("a").get(1)); Assert.assertEquals("2", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo?a=1&a="); d = new QueryStringDecoder("/foo?a=1&a=");
Assert.assertEquals("/foo", d.getPath()); Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.getParameters().size()); Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.getParameters().get("a").size()); Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("1", d.getParameters().get("a").get(0)); Assert.assertEquals("1", d.parameters().get("a").get(0));
Assert.assertEquals("", d.getParameters().get("a").get(1)); Assert.assertEquals("", d.parameters().get("a").get(1));
d = new QueryStringDecoder("/foo?a=1&a=&a="); d = new QueryStringDecoder("/foo?a=1&a=&a=");
Assert.assertEquals("/foo", d.getPath()); Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.getParameters().size()); Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(3, d.getParameters().get("a").size()); Assert.assertEquals(3, d.parameters().get("a").size());
Assert.assertEquals("1", d.getParameters().get("a").get(0)); Assert.assertEquals("1", d.parameters().get("a").get(0));
Assert.assertEquals("", d.getParameters().get("a").get(1)); Assert.assertEquals("", d.parameters().get("a").get(1));
Assert.assertEquals("", d.getParameters().get("a").get(2)); Assert.assertEquals("", d.parameters().get("a").get(2));
d = new QueryStringDecoder("/foo?a=1=&a==2"); d = new QueryStringDecoder("/foo?a=1=&a==2");
Assert.assertEquals("/foo", d.getPath()); Assert.assertEquals("/foo", d.path());
Assert.assertEquals(1, d.getParameters().size()); Assert.assertEquals(1, d.parameters().size());
Assert.assertEquals(2, d.getParameters().get("a").size()); Assert.assertEquals(2, d.parameters().get("a").size());
Assert.assertEquals("1=", d.getParameters().get("a").get(0)); Assert.assertEquals("1=", d.parameters().get("a").get(0));
Assert.assertEquals("=2", d.getParameters().get("a").get(1)); Assert.assertEquals("=2", d.parameters().get("a").get(1));
} }
@Test @Test
@ -110,14 +109,14 @@ public class QueryStringDecoderTest {
buf.append(i); buf.append(i);
buf.append('&'); buf.append('&');
} }
Assert.assertEquals(1024, new QueryStringDecoder(buf.toString()).getParameters().size()); Assert.assertEquals(1024, new QueryStringDecoder(buf.toString()).parameters().size());
} }
@Test @Test
public void testHasPath() throws Exception { public void testHasPath() throws Exception {
QueryStringDecoder decoder = new QueryStringDecoder("1=2", false); QueryStringDecoder decoder = new QueryStringDecoder("1=2", false);
Assert.assertEquals("", decoder.getPath()); Assert.assertEquals("", decoder.path());
Map<String, List<String>> params = decoder.getParameters(); Map<String, List<String>> params = decoder.parameters();
Assert.assertEquals(1, params.size()); Assert.assertEquals(1, params.size());
Assert.assertTrue(params.containsKey("1")); Assert.assertTrue(params.containsKey("1"));
List<String> param = params.get("1"); List<String> param = params.get("1");
@ -166,8 +165,8 @@ public class QueryStringDecoderTest {
private static void assertQueryString(String expected, String actual) { private static void assertQueryString(String expected, String actual) {
QueryStringDecoder ed = new QueryStringDecoder(expected, CharsetUtil.UTF_8); QueryStringDecoder ed = new QueryStringDecoder(expected, CharsetUtil.UTF_8);
QueryStringDecoder ad = new QueryStringDecoder(actual, CharsetUtil.UTF_8); QueryStringDecoder ad = new QueryStringDecoder(actual, CharsetUtil.UTF_8);
Assert.assertEquals(ed.getPath(), ad.getPath()); Assert.assertEquals(ed.path(), ad.path());
Assert.assertEquals(ed.getParameters(), ad.getParameters()); Assert.assertEquals(ed.parameters(), ad.parameters());
} }
// See #189 // See #189
@ -175,8 +174,8 @@ public class QueryStringDecoderTest {
public void testURI() { public void testURI() {
URI uri = URI.create("http://localhost:8080/foo?param1=value1&param2=value2&param3=value3"); URI uri = URI.create("http://localhost:8080/foo?param1=value1&param2=value2&param3=value3");
QueryStringDecoder decoder = new QueryStringDecoder(uri); QueryStringDecoder decoder = new QueryStringDecoder(uri);
Assert.assertEquals("/foo", decoder.getPath()); Assert.assertEquals("/foo", decoder.path());
Map<String, List<String>> params = decoder.getParameters(); Map<String, List<String>> params = decoder.parameters();
Assert.assertEquals(3, params.size()); Assert.assertEquals(3, params.size());
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator(); Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
@ -204,8 +203,8 @@ public class QueryStringDecoderTest {
public void testURISlashPath() { public void testURISlashPath() {
URI uri = URI.create("http://localhost:8080/?param1=value1&param2=value2&param3=value3"); URI uri = URI.create("http://localhost:8080/?param1=value1&param2=value2&param3=value3");
QueryStringDecoder decoder = new QueryStringDecoder(uri); QueryStringDecoder decoder = new QueryStringDecoder(uri);
Assert.assertEquals("/", decoder.getPath()); Assert.assertEquals("/", decoder.path());
Map<String, List<String>> params = decoder.getParameters(); Map<String, List<String>> params = decoder.parameters();
Assert.assertEquals(3, params.size()); Assert.assertEquals(3, params.size());
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator(); Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
@ -233,8 +232,8 @@ public class QueryStringDecoderTest {
public void testURINoPath() { public void testURINoPath() {
URI uri = URI.create("http://localhost:8080?param1=value1&param2=value2&param3=value3"); URI uri = URI.create("http://localhost:8080?param1=value1&param2=value2&param3=value3");
QueryStringDecoder decoder = new QueryStringDecoder(uri); QueryStringDecoder decoder = new QueryStringDecoder(uri);
Assert.assertEquals("", decoder.getPath()); Assert.assertEquals("", decoder.path());
Map<String, List<String>> params = decoder.getParameters(); Map<String, List<String>> params = decoder.parameters();
Assert.assertEquals(3, params.size()); Assert.assertEquals(3, params.size());
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator(); Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();

View File

@ -81,7 +81,7 @@ public class HttpSnoopServerHandler extends ChannelInboundMessageHandlerAdapter<
} }
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri()); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri());
Map<String, List<String>> params = queryStringDecoder.getParameters(); Map<String, List<String>> params = queryStringDecoder.parameters();
if (!params.isEmpty()) { if (!params.isEmpty()) {
for (Entry<String, List<String>> p: params.entrySet()) { for (Entry<String, List<String>> p: params.entrySet()) {
String key = p.getKey(); String key = p.getKey();

View File

@ -113,7 +113,7 @@ public class HttpUploadServerHandler extends ChannelInboundMessageHandlerAdapter
responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n"); responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
responseContent.append("===================================\r\n"); responseContent.append("===================================\r\n");
responseContent.append("VERSION: " + request.protocolVersion().getText() + "\r\n"); responseContent.append("VERSION: " + request.protocolVersion().text() + "\r\n");
responseContent.append("REQUEST_URI: " + request.uri() + "\r\n\r\n"); responseContent.append("REQUEST_URI: " + request.uri() + "\r\n\r\n");
responseContent.append("\r\n\r\n"); responseContent.append("\r\n\r\n");
@ -139,7 +139,7 @@ public class HttpUploadServerHandler extends ChannelInboundMessageHandlerAdapter
responseContent.append("\r\n\r\n"); responseContent.append("\r\n\r\n");
QueryStringDecoder decoderQuery = new QueryStringDecoder(request.uri()); QueryStringDecoder decoderQuery = new QueryStringDecoder(request.uri());
Map<String, List<String>> uriAttributes = decoderQuery.getParameters(); Map<String, List<String>> uriAttributes = decoderQuery.parameters();
for (Entry<String, List<String>> attr: uriAttributes.entrySet()) { for (Entry<String, List<String>> attr: uriAttributes.entrySet()) {
for (String attrVal: attr.getValue()) { for (String attrVal: attr.getValue()) {
responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n"); responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n");