Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Empty checks
- //-----------------------------------------------------------------------
- /**
- * <p>Checks if a CharSequence is empty ("") or null.</p>
- *
- * <pre>
- * StringUtils.isEmpty(null) = true
- * StringUtils.isEmpty("") = true
- * StringUtils.isEmpty(" ") = false
- * StringUtils.isEmpty("bob") = false
- * StringUtils.isEmpty(" bob ") = false
- * </pre>
- *
- * <p>NOTE: This method changed in Lang version 2.0.
- * It no longer trims the CharSequence.
- * That functionality is available in isBlank().</p>
- *
- * @param cs the CharSequence to check, may be null
- * @return {@code true} if the CharSequence is empty or null
- * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)
- */
- public static boolean isEmpty(final CharSequence cs) {
- return cs == null || cs.length() == 0;
- }
- /**
- * <p>Checks if a CharSequence is not empty ("") and not null.</p>
- *
- * <pre>
- * StringUtils.isNotEmpty(null) = false
- * StringUtils.isNotEmpty("") = false
- * StringUtils.isNotEmpty(" ") = true
- * StringUtils.isNotEmpty("bob") = true
- * StringUtils.isNotEmpty(" bob ") = true
- * </pre>
- *
- * @param cs the CharSequence to check, may be null
- * @return {@code true} if the CharSequence is not empty and not null
- * @since 3.0 Changed signature from isNotEmpty(String) to isNotEmpty(CharSequence)
- */
- public static boolean isNotEmpty(final CharSequence cs) {
- return !isEmpty(cs);
- }
- /**
- * <p>Checks if any one of the CharSequences are empty ("") or null.</p>
- *
- * <pre>
- * StringUtils.isAnyEmpty(null) = true
- * StringUtils.isAnyEmpty(null, "foo") = true
- * StringUtils.isAnyEmpty("", "bar") = true
- * StringUtils.isAnyEmpty("bob", "") = true
- * StringUtils.isAnyEmpty(" bob ", null) = true
- * StringUtils.isAnyEmpty(" ", "bar") = false
- * StringUtils.isAnyEmpty("foo", "bar") = false
- * </pre>
- *
- * @param css the CharSequences to check, may be null or empty
- * @return {@code true} if any of the CharSequences are empty or null
- * @since 3.2
- */
- public static boolean isAnyEmpty(final CharSequence... css) {
- if (ArrayUtils.isEmpty(css)) {
- return true;
- }
- for (final CharSequence cs : css){
- if (isEmpty(cs)) {
- return true;
- }
- }
- return false;
- }
- /**
- * <p>Checks if none of the CharSequences are empty ("") or null.</p>
- *
- * <pre>
- * StringUtils.isNoneEmpty(null) = false
- * StringUtils.isNoneEmpty(null, "foo") = false
- * StringUtils.isNoneEmpty("", "bar") = false
- * StringUtils.isNoneEmpty("bob", "") = false
- * StringUtils.isNoneEmpty(" bob ", null) = false
- * StringUtils.isNoneEmpty(" ", "bar") = true
- * StringUtils.isNoneEmpty("foo", "bar") = true
- * </pre>
- *
- * @param css the CharSequences to check, may be null or empty
- * @return {@code true} if none of the CharSequences are empty or null
- * @since 3.2
- */
- public static boolean isNoneEmpty(final CharSequence... css) {
- return !isAnyEmpty(css);
- }
- // Joining
- //-----------------------------------------------------------------------
- /**
- * <p>Joins the elements of the provided array into a single String
- * containing the provided list of elements.</p>
- *
- * <p>No separator is added to the joined String.
- * Null objects or empty strings within the array are represented by
- * empty strings.</p>
- *
- * <pre>
- * StringUtils.join(null) = null
- * StringUtils.join([]) = ""
- * StringUtils.join([null]) = ""
- * StringUtils.join(["a", "b", "c"]) = "abc"
- * StringUtils.join([null, "", "a"]) = "a"
- * </pre>
- *
- * @param <T> the specific type of values to join together
- * @param elements the values to join together, may be null
- * @return the joined String, {@code null} if null array input
- * @since 2.0
- * @since 3.0 Changed signature to use varargs
- */
- public static <T> String join(final T... elements) {
- return join(elements, null);
- }
- /**
- * <p>Joins the elements of the provided array into a single String
- * containing the provided list of elements.</p>
- *
- * <p>No delimiter is added before or after the list.
- * Null objects or empty strings within the array are represented by
- * empty strings.</p>
- *
- * <pre>
- * StringUtils.join(null, *) = null
- * StringUtils.join([], *) = ""
- * StringUtils.join([null], *) = ""
- * StringUtils.join(["a", "b", "c"], ';') = "a;b;c"
- * StringUtils.join(["a", "b", "c"], null) = "abc"
- * StringUtils.join([null, "", "a"], ';') = ";;a"
- * </pre>
- *
- * @param array the array of values to join together, may be null
- * @param separator the separator character to use
- * @return the joined String, {@code null} if null array input
- * @since 2.0
- */
- public static String join(final Object[] array, final char separator) {
- if (array == null) {
- return null;
- }
- 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.
- * </p>
- *
- * <p>
- * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
- * by empty strings.
- * </p>
- *
- * <pre>
- * StringUtils.join(null, *) = null
- * StringUtils.join([], *) = ""
- * StringUtils.join([null], *) = ""
- * StringUtils.join([1, 2, 3], ';') = "1;2;3"
- * StringUtils.join([1, 2, 3], null) = "123"
- * </pre>
- *
- * @param array
- * the array of values to join together, may be null
- * @param separator
- * the separator character to use
- * @return the joined String, {@code null} if null array input
- * @since 3.2
- */
- public static String join(final long[] array, final char separator) {
- if (array == null) {
- return null;
- }
- 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.
- * </p>
- *
- * <p>
- * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
- * by empty strings.
- * </p>
- *
- * <pre>
- * StringUtils.join(null, *) = null
- * StringUtils.join([], *) = ""
- * StringUtils.join([null], *) = ""
- * StringUtils.join([1, 2, 3], ';') = "1;2;3"
- * StringUtils.join([1, 2, 3], null) = "123"
- * </pre>
- *
- * @param array
- * the array of values to join together, may be null
- * @param separator
- * the separator character to use
- * @return the joined String, {@code null} if null array input
- * @since 3.2
- */
- public static String join(final int[] array, final char separator) {
- if (array == null) {
- return null;
- }
- 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.
- * </p>
- *
- * <p>
- * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
- * by empty strings.
- * </p>
- *
- * <pre>
- * StringUtils.join(null, *) = null
- * StringUtils.join([], *) = ""
- * StringUtils.join([null], *) = ""
- * StringUtils.join([1, 2, 3], ';') = "1;2;3"
- * StringUtils.join([1, 2, 3], null) = "123"
- * </pre>
- *
- * @param array
- * the array of values to join together, may be null
- * @param separator
- * the separator character to use
- * @return the joined String, {@code null} if null array input
- * @since 3.2
- */
- public static String join(final short[] array, final char separator) {
- if (array == null) {
- return null;
- }
- 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.
- * </p>
- *
- * <p>
- * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
- * by empty strings.
- * </p>
- *
- * <pre>
- * StringUtils.join(null, *) = null
- * StringUtils.join([], *) = ""
- * StringUtils.join([null], *) = ""
- * StringUtils.join([1, 2, 3], ';') = "1;2;3"
- * StringUtils.join([1, 2, 3], null) = "123"
- * </pre>
- *
- * @param array
- * the array of values to join together, may be null
- * @param separator
- * the separator character to use
- * @return the joined String, {@code null} if null array input
- * @since 3.2
- */
- public static String join(final byte[] array, final char separator) {
- if (array == null) {
- return null;
- }
- 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.
- * </p>
- *
- * <p>
- * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
- * by empty strings.
- * </p>
- *
- * <pre>
- * StringUtils.join(null, *) = null
- * StringUtils.join([], *) = ""
- * StringUtils.join([null], *) = ""
- * StringUtils.join([1, 2, 3], ';') = "1;2;3"
- * StringUtils.join([1, 2, 3], null) = "123"
- * </pre>
- *
- * @param array
- * the array of values to join together, may be null
- * @param separator
- * the separator character to use
- * @return the joined String, {@code null} if null array input
- * @since 3.2
- */
- public static String join(final char[] array, final char separator) {
- if (array == null) {
- return null;
- }
- 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.
- * </p>
- *
- * <p>
- * No delimiter is added before or after the list. Null objects or empty strings within the array are represented
- * by empty strings.
- * </p>
- *
- * <pre>
- * StringUtils.join(null, *) = null
- * StringUtils.join([], *) = ""
- * StringUtils.join([null], *) = ""
- * StringUtils.join([1, 2, 3], ';') = "1;2;3"
- * StringUtils.join([1, 2, 3], null) = "123"
- * </pre>
- *
- * @param array
- * the array of values to join together, may be null
- * @param separator
- * the separator character to use
- * @return the joined String, {@code null} if null array input
- * @since 3.2
- */
- public static String join(final float[] array, final char separator) {
- if (array == null) {
- return null;
- }
- return join(array, separator, 0, array.length);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement