Refactored class Fields to a better API.

This commit is contained in:
Simone Bordet 2013-10-18 13:55:49 +02:00
parent 0d8956cad8
commit 2d6190da59
24 changed files with 155 additions and 153 deletions

View File

@ -523,13 +523,13 @@ public class HttpRequest implements Request
for (Iterator<Fields.Field> iterator = params.iterator(); iterator.hasNext();)
{
Fields.Field field = iterator.next();
String[] values = field.values();
for (int i = 0; i < values.length; ++i)
List<String> values = field.getValues();
for (int i = 0; i < values.size(); ++i)
{
if (i > 0)
result.append("&");
result.append(field.name()).append("=");
result.append(urlEncode(values[i]));
result.append(field.getName()).append("=");
result.append(urlEncode(values.get(i)));
}
if (iterator.hasNext())
result.append("&");

View File

@ -82,7 +82,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
Assert.assertEquals(path, request.getPath());
Assert.assertNull(request.getQuery());
Fields params = request.getParams();
Assert.assertEquals(0, params.size());
Assert.assertEquals(0, params.getSize());
Assert.assertTrue(request.getURI().toString().endsWith(path));
ContentResponse response = request.send();
@ -118,8 +118,8 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
Assert.assertEquals(query, request.getQuery());
Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
Fields params = request.getParams();
Assert.assertEquals(1, params.size());
Assert.assertEquals(value, params.get(name).value());
Assert.assertEquals(1, params.getSize());
Assert.assertEquals(value, params.get(name).getValue());
ContentResponse response = request.send();
@ -155,8 +155,8 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
Assert.assertEquals(query, request.getQuery());
Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
Fields params = request.getParams();
Assert.assertEquals(1, params.size());
Assert.assertEquals(value, params.get(name).value());
Assert.assertEquals(1, params.getSize());
Assert.assertEquals(value, params.get(name).getValue());
ContentResponse response = request.send();
@ -194,9 +194,9 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
Assert.assertEquals(query, request.getQuery());
Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
Fields params = request.getParams();
Assert.assertEquals(2, params.size());
Assert.assertEquals(value1, params.get(name1).value());
Assert.assertEquals(value2, params.get(name2).value());
Assert.assertEquals(2, params.getSize());
Assert.assertEquals(value1, params.get(name1).getValue());
Assert.assertEquals(value2, params.get(name2).getValue());
ContentResponse response = request.send();
@ -238,9 +238,9 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
Assert.assertEquals(query, request.getQuery());
Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
Fields params = request.getParams();
Assert.assertEquals(2, params.size());
Assert.assertEquals(value1, params.get(name1).value());
Assert.assertEquals(value2, params.get(name2).value());
Assert.assertEquals(2, params.getSize());
Assert.assertEquals(value1, params.get(name1).getValue());
Assert.assertEquals(value2, params.get(name2).getValue());
ContentResponse response = request.send();
@ -273,7 +273,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
Assert.assertEquals(query, request.getQuery());
Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
Fields params = request.getParams();
Assert.assertEquals(0, params.size());
Assert.assertEquals(0, params.getSize());
ContentResponse response = request.send();
@ -306,7 +306,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest
Assert.assertEquals(query, request.getQuery());
Assert.assertTrue(request.getURI().toString().endsWith(pathQuery));
Fields params = request.getParams();
Assert.assertEquals(0, params.size());
Assert.assertEquals(0, params.getSize());
ContentResponse response = request.send();

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.spdy.generator;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;
import org.eclipse.jetty.spdy.CompressionDictionary;
@ -42,24 +43,24 @@ public class HeadersBlockGenerator
{
// TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ?
Charset iso1 = Charset.forName("ISO-8859-1");
ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.size() * 64);
writeCount(version, buffer, headers.size());
ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.getSize() * 64);
writeCount(version, buffer, headers.getSize());
for (Fields.Field header : headers)
{
String name = header.name().toLowerCase(Locale.ENGLISH);
String name = header.getName().toLowerCase(Locale.ENGLISH);
byte[] nameBytes = name.getBytes(iso1);
writeNameLength(version, buffer, nameBytes.length);
buffer.write(nameBytes, 0, nameBytes.length);
// Most common path first
String value = header.value();
String value = header.getValue();
byte[] valueBytes = value.getBytes(iso1);
if (header.hasMultipleValues())
{
String[] values = header.values();
for (int i = 1; i < values.length; ++i)
List<String> values = header.getValues();
for (int i = 1; i < values.size(); ++i)
{
byte[] moreValueBytes = values[i].getBytes(iso1);
byte[] moreValueBytes = values.get(i).getBytes(iso1);
byte[] newValueBytes = new byte[valueBytes.length + 1 + moreValueBytes.length];
System.arraycopy(valueBytes, 0, newValueBytes, 0, valueBytes.length);
newValueBytes[valueBytes.length] = 0;

View File

@ -222,7 +222,7 @@ public class ClientUsageTest
{
// Do something with the response
Fields headers = replyInfo.getHeaders();
int contentLength = headers.get("content-length").valueAsInt();
int contentLength = headers.get("content-length").getValueAsInt();
stream.setAttribute("content-length", contentLength);
if (!replyInfo.isClose())
stream.setAttribute("builder", new StringBuilder());

View File

@ -18,10 +18,6 @@
package org.eclipse.jetty.spdy.frames;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.nio.ByteBuffer;
import org.eclipse.jetty.io.MappedByteBufferPool;
@ -34,6 +30,10 @@ import org.eclipse.jetty.util.Fields;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
public class HeadersGenerateParseTest
{
@ -85,7 +85,7 @@ public class HeadersGenerateParseTest
parser.parse(createHeadersFrameBuffer(headers));
HeadersFrame parsedHeadersFrame = assertExpectationsAreMet(headers);
Fields.Field viaHeader = parsedHeadersFrame.getHeaders().get("via");
assertThat("Via Header name is lowercase", viaHeader.name(), is("via"));
assertThat("Via Header name is lowercase", viaHeader.getName(), is("via"));
}
private HeadersFrame assertExpectationsAreMet(Fields headers)

View File

@ -62,9 +62,9 @@ public class HttpReceiverOverSPDY extends HttpReceiver implements StreamFrameLis
Fields fields = replyInfo.getHeaders();
short spdy = stream.getSession().getVersion();
HttpVersion version = HttpVersion.fromString(fields.get(HTTPSPDYHeader.VERSION.name(spdy)).value());
HttpVersion version = HttpVersion.fromString(fields.get(HTTPSPDYHeader.VERSION.name(spdy)).getValue());
response.version(version);
String[] status = fields.get(HTTPSPDYHeader.STATUS.name(spdy)).value().split(" ", 2);
String[] status = fields.get(HTTPSPDYHeader.STATUS.name(spdy)).getValue().split(" ", 2);
Integer code = Integer.parseInt(status[0]);
response.status(code);
@ -75,11 +75,11 @@ public class HttpReceiverOverSPDY extends HttpReceiver implements StreamFrameLis
{
for (Fields.Field field : fields)
{
String name = field.name();
String name = field.getName();
if (HTTPSPDYHeader.from(spdy, name) != null)
continue;
// TODO: handle multiple values properly
HttpField httpField = new HttpField(name, field.value());
HttpField httpField = new HttpField(name, field.getValue());
responseHeader(exchange, httpField);
}

View File

@ -102,7 +102,7 @@ public class HTTPSPDYServerConnectionFactory extends SPDYServerConnectionFactory
// if clients have to accept it.
// So we inject the accept-encoding header here, even if not set by the client. This will enforce SPDY
// clients to follow the spec and enable gzip compression if GzipFilter or the like is enabled.
if (!(headers.get("accept-encoding") != null && headers.get("accept-encoding").value().contains
if (!(headers.get("accept-encoding") != null && headers.get("accept-encoding").getValue().contains
("gzip")))
headers.add("accept-encoding", "gzip");
HttpTransportOverSPDY transport = new HttpTransportOverSPDY(connector, httpConfiguration, endPoint,

View File

@ -19,8 +19,6 @@
package org.eclipse.jetty.spdy.server.http;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.Queue;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpMethod;
@ -172,19 +170,19 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
return false;
}
HttpMethod httpMethod = HttpMethod.fromString(methodHeader.value());
HttpVersion httpVersion = HttpVersion.fromString(versionHeader.value());
HttpMethod httpMethod = HttpMethod.fromString(methodHeader.getValue());
HttpVersion httpVersion = HttpVersion.fromString(versionHeader.getValue());
// TODO should handle URI as byte buffer as some bad clients send WRONG encodings in query string
// that we have to deal with
ByteBuffer uri = BufferUtil.toBuffer(uriHeader.value());
ByteBuffer uri = BufferUtil.toBuffer(uriHeader.getValue());
LOG.debug("HTTP > {} {} {}", httpMethod, uriHeader.value(), httpVersion);
LOG.debug("HTTP > {} {} {}", httpMethod, uriHeader.getValue(), httpVersion);
startRequest(httpMethod, httpMethod.asString(), uri, httpVersion);
Fields.Field schemeHeader = headers.get(HTTPSPDYHeader.SCHEME.name(version));
if (schemeHeader != null)
getRequest().setScheme(schemeHeader.value());
getRequest().setScheme(schemeHeader.getValue());
return true;
}
@ -192,7 +190,7 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
{
for (Fields.Field header : headers)
{
String name = header.name();
String name = header.getName();
// Skip special SPDY headers, unless it's the "host" header
HTTPSPDYHeader specialHeader = HTTPSPDYHeader.from(stream.getSession().getVersion(), name);
@ -217,7 +215,7 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
default:
{
// Spec says headers must be single valued
String value = header.value();
String value = header.getValue();
LOG.debug("HTTP > {}: {}", name, value);
parsedHeader(new HttpField(name,value));
break;

View File

@ -121,7 +121,7 @@ public class HttpTransportOverSPDY implements HttpTransport
// info!=null content!=null lastContent==false reply, commit with content
// info!=null content!=null lastContent==true reply, commit with content and complete
boolean isHeadRequest = HttpMethod.HEAD.name().equalsIgnoreCase(requestHeaders.get(HTTPSPDYHeader.METHOD.name(version)).value());
boolean isHeadRequest = HttpMethod.HEAD.name().equalsIgnoreCase(requestHeaders.get(HTTPSPDYHeader.METHOD.name(version)).getValue());
boolean hasContent = BufferUtil.hasContent(content) && !isHeadRequest;
boolean close = !hasContent && lastContent;
@ -222,7 +222,7 @@ public class HttpTransportOverSPDY implements HttpTransport
stream.headers(new HeadersInfo(replyInfo.getHeaders(), replyInfo.isClose()), callback);
Fields responseHeaders = replyInfo.getHeaders();
if (responseHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().startsWith("200") && !stream.isClosed())
if (responseHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().startsWith("200") && !stream.isClosed())
{
Set<String> pushResources = pushStrategy.apply(stream, requestHeaders, responseHeaders);
if (pushResources.size() > 0)
@ -353,7 +353,7 @@ public class HttpTransportOverSPDY implements HttpTransport
newRequestHeaders.put(scheme);
newRequestHeaders.put(host);
newRequestHeaders.put(HTTPSPDYHeader.URI.name(version), pushResourcePath);
String referrer = scheme.value() + "://" + host.value() + uri.value();
String referrer = scheme.getValue() + "://" + host.getValue() + uri.getValue();
newRequestHeaders.put("referer", referrer);
newRequestHeaders.put("x-spdy-push", "true");
return newRequestHeaders;
@ -363,7 +363,7 @@ public class HttpTransportOverSPDY implements HttpTransport
{
final Fields pushHeaders = new Fields();
if (version == SPDY.V2)
pushHeaders.put(HTTPSPDYHeader.URI.name(version), scheme.value() + "://" + host.value() + pushResourcePath);
pushHeaders.put(HTTPSPDYHeader.URI.name(version), scheme.getValue() + "://" + host.getValue() + pushResourcePath);
else
{
pushHeaders.put(HTTPSPDYHeader.URI.name(version), pushResourcePath);

View File

@ -160,12 +160,12 @@ public class ReferrerPushStrategy implements PushStrategy
Set<String> result = Collections.<String>emptySet();
short version = stream.getSession().getVersion();
if (!isIfModifiedSinceHeaderPresent(requestHeaders) && isValidMethod(requestHeaders.get(HTTPSPDYHeader.METHOD
.name(version)).value()) && !isUserAgentBlacklisted(requestHeaders))
.name(version)).getValue()) && !isUserAgentBlacklisted(requestHeaders))
{
String scheme = requestHeaders.get(HTTPSPDYHeader.SCHEME.name(version)).value();
String host = requestHeaders.get(HTTPSPDYHeader.HOST.name(version)).value();
String scheme = requestHeaders.get(HTTPSPDYHeader.SCHEME.name(version)).getValue();
String host = requestHeaders.get(HTTPSPDYHeader.HOST.name(version)).getValue();
String origin = scheme + "://" + host;
String url = requestHeaders.get(HTTPSPDYHeader.URI.name(version)).value();
String url = requestHeaders.get(HTTPSPDYHeader.URI.name(version)).getValue();
String absoluteURL = origin + url;
LOG.debug("Applying push strategy for {}", absoluteURL);
if (isMainResource(url, responseHeaders))
@ -178,7 +178,7 @@ public class ReferrerPushStrategy implements PushStrategy
Fields.Field referrerHeader = requestHeaders.get("referer");
if (referrerHeader != null)
{
String referrer = referrerHeader.value();
String referrer = referrerHeader.getValue();
MainResource mainResource = mainResources.get(referrer);
if (mainResource == null)
mainResource = getOrCreateMainResource(referrer);
@ -237,7 +237,7 @@ public class ReferrerPushStrategy implements PushStrategy
Fields.Field userAgentHeader = headers.get("user-agent");
if (userAgentHeader != null)
for (Pattern userAgentPattern : userAgentBlacklist)
if (userAgentPattern.matcher(userAgentHeader.value()).matches())
if (userAgentPattern.matcher(userAgentHeader.getValue()).matches())
return true;
return false;
}
@ -252,7 +252,7 @@ public class ReferrerPushStrategy implements PushStrategy
if (header == null)
return true;
String contentType = header.value().toLowerCase(Locale.ENGLISH);
String contentType = header.getValue().toLowerCase(Locale.ENGLISH);
for (String pushContentType : pushContentTypes)
if (contentType.startsWith(pushContentType))
return true;

View File

@ -76,8 +76,8 @@ public class HTTPProxyEngine extends ProxyEngine
public StreamFrameListener proxy(final Stream clientStream, SynInfo clientSynInfo, ProxyEngineSelector.ProxyServerInfo proxyServerInfo)
{
short version = clientStream.getSession().getVersion();
String method = clientSynInfo.getHeaders().get(HTTPSPDYHeader.METHOD.name(version)).value();
String path = clientSynInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).value();
String method = clientSynInfo.getHeaders().get(HTTPSPDYHeader.METHOD.name(version)).getValue();
String path = clientSynInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).getValue();
Fields headers = new Fields(clientSynInfo.getHeaders(), false);
@ -249,8 +249,8 @@ public class HTTPProxyEngine extends ProxyEngine
private void addNonSpdyHeadersToRequest(short version, Fields headers, Request request)
{
for (Fields.Field header : headers)
if (HTTPSPDYHeader.from(version, header.name()) == null)
request.header(header.name(), header.value());
if (HTTPSPDYHeader.from(version, header.getName()) == null)
request.header(header.getName(), header.getValue());
}
static class LoggingCallback extends Callback.Adapter

View File

@ -98,7 +98,7 @@ public abstract class ProxyEngine
addViaHeader(headers);
Fields.Field schemeField = headers.get(HTTPSPDYHeader.SCHEME.name(stream.getSession().getVersion()));
if(schemeField != null)
headers.add("X-Forwarded-Proto", schemeField.value());
headers.add("X-Forwarded-Proto", schemeField.getValue());
InetSocketAddress address = stream.getSession().getRemoteAddress();
if (address != null)
{

View File

@ -71,7 +71,7 @@ public class ProxyEngineSelector extends ServerSessionFrameListener.Adapter
return null;
}
String host = hostHeader.value();
String host = hostHeader.getValue();
int colon = host.indexOf(':');
if (colon >= 0)
host = host.substring(0, colon);

View File

@ -200,7 +200,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
public void rst(RstInfo rstInfo, Callback handler)
{
HttpGenerator.ResponseInfo info = new HttpGenerator.ResponseInfo(HttpVersion.fromString(headers.get
("version").value()), null, 0, 502, "SPDY reset received from upstream server", false);
("version").getValue()), null, 0, 502, "SPDY reset received from upstream server", false);
send(info, null, true, new Callback.Adapter());
}
@ -247,24 +247,24 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
headers.remove(HTTPSPDYHeader.SCHEME.name(version));
String status = headers.remove(HTTPSPDYHeader.STATUS.name(version)).value();
String status = headers.remove(HTTPSPDYHeader.STATUS.name(version)).getValue();
Matcher matcher = statusRegexp.matcher(status);
matcher.matches();
int code = Integer.parseInt(matcher.group(1));
String reason = matcher.group(2).trim();
HttpVersion httpVersion = HttpVersion.fromString(headers.remove(HTTPSPDYHeader.VERSION.name(version)).value());
HttpVersion httpVersion = HttpVersion.fromString(headers.remove(HTTPSPDYHeader.VERSION.name(version)).getValue());
// Convert the Host header from a SPDY special header to a normal header
Fields.Field host = headers.remove(HTTPSPDYHeader.HOST.name(version));
if (host != null)
headers.put("host", host.value());
headers.put("host", host.getValue());
HttpFields fields = new HttpFields();
for (Fields.Field header : headers)
{
String name = camelize(header.name());
fields.put(name, header.value());
String name = camelize(header.getName());
fields.put(name, header.getValue());
}
// TODO: handle better the HEAD last parameter
@ -326,7 +326,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
private void addPersistenceHeader(Fields headersToAddTo)
{
HttpVersion httpVersion = HttpVersion.fromString(headers.get("version").value());
HttpVersion httpVersion = HttpVersion.fromString(headers.get("version").getValue());
boolean persistent = false;
switch (httpVersion)
{
@ -334,9 +334,9 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
{
Fields.Field keepAliveHeader = headers.get(HttpHeader.KEEP_ALIVE.asString());
if(keepAliveHeader!=null)
persistent = HttpHeaderValue.KEEP_ALIVE.asString().equals(keepAliveHeader.value());
persistent = HttpHeaderValue.KEEP_ALIVE.asString().equals(keepAliveHeader.getValue());
if (!persistent)
persistent = HttpMethod.CONNECT.is(headers.get("method").value());
persistent = HttpMethod.CONNECT.is(headers.get("method").getValue());
if (persistent)
headersToAddTo.add(HttpHeader.CONNECTION.asString(), HttpHeaderValue.KEEP_ALIVE.asString());
break;
@ -345,11 +345,11 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
{
Fields.Field connectionHeader = headers.get(HttpHeader.CONNECTION.asString());
if(connectionHeader != null)
persistent = !HttpHeaderValue.CLOSE.asString().equals(connectionHeader.value());
persistent = !HttpHeaderValue.CLOSE.asString().equals(connectionHeader.getValue());
else
persistent = true;
if (!persistent)
persistent = HttpMethod.CONNECT.is(headers.get("method").value());
persistent = HttpMethod.CONNECT.is(headers.get("method").getValue());
if (!persistent)
headersToAddTo.add(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
break;

View File

@ -212,7 +212,7 @@ public class SPDYProxyEngine extends ProxyEngine implements StreamFrameListener
if (header != null)
{
String toName = httpHeader.name(toVersion);
for (String value : header.values())
for (String value : header.getValues())
headers.add(toName, value);
}
}

View File

@ -90,7 +90,7 @@ public class ConcurrentStreamsTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
slowClientLatch.countDown();
}
});
@ -104,7 +104,7 @@ public class ConcurrentStreamsTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
Assert.assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
fastClientLatch.countDown();
}
});

View File

@ -367,7 +367,7 @@ public class PushStrategyBenchmarkTest extends AbstractHTTPSPDYTest
@Override
public StreamFrameListener onSyn(Stream stream, SynInfo synInfo)
{
String path = synInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).value();
String path = synInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).getValue();
addPushedResource(path);
return new DataListener();
}

View File

@ -175,7 +175,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
assertThat("Stream is unidirectional", stream.isUnidirectional(), is(true));
assertThat("URI header ends with css", pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version))
.value().endsWith
.getValue().endsWith
("" +
".css"),
is(true));
@ -279,7 +279,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
public StreamFrameListener onPush(Stream stream, PushInfo pushInfo)
{
LOG.info("onPush: stream: {}, pushInfo: {}", stream, pushInfo);
String uriHeader = pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).value();
String uriHeader = pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).getValue();
switch ((int)allExpectedPushesReceivedLatch.getCount())
{
case 4:
@ -377,7 +377,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
public StreamFrameListener onPush(Stream stream, PushInfo pushInfo)
{
LOG.info("Received push for stream: {} {}", stream.getId(), pushInfo);
String uriHeader = pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).value();
String uriHeader = pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).getValue();
switch ((int)allExpectedPushesReceivedLatch.getCount())
{
case 4:
@ -474,7 +474,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
assertThat("Stream is unidirectional", stream.isUnidirectional(), is(true));
assertThat("URI header ends with css", pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version))
.value().endsWith
.getValue().endsWith
("" +
".css"),
is(true));
@ -495,7 +495,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)
{
assertThat(replyInfo.getHeaders().get(HTTPSPDYHeader.STATUS.name(version)).value(), is("200 OK"));
assertThat(replyInfo.getHeaders().get(HTTPSPDYHeader.STATUS.name(version)).getValue(), is("200 OK"));
}
@Override
@ -527,7 +527,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
assertThat("Stream is unidirectional", stream.isUnidirectional(), is(true));
assertThat("URI header ends with css", pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version))
.value().endsWith
.getValue().endsWith
("" +
".css"),
is(true));
@ -747,7 +747,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
public StreamFrameListener onPush(Stream stream, PushInfo pushInfo)
{
Assert.assertTrue(stream.isUnidirectional());
Assert.assertTrue(pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).value().endsWith("" +
Assert.assertTrue(pushInfo.getHeaders().get(HTTPSPDYHeader.URI.name(version)).getValue().endsWith("" +
".css"));
return new StreamFrameListener.Adapter()
{
@ -1090,7 +1090,7 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
private boolean validateHeader(Fields headers, String name, String expectedValue)
{
Fields.Field header = headers.get(name);
if (header != null && expectedValue.equals(header.value()))
if (header != null && expectedValue.equals(header.getValue()))
return true;
System.out.println(name + " not valid! Expected: " + expectedValue + " headers received:" + headers);
return false;
@ -1100,9 +1100,9 @@ public class ReferrerPushStrategyTest extends AbstractHTTPSPDYTest
{
Fields.Field uriHeader = headers.get(HTTPSPDYHeader.URI.name(version));
if (uriHeader != null)
if (version == SPDY.V2 && uriHeader.value().startsWith("http://"))
if (version == SPDY.V2 && uriHeader.getValue().startsWith("http://"))
return true;
else if (version == SPDY.V3 && uriHeader.value().startsWith("/")
else if (version == SPDY.V3 && uriHeader.getValue().startsWith("/")
&& headers.get(HTTPSPDYHeader.HOST.name(version)) != null && headers.get(HTTPSPDYHeader.SCHEME.name(version)) != null)
return true;
System.out.println(HTTPSPDYHeader.URI.name(version) + " not valid!");

View File

@ -97,7 +97,7 @@ public class SSLExternalServerTest extends AbstractHTTPSPDYTest
Fields.Field versionHeader = headers.get(HTTPSPDYHeader.STATUS.name(version));
if (versionHeader != null)
{
Matcher matcher = Pattern.compile("(\\d{3}).*").matcher(versionHeader.value());
Matcher matcher = Pattern.compile("(\\d{3}).*").matcher(versionHeader.getValue());
if (matcher.matches() && Integer.parseInt(matcher.group(1)) < 400)
latch.countDown();
}

View File

@ -108,7 +108,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"), is(true));
assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"), is(true));
assertThat(replyHeaders.get(HttpHeader.SERVER.asString()), is(notNullValue()));
assertThat(replyHeaders.get(HttpHeader.X_POWERED_BY.asString()), is(notNullValue()));
replyLatch.countDown();
@ -149,7 +149,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -192,11 +192,11 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertThat("isClose is true", replyInfo.isClose(), is(true));
Fields replyHeaders = replyInfo.getHeaders();
assertThat("response code is 200 OK", replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value()
assertThat("response code is 200 OK", replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue()
.contains("200"), is(true));
assertThat(replyInfo.getHeaders().get("Set-Cookie").values()[0], is(cookie1 + "=\"" + cookie1Value +
assertThat(replyInfo.getHeaders().get("Set-Cookie").getValues().get(0), is(cookie1 + "=\"" + cookie1Value +
"\";Version=1"));
assertThat(replyInfo.getHeaders().get("Set-Cookie").values()[1], is(cookie2 + "=\"" + cookie2Value +
assertThat(replyInfo.getHeaders().get("Set-Cookie").getValues().get(1), is(cookie2 + "=\"" + cookie2Value +
"\";Version=1"));
replyLatch.countDown();
}
@ -234,7 +234,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -276,7 +276,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -325,7 +325,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -367,7 +367,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -411,7 +411,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.toString(), replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.toString(), replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -453,7 +453,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -499,7 +499,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -554,7 +554,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
assertEquals(1, replyFrames.incrementAndGet());
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -607,7 +607,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -663,7 +663,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -716,7 +716,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -769,7 +769,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -827,7 +827,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -880,8 +880,8 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
assertEquals(1, replies.incrementAndGet());
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("302"));
assertTrue(replyHeaders.get("location").value().endsWith(suffix));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("302"));
assertTrue(replyHeaders.get("location").getValue().endsWith(suffix));
replyLatch.countDown();
}
});
@ -918,7 +918,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
assertEquals(1, replies.incrementAndGet());
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("404"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("404"));
replyLatch.countDown();
}
@ -962,7 +962,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
assertEquals(1, replies.incrementAndGet());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("500"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("500"));
replyLatch.countDown();
if (replyInfo.isClose())
latch.countDown();
@ -1018,8 +1018,8 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
assertEquals(1, replyFrames.incrementAndGet());
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get("extra").value().contains("X"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
assertTrue(replyHeaders.get("extra").getValue().contains("X"));
replyLatch.countDown();
}
@ -1077,7 +1077,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
assertEquals(1, replyFrames.incrementAndGet());
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -1130,7 +1130,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
{
Assert.assertFalse(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
@ -1191,7 +1191,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -1234,7 +1234,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -1279,7 +1279,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -1347,7 +1347,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
replyLatch.countDown();
}
});
@ -1415,7 +1415,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
responseLatch.countDown();
}
@ -1456,7 +1456,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"));
assertTrue(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"));
responseLatch.countDown();
}
});

View File

@ -115,7 +115,7 @@ public class SimpleHTTPBenchmarkTest extends AbstractHTTPSPDYTest
{
assertTrue(replyInfo.isClose());
Fields replyHeaders = replyInfo.getHeaders();
assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"), CoreMatchers.is(true));
assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"), CoreMatchers.is(true));
assertThat(replyHeaders.get(HttpHeader.SERVER.asString()), CoreMatchers.is(notNullValue()));
assertThat(replyHeaders.get(HttpHeader.X_POWERED_BY.asString()), CoreMatchers.is(notNullValue()));
replyLatch.countDown();
@ -138,7 +138,7 @@ public class SimpleHTTPBenchmarkTest extends AbstractHTTPSPDYTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields replyHeaders = replyInfo.getHeaders();
assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"), CoreMatchers.is(true));
assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).getValue().contains("200"), CoreMatchers.is(true));
assertThat(replyHeaders.get(HttpHeader.SERVER.asString()), CoreMatchers.is(notNullValue()));
assertThat(replyHeaders.get(HttpHeader.X_POWERED_BY.asString()), CoreMatchers.is(notNullValue()));
replyLatch.countDown();

View File

@ -317,7 +317,7 @@ public class ProxySPDYToHTTPTest
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)
{
assertThat("Status code is 302", replyInfo.getHeaders().get(HTTPSPDYHeader.STATUS.name(version)).value(),
assertThat("Status code is 302", replyInfo.getHeaders().get(HTTPSPDYHeader.STATUS.name(version)).getValue(),
is("302"));
assertThat("Location header has been received", replyInfo.getHeaders().get("Location"), is(notNullValue()));
replyLatch.countDown();
@ -484,7 +484,7 @@ public class ProxySPDYToHTTPTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields headers = replyInfo.getHeaders();
assertThat("status is 504", headers.get(HTTPSPDYHeader.STATUS.name(version)).value(), is("504"));
assertThat("status is 504", headers.get(HTTPSPDYHeader.STATUS.name(version)).getValue(), is("504"));
replyLatch.countDown();
}

View File

@ -230,8 +230,8 @@ public class ProxySPDYToSPDYLoadTest
public void onReply(Stream stream, ReplyInfo replyInfo)
{
Fields headers = replyInfo.getHeaders();
assertThat("uuid matches expected uuid", headers.get(UUID_HEADER_NAME).value(), is(uuid));
assertThat("response comes from the given server", headers.get(SERVER_ID_HEADER).value(),
assertThat("uuid matches expected uuid", headers.get(UUID_HEADER_NAME).getValue(), is(uuid));
assertThat("response comes from the given server", headers.get(SERVER_ID_HEADER).getValue(),
is(serverIdentificationString));
replyLatch.countDown();
}
@ -272,7 +272,7 @@ public class ProxySPDYToSPDYLoadTest
Assert.assertNotNull(uuidHeader);
Fields responseHeaders = new Fields();
responseHeaders.put(UUID_HEADER_NAME, uuidHeader.value());
responseHeaders.put(UUID_HEADER_NAME, uuidHeader.getValue());
responseHeaders.put(SERVER_ID_HEADER, serverId);
stream.reply(new ReplyInfo(responseHeaders, false), new Callback.Adapter());
return new StreamFrameListener.Adapter()

View File

@ -18,11 +18,13 @@
package org.eclipse.jetty.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -82,7 +84,7 @@ public class Fields implements Iterable<Fields.Field>
if (obj == null || getClass() != obj.getClass())
return false;
Fields that = (Fields)obj;
if (size() != that.size())
if (getSize() != that.getSize())
return false;
if (caseSensitive != that.caseSensitive)
return false;
@ -105,11 +107,11 @@ public class Fields implements Iterable<Fields.Field>
/**
* @return a set of field names
*/
public Set<String> names()
public Set<String> getNames()
{
Set<String> result = new LinkedHashSet<>();
for (Field field : fields.values())
result.add(field.name());
result.add(field.getName());
return result;
}
@ -141,14 +143,14 @@ public class Fields implements Iterable<Fields.Field>
}
/**
* <p>Inserts or replaces the given {@link Field}, mapped to the {@link Field#name() field's name}</p>
* <p>Inserts or replaces the given {@link Field}, mapped to the {@link Field#getName() field's name}</p>
*
* @param field the field to put
*/
public void put(Field field)
{
if (field != null)
fields.put(normalizeName(field.name()), field);
fields.put(normalizeName(field.getName()), field);
}
/**
@ -170,7 +172,7 @@ public class Fields implements Iterable<Fields.Field>
}
else
{
field = new Field(field.name(), field.values(), value);
field = new Field(field.getName(), field.getValues(), value);
fields.put(key, field);
}
}
@ -206,7 +208,7 @@ public class Fields implements Iterable<Fields.Field>
/**
* @return the number of fields
*/
public int size()
public int getSize()
{
return fields.size();
}
@ -233,19 +235,20 @@ public class Fields implements Iterable<Fields.Field>
public static class Field
{
private final String name;
private final String[] values;
private final List<String> values;
public Field(String name, String value)
{
this(name, new String[]{value});
this(name, Collections.singletonList(value));
}
private Field(String name, String[] values, String... moreValues)
private Field(String name, List<String> values, String... moreValues)
{
this.name = name;
this.values = new String[values.length + moreValues.length];
System.arraycopy(values, 0, this.values, 0, values.length);
System.arraycopy(moreValues, 0, this.values, values.length, moreValues.length);
List<String> list = new ArrayList<>(values.size() + moreValues.length);
list.addAll(values);
list.addAll(Arrays.asList(moreValues));
this.values = Collections.unmodifiableList(list);
}
public boolean equals(Field that, boolean caseSensitive)
@ -256,7 +259,7 @@ public class Fields implements Iterable<Fields.Field>
return false;
if (caseSensitive)
return equals(that);
return name.equalsIgnoreCase(that.name) && Arrays.equals(values, that.values);
return name.equalsIgnoreCase(that.name) && values.equals(that.values);
}
@Override
@ -267,21 +270,21 @@ public class Fields implements Iterable<Fields.Field>
if (obj == null || getClass() != obj.getClass())
return false;
Field that = (Field)obj;
return name.equals(that.name) && Arrays.equals(values, that.values);
return name.equals(that.name) && values.equals(that.values);
}
@Override
public int hashCode()
{
int result = name.hashCode();
result = 31 * result + Arrays.hashCode(values);
result = 31 * result + values.hashCode();
return result;
}
/**
* @return the field's name
*/
public String name()
public String getName()
{
return name;
}
@ -289,29 +292,29 @@ public class Fields implements Iterable<Fields.Field>
/**
* @return the first field's value
*/
public String value()
public String getValue()
{
return values[0];
return values.get(0);
}
/**
* <p>Attempts to convert the result of {@link #value()} to an integer,
* <p>Attempts to convert the result of {@link #getValue()} to an integer,
* returning it if the conversion is successful; returns null if the
* result of {@link #value()} is null.</p>
* result of {@link #getValue()} is null.</p>
*
* @return the result of {@link #value()} converted to an integer, or null
* @return the result of {@link #getValue()} converted to an integer, or null
* @throws NumberFormatException if the conversion fails
*/
public Integer valueAsInt()
public Integer getValueAsInt()
{
final String value = value();
final String value = getValue();
return value == null ? null : Integer.valueOf(value);
}
/**
* @return the field's values
*/
public String[] values()
public List<String> getValues()
{
return values;
}
@ -321,13 +324,13 @@ public class Fields implements Iterable<Fields.Field>
*/
public boolean hasMultipleValues()
{
return values.length > 1;
return values.size() > 1;
}
@Override
public String toString()
{
return Arrays.toString(values);
return String.format("%s=%s", name, values);
}
}
}