[cp-patches] FYI: Genericize gnu.java.net.protocol.http.* a bit more...

David Daney ddaney at avtrex.com
Fri Dec 22 00:46:00 UTC 2006


Tom Tromey already did the heavy lifting here.  This patch just tweaks 
it a  bit.

2006-12-21  David Daney  <ddaney at avtrex.com)

    * gnu/java/net/protocol/http/Headers.java: Update imports.  Implement
    Iterable<Headers.HeaderElement>.
    (iterator): Make public.
    * gnu/java/net/protocol/http/Request.java (dispatch): Use enhanced for
    loop.
    (notifyHeaderHandlers): Same.
    * gnu/java/net/protocol/http/SimpleCookieManager.java (addCookies):
    Remove unneeded cast.

-------------- next part --------------
Index: gnu/java/net/protocol/http/Headers.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/net/protocol/http/Headers.java,v
retrieving revision 1.10
diff -u -p -r1.10 Headers.java
--- gnu/java/net/protocol/http/Headers.java	18 Dec 2006 21:37:38 -0000	1.10
+++ gnu/java/net/protocol/http/Headers.java	22 Dec 2006 00:30:24 -0000
@@ -42,6 +42,7 @@ import gnu.java.net.LineInputStream;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.Iterable;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
@@ -61,7 +62,7 @@ import java.util.Map;
  * @author Chris Burdess (dog at gnu.org)
  * @author David Daney (ddaney at avtrex.com)
  */
-class Headers
+class Headers implements Iterable<Headers.HeaderElement>
 {
   /**
    * A list of HeaderElements
@@ -104,7 +105,7 @@ class Headers
    *
    * @return the Iterator.
    */
-  Iterator<HeaderElement> iterator()
+  public Iterator<HeaderElement> iterator()
   {
     return headers.iterator();
   }
Index: gnu/java/net/protocol/http/Request.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/net/protocol/http/Request.java,v
retrieving revision 1.11
diff -u -p -r1.11 Request.java
--- gnu/java/net/protocol/http/Request.java	18 Dec 2006 21:37:38 -0000	1.11
+++ gnu/java/net/protocol/http/Request.java	22 Dec 2006 00:30:25 -0000
@@ -302,9 +302,8 @@ public class Request
             String line = method + ' ' + requestUri + ' ' + version + CRLF;
             out.write(line.getBytes(US_ASCII));
             // Request headers
-            for (Iterator i = requestHeaders.iterator(); i.hasNext(); )
+            for (Headers.HeaderElement elt : requestHeaders)
               {
-                Headers.HeaderElement elt = (Headers.HeaderElement)i.next();
                 line = elt.name + HEADER_SEP + elt.value + CRLF;
                 out.write(line.getBytes(US_ASCII));
               }
@@ -439,9 +438,8 @@ public class Request
 
   void notifyHeaderHandlers(Headers headers)
   {
-    for (Iterator i = headers.iterator(); i.hasNext(); )
+    for (Headers.HeaderElement entry : headers)
       {
-        Headers.HeaderElement entry = (Headers.HeaderElement) i.next();
         // Handle Set-Cookie
         if ("Set-Cookie".equalsIgnoreCase(entry.name))
             handleSetCookie(entry.value);
Index: gnu/java/net/protocol/http/SimpleCookieManager.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/net/protocol/http/SimpleCookieManager.java,v
retrieving revision 1.3
diff -u -p -r1.3 SimpleCookieManager.java
--- gnu/java/net/protocol/http/SimpleCookieManager.java	18 Dec 2006 21:37:39 -0000	1.3
+++ gnu/java/net/protocol/http/SimpleCookieManager.java	22 Dec 2006 00:30:25 -0000
@@ -1,5 +1,5 @@
 /* CookieManager.java --
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -110,7 +110,7 @@ public class SimpleCookieManager
         ArrayList<String> expired = new ArrayList<String>();
         for (Map.Entry<String, Cookie> entry : map.entrySet())
           {
-            Cookie cookie = (Cookie) entry.getValue();
+            Cookie cookie = entry.getValue();
             Date expires = cookie.getExpiryDate();
             if (expires != null && expires.before(now))
               {


More information about the Classpath-patches mailing list