diff --git a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java deleted file mode 100644 index 6ea62a3e4..000000000 --- a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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; - -/** - *

Operations on {@code CharSequence} that are - * null safe.

- * - *

#ThreadSafe#

- * - * @author Apache Software Foundation - * @author Gary Gregory - * @since 3.0 - * @version $Id$ - */ -public class CharSequenceUtils { - - /** - *

{@code CharSequenceUtils} instances should NOT be constructed in - * standard programming. Instead, the static methods on the class should - * be used, such as {@code CharSequenceUtils.subSequence(cs, 4);}.

- * - *

This constructor is public to permit tools that require a JavaBean - * instance to operate.

- */ - public CharSequenceUtils() { - super(); - } - - //----------------------------------------------------------------------- - /** - *

Returns a new {@code CharSequence} that is a subsequence of this - * sequence starting with the {@code char} value at the specified index.

- * - *

This provides the {@code CharSequence} equivalent to {@link String#substring(int)}. - * The length (in {@code char}) of the returned sequence is {@code length() - start}, - * so if {@code start == end} then an empty sequence is returned.

- * - * @param cs the specified subsequence, null returns null - * @param start the start index, inclusive, valid - * @return a new subsequence, may be null - * @throws IndexOutOfBoundsException if {@code start} is negative or if - * {@code start} is greater than {@code length()} - */ - public static CharSequence subSequence(CharSequence cs, int start) { - return cs == null ? null : cs.subSequence(start, cs.length()); - } - -} diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 686d017e7..263b9b318 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -5021,7 +5021,7 @@ public static String capitalize(CharSequence cs) { } return new StringBuilder(strLen) .append(Character.toTitleCase(cs.charAt(0))) - .append(CharSequenceUtils.subSequence(cs, 1)) + .append(StringUtils.subSequence(cs, 1)) .toString(); } @@ -5056,7 +5056,7 @@ public static String uncapitalize(CharSequence cs) { } return new StringBuilder(strLen) .append(Character.toLowerCase(cs.charAt(0))) - .append(CharSequenceUtils.subSequence(cs, 1)) + .append(StringUtils.subSequence(cs, 1)) .toString(); } @@ -6384,4 +6384,24 @@ public static boolean endsWithAny(String string, String... searchStrings) { } return false; } + + //----------------------------------------------------------------------- + /** + *

Returns a new {@code CharSequence} that is a subsequence of this + * sequence starting with the {@code char} value at the specified index.

+ * + *

This provides the {@code CharSequence} equivalent to {@link String#substring(int)}. + * The length (in {@code char}) of the returned sequence is {@code length() - start}, + * so if {@code start == end} then an empty sequence is returned.

+ * + * @param cs the specified subsequence, null returns null + * @param start the start index, inclusive, valid + * @return a new subsequence, may be null + * @throws IndexOutOfBoundsException if {@code start} is negative or if + * {@code start} is greater than {@code length()} + */ + public static CharSequence subSequence(CharSequence cs, int start) { + return cs == null ? null : cs.subSequence(start, cs.length()); + } + } diff --git a/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java b/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java deleted file mode 100644 index a58653597..000000000 --- a/src/test/java/org/apache/commons/lang3/CharSequenceUtilsTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - -import junit.framework.Assert; -import junit.framework.TestCase; - -/** - * Tests CharSequenceUtils - * - * @author Gary Gregory - * @version $Id$ - */ -public class CharSequenceUtilsTest extends TestCase { - - //----------------------------------------------------------------------- - public void testConstructor() { - assertNotNull(new CharSequenceUtils()); - Constructor[] cons = CharSequenceUtils.class.getDeclaredConstructors(); - assertEquals(1, cons.length); - assertEquals(true, Modifier.isPublic(cons[0].getModifiers())); - assertEquals(true, Modifier.isPublic(CharSequenceUtils.class.getModifiers())); - assertEquals(false, Modifier.isFinal(CharSequenceUtils.class.getModifiers())); - } - - //----------------------------------------------------------------------- - 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 - } - } - -} diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java index 3458038a5..94b72b27c 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsSubstringTest.java @@ -17,6 +17,7 @@ package org.apache.commons.lang3; import junit.framework.TestCase; +import org.junit.Assert; /** * Unit tests {@link org.apache.commons.lang3.StringUtils} - Substring methods @@ -312,4 +313,38 @@ public void testCountMatches_String() { assertEquals(4, StringUtils.countMatches("oooooooooooo", "ooo")); } + + //----------------------------------------------------------------------- + public void testSubSequence() { + // + // null input + // + Assert.assertEquals(null, StringUtils.subSequence(null, -1)); + Assert.assertEquals(null, StringUtils.subSequence(null, 0)); + Assert.assertEquals(null, StringUtils.subSequence(null, 1)); + // + // non-null input + // + Assert.assertEquals(StringUtils.EMPTY, StringUtils.subSequence(StringUtils.EMPTY, 0)); + Assert.assertEquals("012", StringUtils.subSequence("012", 0)); + Assert.assertEquals("12", StringUtils.subSequence("012", 1)); + Assert.assertEquals("2", StringUtils.subSequence("012", 2)); + Assert.assertEquals(StringUtils.EMPTY, StringUtils.subSequence("012", 3)); + // + // Exception expected + // + try { + Assert.assertEquals(null, StringUtils.subSequence(StringUtils.EMPTY, -1)); + Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); + } catch (IndexOutOfBoundsException e) { + // Expected + } + try { + Assert.assertEquals(null, StringUtils.subSequence(StringUtils.EMPTY, 1)); + Assert.fail("Expected " + IndexOutOfBoundsException.class.getName()); + } catch (IndexOutOfBoundsException e) { + // Expected + } + } + }