http-client-branch: Builders as interfaces http-client-branch
authorchegar
Fri, 16 Feb 2018 16:23:54 +0000
branchhttp-client-branch
changeset 56140 049b6940e9db
parent 56139 b3d6203051df
child 56141 c28d710b8ef9
http-client-branch: Builders as interfaces
src/java.net.http/share/classes/java/net/http/HttpClient.java
src/java.net.http/share/classes/java/net/http/HttpRequest.java
src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java
src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestBuilderImpl.java
--- a/src/java.net.http/share/classes/java/net/http/HttpClient.java	Fri Feb 16 16:09:14 2018 +0000
+++ b/src/java.net.http/share/classes/java/net/http/HttpClient.java	Fri Feb 16 16:23:54 2018 +0000
@@ -175,7 +175,7 @@
      *
      * @since 11
      */
-    public abstract static class Builder {
+    public interface Builder {
 
         /**
          * A proxy selector that always return {@link Proxy#NO_PROXY} implying
@@ -187,10 +187,6 @@
          */
         public static final ProxySelector NO_PROXY = ProxySelector.of(null);
 
-        /**
-         * Creates a Builder.
-         */
-        protected Builder() {}
 
         /**
          * Sets a cookie handler.
@@ -198,7 +194,7 @@
          * @param cookieHandler the cookie handler
          * @return this builder
          */
-        public abstract Builder cookieHandler(CookieHandler cookieHandler);
+        public Builder cookieHandler(CookieHandler cookieHandler);
 
         /**
          * Sets an {@code SSLContext}.
@@ -212,7 +208,7 @@
          * @param sslContext the SSLContext
          * @return this builder
          */
-        public abstract Builder sslContext(SSLContext sslContext);
+        public Builder sslContext(SSLContext sslContext);
 
         /**
          * Sets an {@code SSLParameters}.
@@ -229,7 +225,7 @@
          * @param sslParameters the SSLParameters
          * @return this builder
          */
-        public abstract Builder sslParameters(SSLParameters sslParameters);
+        public Builder sslParameters(SSLParameters sslParameters);
 
         /**
          * Sets the executor to be used for asynchronous and dependent tasks.
@@ -247,7 +243,7 @@
          * @param executor the Executor
          * @return this builder
          */
-        public abstract Builder executor(Executor executor);
+        public Builder executor(Executor executor);
 
         /**
          * Specifies whether requests will automatically follow redirects issued
@@ -260,7 +256,7 @@
          * @param policy the redirection policy
          * @return this builder
          */
-        public abstract Builder followRedirects(Redirect policy);
+        public Builder followRedirects(Redirect policy);
 
         /**
          * Requests a specific HTTP protocol version where possible.
@@ -284,7 +280,7 @@
          * @param version the requested HTTP protocol version
          * @return this builder
          */
-        public abstract Builder version(HttpClient.Version version);
+        public Builder version(HttpClient.Version version);
 
         /**
          * Sets the default priority for any HTTP/2 requests sent from this
@@ -295,7 +291,7 @@
          * @return this builder
          * @throws IllegalArgumentException if the given priority is out of range
          */
-        public abstract Builder priority(int priority);
+        public Builder priority(int priority);
 
         /**
          * Sets a {@link java.net.ProxySelector}.
@@ -318,7 +314,7 @@
          * @param selector the ProxySelector
          * @return this builder
          */
-        public abstract Builder proxy(ProxySelector selector);
+        public Builder proxy(ProxySelector selector);
 
         /**
          * Sets an authenticator to use for HTTP authentication.
@@ -326,7 +322,7 @@
          * @param a the Authenticator
          * @return this builder
          */
-        public abstract Builder authenticator(Authenticator a);
+        public Builder authenticator(Authenticator a);
 
         /**
          * Returns a new {@link HttpClient} built from the current state of this
@@ -334,7 +330,7 @@
          *
          * @return this builder
          */
-        public abstract HttpClient build();
+        public HttpClient build();
     }
 
 
--- a/src/java.net.http/share/classes/java/net/http/HttpRequest.java	Fri Feb 16 16:09:14 2018 +0000
+++ b/src/java.net.http/share/classes/java/net/http/HttpRequest.java	Fri Feb 16 16:23:54 2018 +0000
@@ -122,12 +122,7 @@
      *
      * @since 11
      */
-    public abstract static class Builder {
-
-        /**
-         * Creates a Builder.
-         */
-        protected Builder() {}
+    public interface Builder {
 
         /**
          * Sets this {@code HttpRequest}'s request {@code URI}.
@@ -137,7 +132,7 @@
          * @throws IllegalArgumentException if the {@code URI} scheme is not
          *         supported
          */
-        public abstract Builder uri(URI uri);
+        public Builder uri(URI uri);
 
         /**
          * Requests the server to acknowledge the request before sending the
@@ -150,7 +145,7 @@
          * @param enable {@code true} if Expect continue to be sent
          * @return this request builder
          */
-        public abstract Builder expectContinue(boolean enable);
+        public Builder expectContinue(boolean enable);
 
         /**
          * Sets the preferred {@link HttpClient.Version} for this request.
@@ -163,7 +158,7 @@
          * @param version the HTTP protocol version requested
          * @return this request builder
          */
-        public abstract Builder version(HttpClient.Version version);
+        public Builder version(HttpClient.Version version);
 
         /**
          * Adds the given name value pair to the set of headers for this request.
@@ -185,7 +180,7 @@
          *         RFC 7230 section-3.2</a>, or the header name or value is restricted
          *         by the implementation.
          */
-        public abstract Builder header(String name, String value);
+        public Builder header(String name, String value);
 
         /**
          * Adds the given name value pairs to the set of headers for this
@@ -203,7 +198,7 @@
          *         {@linkplain #header(String, String) restricted} by the
          *         implementation.
          */
-        public abstract Builder headers(String... headers);
+        public Builder headers(String... headers);
 
         /**
          * Sets a timeout for this request. If the response is not received
@@ -235,7 +230,7 @@
          *         {@linkplain #header(String, String) restricted} by the
          *         implementation.
          */
-        public abstract Builder setHeader(String name, String value);
+        public Builder setHeader(String name, String value);
 
         /**
          * Sets the request method of this builder to GET.
@@ -243,7 +238,7 @@
          *
          * @return a {@code HttpRequest}
          */
-        public abstract Builder GET();
+        public Builder GET();
 
         /**
          * Sets the request method of this builder to POST and sets its
@@ -253,7 +248,7 @@
          *
          * @return a {@code HttpRequest}
          */
-        public abstract Builder POST(BodyPublisher bodyPublisher);
+        public Builder POST(BodyPublisher bodyPublisher);
 
         /**
          * Sets the request method of this builder to PUT and sets its
@@ -263,7 +258,7 @@
          *
          * @return a {@code HttpRequest}
          */
-        public abstract Builder PUT(BodyPublisher bodyPublisher);
+        public Builder PUT(BodyPublisher bodyPublisher);
 
         /**
          * Sets the request method of this builder to DELETE and sets its
@@ -274,7 +269,7 @@
          * @return a {@code HttpRequest}
          */
 
-        public abstract Builder DELETE(BodyPublisher bodyPublisher);
+        public Builder DELETE(BodyPublisher bodyPublisher);
 
         /**
          * Sets the request method and request body of this builder to the
@@ -291,7 +286,7 @@
          * @return a {@code HttpRequest}
          * @throws IllegalArgumentException if the method is restricted
          */
-        public abstract Builder method(String method, BodyPublisher bodyPublisher);
+        public Builder method(String method, BodyPublisher bodyPublisher);
 
         /**
          * Builds and returns a {@link HttpRequest}.
@@ -299,7 +294,7 @@
          * @return the request
          * @throws IllegalStateException if a URI has not been set
          */
-        public abstract HttpRequest build();
+        public HttpRequest build();
 
         /**
          * Returns an exact duplicate copy of this {@code Builder} based on
@@ -308,7 +303,7 @@
          *
          * @return an exact copy of this Builder
          */
-        public abstract Builder copy();
+        public Builder copy();
     }
 
     /**
--- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java	Fri Feb 16 16:09:14 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java	Fri Feb 16 16:23:54 2018 +0000
@@ -35,7 +35,7 @@
 import jdk.internal.net.http.common.Utils;
 import static java.util.Objects.requireNonNull;
 
-public class HttpClientBuilderImpl extends HttpClient.Builder {
+public class HttpClientBuilderImpl implements HttpClient.Builder {
 
     CookieHandler cookieHandler;
     HttpClient.Redirect followRedirects;
--- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestBuilderImpl.java	Fri Feb 16 16:09:14 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestBuilderImpl.java	Fri Feb 16 16:23:54 2018 +0000
@@ -38,7 +38,7 @@
 import static jdk.internal.net.http.common.Utils.isValidName;
 import static jdk.internal.net.http.common.Utils.isValidValue;
 
-public class HttpRequestBuilderImpl extends HttpRequest.Builder {
+public class HttpRequestBuilderImpl implements HttpRequest.Builder {
 
     private HttpHeadersImpl userHeaders;
     private URI uri;