You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gh...@apache.org on 2006/06/29 22:18:29 UTC

svn commit: r418129 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Scanner.java test/java/tests/api/java/util/ScannerTest.java

Author: gharley
Date: Thu Jun 29 13:18:29 2006
New Revision: 418129

URL: http://svn.apache.org/viewvc?rev=418129&view=rev
Log:
HARMONY 705 : Implementation of java.util.Scanner.next(String)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Scanner.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ScannerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Scanner.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Scanner.java?rev=418129&r1=418128&r2=418129&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Scanner.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Scanner.java Thu Jun 29 13:18:29 2006
@@ -444,9 +444,26 @@
         }
     }
 
-    //TODO: To implement this feature
+    /**
+     * Returns the next token which is prefixed and postfixed by input that
+     * matches the delimiter pattern if this token matches the pattern
+     * constructed from the sepcified string. This method may be blocked when it
+     * is waiting for input to scan. If this match successes, the scanner
+     * advances past the nest token that matched the pattern.
+     * 
+     * The invocation of this method in the form next(pattern) behaves in the
+     * same way as the invocaiton of next(Pattern.compile(pattern)).
+     * 
+     * @param pattern
+     *            the string specifying the pattern to scan for
+     * @return the next token
+     * @throws IllegalStateException
+     *             if this scanner has been closed
+     * @throws NoSuchElementException
+     *             if input has been exhausted
+     */
     public String next(String pattern) {
-        throw new NotYetImplementedException();
+        return next(Pattern.compile(pattern));
     }
 
     //TODO: To implement this feature

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ScannerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ScannerTest.java?rev=418129&r1=418128&r2=418129&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ScannerTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/ScannerTest.java Thu Jun 29 13:18:29 2006
@@ -516,6 +516,54 @@
         }
     }
 
+    /**
+     * @throws IOException
+     * @tests java.util.Scanner#next(String)
+     */
+    public void test_nextLString() throws IOException {
+        s = new Scanner("b*a*").useDelimiter("\\*");
+        assertEquals("b", s.next("a*b"));
+        try {
+            s.next("a*b");
+            fail("should throw InputMismatchException");
+        } catch (InputMismatchException e) {
+            // Expected
+        }
+
+        s = new Scanner("word ? ");
+        assertEquals("word", s.next("\\w+"));
+        try {
+            s.next("\\w+");
+            fail("should throw InputMismatchException");
+        } catch (InputMismatchException e) {
+            // Expected
+        }
+
+        s = new Scanner("word1 next  ");
+        assertEquals("word1", s.next("\\w+"));
+        assertEquals("next", s.next("\\w+"));
+        // test boundary case
+        try {
+            s.next("\\w+");
+            fail("should throw NoSuchElementException");
+        } catch (NoSuchElementException e) {
+            // Expected
+        }
+
+        // test socket inputStream
+        os.write("aab 2".getBytes());
+        serverSocket.close();
+
+        s = new Scanner(client);
+        assertEquals("aab", s.next("a*b"));
+        try {
+            s.next("a*b");
+            fail("should throw InputMismatchException");
+        } catch (InputMismatchException e) {
+            // Expected
+        }
+    }
+    
     public void setUp() throws Exception {
         super.setUp();