I'm checking this in.

While looking at a jar oddity I found that it was still explicitly
using iterators.  IMO it is cleaner to use the 1.5 foreach feature.
This patch implements this.

Tom

ChangeLog:
2008-10-16  Tom Tromey  <[EMAIL PROTECTED]>

        * tools/gnu/classpath/tools/jar/WorkSet.java (initSet): Use
        foreach.  Change argument type.
        (WorkSet): Change argument type.
        * tools/gnu/classpath/tools/jar/Indexer.java (indexJarFile): Use
        foreach.
        * tools/gnu/classpath/tools/jar/Creator.java
        (writeCommandLineEntries): Use foreach.
        (getAllEntries): Likewise.

Index: tools/gnu/classpath/tools/jar/Creator.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/tools/gnu/classpath/tools/jar/Creator.java,v
retrieving revision 1.8
diff -u -r1.8 Creator.java
--- tools/gnu/classpath/tools/jar/Creator.java  26 May 2008 19:03:41 -0000      
1.8
+++ tools/gnu/classpath/tools/jar/Creator.java  16 Oct 2008 17:12:45 -0000
@@ -1,5 +1,5 @@
 /* Creator.java - create a new jar file
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2008 Free Software Foundation, Inc.
 
  This file is part of GNU Classpath.
 
@@ -49,7 +49,6 @@
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
@@ -179,13 +178,9 @@
 
   private ArrayList<Entry> getAllEntries(Main parameters)
   {
-    Iterator it = parameters.entries.iterator();
     ArrayList<Entry> allEntries = new ArrayList<Entry>();
-    while (it.hasNext())
-      {
-        Entry entry = (Entry) it.next();
-        addEntries(allEntries, entry);
-      }
+    for (Entry entry : parameters.entries)
+      addEntries(allEntries, entry);
     return allEntries;
   }
 
@@ -196,13 +191,9 @@
     writtenItems.add("META-INF/"); //$NON-NLS-1$
     writtenItems.add(JarFile.MANIFEST_NAME);
 
-    ArrayList allEntries = getAllEntries(parameters);
-    Iterator it = allEntries.iterator();
-    while (it.hasNext())
-      {
-        Entry entry = (Entry) it.next();
-        writeFile(entry.file, entry.name, parameters.verbose);
-      }
+    ArrayList<Entry> allEntries = getAllEntries(parameters);
+    for (Entry entry : allEntries)
+      writeFile(entry.file, entry.name, parameters.verbose);
   }
 
   protected Manifest createManifest(Main parameters)
Index: tools/gnu/classpath/tools/jar/Indexer.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/tools/gnu/classpath/tools/jar/Indexer.java,v
retrieving revision 1.7
diff -u -r1.7 Indexer.java
--- tools/gnu/classpath/tools/jar/Indexer.java  7 May 2008 01:45:43 -0000       
1.7
+++ tools/gnu/classpath/tools/jar/Indexer.java  16 Oct 2008 17:12:45 -0000
@@ -1,5 +1,5 @@
 /* Indexer.java -- add index.list file to jar
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -46,7 +46,6 @@
 import java.io.OutputStream;
 import java.text.MessageFormat;
 import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.StringTokenizer;
 import java.util.jar.Attributes;
@@ -90,10 +89,9 @@
         result.append(fileName);
         // Any line ending will do.
         result.append('\n');
-        Iterator i = entries.iterator();
-        while (i.hasNext())
+       for (String s : entries)
           {
-            result.append(i.next());
+            result.append(s);
             result.append('\n');
           }
         // Paragraph break.
Index: tools/gnu/classpath/tools/jar/WorkSet.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/tools/gnu/classpath/tools/jar/WorkSet.java,v
retrieving revision 1.2
diff -u -r1.2 WorkSet.java
--- tools/gnu/classpath/tools/jar/WorkSet.java  15 Dec 2006 19:45:38 -0000      
1.2
+++ tools/gnu/classpath/tools/jar/WorkSet.java  16 Oct 2008 17:12:45 -0000
@@ -1,5 +1,5 @@
 /* WorkSet.java -- Helper to track what files to work on
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -40,21 +40,18 @@
 
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.Iterator;
 
 public class WorkSet
 {
   private HashSet<String> allItems;
 
-  private void initSet(ArrayList entries)
+  private void initSet(ArrayList<Entry> entries)
   {
     if (entries == null || entries.isEmpty())
       return;
     allItems = new HashSet<String>();
-    Iterator it = entries.iterator();
-    while (it.hasNext())
+    for (Entry entry : entries)
       {
-        Entry entry = (Entry) it.next();
         int len = entry.name.length();
         while (len > 0 && entry.name.charAt(len - 1) == '/')
           --len;
@@ -63,7 +60,7 @@
       }
   }
 
-  public WorkSet(ArrayList entries)
+  public WorkSet(ArrayList<Entry> entries)
   {
     initSet(entries);
   }

Reply via email to