hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [2/2] httpcomponents-core git commit: HTTPCORE-499 Make interface Header extend NameValuePair.
Date Tue, 12 Dec 2017 23:52:04 GMT
HTTPCORE-499 Make interface Header extend NameValuePair.


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

Branch: refs/heads/master
Commit: c01ea7ec4a93f45e337b3e24f82ec881106ae0e6
Parents: 1c4729b
Author: Gary Gregory <ggregory@apache.org>
Authored: Tue Dec 12 16:52:00 2017 -0700
Committer: Gary Gregory <ggregory@apache.org>
Committed: Tue Dec 12 16:52:00 2017 -0700

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  3 ++
 .../java/org/apache/hc/core5/http/Header.java   | 22 +++-------
 .../hc/core5/http/message/BasicHeader.java      | 46 +++-----------------
 .../core5/http/message/BasicNameValuePair.java  | 22 ++++++++++
 4 files changed, 36 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c01ea7ec/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index e03aece..fa4e449 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -7,6 +7,9 @@ Changelog
 * HTTPCORE-496: Add API org.apache.http.protocol.UriPatternMatcher.entrySet().
   Contributed by Gary Gregory <ggregory at apache.org>
 
+* HTTPCORE-499 Make interface Header extend NameValuePair
+  Contributed by Gary Gregory <ggregory at apache.org>
+
 
 Release 5.0-BETA1
 -------------------

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c01ea7ec/httpcore5/src/main/java/org/apache/hc/core5/http/Header.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/Header.java b/httpcore5/src/main/java/org/apache/hc/core5/http/Header.java
index 7c9e68e..62d7a29 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/Header.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/Header.java
@@ -28,31 +28,21 @@
 package org.apache.hc.core5.http;
 
 /**
- * Represents an HTTP header field consisting of a field name and a field value..
+ * Represents an HTTP header field consisting of a field name and a field
+ * value.
  *
  * @since 4.0
  */
-public interface Header {
-
-    /**
-     * Get the name of the Header.
-     *
-     * @return the name of the Header,  never {@code null}
-     */
-    String getName();
-
-    /**
-     * Get the value of the Header.
-     *
-     * @return the value of the Header,  may be {@code null}
-     */
-    String getValue();
+public interface Header extends NameValuePair {
 
     /**
      * Returns {@code true} if the header should be considered sensitive.
      * <p>
      * Some encoding schemes such as HPACK impose restrictions on encoded
      * representation of sensitive headers.
+     * </p>
+     * 
+     * @return {@code true} if the header should be considered sensitive.
      *
      * @since 5.0
      */

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c01ea7ec/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
index 68adb49..7441ec5 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
@@ -27,15 +27,12 @@
 
 package org.apache.hc.core5.http.message;
 
-import java.io.Serializable;
-import java.util.Locale;
 import java.util.Objects;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.LangUtils;
 
 /**
  * Immutable {@link Header}.
@@ -43,12 +40,10 @@ import org.apache.hc.core5.util.LangUtils;
  * @since 4.0
  */
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
-public class BasicHeader implements Header, Serializable {
+public class BasicHeader extends BasicNameValuePair implements Header {
 
     private static final long serialVersionUID = -5427236326487562174L;
 
-    private final String name;
-    private final String value;
     private final boolean sensitive;
 
     /**
@@ -61,9 +56,7 @@ public class BasicHeader implements Header, Serializable {
      * @since 5.0
      */
     public BasicHeader(final String name, final Object value, final boolean sensitive) {
-        super();
-        this.name = Args.notNull(name, "Name");
-        this.value = Objects.toString(value, null);
+        super(Args.notNull(name, "Name"), Objects.toString(value, null));
         this.sensitive = sensitive;
     }
 
@@ -78,16 +71,6 @@ public class BasicHeader implements Header, Serializable {
     }
 
     @Override
-    public String getName() {
-        return this.name;
-    }
-
-    @Override
-    public String getValue() {
-        return this.value;
-    }
-
-    @Override
     public boolean isSensitive() {
         return this.sensitive;
     }
@@ -95,30 +78,11 @@ public class BasicHeader implements Header, Serializable {
     @Override
     public String toString() {
         final StringBuilder buf = new StringBuilder();
-        buf.append(this.name).append(": ");
-        if (this.value != null) {
-            buf.append(this.value);
+        buf.append(this.getName()).append(": ");
+        if (this.getValue() != null) {
+            buf.append(this.getValue());
         }
         return buf.toString();
     }
 
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof BasicHeader) {
-            final BasicHeader that = (BasicHeader) obj;
-            return this.name.equalsIgnoreCase(that.name) && LangUtils.equals(this.value,
that.value);
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        int hash = LangUtils.HASH_SEED;
-        hash = LangUtils.hashCode(hash, this.name.toLowerCase(Locale.ROOT));
-        hash = LangUtils.hashCode(hash, this.value);
-        return hash;
-    }
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c01ea7ec/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
index b6bc887..28e6407 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/BasicNameValuePair.java
@@ -28,11 +28,13 @@
 package org.apache.hc.core5.http.message;
 
 import java.io.Serializable;
+import java.util.Locale;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.NameValuePair;
 import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.LangUtils;
 
 /**
  * Basic implementation of {@link NameValuePair}.
@@ -84,4 +86,24 @@ public class BasicNameValuePair implements NameValuePair, Serializable
{
         return buffer.toString();
     }
 
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof BasicNameValuePair) {
+            final BasicNameValuePair that = (BasicNameValuePair) obj;
+            return this.name.equalsIgnoreCase(that.name) && LangUtils.equals(this.value,
that.value);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = LangUtils.HASH_SEED;
+        hash = LangUtils.hashCode(hash, this.name.toLowerCase(Locale.ROOT));
+        hash = LangUtils.hashCode(hash, this.value);
+        return hash;
+    }
+
 }


Mime
View raw message