Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 4923 invoked from network); 22 Jul 2010 03:11:38 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Jul 2010 03:11:38 -0000 Received: (qmail 50091 invoked by uid 500); 22 Jul 2010 03:11:37 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 49742 invoked by uid 500); 22 Jul 2010 03:11:35 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 49735 invoked by uid 99); 22 Jul 2010 03:11:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jul 2010 03:11:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jul 2010 03:11:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0ABA82388A02; Thu, 22 Jul 2010 03:10:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r966488 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/CharSequenceUtils.java test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java Date: Thu, 22 Jul 2010 03:10:36 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100722031037.0ABA82388A02@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ggregory Date: Thu Jul 22 03:10:36 2010 New Revision: 966488 URL: http://svn.apache.org/viewvc?rev=966488&view=rev Log: svn ps svn:eol-style native src/main/java/org/apache/commons/lang3/CharSequenceUtils.java svn ps svn:eol-style native src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java (contents, props changed) commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java (contents, props changed) Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java?rev=966488&r1=966487&r2=966488&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java Thu Jul 22 03:10:36 2010 @@ -1,61 +1,61 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.commons.lang3; - -/** - * Null-safe CharSequence utility methods. - * - * @author Gary Gregory - */ -public class CharSequenceUtils { - - /** - * Gets a CharSequence length or 0 if the CharSequence is - * null. - * - * @param cs - * a CharSequence or null - * @return CharSequence length or 0 if the CharSequence is - * null. - * @since 3.0 - */ - public static int length(CharSequence cs) { - return cs == null ? 0 : cs.length(); - } - - /** - * Returns a new CharSequence that is a subsequence of this - * sequence starting with the char value at the specified - * index. The length (in chars) of the returned sequence is - * length() - start, so if start == end then an - * empty sequence is returned.

- * - * @param cs - * the specified subsequence, may be null - * @param start - * the start index, inclusive - * @return a new subsequence or null - * - * @throws IndexOutOfBoundsException - * if start is negative or if start is - * greater than length() - * @since 3.0 - */ - public static CharSequence subSequence(CharSequence cs, int start) { - return cs == null ? null : cs.subSequence(start, cs.length()); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.commons.lang3; + +/** + * Null-safe CharSequence utility methods. + * + * @author Gary Gregory + */ +public class CharSequenceUtils { + + /** + * Gets a CharSequence length or 0 if the CharSequence is + * null. + * + * @param cs + * a CharSequence or null + * @return CharSequence length or 0 if the CharSequence is + * null. + * @since 3.0 + */ + public static int length(CharSequence cs) { + return cs == null ? 0 : cs.length(); + } + + /** + * Returns a new CharSequence that is a subsequence of this + * sequence starting with the char value at the specified + * index. The length (in chars) of the returned sequence is + * length() - start, so if start == end then an + * empty sequence is returned.

+ * + * @param cs + * the specified subsequence, may be null + * @param start + * the start index, inclusive + * @return a new subsequence or null + * + * @throws IndexOutOfBoundsException + * if start is negative or if start is + * greater than length() + * @since 3.0 + */ + public static CharSequence subSequence(CharSequence cs, int start) { + return cs == null ? null : cs.subSequence(start, cs.length()); + } +} Propchange: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java?rev=966488&r1=966487&r2=966488&view=diff ============================================================================== --- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java (original) +++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java Thu Jul 22 03:10:36 2010 @@ -1,92 +1,92 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.commons.lang3; - -import java.nio.CharBuffer; - -import junit.framework.Assert; -import junit.framework.TestCase; - -/** - * Tests CharSequenceUtils - * - * @author Gary Gregory - */ -public class CharSequenceUtilsTest extends TestCase { - - public void testLength_CharBuffer() { - Assert.assertEquals(0, CharSequenceUtils.length(CharBuffer.wrap(""))); - Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap("A"))); - Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap(" "))); - Assert.assertEquals(8, CharSequenceUtils.length(CharBuffer.wrap("ABCDEFGH"))); - } - - public void testLength_String() { - Assert.assertEquals(0, CharSequenceUtils.length(null)); - Assert.assertEquals(0, CharSequenceUtils.length("")); - Assert.assertEquals(1, CharSequenceUtils.length("A")); - Assert.assertEquals(1, CharSequenceUtils.length(" ")); - Assert.assertEquals(8, CharSequenceUtils.length("ABCDEFGH")); - } - - public void testLength_StringBuffer() { - Assert.assertEquals(0, CharSequenceUtils.length(new StringBuffer(""))); - Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer("A"))); - Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer(" "))); - Assert.assertEquals(8, CharSequenceUtils.length(new StringBuffer("ABCDEFGH"))); - } - - public void testLength_StringBuilder() { - Assert.assertEquals(0, CharSequenceUtils.length(new StringBuilder(""))); - Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder("A"))); - Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder(" "))); - Assert.assertEquals(8, CharSequenceUtils.length(new StringBuilder("ABCDEFGH"))); - } - - public void testSubSequence() { - // - // null input - // - Assert.assertEquals(null, CharSequenceUtils.subSequence(null, -1)); - Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 0)); - Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 1)); - // - // non-null input - // - Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence(StringUtils.EMPTY, 0)); - Assert.assertEquals("012", CharSequenceUtils.subSequence("012", 0)); - Assert.assertEquals("12", CharSequenceUtils.subSequence("012", 1)); - Assert.assertEquals("2", CharSequenceUtils.subSequence("012", 2)); - Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3)); - // - // Exception expected - // - try { - Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, -1)); - Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); - } catch (IndexOutOfBoundsException e) { - // Expected - } - try { - Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, 1)); - Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); - } catch (IndexOutOfBoundsException e) { - // Expected - } - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.commons.lang3; + +import java.nio.CharBuffer; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Tests CharSequenceUtils + * + * @author Gary Gregory + */ +public class CharSequenceUtilsTest extends TestCase { + + public void testLength_CharBuffer() { + Assert.assertEquals(0, CharSequenceUtils.length(CharBuffer.wrap(""))); + Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap("A"))); + Assert.assertEquals(1, CharSequenceUtils.length(CharBuffer.wrap(" "))); + Assert.assertEquals(8, CharSequenceUtils.length(CharBuffer.wrap("ABCDEFGH"))); + } + + public void testLength_String() { + Assert.assertEquals(0, CharSequenceUtils.length(null)); + Assert.assertEquals(0, CharSequenceUtils.length("")); + Assert.assertEquals(1, CharSequenceUtils.length("A")); + Assert.assertEquals(1, CharSequenceUtils.length(" ")); + Assert.assertEquals(8, CharSequenceUtils.length("ABCDEFGH")); + } + + public void testLength_StringBuffer() { + Assert.assertEquals(0, CharSequenceUtils.length(new StringBuffer(""))); + Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer("A"))); + Assert.assertEquals(1, CharSequenceUtils.length(new StringBuffer(" "))); + Assert.assertEquals(8, CharSequenceUtils.length(new StringBuffer("ABCDEFGH"))); + } + + public void testLength_StringBuilder() { + Assert.assertEquals(0, CharSequenceUtils.length(new StringBuilder(""))); + Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder("A"))); + Assert.assertEquals(1, CharSequenceUtils.length(new StringBuilder(" "))); + Assert.assertEquals(8, CharSequenceUtils.length(new StringBuilder("ABCDEFGH"))); + } + + public void testSubSequence() { + // + // null input + // + Assert.assertEquals(null, CharSequenceUtils.subSequence(null, -1)); + Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 0)); + Assert.assertEquals(null, CharSequenceUtils.subSequence(null, 1)); + // + // non-null input + // + Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence(StringUtils.EMPTY, 0)); + Assert.assertEquals("012", CharSequenceUtils.subSequence("012", 0)); + Assert.assertEquals("12", CharSequenceUtils.subSequence("012", 1)); + Assert.assertEquals("2", CharSequenceUtils.subSequence("012", 2)); + Assert.assertEquals(StringUtils.EMPTY, CharSequenceUtils.subSequence("012", 3)); + // + // Exception expected + // + try { + Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, -1)); + Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); + } catch (IndexOutOfBoundsException e) { + // Expected + } + try { + Assert.assertEquals(null, CharSequenceUtils.subSequence(StringUtils.EMPTY, 1)); + Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); + } catch (IndexOutOfBoundsException e) { + // Expected + } + } + +} Propchange: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java ------------------------------------------------------------------------------ svn:eol-style = native