This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push: new d572b37 Use our own APIs. d572b37 is described below commit d572b37a7d1bb1e93de55cac617b73ab7d725f72 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Wed Sep 11 11:15:21 2019 -0400 Use our own APIs. --- .../java/org/apache/commons/lang3/ArrayUtils.java | 36 +++++++------- .../java/org/apache/commons/lang3/StringUtils.java | 57 +++++++++++----------- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 51363ce..fc3eb4c 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -1872,7 +1872,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final Object[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -1901,7 +1901,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final long[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -1929,7 +1929,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final int[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -1957,7 +1957,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final short[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -1985,7 +1985,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final char[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -2013,7 +2013,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final byte[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -2041,7 +2041,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final double[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -2069,7 +2069,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final float[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -2097,7 +2097,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final boolean[] array, final int offset1, final int offset2) { - if (array == null || array.length == 0) { + if (isEmpty(array)) { return; } swap(array, offset1, offset2, 1); @@ -2128,7 +2128,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final boolean[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2170,7 +2170,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final byte[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2212,7 +2212,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final char[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2254,7 +2254,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final double[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2296,7 +2296,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final float[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2339,7 +2339,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final int[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2381,7 +2381,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final long[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2423,7 +2423,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final Object[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { @@ -2465,7 +2465,7 @@ public class ArrayUtils { * @since 3.5 */ public static void swap(final short[] array, int offset1, int offset2, int len) { - if (array == null || array.length == 0 || offset1 >= array.length || offset2 >= array.length) { + if (isEmpty(array) || offset1 >= array.length || offset2 >= array.length) { return; } if (offset1 < 0) { diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 7937547..03f7478 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -426,7 +426,7 @@ public class StringUtils { if (str == null || isEmpty(suffix) || endsWith(str, suffix, ignoreCase)) { return str; } - if (suffixes != null && suffixes.length > 0) { + if (ArrayUtils.isNotEmpty(suffixes)) { for (final CharSequence s : suffixes) { if (endsWith(str, s, ignoreCase)) { return str; @@ -534,8 +534,8 @@ public class StringUtils { * @since 2.0 */ public static String capitalize(final String str) { - int strLen; - if (str == null || (strLen = str.length()) == 0) { + int strLen = length(str); + if (strLen == 0) { return str; } @@ -2009,7 +2009,7 @@ public class StringUtils { * @since 2.4 */ public static String getCommonPrefix(final String... strs) { - if (strs == null || strs.length == 0) { + if (ArrayUtils.isEmpty(strs)) { return EMPTY; } final int smallestIndexOfDiff = indexOfDifference(strs); @@ -2905,7 +2905,7 @@ public class StringUtils { * @since 3.0 Changed signature from indexOfDifference(String...) to indexOfDifference(CharSequence...) */ public static int indexOfDifference(final CharSequence... css) { - if (css == null || css.length <= 1) { + if (ArrayUtils.getLength(css) <= 1) { return INDEX_NOT_FOUND; } boolean anyStringNull = false; @@ -3176,7 +3176,7 @@ public class StringUtils { * @since 3.0 Changed signature from isAllLowerCase(String) to isAllLowerCase(CharSequence) */ public static boolean isAllLowerCase(final CharSequence cs) { - if (cs == null || isEmpty(cs)) { + if (isEmpty(cs)) { return false; } final int sz = cs.length(); @@ -3211,7 +3211,7 @@ public class StringUtils { * @since 3.0 Changed signature from isAllUpperCase(String) to isAllUpperCase(CharSequence) */ public static boolean isAllUpperCase(final CharSequence cs) { - if (cs == null || isEmpty(cs)) { + if (isEmpty(cs)) { return false; } final int sz = cs.length(); @@ -3491,8 +3491,8 @@ public class StringUtils { * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) */ public static boolean isBlank(final CharSequence cs) { - int strLen; - if (cs == null || (strLen = cs.length()) == 0) { + int strLen = length(cs); + if (strLen == 0) { return true; } for (int i = 0; i < strLen; i++) { @@ -4388,6 +4388,7 @@ public class StringUtils { return join(subList.iterator(), separator); } + /** * <p> * Joins the elements of the provided array into a single String containing the provided list of elements. @@ -4420,7 +4421,6 @@ public class StringUtils { return join(array, separator, 0, array.length); } - /** * <p> * Joins the elements of the provided array into a single String containing the provided list of elements. @@ -4721,6 +4721,7 @@ public class StringUtils { return buf.toString(); } + // Joining //----------------------------------------------------------------------- /** @@ -4750,7 +4751,6 @@ public class StringUtils { return join(elements, null); } - /** * <p>Joins the elements of the provided varargs into a * single String containing the provided elements.</p> @@ -5679,7 +5679,7 @@ public class StringUtils { if (str == null || isEmpty(prefix) || startsWith(str, prefix, ignoreCase)) { return str; } - if (prefixes != null && prefixes.length > 0) { + if (ArrayUtils.isNotEmpty(prefixes)) { for (final CharSequence p : prefixes) { if (startsWith(str, p, ignoreCase)) { return str; @@ -6237,6 +6237,9 @@ public class StringUtils { } } + // Conversion + //----------------------------------------------------------------------- + /** * <p>Repeat a String {@code repeat} times to form a * new String, with a String separator injected each time. </p> @@ -6266,9 +6269,6 @@ public class StringUtils { return removeEnd(result, separator); } - // Conversion - //----------------------------------------------------------------------- - /** * <p>Replaces all occurrences of a String within another String.</p> * @@ -6636,8 +6636,7 @@ public class StringUtils { // mchyzer Performance note: This creates very few new objects (one major goal) // let me know if there are performance requests, we can create a harness to measure - if (text == null || text.isEmpty() || searchList == null || - searchList.length == 0 || replacementList == null || replacementList.length == 0) { + if (isEmpty(text) || ArrayUtils.isEmpty(searchList) || ArrayUtils.isEmpty(replacementList)) { return text; } @@ -8257,8 +8256,8 @@ public class StringUtils { * @return the stripped String, {@code null} if null String input */ public static String stripEnd(final String str, final String stripChars) { - int end; - if (str == null || (end = str.length()) == 0) { + int end = length(str); + if (end == 0) { return str; } @@ -8301,8 +8300,8 @@ public class StringUtils { * @return the stripped String, {@code null} if null String input */ public static String stripStart(final String str, final String stripChars) { - int strLen; - if (str == null || (strLen = str.length()) == 0) { + int strLen = length(str); + if (strLen == 0) { return str; } int start = 0; @@ -8533,6 +8532,9 @@ public class StringUtils { return str.substring(pos + separator.length()); } + // startsWith + //----------------------------------------------------------------------- + /** * <p>Gets the substring after the last occurrence of a separator. * The separator is not returned.</p> @@ -8576,9 +8578,6 @@ public class StringUtils { return str.substring(pos + separator.length()); } - // startsWith - //----------------------------------------------------------------------- - // SubStringAfter/SubStringBefore //----------------------------------------------------------------------- /** @@ -8687,6 +8686,9 @@ public class StringUtils { return substringBetween(str, tag, tag); } + // endsWith + //----------------------------------------------------------------------- + /** * <p>Gets the String that is nested in between two Strings. * Only the first match is returned.</p> @@ -8728,9 +8730,6 @@ public class StringUtils { return null; } - // endsWith - //----------------------------------------------------------------------- - /** * <p>Searches a String for substrings delimited by a start and end tag, * returning all matching substrings in an array.</p> @@ -9147,8 +9146,8 @@ public class StringUtils { * @since 2.0 */ public static String uncapitalize(final String str) { - int strLen; - if (str == null || (strLen = str.length()) == 0) { + int strLen = length(str); + if (strLen == 0) { return str; }