Use our own APIs.

This commit is contained in:
Gary Gregory 2019-09-11 11:15:21 -04:00
parent 975df007a5
commit d572b37a7d
2 changed files with 46 additions and 47 deletions

View File

@ -1872,7 +1872,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final Object[] array, final int offset1, final int offset2) { public static void swap(final Object[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -1901,7 +1901,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final long[] array, final int offset1, final int offset2) { public static void swap(final long[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -1929,7 +1929,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final int[] array, final int offset1, final int offset2) { public static void swap(final int[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -1957,7 +1957,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final short[] array, final int offset1, final int offset2) { public static void swap(final short[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -1985,7 +1985,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final char[] array, final int offset1, final int offset2) { public static void swap(final char[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -2013,7 +2013,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final byte[] array, final int offset1, final int offset2) { public static void swap(final byte[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -2041,7 +2041,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final double[] array, final int offset1, final int offset2) { public static void swap(final double[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -2069,7 +2069,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final float[] array, final int offset1, final int offset2) { public static void swap(final float[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -2097,7 +2097,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final boolean[] array, final int offset1, final int offset2) { public static void swap(final boolean[] array, final int offset1, final int offset2) {
if (array == null || array.length == 0) { if (isEmpty(array)) {
return; return;
} }
swap(array, offset1, offset2, 1); swap(array, offset1, offset2, 1);
@ -2128,7 +2128,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final boolean[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2170,7 +2170,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final byte[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2212,7 +2212,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final char[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2254,7 +2254,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final double[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2296,7 +2296,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final float[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2339,7 +2339,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final int[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2381,7 +2381,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final long[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2423,7 +2423,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final Object[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {
@ -2465,7 +2465,7 @@ public class ArrayUtils {
* @since 3.5 * @since 3.5
*/ */
public static void swap(final short[] array, int offset1, int offset2, int len) { 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; return;
} }
if (offset1 < 0) { if (offset1 < 0) {

View File

@ -426,7 +426,7 @@ public class StringUtils {
if (str == null || isEmpty(suffix) || endsWith(str, suffix, ignoreCase)) { if (str == null || isEmpty(suffix) || endsWith(str, suffix, ignoreCase)) {
return str; return str;
} }
if (suffixes != null && suffixes.length > 0) { if (ArrayUtils.isNotEmpty(suffixes)) {
for (final CharSequence s : suffixes) { for (final CharSequence s : suffixes) {
if (endsWith(str, s, ignoreCase)) { if (endsWith(str, s, ignoreCase)) {
return str; return str;
@ -534,8 +534,8 @@ public class StringUtils {
* @since 2.0 * @since 2.0
*/ */
public static String capitalize(final String str) { public static String capitalize(final String str) {
int strLen; int strLen = length(str);
if (str == null || (strLen = str.length()) == 0) { if (strLen == 0) {
return str; return str;
} }
@ -2009,7 +2009,7 @@ public class StringUtils {
* @since 2.4 * @since 2.4
*/ */
public static String getCommonPrefix(final String... strs) { public static String getCommonPrefix(final String... strs) {
if (strs == null || strs.length == 0) { if (ArrayUtils.isEmpty(strs)) {
return EMPTY; return EMPTY;
} }
final int smallestIndexOfDiff = indexOfDifference(strs); final int smallestIndexOfDiff = indexOfDifference(strs);
@ -2905,7 +2905,7 @@ public class StringUtils {
* @since 3.0 Changed signature from indexOfDifference(String...) to indexOfDifference(CharSequence...) * @since 3.0 Changed signature from indexOfDifference(String...) to indexOfDifference(CharSequence...)
*/ */
public static int indexOfDifference(final CharSequence... css) { public static int indexOfDifference(final CharSequence... css) {
if (css == null || css.length <= 1) { if (ArrayUtils.getLength(css) <= 1) {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
boolean anyStringNull = false; boolean anyStringNull = false;
@ -3176,7 +3176,7 @@ public class StringUtils {
* @since 3.0 Changed signature from isAllLowerCase(String) to isAllLowerCase(CharSequence) * @since 3.0 Changed signature from isAllLowerCase(String) to isAllLowerCase(CharSequence)
*/ */
public static boolean isAllLowerCase(final CharSequence cs) { public static boolean isAllLowerCase(final CharSequence cs) {
if (cs == null || isEmpty(cs)) { if (isEmpty(cs)) {
return false; return false;
} }
final int sz = cs.length(); final int sz = cs.length();
@ -3211,7 +3211,7 @@ public class StringUtils {
* @since 3.0 Changed signature from isAllUpperCase(String) to isAllUpperCase(CharSequence) * @since 3.0 Changed signature from isAllUpperCase(String) to isAllUpperCase(CharSequence)
*/ */
public static boolean isAllUpperCase(final CharSequence cs) { public static boolean isAllUpperCase(final CharSequence cs) {
if (cs == null || isEmpty(cs)) { if (isEmpty(cs)) {
return false; return false;
} }
final int sz = cs.length(); final int sz = cs.length();
@ -3491,8 +3491,8 @@ public class StringUtils {
* @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence) * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
*/ */
public static boolean isBlank(final CharSequence cs) { public static boolean isBlank(final CharSequence cs) {
int strLen; int strLen = length(cs);
if (cs == null || (strLen = cs.length()) == 0) { if (strLen == 0) {
return true; return true;
} }
for (int i = 0; i < strLen; i++) { for (int i = 0; i < strLen; i++) {
@ -4388,6 +4388,7 @@ public class StringUtils {
return join(subList.iterator(), separator); return join(subList.iterator(), separator);
} }
/** /**
* <p> * <p>
* Joins the elements of the provided array into a single String containing the provided list of elements. * 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); return join(array, separator, 0, array.length);
} }
/** /**
* <p> * <p>
* Joins the elements of the provided array into a single String containing the provided list of elements. * 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(); return buf.toString();
} }
// Joining // Joining
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -4750,7 +4751,6 @@ public class StringUtils {
return join(elements, null); return join(elements, null);
} }
/** /**
* <p>Joins the elements of the provided varargs into a * <p>Joins the elements of the provided varargs into a
* single String containing the provided elements.</p> * single String containing the provided elements.</p>
@ -5679,7 +5679,7 @@ public class StringUtils {
if (str == null || isEmpty(prefix) || startsWith(str, prefix, ignoreCase)) { if (str == null || isEmpty(prefix) || startsWith(str, prefix, ignoreCase)) {
return str; return str;
} }
if (prefixes != null && prefixes.length > 0) { if (ArrayUtils.isNotEmpty(prefixes)) {
for (final CharSequence p : prefixes) { for (final CharSequence p : prefixes) {
if (startsWith(str, p, ignoreCase)) { if (startsWith(str, p, ignoreCase)) {
return str; return str;
@ -6237,6 +6237,9 @@ public class StringUtils {
} }
} }
// Conversion
//-----------------------------------------------------------------------
/** /**
* <p>Repeat a String {@code repeat} times to form a * <p>Repeat a String {@code repeat} times to form a
* new String, with a String separator injected each time. </p> * new String, with a String separator injected each time. </p>
@ -6266,9 +6269,6 @@ public class StringUtils {
return removeEnd(result, separator); return removeEnd(result, separator);
} }
// Conversion
//-----------------------------------------------------------------------
/** /**
* <p>Replaces all occurrences of a String within another String.</p> * <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) // 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 // let me know if there are performance requests, we can create a harness to measure
if (text == null || text.isEmpty() || searchList == null || if (isEmpty(text) || ArrayUtils.isEmpty(searchList) || ArrayUtils.isEmpty(replacementList)) {
searchList.length == 0 || replacementList == null || replacementList.length == 0) {
return text; return text;
} }
@ -8257,8 +8256,8 @@ public class StringUtils {
* @return the stripped String, {@code null} if null String input * @return the stripped String, {@code null} if null String input
*/ */
public static String stripEnd(final String str, final String stripChars) { public static String stripEnd(final String str, final String stripChars) {
int end; int end = length(str);
if (str == null || (end = str.length()) == 0) { if (end == 0) {
return str; return str;
} }
@ -8301,8 +8300,8 @@ public class StringUtils {
* @return the stripped String, {@code null} if null String input * @return the stripped String, {@code null} if null String input
*/ */
public static String stripStart(final String str, final String stripChars) { public static String stripStart(final String str, final String stripChars) {
int strLen; int strLen = length(str);
if (str == null || (strLen = str.length()) == 0) { if (strLen == 0) {
return str; return str;
} }
int start = 0; int start = 0;
@ -8533,6 +8532,9 @@ public class StringUtils {
return str.substring(pos + separator.length()); return str.substring(pos + separator.length());
} }
// startsWith
//-----------------------------------------------------------------------
/** /**
* <p>Gets the substring after the last occurrence of a separator. * <p>Gets the substring after the last occurrence of a separator.
* The separator is not returned.</p> * The separator is not returned.</p>
@ -8576,9 +8578,6 @@ public class StringUtils {
return str.substring(pos + separator.length()); return str.substring(pos + separator.length());
} }
// startsWith
//-----------------------------------------------------------------------
// SubStringAfter/SubStringBefore // SubStringAfter/SubStringBefore
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -8687,6 +8686,9 @@ public class StringUtils {
return substringBetween(str, tag, tag); return substringBetween(str, tag, tag);
} }
// endsWith
//-----------------------------------------------------------------------
/** /**
* <p>Gets the String that is nested in between two Strings. * <p>Gets the String that is nested in between two Strings.
* Only the first match is returned.</p> * Only the first match is returned.</p>
@ -8728,9 +8730,6 @@ public class StringUtils {
return null; return null;
} }
// endsWith
//-----------------------------------------------------------------------
/** /**
* <p>Searches a String for substrings delimited by a start and end tag, * <p>Searches a String for substrings delimited by a start and end tag,
* returning all matching substrings in an array.</p> * returning all matching substrings in an array.</p>
@ -9147,8 +9146,8 @@ public class StringUtils {
* @since 2.0 * @since 2.0
*/ */
public static String uncapitalize(final String str) { public static String uncapitalize(final String str) {
int strLen; int strLen = length(str);
if (str == null || (strLen = str.length()) == 0) { if (strLen == 0) {
return str; return str;
} }