hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r918631 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/message/HeaderGroup.java test/java/org/apache/http/message/TestHeaderGroup.java
Date Wed, 03 Mar 2010 19:00:11 GMT
Author: olegk
Date: Wed Mar  3 19:00:11 2010
New Revision: 918631

URL: http://svn.apache.org/viewvc?rev=918631&view=rev
Log:
Made header list final; added test cases for header removal with iterator

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java?rev=918631&r1=918630&r2=918631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
Wed Mar  3 19:00:11 2010
@@ -46,7 +46,7 @@
 public class HeaderGroup implements Cloneable {
 
     /** The list of headers for this group, in the order in which they were added */
-    private List headers;
+    private final List headers;
 
     /**
      * Constructor for HeaderGroup.
@@ -274,6 +274,8 @@
      * Returns a copy of this object
      * 
      * @return copy of this object
+     * 
+     * @since 4.0
      */
     public HeaderGroup copy() {
         HeaderGroup clone = new HeaderGroup();
@@ -283,7 +285,8 @@
     
     public Object clone() throws CloneNotSupportedException {
         HeaderGroup clone = (HeaderGroup) super.clone();
-        clone.headers = new ArrayList(this.headers);
+        clone.headers.clear();
+        clone.headers.addAll(this.headers);
         return clone;
     }
     

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java?rev=918631&r1=918630&r2=918631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestHeaderGroup.java
Wed Mar  3 19:00:11 2010
@@ -150,6 +150,27 @@
         assertFalse(i.hasNext());
     }
     
+    public void testHeaderRemove() {
+        HeaderGroup headergroup = new HeaderGroup();
+        Header header1 = new BasicHeader("name", "value1");
+        Header header2 = new BasicHeader("name", "value2");
+        Header header3 = new BasicHeader("name", "value3");
+        headergroup.setHeaders(new Header[] { header1, header2, header3 });
+        Iterator i = headergroup.iterator();
+        assertNotNull(i);
+        assertTrue(i.hasNext());
+        i.next();
+        assertTrue(i.hasNext());
+        i.next();
+        i.remove();
+        assertEquals(2, headergroup.getAllHeaders().length);
+        assertTrue(i.hasNext());
+        i.next();
+        i.remove();
+        assertEquals(1, headergroup.getAllHeaders().length);
+        assertFalse(i.hasNext());
+    }
+    
     public void testCloning() throws Exception {
         HeaderGroup orig = new HeaderGroup();
         Header header1 = new BasicHeader("name", "value1");



Mime
View raw message