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 <code>0</code> if the CharSequence is - * <code>null</code>. - * - * @param cs - * a CharSequence or <code>null</code> - * @return CharSequence length or <code>0</code> if the CharSequence is - * <code>null</code>. - * @since 3.0 - */ - public static int length(CharSequence cs) { - return cs == null ? 0 : cs.length(); - } - - /** - * Returns a new <code>CharSequence</code> that is a subsequence of this - * sequence starting with the <code>char</code> value at the specified - * index. The length (in <code>char</code>s) of the returned sequence is - * <code>length() - start</code>, so if <code>start == end</code> then an - * empty sequence is returned. </p> - * - * @param cs - * the specified subsequence, may be null - * @param start - * the start index, inclusive - * @return a new subsequence or null - * - * @throws IndexOutOfBoundsException - * if <code>start</code> is negative or if <code>start</code> is - * greater than <code>length()</code> - * @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 <code>0</code> if the CharSequence is + * <code>null</code>. + * + * @param cs + * a CharSequence or <code>null</code> + * @return CharSequence length or <code>0</code> if the CharSequence is + * <code>null</code>. + * @since 3.0 + */ + public static int length(CharSequence cs) { + return cs == null ? 0 : cs.length(); + } + + /** + * Returns a new <code>CharSequence</code> that is a subsequence of this + * sequence starting with the <code>char</code> value at the specified + * index. The length (in <code>char</code>s) of the returned sequence is + * <code>length() - start</code>, so if <code>start == end</code> then an + * empty sequence is returned. </p> + * + * @param cs + * the specified subsequence, may be null + * @param start + * the start index, inclusive + * @return a new subsequence or null + * + * @throws IndexOutOfBoundsException + * if <code>start</code> is negative or if <code>start</code> is + * greater than <code>length()</code> + * @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