commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1169520 - in /commons/proper/io/trunk/src/test/java/org/apache/commons/io: ./ filefilter/ input/ output/ testtools/
Date Sun, 11 Sep 2011 20:09:48 GMT
Author: ggregory
Date: Sun Sep 11 20:09:47 2011
New Revision: 1169520

URL: http://svn.apache.org/viewvc?rev=1169520&view=rev
Log:
Convert to Java 5 enhanced for loops.

Modified:
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/DemuxTestCase.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/DemuxTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/DemuxTestCase.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/DemuxTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/DemuxTestCase.java Sun Sep
11 20:09:47 2011
@@ -223,12 +223,11 @@ public class DemuxTestCase
         public void run()
         {
             m_demux.bindStream( m_output );
-            for( int i = 0; i < m_data.length; i++ )
-            {
+            for (byte element : m_data) {
                 try
                 {
                     //System.out.println( "Writing: " + (char)m_data[ i ] );
-                    m_demux.write( m_data[ i ] );
+                    m_demux.write( element );
                     int sleepTime = Math.abs( c_random.nextInt() % 10 );
                     Thread.sleep( sleepTime );
                 }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/DirectoryWalkerTestCase.java
Sun Sep 11 20:09:47 2011
@@ -21,7 +21,6 @@ import java.io.FileFilter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.Assert;
@@ -246,8 +245,7 @@ public class DirectoryWalkerTestCase ext
      */
     private List<File> directoriesOnly(Collection<File> results) {
         List<File> list = new ArrayList<File>(results.size());
-        for (Iterator<File> it = results.iterator(); it.hasNext(); ) {
-            File file = it.next();
+        for (File file : results) {
             if (file.isDirectory()) {
                 list.add(file);
             }
@@ -260,8 +258,7 @@ public class DirectoryWalkerTestCase ext
      */
     private List<File> filesOnly(Collection<File> results) {
         List<File> list = new ArrayList<File>(results.size());
-        for (Iterator<File> it = results.iterator(); it.hasNext(); ) {
-            File file = it.next();
+        for (File file : results) {
             if (file.isFile()) {
                 list.add(file);
             }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/EndianUtilsTest.java Sun Sep
11 20:09:47 2011
@@ -262,20 +262,20 @@ public class EndianUtilsTest extends Tes
     public void testSymmetryOfLong() {
 
         double[] tests = new double[] {34.345, -345.5645, 545.12, 10.043, 7.123456789123};
-        for (int i = 0; i< tests.length ;i++) {
+        for (double test : tests) {
 
             // testing the real problem
             byte[] buffer = new byte[8];
-            long ln1 = Double.doubleToLongBits( tests[i] );
+            long ln1 = Double.doubleToLongBits( test );
             EndianUtils.writeSwappedLong(buffer, 0, ln1);
             long ln2 = EndianUtils.readSwappedLong(buffer, 0);
             assertEquals( ln1, ln2 );
 
             // testing the bug report
             buffer = new byte[8];
-            EndianUtils.writeSwappedDouble(buffer, 0, tests[i]);
+            EndianUtils.writeSwappedDouble(buffer, 0, test);
             double val = EndianUtils.readSwappedDouble(buffer, 0);
-            assertEquals( tests[i], val, 0 );
+            assertEquals( test, val, 0 );
         }
     }
 

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FilenameUtilsWildcardTestCase.java
Sun Sep 11 20:09:47 2011
@@ -229,8 +229,8 @@ public class FilenameUtilsWildcardTestCa
 
         try {
             for (int i = 0; i < data.length; i++) {
-                for (int j = 0; j < locales.length; j++) {
-                    Locale.setDefault(locales[j]);
+                for (Locale locale : locales) {
+                    Locale.setDefault(locale);
                     assertTrue("Test data corrupt: " + i, data[i][0].equalsIgnoreCase(data[i][1]));
                     boolean match = FilenameUtils.wildcardMatch(data[i][0], data[i][1], IOCase.INSENSITIVE);
                     assertTrue(Locale.getDefault().toString() + ": " + i, match);

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/ConditionalFileFilterAbstractTestCase.java
Sun Sep 11 20:09:47 2011
@@ -18,7 +18,6 @@ package org.apache.commons.io.filefilter
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 public abstract class ConditionalFileFilterAbstractTestCase
@@ -63,8 +62,7 @@ public abstract class ConditionalFileFil
       fileFilter.addFileFilter(filters.get(i));
       assertEquals("file filters count: ", i+1, fileFilter.getFileFilters().size());
     }
-    for(Iterator<IOFileFilter> iter = fileFilter.getFileFilters().iterator(); iter.hasNext();)
{
-      IOFileFilter filter = iter.next();
+    for (IOFileFilter filter : fileFilter.getFileFilters()) {
       assertTrue("found file filter", filters.contains(filter));
     }
     assertEquals("file filters count", filters.size(), fileFilter.getFileFilters().size());

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/filefilter/IOFileFilterAbstractTestCase.java
Sun Sep 11 20:09:47 2011
@@ -86,17 +86,17 @@ public abstract class IOFileFilterAbstra
   }
 
   public void resetFalseFilters(TesterFalseFileFilter[] filters) {
-    for(int i = 0; i < filters.length; i++) {
-      if(filters[i] != null) {
-        filters[i].reset();
+    for (TesterFalseFileFilter filter : filters) {
+      if(filter != null) {
+        filter.reset();
       }
     }
   }
   
   public void resetTrueFilters(TesterTrueFileFilter[] filters) {
-    for(int i = 0; i < filters.length; i++) {
-      if(filters[i] != null) {
-        filters[i].reset();
+    for (TesterTrueFileFilter filter : filters) {
+      if(filter != null) {
+        filter.reset();
       }
     }
   }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/AutoCloseInputStreamTest.java
Sun Sep 11 20:09:47 2011
@@ -59,8 +59,8 @@ public class AutoCloseInputStreamTest ex
      * Test the <code>read()</code> method.
      */
     public void testRead() throws IOException {
-        for (int i = 0; i < data.length; i++) {
-            assertEquals("read()", data[i], stream.read());
+        for (byte element : data) {
+            assertEquals("read()", element, stream.read());
             assertFalse("closed", closed);
         }
         assertEquals("read()", -1, stream.read());

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
Sun Sep 11 20:09:47 2011
@@ -44,11 +44,11 @@ public class ReaderInputStreamTest {
     private void testWithSingleByteRead(String testString, String charsetName) throws IOException
{
         byte[] bytes = testString.getBytes(charsetName);
         ReaderInputStream in = new ReaderInputStream(new StringReader(testString), charsetName);
-        for (int i=0; i<bytes.length; i++) {
+        for (byte b : bytes) {
             int read = in.read();
             assertTrue(read >= 0);
             assertTrue(read <= 255);
-            assertEquals(bytes[i], (byte)read);
+            assertEquals(b, (byte)read);
         }
         assertEquals(-1, in.read());
     }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
Sun Sep 11 20:09:47 2011
@@ -366,8 +366,8 @@ public class XmlStreamReaderTest extends
         if (bom == null) {
             bom = new int[0];
         }
-        for (int i = 0; i < bom.length; i++) {
-            baos.write(bom[i]);
+        for (int element : bom) {
+            baos.write(element);
         }
         Writer writer = new OutputStreamWriter(baos, streamEnc);
         String xmlDoc = getXML(bomType, xmlType, streamEnc, prologEnc);

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/ByteArrayOutputStreamTestCase.java
Sun Sep 11 20:09:47 2011
@@ -61,8 +61,8 @@ public class ByteArrayOutputStreamTestCa
                 java.io.ByteArrayOutputStream ref, 
                 int[] instructions) {
         int written = 0;
-        for (int i = 0; i < instructions.length; i++) {
-            written += writeData(baout, ref, instructions[i]);
+        for (int instruction : instructions) {
+            written += writeData(baout, ref, instruction);
         }
         return written;
     }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/output/WriterOutputStreamTest.java
Sun Sep 11 20:09:47 2011
@@ -40,8 +40,8 @@ public class WriterOutputStreamTest exte
         byte[] bytes = testString.getBytes(charsetName);
         StringWriter writer = new StringWriter();
         WriterOutputStream out = new WriterOutputStream(writer, charsetName);
-        for (int i=0; i<bytes.length; i++) {
-            out.write(bytes[i]);
+        for (byte b : bytes) {
+            out.write(b);
         }
         out.close();
         assertEquals(testString, writer.toString());

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java?rev=1169520&r1=1169519&r2=1169520&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/testtools/FileBasedTestCase.java
Sun Sep 11 20:09:47 2011
@@ -98,8 +98,8 @@ public abstract class FileBasedTestCase 
         }
         PrintWriter output = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file),
"UTF-8"));
         try {
-            for (int i = 0; i < data.length; i++) {
-                output.println(data[i]);
+            for (String element : data) {
+                output.println(element);
             }
         } finally {
             IOUtils.closeQuietly(output);



Mime
View raw message