--- old/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpHeaders.java 2017-11-30 04:03:59.598106418 -0800 +++ new/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpHeaders.java 2017-11-30 04:03:59.287079228 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,55 +29,136 @@ import java.util.Map; import java.util.Optional; import java.util.OptionalLong; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; +import static java.util.Objects.requireNonNull; /** * A read-only view of a set of HTTP headers. * {@Incubating} * + *
The methods of this class ( that accept a String header name ), and the + * Map returned by the {@linkplain #map() map} method, operate without regard to + * case when retrieving the header value. + * + *
HttpHeaders instances are immutable.
+ *
* @since 9
*/
-public interface HttpHeaders {
+public abstract class HttpHeaders {
+
+ /**
+ * Creates an HttpHeaders.
+ */
+ protected HttpHeaders() {}
/**
- * Returns an {@link java.util.Optional} containing the first value of the
- * given named (and possibly multi-valued) header. If the header is not
- * present, then the returned {@code Optional} is empty.
+ * Returns an {@link Optional} containing the first value of the given named
+ * (and possibly multi-valued) header. If the header is not present, then
+ * the returned {@code Optional} is empty.
+ *
+ * @implSpec
+ * The default implementation invokes
+ * {@code allValues(name).stream().findFirst()}
*
* @param name the header name
* @return an {@code Optional If the given object is not an {@code HttpHeaders} then this
+ * method returns {@code false}. Two HTTP headers are equal if each
+ * of their corresponding {@linkplain #map() maps} are equal.
+ *
+ * This method satisfies the general contract of the {@link
+ * Object#equals(Object) Object.equals} method.
+ *
+ * @param obj the object to which this object is to be compared
+ * @return {@code true} if, and only if, the given object is an {@code
+ * HttpHeaders} that is equal to this HTTP headers
+ */
+ public final boolean equals(Object obj) {
+ if (!(obj instanceof HttpHeaders))
+ return false;
+ HttpHeaders that = (HttpHeaders)obj;
+ return this.map().equals(that.map());
+ }
+
+ /**
+ * Computes a hash code for this HTTP headers instance.
+ *
+ * The hash code is based upon the components of the HTTP headers
+ * {@linkplain #map() map}, and satisfies the general contract of the
+ * {@link Object#hashCode Object.hashCode} method.
+ *
+ * @return the hash-code value for this HTTP headers
+ */
+ public final int hashCode() {
+ return map().hashCode();
+ }
+
+ /**
+ * Returns this HTTP headers as a string.
+ *
+ * @return a string describing the HTTP headers
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString()).append(" ");
+ sb.append(map());
+ sb.append(" }");
+ return sb.toString();
+ }
}