Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 6218 invoked from network); 15 Mar 2006 15:11:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 15 Mar 2006 15:11:29 -0000 Received: (qmail 32989 invoked by uid 500); 15 Mar 2006 15:11:28 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 32953 invoked by uid 500); 15 Mar 2006 15:11:28 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 32941 invoked by uid 99); 15 Mar 2006 15:11:28 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Mar 2006 07:11:28 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 15 Mar 2006 07:11:23 -0800 Received: (qmail 4902 invoked by uid 65534); 15 Mar 2006 15:10:45 -0000 Message-ID: <20060315151044.4857.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r386087 [33/45] - in /incubator/harmony/enhanced/classlib/trunk: make/ make/patternsets/ modules/jndi/ modules/jndi/META-INF/ modules/jndi/make/ modules/jndi/make/common/ modules/jndi/src/ modules/jndi/src/main/ modules/jndi/src/main/java/ ... Date: Wed, 15 Mar 2006 14:57:17 -0000 To: harmony-commits@incubator.apache.org From: tellison@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternTests.java URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternTests.java?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternTests.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/PatternTests.java Wed Mar 15 06:55:38 2006 @@ -0,0 +1,1549 @@ +/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.api.java.util.regex; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import junit.framework.TestCase; + +/** + * Tests simple Pattern compilation and Matcher methods + * + */ +public class PatternTests extends TestCase { + public void testSimpleMatch() { + Pattern p; + + try { + p = Pattern.compile("foo.*"); + + Matcher m1 = p.matcher("foo123"); + assertTrue(m1.matches()); + assertTrue(m1.find(0)); + assertTrue(m1.lookingAt()); + + Matcher m2 = p.matcher("fox"); + assertFalse(m2.matches()); + assertFalse(m2.find(0)); + assertFalse(m2.lookingAt()); + + assertTrue(Pattern.matches("foo.*", "foo123")); + assertFalse(Pattern.matches("foo.*", "fox")); + + assertFalse(Pattern.matches("bar", "foobar")); + + assertTrue(Pattern.matches("", "")); + + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testCursors() { + Pattern p; + Matcher m; + + try { + p = Pattern.compile("foo"); + + m = p.matcher("foobar"); + assertTrue(m.find()); + assertTrue(m.start() == 0); + assertTrue(m.end() == 3); + assertFalse(m.find()); + + // Note: also testing reset here + m.reset(); + assertTrue(m.find()); + assertTrue(m.start() == 0); + assertTrue(m.end() == 3); + assertFalse(m.find()); + + m.reset("barfoobar"); + assertTrue(m.find()); + assertTrue(m.start() == 3); + assertTrue(m.end() == 6); + assertFalse(m.find()); + + m.reset("barfoo"); + assertTrue(m.find()); + assertTrue(m.start() == 3); + assertTrue(m.end() == 6); + assertFalse(m.find()); + + m.reset("foobarfoobarfoo"); + assertTrue(m.find()); + assertTrue(m.start() == 0); + assertTrue(m.end() == 3); + assertTrue(m.find()); + assertTrue(m.start() == 6); + assertTrue(m.end() == 9); + assertTrue(m.find()); + assertTrue(m.start() == 12); + assertTrue(m.end() == 15); + assertFalse(m.find()); + assertTrue(m.find(0)); + assertTrue(m.start() == 0); + assertTrue(m.end() == 3); + assertTrue(m.find(4)); + assertTrue(m.start() == 6); + assertTrue(m.end() == 9); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testGroups() { + Pattern p; + Matcher m; + + try { + p = Pattern.compile("(p[0-9]*)#?(q[0-9]*)"); + + m = p.matcher("p1#q3p2q42p5p71p63#q888"); + assertTrue(m.find()); + assertTrue(m.start() == 0); + assertTrue(m.end() == 5); + assertTrue(m.groupCount() == 2); + assertTrue(m.start(0) == 0); + assertTrue(m.end(0) == 5); + assertTrue(m.start(1) == 0); + assertTrue(m.end(1) == 2); + assertTrue(m.start(2) == 3); + assertTrue(m.end(2) == 5); + assertTrue(m.group().equals("p1#q3")); + assertTrue(m.group(0).equals("p1#q3")); + assertTrue(m.group(1).equals("p1")); + assertTrue(m.group(2).equals("q3")); + + assertTrue(m.find()); + assertTrue(m.start() == 5); + assertTrue(m.end() == 10); + assertTrue(m.groupCount() == 2); + assertTrue(m.end(0) == 10); + assertTrue(m.start(1) == 5); + assertTrue(m.end(1) == 7); + assertTrue(m.start(2) == 7); + assertTrue(m.end(2) == 10); + assertTrue(m.group().equals("p2q42")); + assertTrue(m.group(0).equals("p2q42")); + assertTrue(m.group(1).equals("p2")); + assertTrue(m.group(2).equals("q42")); + + assertTrue(m.find()); + assertTrue(m.start() == 15); + assertTrue(m.end() == 23); + assertTrue(m.groupCount() == 2); + assertTrue(m.start(0) == 15); + assertTrue(m.end(0) == 23); + assertTrue(m.start(1) == 15); + assertTrue(m.end(1) == 18); + assertTrue(m.start(2) == 19); + assertTrue(m.end(2) == 23); + assertTrue(m.group().equals("p63#q888")); + assertTrue(m.group(0).equals("p63#q888")); + assertTrue(m.group(1).equals("p63")); + assertTrue(m.group(2).equals("q888")); + assertFalse(m.find()); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testReplace() { + Pattern p; + Matcher m; + + // Note: examples from book, + // Hitchens, Ron, 2002, "Java NIO", O'Reilly, page 171 + try { + p = Pattern.compile("a*b"); + + m = p.matcher("aabfooaabfooabfoob"); + assertTrue(m.replaceAll("-").equals("-foo-foo-foo-")); + assertTrue(m.replaceFirst("-").equals("-fooaabfooabfoob")); + + /* + * p = Pattern.compile ("\\p{Blank}"); + * + * m = p.matcher ("fee fie foe fum"); assertTrue + * (m.replaceFirst("-").equals ("fee-fie foe fum")); assertTrue + * (m.replaceAll("-").equals ("fee-fie-foe-fum")); + */ + + p = Pattern.compile("([bB])yte"); + + m = p.matcher("Byte for byte"); + assertTrue(m.replaceFirst("$1ite").equals("Bite for byte")); + assertTrue(m.replaceAll("$1ite").equals("Bite for bite")); + + p = Pattern.compile("\\d\\d\\d\\d([- ])"); + + m = p.matcher("card #1234-5678-1234"); + assertTrue(m.replaceFirst("xxxx$1").equals("card #xxxx-5678-1234")); + assertTrue(m.replaceAll("xxxx$1").equals("card #xxxx-xxxx-1234")); + + p = Pattern.compile("(up|left)( *)(right|down)"); + + m = p.matcher("left right, up down"); + assertTrue(m.replaceFirst("$3$2$1").equals("right left, up down")); + assertTrue(m.replaceAll("$3$2$1").equals("right left, down up")); + + p = Pattern.compile("([CcPp][hl]e[ea]se)"); + + m = p.matcher("I want cheese. Please."); + assertTrue(m.replaceFirst(" $1 ").equals( + "I want cheese . Please.")); + assertTrue(m.replaceAll(" $1 ").equals( + "I want cheese . Please .")); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testEscapes() { + Pattern p; + Matcher m; + boolean triggerError; + + try { + // Test \\ sequence + p = Pattern.compile("([a-z]+)\\\\([a-z]+);"); + m = p.matcher("fred\\ginger;abbott\\costello;jekell\\hyde;"); + assertTrue(m.find()); + assertTrue(m.group(1).equals("fred")); + assertTrue(m.group(2).equals("ginger")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("abbott")); + assertTrue(m.group(2).equals("costello")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("jekell")); + assertTrue(m.group(2).equals("hyde")); + assertFalse(m.find()); + + // Test \n, \t, \r, \f, \e, \a sequences + p = Pattern.compile("([a-z]+)[\\n\\t\\r\\f\\e\\a]+([a-z]+)"); + m = p.matcher("aa\nbb;cc\u0009\rdd;ee\u000C\u001Bff;gg\n\u0007hh"); + assertTrue(m.find()); + assertTrue(m.group(1).equals("aa")); + assertTrue(m.group(2).equals("bb")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("cc")); + assertTrue(m.group(2).equals("dd")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("ee")); + assertTrue(m.group(2).equals("ff")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("gg")); + assertTrue(m.group(2).equals("hh")); + assertFalse(m.find()); + + // Test \\u and \\x sequences + p = Pattern.compile("([0-9]+)[\\u0020:\\x21];"); + m = p.matcher("11:;22 ;33-;44!;"); + assertTrue(m.find()); + assertTrue(m.group(1).equals("11")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("22")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("44")); + assertFalse(m.find()); + + // Test invalid unicode sequences + triggerError = false; + try { + p = Pattern.compile("\\u"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\u;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\u002"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\u002;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + + // Test invalid hex sequences + triggerError = false; + try { + p = Pattern.compile("\\x"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\x;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\xa"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\xa;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + + // Test \0 (octal) sequences (1, 2 and 3 digit) + p = Pattern.compile("([0-9]+)[\\07\\040\\0160];"); + m = p.matcher("11\u0007;22:;33 ;44p;"); + assertTrue(m.find()); + assertTrue(m.group(1).equals("11")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("33")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("44")); + assertFalse(m.find()); + + // Test invalid octal sequences + triggerError = false; + try { + p = Pattern.compile("\\08"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\0477"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + triggerError = false; + try { + p = Pattern.compile("\\0"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\0;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + + // Test \c (control character) sequence + p = Pattern.compile("([0-9]+)[\\cA\\cB\\cC\\cD];"); + m = p.matcher("11\u0001;22:;33\u0002;44p;55\u0003;66\u0004;"); + assertTrue(m.find()); + assertTrue(m.group(1).equals("11")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("33")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("55")); + assertTrue(m.find()); + assertTrue(m.group(1).equals("66")); + assertFalse(m.find()); + + // More thorough control escape test + // Ensure that each escape matches exactly the corresponding + // character + // code and no others (well, from 0-255 at least) + int i, j; + for (i = 0; i < 26; i++) { + p = Pattern.compile("\\c" + + Character.toString((char) ('A' + i))); + int match_char = -1; + for (j = 0; j < 255; j++) { + m = p.matcher(Character.toString((char) j)); + if (m.matches()) { + assertTrue(match_char == -1); + match_char = j; + } + } + assertTrue(match_char == i + 1); + } + + // Test invalid control escapes + triggerError = false; + try { + p = Pattern.compile("\\c"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\c;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + triggerError = false; + try { + p = Pattern.compile("\\ca;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + triggerError = false; + try { + p = Pattern.compile("\\c4;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testCharacterClasses() { + Pattern p; + Matcher m; + boolean triggerError; + + try { + // Test one character range + p = Pattern.compile("[p].*[l]"); + m = p.matcher("paul"); + assertTrue(m.matches()); + m = p.matcher("pool"); + assertTrue(m.matches()); + m = p.matcher("pong"); + assertFalse(m.matches()); + m = p.matcher("pl"); + assertTrue(m.matches()); + + // Test two character range + p = Pattern.compile("[pm].*[lp]"); + m = p.matcher("prop"); + assertTrue(m.matches()); + m = p.matcher("mall"); + assertTrue(m.matches()); + m = p.matcher("pong"); + assertFalse(m.matches()); + m = p.matcher("pill"); + assertTrue(m.matches()); + + // Test range including [ and ] + p = Pattern.compile("[<\\[].*[\\]>]"); + m = p.matcher(""); + assertTrue(m.matches()); + m = p.matcher("[bar]"); + assertTrue(m.matches()); + m = p.matcher("{foobar]"); + assertFalse(m.matches()); + m = p.matcher(""); + m = p.matcher(""); + assertTrue(m.matches()); + m = p.matcher(""); + assertFalse(m.matches()); + m = p + .matcher("xyz zzz"); + assertTrue(m.find()); + assertTrue(m.find()); + assertFalse(m.find()); + + // Test \S (not whitespace) + p = Pattern.compile("<[a-z] \\S[0-9][\\S\n]+[^\\S]221>"); + m = p.matcher(""); + assertTrue(m.matches()); + m = p.matcher(""); + assertTrue(m.matches()); + m = p.matcher(""); + assertFalse(m.matches()); + m = p.matcher(""); + assertTrue(m.matches()); + p = Pattern + .compile("<[a-z] \\S[0-9][\\S\n]+[^\\S]221[\\S&&[^abc]]>"); + m = p.matcher(""); + assertTrue(m.matches()); + m = p.matcher(""); + assertTrue(m.matches()); + m = p.matcher(""); + assertFalse(m.matches()); + m = p.matcher(""); + assertFalse(m.matches()); + m = p.matcher(""); + assertFalse(m.matches()); + m = p.matcher(""); + assertTrue(m.matches()); + + // Test \w (ascii word) + p = Pattern.compile("<\\w+\\s[0-9]+;[^\\w]\\w+/[\\w$]+;"); + m = p.matcher(""); + * m = p.matcher(""); assertTrue(m.matches()); m = + * p.matcher(""); assertTrue(m.matches()); m = + * p.matcher(""); assertFalse(m.matches()); + */ + p = Pattern.compile("\\p{Lower}+"); + m = p.matcher("abcdefghijklmnopqrstuvwxyz"); + assertTrue(m.matches()); + + // Invalid uses of \p{Lower} + triggerError = false; + try { + p = Pattern.compile("\\p"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\p;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\p{"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\p{;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\p{Lower"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\p{Lower;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + + // Test \p{Upper} + /* + * FIXME: Requires complex range processing + * p = Pattern.compile("<\\p{Upper}\\d\\P{Upper}:[\\p{Upper}z]\\s[^\\P{Upper}]>"); + * m = p.matcher(""); assertTrue(m.matches()); m = + * p.matcher(""); assertTrue(m.matches()); m = + * p.matcher(""); assertFalse(m.matches()); + */ + p = Pattern.compile("\\p{Upper}+"); + m = p.matcher("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + assertTrue(m.matches()); + + // Invalid uses of \p{Upper} + triggerError = false; + try { + p = Pattern.compile("\\p{Upper"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\p{Upper;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + + // Test \p{ASCII} + /* + * FIXME: Requires complex range processing p = Pattern.compile("<\\p{ASCII}\\d\\P{ASCII}:[\\p{ASCII}\u1234]\\s[^\\P{ASCII}]>"); + * m = p.matcher(""); assertTrue(m.matches()); m = + * p.matcher(""); assertTrue(m.matches()); m = + * p.matcher("<\u00846#:E E>"); assertFalse(m.matches()) + */; + int i; + p = Pattern.compile("\\p{ASCII}"); + for (i = 0; i < 0x80; i++) { + m = p.matcher(Character.toString((char) i)); + assertTrue(m.matches()); + } + for (; i < 0xff; i++) { + m = p.matcher(Character.toString((char) i)); + assertFalse(m.matches()); + } + + // Invalid uses of \p{ASCII} + triggerError = false; + try { + p = Pattern.compile("\\p{ASCII"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + triggerError = false; + try { + p = Pattern.compile("\\p{ASCII;"); + } catch (PatternSyntaxException e) { + triggerError = true; + } + assertTrue(triggerError); + + // Test \p{Alpha} + // TODO + + // Test \p{Digit} + // TODO + + // Test \p{XDigit} + // TODO + + // Test \p{Alnum} + // TODO + + // Test \p{Punct} + // TODO + + // Test \p{Graph} + // TODO + + // Test \p{Print} + // TODO + + // Test \p{Blank} + // TODO + + // Test \p{Space} + // TODO + + // Test \p{Cntrl} + // TODO + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testUnicodeCategories() { + // Test Unicode categories using \p and \P + // One letter codes: L, M, N, P, S, Z, C + // Two letter codes: Lu, Nd, Sc, Sm, ... + // See java.lang.Character and Unicode standard for complete list + // TODO + try { + // Test \p{L} + // TODO + + // Test \p{N} + // TODO + + // ... etc + + // Test two letter codes: + // From unicode.org: + // Lu + // Ll + // Lt + // Lm + // Lo + // Mn + // Mc + // Me + // Nd + // Nl + // No + // Pc + // Pd + // Ps + // Pe + // Pi + // Pf + // Po + // Sm + // Sc + // Sk + // So + // Zs + // Zl + // Zp + // Cc + // Cf + // Cs + // Co + // Cn + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testUnicodeBlocks() { + Pattern p; + Matcher m; + int i, j; + + // Test Unicode blocks using \p and \P + // FIXME: + // Note that LatinExtended-B and ArabicPresentations-B are unrecognized + // by the reference JDK. + try { + for (i = 0; i < UBlocks.length; i++) { + /* + * p = Pattern.compile("\\p{"+UBlocks[i].name+"}"); + * + * if (UBlocks[i].low > 0) { m = + * p.matcher(Character.toString((char)(UBlocks[i].low-1))); + * assertFalse(m.matches()); } for (j=UBlocks[i].low; j <= + * UBlocks[i].high; j++) { m = + * p.matcher(Character.toString((char)j)); + * assertTrue(m.matches()); } if (UBlocks[i].high < 0xFFFF) { m = + * p.matcher(Character.toString((char)(UBlocks[i].high+1))); + * assertFalse(m.matches()); } + * + * p = Pattern.compile("\\P{"+UBlocks[i].name+"}"); + * + * if (UBlocks[i].low > 0) { m = + * p.matcher(Character.toString((char)(UBlocks[i].low-1))); + * assertTrue(m.matches()); } for (j=UBlocks[i].low; j < + * UBlocks[i].high; j++) { m = + * p.matcher(Character.toString((char)j)); + * assertFalse(m.matches()); } if (UBlocks[i].high < 0xFFFF) { m = + * p.matcher(Character.toString((char)(UBlocks[i].high+1))); + * assertTrue(m.matches()); } + */ + + p = Pattern.compile("\\p{In" + UBlocks[i].name + "}"); + + if (UBlocks[i].low > 0) { + m = p.matcher(Character + .toString((char) (UBlocks[i].low - 1))); + assertFalse(m.matches()); + } + for (j = UBlocks[i].low; j <= UBlocks[i].high; j++) { + m = p.matcher(Character.toString((char) j)); + assertTrue(m.matches()); + } + if (UBlocks[i].high < 0xFFFF) { + m = p.matcher(Character + .toString((char) (UBlocks[i].high + 1))); + assertFalse(m.matches()); + } + + p = Pattern.compile("\\P{In" + UBlocks[i].name + "}"); + + if (UBlocks[i].low > 0) { + m = p.matcher(Character + .toString((char) (UBlocks[i].low - 1))); + assertTrue(m.matches()); + } + for (j = UBlocks[i].low; j < UBlocks[i].high; j++) { + m = p.matcher(Character.toString((char) j)); + assertFalse(m.matches()); + } + if (UBlocks[i].high < 0xFFFF) { + m = p.matcher(Character + .toString((char) (UBlocks[i].high + 1))); + assertTrue(m.matches()); + } + } + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testCapturingGroups() { + try { + // Test simple capturing groups + // TODO + + // Test grouping without capture (?:...) + // TODO + + // Test combination of grouping and capture + // TODO + + // Test \ sequence with capturing and non-capturing groups + // TODO + + // Test \ with out of range + // TODO + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testRepeats() { + try { + // Test ? + // TODO + + // Test * + // TODO + + // Test + + // TODO + + // Test {}, including 0, 1 and more + // TODO + + // Test {,}, including 0, 1 and more + // TODO + + // Test {,}, with n1 < n2, n1 = n2 and n1 > n2 (illegal?) + // TODO + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testAnchors() { + try { + // Test ^, default and MULTILINE + // TODO + + // Test $, default and MULTILINE + // TODO + + // Test \b (word boundary) + // TODO + + // Test \B (not a word boundary) + // TODO + + // Test \A (beginning of string) + // TODO + + // Test \Z (end of string) + // TODO + + // Test \z (end of string) + // TODO + + // Test \G + // TODO + + // Test positive lookahead using (?=...) + // TODO + + // Test negative lookahead using (?!...) + // TODO + + // Test positive lookbehind using (?<=...) + // TODO + + // Test negative lookbehind using (?...) + // TODO + + // Test (?onflags-offflags) + // Valid flags are i,m,d,s,u,x + // TODO + + // Test (?onflags-offflags:...) + // TODO + + // Test \Q, \E + p = Pattern.compile("[a-z]+;\\Q[a-z]+;\\Q(foo.*);\\E[0-9]+"); + m = p.matcher("abc;[a-z]+;\\Q(foo.*);411"); + assertTrue(m.matches()); + m = p.matcher("abc;def;foo42;555"); + assertFalse(m.matches()); + m = p.matcher("abc;\\Qdef;\\Qfoo99;\\E123"); + assertFalse(m.matches()); + + p = Pattern.compile("[a-z]+;(foo[0-9]-\\Q(...)\\E);[0-9]+"); + m = p.matcher("abc;foo5-(...);123"); + assertTrue(m.matches()); + assertTrue(m.group(1).equals("foo5-(...)")); + m = p.matcher("abc;foo9-(xxx);789"); + assertFalse(m.matches()); + + p = Pattern.compile("[a-z]+;(bar[0-9]-[a-z\\Q$-\\E]+);[0-9]+"); + m = p.matcher("abc;bar0-def$-;123"); + assertTrue(m.matches()); + + // FIXME: + // This should work the same as the pattern above but fails with the + // the reference JDK + p = Pattern.compile("[a-z]+;(bar[0-9]-[a-z\\Q-$\\E]+);[0-9]+"); + m = p.matcher("abc;bar0-def$-;123"); + // assertTrue(m.matches()); + + // FIXME: + // This should work too .. it looks as if just about anything that + // has more + // than one character between \Q and \E is broken in the the reference JDK + p = Pattern.compile("[a-z]+;(bar[0-9]-[a-z\\Q[0-9]\\E]+);[0-9]+"); + m = p.matcher("abc;bar0-def[99]-]0x[;123"); + // assertTrue(m.matches()); + + // This is the same as above but with explicit escapes .. and this + // does work + // on the the reference JDK + p = Pattern.compile("[a-z]+;(bar[0-9]-[a-z\\[0\\-9\\]]+);[0-9]+"); + m = p.matcher("abc;bar0-def[99]-]0x[;123"); + assertTrue(m.matches()); + + // Test # + // TODO + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testCompile1() { + try { + Pattern pattern = Pattern + .compile("[0-9A-Za-z][0-9A-Za-z\\x2e\\x3a\\x2d\\x5f]*"); + String name = "iso-8859-1"; + assertTrue(pattern.matcher(name).matches()); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testCompile2() { + String findString = "\\Qimport\\E"; + + try { + Pattern pattern = Pattern.compile(findString, 0); + Matcher matcher = pattern.matcher(new String( + "import a.A;\n\n import b.B;\nclass C {}")); + + assertTrue(matcher.find(0)); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + public void testCompile3() { + Pattern p; + Matcher m; + try { + p = Pattern.compile("a$"); + m = p.matcher("a\n"); + assertTrue(m.find()); + assertTrue(m.group().equals("a")); + assertFalse(m.find()); + + p = Pattern.compile("(a$)"); + m = p.matcher("a\n"); + assertTrue(m.find()); + assertTrue(m.group().equals("a")); + assertTrue(m.group(1).equals("a")); + assertFalse(m.find()); + + p = Pattern.compile("^.*$", Pattern.MULTILINE); + + m = p.matcher("a\n"); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("a")); + assertFalse(m.find()); + + m = p.matcher("a\nb\n"); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("a")); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("b")); + assertFalse(m.find()); + + m = p.matcher("a\nb"); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("a")); + assertTrue(m.find()); + assertTrue(m.group().equals("b")); + assertFalse(m.find()); + + m = p.matcher("\naa\r\nbb\rcc\n\n"); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("")); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("aa")); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("bb")); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("cc")); + assertTrue(m.find()); + // System.out.println("["+m.group()+"]"); + assertTrue(m.group().equals("")); + assertFalse(m.find()); + + m = p.matcher("a"); + assertTrue(m.find()); + assertTrue(m.group().equals("a")); + assertFalse(m.find()); + + m = p.matcher(""); + // FIXME: This matches the reference behaviour but is + // inconsistent with matching "a" - ie. the end of the + // target string should match against $ always but this + // appears to work with the null string only when not in + // multiline mode (see below) + assertFalse(m.find()); + + p = Pattern.compile("^.*$"); + m = p.matcher(""); + assertTrue(m.find()); + assertTrue(m.group().equals("")); + assertFalse(m.find()); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + assertTrue(false); + } + } + + public void testCompile4() { + String findString = "\\Qpublic\\E"; + StringBuffer text = new StringBuffer(" public class Class {\n" + + " public class Class {"); + + Pattern pattern = Pattern.compile(findString, 0); + Matcher matcher = pattern.matcher(text); + + boolean found = matcher.find(); + assertTrue(found); + assertTrue(matcher.start() == 4); + if (found) { + // modify text + text.delete(0, text.length()); + text.append("Text have been changed."); + } + + found = matcher.find(); + assertFalse(found); + } + + public void testCompile5() { + Pattern p = Pattern.compile("^[0-9]"); + String s[] = p.split("12", -1); + assertEquals("", s[0]); + assertEquals("2", s[1]); + assertEquals(2, s.length); + } + + +// public void testCompile6() { +// String regex = "[\\p{L}[\\p{Mn}[\\p{Pc}[\\p{Nd}[\\p{Nl}[\\p{Sc}]]]]]]+"; +// String regex = "[\\p{L}\\p{Mn}\\p{Pc}\\p{Nd}\\p{Nl}\\p{Sc}]+"; +// try { +// Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); +// assertTrue(true); +// } catch (PatternSyntaxException e) { +// System.out.println(e.getMessage()); +// assertTrue(false); +// } +// } + + + private static class UBInfo { + public UBInfo(int low, int high, String name) { + this.name = name; + this.low = low; + this.high = high; + } + + public String name; + + public int low, high; + } + + // A table representing the unicode categories + //private static UBInfo[] UCategories = { + // Lu + // Ll + // Lt + // Lm + // Lo + // Mn + // Mc + // Me + // Nd + // Nl + // No + // Pc + // Pd + // Ps + // Pe + // Pi + // Pf + // Po + // Sm + // Sc + // Sk + // So + // Zs + // Zl + // Zp + // Cc + // Cf + // Cs + // Co + // Cn + //}; + + // A table representing the unicode character blocks + private static UBInfo[] UBlocks = { + /* 0000; 007F; Basic Latin */ + new UBInfo(0x0000, 0x007F, "BasicLatin"), // Character.UnicodeBlock.BASIC_LATIN + /* 0080; 00FF; Latin-1 Supplement */ + new UBInfo(0x0080, 0x00FF, "Latin-1Supplement"), // Character.UnicodeBlock.LATIN_1_SUPPLEMENT + /* 0100; 017F; Latin Extended-A */ + new UBInfo(0x0100, 0x017F, "LatinExtended-A"), // Character.UnicodeBlock.LATIN_EXTENDED_A + /* 0180; 024F; Latin Extended-B */ + // new UBInfo (0x0180,0x024F,"InLatinExtended-B"), // + // Character.UnicodeBlock.LATIN_EXTENDED_B + /* 0250; 02AF; IPA Extensions */ + new UBInfo(0x0250, 0x02AF, "IPAExtensions"), // Character.UnicodeBlock.IPA_EXTENSIONS + /* 02B0; 02FF; Spacing Modifier Letters */ + new UBInfo(0x02B0, 0x02FF, "SpacingModifierLetters"), // Character.UnicodeBlock.SPACING_MODIFIER_LETTERS + /* 0300; 036F; Combining Diacritical Marks */ + new UBInfo(0x0300, 0x036F, "CombiningDiacriticalMarks"), // Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS + /* 0370; 03FF; Greek */ + new UBInfo(0x0370, 0x03FF, "Greek"), // Character.UnicodeBlock.GREEK + /* 0400; 04FF; Cyrillic */ + new UBInfo(0x0400, 0x04FF, "Cyrillic"), // Character.UnicodeBlock.CYRILLIC + /* 0530; 058F; Armenian */ + new UBInfo(0x0530, 0x058F, "Armenian"), // Character.UnicodeBlock.ARMENIAN + /* 0590; 05FF; Hebrew */ + new UBInfo(0x0590, 0x05FF, "Hebrew"), // Character.UnicodeBlock.HEBREW + /* 0600; 06FF; Arabic */ + new UBInfo(0x0600, 0x06FF, "Arabic"), // Character.UnicodeBlock.ARABIC + /* 0700; 074F; Syriac */ + new UBInfo(0x0700, 0x074F, "Syriac"), // Character.UnicodeBlock.SYRIAC + /* 0780; 07BF; Thaana */ + new UBInfo(0x0780, 0x07BF, "Thaana"), // Character.UnicodeBlock.THAANA + /* 0900; 097F; Devanagari */ + new UBInfo(0x0900, 0x097F, "Devanagari"), // Character.UnicodeBlock.DEVANAGARI + /* 0980; 09FF; Bengali */ + new UBInfo(0x0980, 0x09FF, "Bengali"), // Character.UnicodeBlock.BENGALI + /* 0A00; 0A7F; Gurmukhi */ + new UBInfo(0x0A00, 0x0A7F, "Gurmukhi"), // Character.UnicodeBlock.GURMUKHI + /* 0A80; 0AFF; Gujarati */ + new UBInfo(0x0A80, 0x0AFF, "Gujarati"), // Character.UnicodeBlock.GUJARATI + /* 0B00; 0B7F; Oriya */ + new UBInfo(0x0B00, 0x0B7F, "Oriya"), // Character.UnicodeBlock.ORIYA + /* 0B80; 0BFF; Tamil */ + new UBInfo(0x0B80, 0x0BFF, "Tamil"), // Character.UnicodeBlock.TAMIL + /* 0C00; 0C7F; Telugu */ + new UBInfo(0x0C00, 0x0C7F, "Telugu"), // Character.UnicodeBlock.TELUGU + /* 0C80; 0CFF; Kannada */ + new UBInfo(0x0C80, 0x0CFF, "Kannada"), // Character.UnicodeBlock.KANNADA + /* 0D00; 0D7F; Malayalam */ + new UBInfo(0x0D00, 0x0D7F, "Malayalam"), // Character.UnicodeBlock.MALAYALAM + /* 0D80; 0DFF; Sinhala */ + new UBInfo(0x0D80, 0x0DFF, "Sinhala"), // Character.UnicodeBlock.SINHALA + /* 0E00; 0E7F; Thai */ + new UBInfo(0x0E00, 0x0E7F, "Thai"), // Character.UnicodeBlock.THAI + /* 0E80; 0EFF; Lao */ + new UBInfo(0x0E80, 0x0EFF, "Lao"), // Character.UnicodeBlock.LAO + /* 0F00; 0FFF; Tibetan */ + new UBInfo(0x0F00, 0x0FFF, "Tibetan"), // Character.UnicodeBlock.TIBETAN + /* 1000; 109F; Myanmar */ + new UBInfo(0x1000, 0x109F, "Myanmar"), // Character.UnicodeBlock.MYANMAR + /* 10A0; 10FF; Georgian */ + new UBInfo(0x10A0, 0x10FF, "Georgian"), // Character.UnicodeBlock.GEORGIAN + /* 1100; 11FF; Hangul Jamo */ + new UBInfo(0x1100, 0x11FF, "HangulJamo"), // Character.UnicodeBlock.HANGUL_JAMO + /* 1200; 137F; Ethiopic */ + new UBInfo(0x1200, 0x137F, "Ethiopic"), // Character.UnicodeBlock.ETHIOPIC + /* 13A0; 13FF; Cherokee */ + new UBInfo(0x13A0, 0x13FF, "Cherokee"), // Character.UnicodeBlock.CHEROKEE + /* 1400; 167F; Unified Canadian Aboriginal Syllabics */ + new UBInfo(0x1400, 0x167F, "UnifiedCanadianAboriginalSyllabics"), // Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS + /* 1680; 169F; Ogham */ + new UBInfo(0x1680, 0x169F, "Ogham"), // Character.UnicodeBlock.OGHAM + /* 16A0; 16FF; Runic */ + new UBInfo(0x16A0, 0x16FF, "Runic"), // Character.UnicodeBlock.RUNIC + /* 1780; 17FF; Khmer */ + new UBInfo(0x1780, 0x17FF, "Khmer"), // Character.UnicodeBlock.KHMER + /* 1800; 18AF; Mongolian */ + new UBInfo(0x1800, 0x18AF, "Mongolian"), // Character.UnicodeBlock.MONGOLIAN + /* 1E00; 1EFF; Latin Extended Additional */ + new UBInfo(0x1E00, 0x1EFF, "LatinExtendedAdditional"), // Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL + /* 1F00; 1FFF; Greek Extended */ + new UBInfo(0x1F00, 0x1FFF, "GreekExtended"), // Character.UnicodeBlock.GREEK_EXTENDED + /* 2000; 206F; General Punctuation */ + new UBInfo(0x2000, 0x206F, "GeneralPunctuation"), // Character.UnicodeBlock.GENERAL_PUNCTUATION + /* 2070; 209F; Superscripts and Subscripts */ + new UBInfo(0x2070, 0x209F, "SuperscriptsandSubscripts"), // Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS + /* 20A0; 20CF; Currency Symbols */ + new UBInfo(0x20A0, 0x20CF, "CurrencySymbols"), // Character.UnicodeBlock.CURRENCY_SYMBOLS + /* 20D0; 20FF; Combining Marks for Symbols */ + new UBInfo(0x20D0, 0x20FF, "CombiningMarksforSymbols"), // Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS + /* 2100; 214F; Letterlike Symbols */ + new UBInfo(0x2100, 0x214F, "LetterlikeSymbols"), // Character.UnicodeBlock.LETTERLIKE_SYMBOLS + /* 2150; 218F; Number Forms */ + new UBInfo(0x2150, 0x218F, "NumberForms"), // Character.UnicodeBlock.NUMBER_FORMS + /* 2190; 21FF; Arrows */ + new UBInfo(0x2190, 0x21FF, "Arrows"), // Character.UnicodeBlock.ARROWS + /* 2200; 22FF; Mathematical Operators */ + new UBInfo(0x2200, 0x22FF, "MathematicalOperators"), // Character.UnicodeBlock.MATHEMATICAL_OPERATORS + /* 2300; 23FF; Miscellaneous Technical */ + new UBInfo(0x2300, 0x23FF, "MiscellaneousTechnical"), // Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL + /* 2400; 243F; Control Pictures */ + new UBInfo(0x2400, 0x243F, "ControlPictures"), // Character.UnicodeBlock.CONTROL_PICTURES + /* 2440; 245F; Optical Character Recognition */ + new UBInfo(0x2440, 0x245F, "OpticalCharacterRecognition"), // Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION + /* 2460; 24FF; Enclosed Alphanumerics */ + new UBInfo(0x2460, 0x24FF, "EnclosedAlphanumerics"), // Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS + /* 2500; 257F; Box Drawing */ + new UBInfo(0x2500, 0x257F, "BoxDrawing"), // Character.UnicodeBlock.BOX_DRAWING + /* 2580; 259F; Block Elements */ + new UBInfo(0x2580, 0x259F, "BlockElements"), // Character.UnicodeBlock.BLOCK_ELEMENTS + /* 25A0; 25FF; Geometric Shapes */ + new UBInfo(0x25A0, 0x25FF, "GeometricShapes"), // Character.UnicodeBlock.GEOMETRIC_SHAPES + /* 2600; 26FF; Miscellaneous Symbols */ + new UBInfo(0x2600, 0x26FF, "MiscellaneousSymbols"), // Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS + /* 2700; 27BF; Dingbats */ + new UBInfo(0x2700, 0x27BF, "Dingbats"), // Character.UnicodeBlock.DINGBATS + /* 2800; 28FF; Braille Patterns */ + new UBInfo(0x2800, 0x28FF, "BraillePatterns"), // Character.UnicodeBlock.BRAILLE_PATTERNS + /* 2E80; 2EFF; CJK Radicals Supplement */ + new UBInfo(0x2E80, 0x2EFF, "CJKRadicalsSupplement"), // Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT + /* 2F00; 2FDF; Kangxi Radicals */ + new UBInfo(0x2F00, 0x2FDF, "KangxiRadicals"), // Character.UnicodeBlock.KANGXI_RADICALS + /* 2FF0; 2FFF; Ideographic Description Characters */ + new UBInfo(0x2FF0, 0x2FFF, "IdeographicDescriptionCharacters"), // Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS + /* 3000; 303F; CJK Symbols and Punctuation */ + new UBInfo(0x3000, 0x303F, "CJKSymbolsandPunctuation"), // Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION + /* 3040; 309F; Hiragana */ + new UBInfo(0x3040, 0x309F, "Hiragana"), // Character.UnicodeBlock.HIRAGANA + /* 30A0; 30FF; Katakana */ + new UBInfo(0x30A0, 0x30FF, "Katakana"), // Character.UnicodeBlock.KATAKANA + /* 3100; 312F; Bopomofo */ + new UBInfo(0x3100, 0x312F, "Bopomofo"), // Character.UnicodeBlock.BOPOMOFO + /* 3130; 318F; Hangul Compatibility Jamo */ + new UBInfo(0x3130, 0x318F, "HangulCompatibilityJamo"), // Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO + /* 3190; 319F; Kanbun */ + new UBInfo(0x3190, 0x319F, "Kanbun"), // Character.UnicodeBlock.KANBUN + /* 31A0; 31BF; Bopomofo Extended */ + new UBInfo(0x31A0, 0x31BF, "BopomofoExtended"), // Character.UnicodeBlock.BOPOMOFO_EXTENDED + /* 3200; 32FF; Enclosed CJK Letters and Months */ + new UBInfo(0x3200, 0x32FF, "EnclosedCJKLettersandMonths"), // Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS + /* 3300; 33FF; CJK Compatibility */ + new UBInfo(0x3300, 0x33FF, "CJKCompatibility"), // Character.UnicodeBlock.CJK_COMPATIBILITY + /* 3400; 4DB5; CJK Unified Ideographs Extension A */ + new UBInfo(0x3400, 0x4DB5, "CJKUnifiedIdeographsExtensionA"), // Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A + /* 4E00; 9FFF; CJK Unified Ideographs */ + new UBInfo(0x4E00, 0x9FFF, "CJKUnifiedIdeographs"), // Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS + /* A000; A48F; Yi Syllables */ + new UBInfo(0xA000, 0xA48F, "YiSyllables"), // Character.UnicodeBlock.YI_SYLLABLES + /* A490; A4CF; Yi Radicals */ + new UBInfo(0xA490, 0xA4CF, "YiRadicals"), // Character.UnicodeBlock.YI_RADICALS + /* AC00; D7A3; Hangul Syllables */ + new UBInfo(0xAC00, 0xD7A3, "HangulSyllables"), // Character.UnicodeBlock.HANGUL_SYLLABLES + /* D800; DB7F; High Surrogates */ + /* DB80; DBFF; High Private Use Surrogates */ + /* DC00; DFFF; Low Surrogates */ + /* E000; F8FF; Private Use */ + /* F900; FAFF; CJK Compatibility Ideographs */ + new UBInfo(0xF900, 0xFAFF, "CJKCompatibilityIdeographs"), // Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS + /* FB00; FB4F; Alphabetic Presentation Forms */ + new UBInfo(0xFB00, 0xFB4F, "AlphabeticPresentationForms"), // Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS + /* FB50; FDFF; Arabic Presentation Forms-A */ + new UBInfo(0xFB50, 0xFDFF, "ArabicPresentationForms-A"), // Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A + /* FE20; FE2F; Combining Half Marks */ + new UBInfo(0xFE20, 0xFE2F, "CombiningHalfMarks"), // Character.UnicodeBlock.COMBINING_HALF_MARKS + /* FE30; FE4F; CJK Compatibility Forms */ + new UBInfo(0xFE30, 0xFE4F, "CJKCompatibilityForms"), // Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS + /* FE50; FE6F; Small Form Variants */ + new UBInfo(0xFE50, 0xFE6F, "SmallFormVariants"), // Character.UnicodeBlock.SMALL_FORM_VARIANTS + /* FE70; FEFE; Arabic Presentation Forms-B */ + // new UBInfo (0xFE70,0xFEFE,"InArabicPresentationForms-B"), // + // Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B + /* FEFF; FEFF; Specials */ + new UBInfo(0xFEFF, 0xFEFF, "Specials"), // Character.UnicodeBlock.SPECIALS + /* FF00; FFEF; Halfwidth and Fullwidth Forms */ + new UBInfo(0xFF00, 0xFFEF, "HalfwidthandFullwidthForms"), // Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS + /* FFF0; FFFD; Specials */ + new UBInfo(0xFFF0, 0xFFFD, "Specials") // Character.UnicodeBlock.SPECIALS + }; +} Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ReplaceTests.java URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ReplaceTests.java?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ReplaceTests.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/ReplaceTests.java Wed Mar 15 06:55:38 2006 @@ -0,0 +1,101 @@ +/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.api.java.util.regex; + +import junit.framework.TestCase; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.regex.PatternSyntaxException; + +public class ReplaceTests extends TestCase { + + public void testSimpleReplace() { + String target, pattern, repl, s; + Pattern p = null; + Matcher m; + + target = "foobarfobarfoofo1"; + pattern = "fo[^o]"; + repl = "xxx"; + try { + p = Pattern.compile(pattern); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + m = p.matcher(target); + s = m.replaceFirst(repl); + assertTrue(s.equals("foobarxxxarfoofo1")); + s = m.replaceAll(repl); + assertTrue(s.equals("foobarxxxarfooxxx")); + } + + public void testCaptureReplace() { + String target, pattern, repl, s; + Pattern p = null; + Matcher m; + + target = "[31]foo;bar[42];[99]xyz"; + pattern = "\\[([0-9]+)\\]([a-z]+)"; + repl = "$2[$1]"; + try { + p = Pattern.compile(pattern); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + m = p.matcher(target); + s = m.replaceFirst(repl); + assertTrue(s.equals("foo[31];bar[42];[99]xyz")); + s = m.replaceAll(repl); + assertTrue(s.equals("foo[31];bar[42];xyz[99]")); + + target = "[31]foo(42)bar{63}zoo;[12]abc(34)def{56}ghi;{99}xyz[88]xyz(77)xyz;"; + pattern = "\\[([0-9]+)\\]([a-z]+)\\(([0-9]+)\\)([a-z]+)\\{([0-9]+)\\}([a-z]+)"; + repl = "[$5]$6($3)$4{$1}$2"; + try { + p = Pattern.compile(pattern); + } catch (PatternSyntaxException e) { + System.out.println(e.getMessage()); + fail(); + } + m = p.matcher(target); + s = m.replaceFirst(repl); + // System.out.println(s); + assertTrue(s + .equals("[63]zoo(42)bar{31}foo;[12]abc(34)def{56}ghi;{99}xyz[88]xyz(77)xyz;")); + s = m.replaceAll(repl); + // System.out.println(s); + assertTrue(s + .equals("[63]zoo(42)bar{31}foo;[56]ghi(34)def{12}abc;{99}xyz[88]xyz(77)xyz;")); + } + + public void testEscapeReplace() { + String target, pattern, repl, s; + + target = "foo'bar''foo"; + pattern = "'"; + repl = "\\'"; + s = target.replaceAll(pattern, repl); + assertTrue(s.equals("foo'bar''foo")); + repl = "\\\\'"; + s = target.replaceAll(pattern, repl); + assertTrue(s.equals("foo\\'bar\\'\\'foo")); + repl = "\\$3"; + s = target.replaceAll(pattern, repl); + assertTrue(s.equals("foo$3bar$3$3foo")); + } +} Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/SplitTests.java URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/SplitTests.java?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/SplitTests.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/api/java/util/regex/SplitTests.java Wed Mar 15 06:55:38 2006 @@ -0,0 +1,178 @@ +/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.api.java.util.regex; + +import junit.framework.TestCase; +import java.util.regex.*; + +/** + * TODO Type description + * + */ +public class SplitTests extends TestCase { + + public void testSimple() { + Pattern p = Pattern.compile("/"); + String[] results = p.split("have/you/done/it/right"); + String[] expected = new String[] { "have", "you", "done", "it", "right" }; + assertEquals(expected.length, results.length); + for (int i = 0; i < expected.length; i++) { + assertEquals(results[i], expected[i]); + } + } + + public void testSplit1() { + Pattern p = null; + + // This set of tests comes from the O'Reilly NIO book, page 160 + try { + p = Pattern.compile(" "); + } catch (PatternSyntaxException e) { + fail(); + } + + String input = "poodle zoo"; + String tokens[]; + + tokens = p.split(input, 1); + assertTrue(tokens.length == 1); + assertTrue(tokens[0].equals(input)); + tokens = p.split(input, 2); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poodle")); + assertTrue(tokens[1].equals("zoo")); + tokens = p.split(input, 5); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poodle")); + assertTrue(tokens[1].equals("zoo")); + tokens = p.split(input, -2); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poodle")); + assertTrue(tokens[1].equals("zoo")); + tokens = p.split(input, 0); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poodle")); + assertTrue(tokens[1].equals("zoo")); + tokens = p.split(input); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poodle")); + assertTrue(tokens[1].equals("zoo")); + + try { + p = Pattern.compile("d"); + } catch (PatternSyntaxException e) { + fail(); + return; + } + + tokens = p.split(input, 1); + assertTrue(tokens.length == 1); + assertTrue(tokens[0].equals(input)); + tokens = p.split(input, 2); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poo")); + assertTrue(tokens[1].equals("le zoo")); + tokens = p.split(input, 5); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poo")); + assertTrue(tokens[1].equals("le zoo")); + tokens = p.split(input, -2); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poo")); + assertTrue(tokens[1].equals("le zoo")); + tokens = p.split(input, 0); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poo")); + assertTrue(tokens[1].equals("le zoo")); + tokens = p.split(input); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("poo")); + assertTrue(tokens[1].equals("le zoo")); + + try { + p = Pattern.compile("o"); + } catch (PatternSyntaxException e) { + fail(); + } + + tokens = p.split(input, 1); + assertTrue(tokens.length == 1); + assertTrue(tokens[0].equals(input)); + tokens = p.split(input, 2); + assertTrue(tokens.length == 2); + assertTrue(tokens[0].equals("p")); + assertTrue(tokens[1].equals("odle zoo")); + tokens = p.split(input, 5); + assertTrue(tokens.length == 5); + assertTrue(tokens[0].equals("p")); + assertTrue(tokens[1].equals("")); + assertTrue(tokens[2].equals("dle z")); + assertTrue(tokens[3].equals("")); + assertTrue(tokens[4].equals("")); + tokens = p.split(input, -2); + assertTrue(tokens.length == 5); + assertTrue(tokens[0].equals("p")); + assertTrue(tokens[1].equals("")); + assertTrue(tokens[2].equals("dle z")); + assertTrue(tokens[3].equals("")); + assertTrue(tokens[4].equals("")); + tokens = p.split(input, 0); + assertTrue(tokens.length == 3); + assertTrue(tokens[0].equals("p")); + assertTrue(tokens[1].equals("")); + assertTrue(tokens[2].equals("dle z")); + tokens = p.split(input); + assertTrue(tokens.length == 3); + assertTrue(tokens[0].equals("p")); + assertTrue(tokens[1].equals("")); + assertTrue(tokens[2].equals("dle z")); + } + + public void testSplit2() { + Pattern p = Pattern.compile(""); + String s[]; + s = p.split("a", -1); + assertEquals(3, s.length); + assertEquals("", s[0]); + assertEquals("a", s[1]); + assertEquals("", s[2]); + + s = p.split("", -1); + assertEquals(1, s.length); + assertEquals("", s[0]); + + s = p.split("abcd", -1); + assertEquals(6, s.length); + assertEquals("", s[0]); + assertEquals("a", s[1]); + assertEquals("b", s[2]); + assertEquals("c", s[3]); + assertEquals("d", s[4]); + assertEquals("", s[5]); + + // Match with a surrogate pair .. strangely splits the surrogate pair. I + // would have expected + // the third matched string to be "\ud869\uded6" (aka \u2a6d6) + s = p.split("a\ud869\uded6b", -1); + assertEquals(6, s.length); + assertEquals("", s[0]); + assertEquals("a", s[1]); + assertEquals("\ud869", s[2]); + assertEquals("\uded6", s[3]); + assertEquals("b", s[4]); + assertEquals("", s[5]); + } +} Added: incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/regex/AllTests.java URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/regex/AllTests.java?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/regex/AllTests.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/regex/src/test/java/tests/regex/AllTests.java Wed Mar 15 06:55:38 2006 @@ -0,0 +1,37 @@ +/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tests.regex; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite that includes all tests for the Regex project. + */ +public class AllTests { + + public static void main(String[] args) { + junit.textui.TestRunner.run(AllTests.suite()); + } + + public static Test suite() { + TestSuite suite = new TestSuite("All Regex test suites"); + // $JUnit-BEGIN$ + suite.addTest(tests.api.java.util.regex.AllTests.suite()); + // $JUnit-END$ + return suite; + } +} Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF?rev=386087&r1=386086&r2=386087&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/sql/META-INF/MANIFEST.MF Wed Mar 15 06:55:38 2006 @@ -5,5 +5,19 @@ Bundle-Version: 1.0.0 Bundle-ClassPath: . Eclipse-JREBundle: true -Export-Package: java.sql -Import-Package: java.lang +Export-Package: java.sql, + javax.sql, + javax.sql.rowset, + javax.sql.rowset.serial, + javax.sql.rowset.spi, + javax.transaction, + javax.transaction.xa +Import-Package: java.lang, + java.util, + java.io, + com.ibm.oti.vm, + java.security, + java.math, + java.net, + java.text, + java.rmi Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/make/build.xml URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/make/build.xml?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/sql/make/build.xml (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/sql/make/build.xml Wed Mar 15 06:55:38 2006 @@ -0,0 +1,115 @@ + + + + + Build for SQL component + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/build.xml URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/build.xml?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/build.xml (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/build.xml Wed Mar 15 06:55:38 2006 @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/hyproperties.xml URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/hyproperties.xml?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/hyproperties.xml (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/sql/make/common/hyproperties.xml Wed Mar 15 06:55:38 2006 @@ -0,0 +1,44 @@ + + + + + + +
+ + +
+ + + + + +
+ +
+ + + + + + + + + + + + Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/com/ibm/common/ClassUtils.java URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/com/ibm/common/ClassUtils.java?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/com/ibm/common/ClassUtils.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/com/ibm/common/ClassUtils.java Wed Mar 15 06:55:38 2006 @@ -0,0 +1,61 @@ +/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.ibm.common; + +/** + * A class containing sets of utility functions relating to Classes, ClassLoaders and associated + * aspects of Java + * + */ +public class ClassUtils { + + /** + * Gets the ClassLoader of method that called the method which called this method. + * ie if C2.m2() calls this method, and C1.m1() calls C2.m2(), this method returns the + * ClassLoader for class C1. + * @return The ClassLoader of the caller's caller. + * TODO - needs completing + */ + public static ClassLoader getCallerClassLoader() { + return null; + } // end method getCallerClassLoader + + /** + * Finds if a supplied Object belongs to the given ClassLoader. + * @param theObject the object to check + * @param theClassLoader the ClassLoader + * @return true if the Object does belong to the ClassLoader, false otherwise + */ + public static boolean isClassFromClassLoader( Object theObject, ClassLoader theClassLoader ) { + + if( (theObject == null) || (theClassLoader == null) ) return false; + + Class objectClass = theObject.getClass(); + + try { + Class checkClass = Class.forName(objectClass.getName(), true, theClassLoader); + if( checkClass == objectClass ) return true; + } catch ( Throwable t ) { + + } // end try + + return false; + } // end method isClassFromClassLoader( Object, ClassLoader ) + +} // end class ClassUtils + + Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Array.java URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Array.java?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Array.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/Array.java Wed Mar 15 06:55:38 2006 @@ -0,0 +1,131 @@ +/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package java.sql; + +import java.util.Map; + +/** + * A Java representation of the SQL ARRAY type. + * + */ +public interface Array { + + /** + * Retrieves the contents of the SQL ARRAY value as a Java array object. + * + * @return A Java array containing the elements of this Array + * @throws SQLException + */ + public Object getArray() throws SQLException; + + /** + * Returns part of the SQL ARRAY associated with this Array, starting at a + * particular index and comprising up to count successive elements of the + * SQL array. + * + * @param index + * @param count + * @return A Java array containing the subportion of elements of this Array + * @throws SQLException + */ + public Object getArray(long index, int count) throws SQLException; + + /** + * Returns part of the SQL ARRAY associated with this Array, starting at a + * particular index and comprising up to count successive elements of the + * SQL array. + * + * @param index + * @param count + * @param map + * @return A Java array containing the subportion of elements of this Array + * @throws SQLException + */ + public Object getArray(long index, int count, Map map) throws SQLException; + + /** + * Returns the SQL ARRAY associated with this Array. + * + * @param map + * @return A Java array containing the elements of this Array + * @throws SQLException + */ + public Object getArray(Map map) throws SQLException; + + /** + * Returns the JDBC type of the entries in this Array's associated array. + * + * @return An integer constant from the java.sql.Types class + * @throws SQLException + */ + public int getBaseType() throws SQLException; + + /** + * Returns the SQL type name of the entries in the array associated with + * this Array. + * + * @return The database specific name or a fully-qualified SQL type name. + * @throws SQLException + */ + public String getBaseTypeName() throws SQLException; + + /** + * Returns a ResultSet object which holds the entries of the SQL ARRAY + * associated with this Array. + * + * @return the ResultSet + * @throws SQLException + */ + public ResultSet getResultSet() throws SQLException; + + /** + * Returns a ResultSet object that holds the entries of a subarray, + * beginning at a particular index and comprising up to count successive + * entries. + * + * @param index + * @param count + * @return the ResultSet + * @throws SQLException + */ + public ResultSet getResultSet(long index, int count) throws SQLException; + + /** + * Returns a ResultSet object that holds the entries of a subarray, + * beginning at a particular index and comprising up to count successive + * entries. + * + * @param index + * @param count + * @param map + * @return the ResultSet + * @throws SQLException + */ + public ResultSet getResultSet(long index, int count, Map map) + throws SQLException; + + /** + * Returns a ResultSet object which holds the entries of the SQL ARRAY + * associated with this Array. + * + * @param map + * @return the ResultSet + * @throws SQLException + */ + public ResultSet getResultSet(Map map) throws SQLException; + +} // end interface Array + Added: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/BatchUpdateException.java URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/BatchUpdateException.java?rev=386087&view=auto ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/BatchUpdateException.java (added) +++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/BatchUpdateException.java Wed Mar 15 06:55:38 2006 @@ -0,0 +1,147 @@ +/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package java.sql; + +import java.io.Serializable; + +/** + * An exception thrown if a problem occurs during a batch update operation. + *

+ * A BatchUpdateException provides additional information about the problem that + * occurred, compared with a standard SQLException. It supplies update counts + * for successful commands that executed within the batch update, but before the + * exception was encountered. + *

+ * The element order in the array of update counts matches the order that the + * commands were added to the batch operation. + *

+ * Once a batch update command fails and a BatchUpdateException is thrown, the + * JDBC driver may continue processing the remaining commands in the batch. If + * the driver does process more commands after the problem occurs, the array + * returned by BatchUpdateException.getUpdateCounts has an element for every + * command in the batch, not only those that executed successfully. In this + * case, the array element for any command which encountered a problem is set to + * Statement.EXECUTE_FAILED. + * + */ +public class BatchUpdateException extends SQLException implements Serializable { + + private static final long serialVersionUID = 5977529877145521757L; + + private int[] theUpdateCounts = null; + + /** + * Creates a BatchUpdateException with the Reason, SQLState, and Update + * Counts set to null and a Vendor Code of 0. + */ + public BatchUpdateException() { + super(); + } // end method BatchUpdateException() + + /** + * Creates a BatchUpdateException with the Update Counts set to the supplied + * value and the Reason, SQLState set to null and a Vendor Code of 0. + * + * @param updateCounts + * the array of Update Counts to use in initialization + */ + public BatchUpdateException(int[] updateCounts) { + super(); + this.theUpdateCounts = updateCounts; + } // end method BatchUpdateException( + + /** + * Creates a BatchUpdateException with the Update Counts set to the supplied + * value, the Reason set to the supplied value and SQLState set to null and + * a Vendor Code of 0. + * + * @param reason + * the initialization value for Reason + * @param updateCounts + * the array of Update Counts to set + */ + public BatchUpdateException(String reason, int[] updateCounts) { + super(reason); + this.theUpdateCounts = updateCounts; + } // end method BatchUpdateException( + + /** + * Creates a BatchUpdateException with the Update Counts set to the supplied + * value, the Reason set to the supplied value, the SQLState initialized to + * the supplied value and the Vendor Code initialized to 0. + * + * @param reason + * the value to use for the Reason + * @param SQLState + * the X/OPEN value to use for the SQLState + * @param updateCounts + * the array of Update Counts to set + */ + public BatchUpdateException(String reason, String SQLState, + int[] updateCounts) { + super(reason, SQLState); + this.theUpdateCounts = updateCounts; + } // end method BatchUpdateException( + + /** + * Creates a BatchUpdateException with the Update Counts set to the supplied + * value, the Reason set to the supplied value, the SQLState initialized to + * the supplied value and the Vendor Code set to the supplied value. + * + * @param reason + * the value to use for the Reason + * @param SQLState + * the X/OPEN value to use for the SQLState + * @param vendorCode + * the value to use for the vendor error code + * @param updateCounts + * the array of Update Counts to set + */ + public BatchUpdateException(String reason, String SQLState, int vendorCode, + int[] updateCounts) { + super(reason, SQLState, vendorCode); + this.theUpdateCounts = updateCounts; + } // end method BatchUpdateException( + + /** + * Gets the Update Counts array. + *

+ * If a batch update command fails and a BatchUpdateException is thrown, the + * JDBC driver may continue processing the remaining commands in the batch. + * If the driver does process more commands after the problem occurs, the + * array returned by BatchUpdateException.getUpdateCounts has + * an element for every command in the batch, not only those that executed + * successfully. In this case, the array element for any command which + * encountered a problem is set to Statement.EXECUTE_FAILED. + * + * @return an array that contains the successful update counts, before this + * exception. Alternatively, if the driver continues to process + * commands following an error, one of these listed items for every + * command the batch contains: + *

    + *
  1. an count of the updates
  2. + *
  3. Statement.SUCCESS_NO_INFO indicating that the + * command completed successfully, but the amount of altered rows is + * not known.
  4. + *
  5. Statement.EXECUTE_FAILED indicating that the + * command was unsuccessful. + *
+ */ + public int[] getUpdateCounts() { + return theUpdateCounts; + } // end method getUpdateCounts() +} // end class BatchUpdateException +