hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-core git commit: Generic Factory function to take an input parameter
Date Wed, 08 Nov 2017 15:00:02 GMT
Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 635437371 -> 6893add31


Generic Factory function to take an input parameter


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/6893add3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/6893add3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/6893add3

Branch: refs/heads/master
Commit: 6893add31a39a92783416587532fb47d216c7ab9
Parents: 6354373
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Wed Nov 8 15:08:44 2017 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Wed Nov 8 15:56:35 2017 +0100

----------------------------------------------------------------------
 .../org/apache/hc/core5/function/Factory.java     |  4 ++--
 .../http/protocol/RequestHandlerRegistry.java     | 18 +++++++++---------
 .../http/protocol/TestRequestHandlerRegistry.java |  6 +++---
 3 files changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/6893add3/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java b/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java
index ea9cb95..6236202 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/function/Factory.java
@@ -32,8 +32,8 @@ package org.apache.hc.core5.function;
  *
  * @since 5.0
  */
-public interface Factory<T> {
+public interface Factory<P, T> {
 
-    T create();
+    T create(P parameter);
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/6893add3/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
index fecdc43..935d3a9 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestHandlerRegistry.java
@@ -33,7 +33,7 @@ import java.util.concurrent.ConcurrentMap;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.function.Factory;
+import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpRequestMapper;
 import org.apache.hc.core5.http.MisdirectedRequestException;
@@ -46,31 +46,31 @@ public class RequestHandlerRegistry<T> implements HttpRequestMapper<T>
{
     private final static String LOCALHOST = "localhost";
 
     private final String canonicalHostName;
-    private final Factory<LookupRegistry<T>> registryFactory;
+    private final Supplier<LookupRegistry<T>> registrySupplier;
     private final LookupRegistry<T> primary;
     private final ConcurrentMap<String, LookupRegistry<T>> virtualMap;
 
-    public RequestHandlerRegistry(final String canonicalHostName, final Factory<LookupRegistry<T>>
registryFactory) {
+    public RequestHandlerRegistry(final String canonicalHostName, final Supplier<LookupRegistry<T>>
registrySupplier) {
         this.canonicalHostName = Args.notNull(canonicalHostName, "Canonical hostname").toLowerCase(Locale.ROOT);
-        this.registryFactory = registryFactory != null ? registryFactory : new Factory<LookupRegistry<T>>()
{
+        this.registrySupplier = registrySupplier != null ? registrySupplier : new Supplier<LookupRegistry<T>>()
{
 
             @Override
-            public LookupRegistry<T> create() {
+            public LookupRegistry<T> get() {
                 return new UriPatternMatcher<>();
             }
 
         };
-        this.primary = this.registryFactory.create();
+        this.primary = this.registrySupplier.get();
         this.virtualMap = new ConcurrentHashMap<>();
     }
 
 
 
     public RequestHandlerRegistry(final String canonicalHostName, final UriPatternType patternType)
{
-        this(canonicalHostName, new Factory<LookupRegistry<T>>() {
+        this(canonicalHostName, new Supplier<LookupRegistry<T>>() {
 
             @Override
-            public LookupRegistry<T> create() {
+            public LookupRegistry<T> get() {
                 return UriPatternType.newMatcher(patternType);
             }
 
@@ -122,7 +122,7 @@ public class RequestHandlerRegistry<T> implements HttpRequestMapper<T>
{
         } else {
             LookupRegistry<T> patternMatcher = virtualMap.get(key);
             if (patternMatcher == null) {
-                final LookupRegistry<T> newPatternMatcher = registryFactory.create();
+                final LookupRegistry<T> newPatternMatcher = registrySupplier.get();
                 patternMatcher = virtualMap.putIfAbsent(key, newPatternMatcher);
                 if (patternMatcher == null) {
                     patternMatcher = newPatternMatcher;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/6893add3/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
b/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
index 8342e13..943a69c 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/protocol/TestRequestHandlerRegistry.java
@@ -27,7 +27,7 @@
 
 package org.apache.hc.core5.http.protocol;
 
-import org.apache.hc.core5.function.Factory;
+import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.MisdirectedRequestException;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
@@ -42,10 +42,10 @@ public class TestRequestHandlerRegistry {
 
     @Before
     public void setUp() {
-        handlerRegistry = new RequestHandlerRegistry<>("myhost", new Factory<LookupRegistry<String>>()
{
+        handlerRegistry = new RequestHandlerRegistry<>("myhost", new Supplier<LookupRegistry<String>>()
{
 
             @Override
-            public LookupRegistry<String> create() {
+            public LookupRegistry<String> get() {
                 return new UriPatternMatcher<>();
             }
 


Mime
View raw message