harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r518456 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/SerialClob.java test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
Date Thu, 15 Mar 2007 03:33:06 GMT
Author: smishura
Date: Wed Mar 14 20:33:06 2007
New Revision: 518456

URL: http://svn.apache.org/viewvc?view=rev&rev=518456
Log:
Apply patch for HARMONY-3394:
([classlib][sql] Implementation for SerialClob.position(String, long))

Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java?view=diff&rev=518456&r1=518455&r2=518456
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SerialClob.java
Wed Mar 14 20:33:06 2007
@@ -113,8 +113,31 @@
     }
 
     public long position(String searchstr, long start) throws SerialException,
-            SQLException, NotImplementedException {
-        throw new NotImplementedException();
+            SQLException {
+        if (start < 1 || len - (start - 1) < searchstr.length()) {
+            return -1;
+        }
+        char[] pattern = searchstr.toCharArray();
+        for (int i = (int) start - 1; i < len; i++) {
+            if (match(buf, i, pattern)) {
+                return i + 1;
+            }
+        }
+        return -1;
+    }
+
+    /*
+     * Returns true if the chars array contains exactly the same elements from
+     * start position to start + pattern.length as pattern. Otherwise returns
+     * false.
+     */
+    private boolean match(char[] chars, int start, char[] pattern) {
+        for (int i = 0; i < pattern.length;) {
+            if (chars[start++] != pattern[i++]) {
+                return false;
+            }
+        }
+        return true;
     }
 
     public OutputStream setAsciiStream(long pos) throws SerialException,

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java?view=diff&rev=518456&r1=518455&r2=518456
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialClobTest.java
Wed Mar 14 20:33:06 2007
@@ -150,8 +150,34 @@
         // TODO: Not yet implemented
     }
 
-    public void testPositionLStringJ() {
-        // TODO: Not yet implemented
+    public void testPositionLStringJ() throws Exception {
+        String s = "helloo";
+        char[] buf = s.toCharArray();
+        SerialClob serialClob = new SerialClob(buf);
+        
+        long pos = serialClob.position("llo", 1);
+        assertEquals(3, pos);
+        
+        pos = serialClob.position("llo", 3);
+        assertEquals(3, pos);
+        
+        pos = serialClob.position("o", 6);
+        assertEquals(6, pos);
+        
+        pos = serialClob.position("ooooooo", 1);
+        assertEquals(-1, pos);
+        
+        pos = serialClob.position("llo", 4);
+        assertEquals(-1, pos);
+        
+        pos = serialClob.position("llo", 0);
+        assertEquals(-1, pos);
+        
+        pos = serialClob.position("llo", -1);
+        assertEquals(-1, pos);
+        
+        pos = serialClob.position("llo", 10);
+        assertEquals(-1, pos);
     }
 
     public void testSetAsciiStream() {



Mime
View raw message