Class LangUtils


  • public class LangUtils
    extends Object
    • Field Detail

      • EMPTY_OBJECT_ARRAY

        public static final Object[] EMPTY_OBJECT_ARRAY
    • Method Detail

      • isValueEmpty

        @Deprecated
        public static boolean isValueEmpty​(String value)
        Deprecated.
      • isEmpty

        public static boolean isEmpty​(String value)
      • isNotEmpty

        public static boolean isNotEmpty​(String value)
      • isValueBlank

        @Deprecated
        public static boolean isValueBlank​(String str)
        Deprecated.
      • isBlank

        public static boolean isBlank​(String str)
      • isNotBlank

        public static boolean isNotBlank​(String value)
      • countMatches

        public static int countMatches​(String str,
                                       char ch)

        Counts how many times the char appears in the given string.

        A null or empty ("") String input returns 0.

         StringUtils.countMatches(null, *)       = 0
         StringUtils.countMatches("", *)         = 0
         StringUtils.countMatches("abba", 0)  = 0
         StringUtils.countMatches("abba", 'a')   = 2
         StringUtils.countMatches("abba", 'b')  = 2
         StringUtils.countMatches("abba", 'x') = 0
         
        Parameters:
        str - the CharSequence to check, may be null
        ch - the char to count
        Returns:
        the number of occurrences, 0 if the CharSequence is null
        Since:
        3.4
      • substring

        public static String substring​(String str,
                                       int start,
                                       int end)

        Gets a substring from the specified String avoiding exceptions.

        A negative start position can be used to start/end n characters from the end of the String.

        The returned substring starts with the character in the start position and ends before the end position. All position counting is zero-based -- i.e., to start at the beginning of the string use start = 0. Negative start and end positions can be used to specify offsets relative to the end of the String.

        If start is not strictly to the left of end, "" is returned.

         StringUtils.substring(null, *, *)    = null
         StringUtils.substring("", * ,  *)    = "";
         StringUtils.substring("abc", 0, 2)   = "ab"
         StringUtils.substring("abc", 2, 0)   = ""
         StringUtils.substring("abc", 2, 4)   = "c"
         StringUtils.substring("abc", 4, 6)   = ""
         StringUtils.substring("abc", 2, 2)   = ""
         StringUtils.substring("abc", -2, -1) = "b"
         StringUtils.substring("abc", -4, 2)  = "ab"
         
        Parameters:
        str - the String to get the substring from, may be null
        start - the position to start from, negative means count back from the end of the String by this many characters
        end - the position to end at (exclusive), negative means count back from the end of the String by this many characters
        Returns:
        substring from start position to end position, null if null String input
      • contains

        public static boolean contains​(Object[] array,
                                       Object object)
      • concat

        public static String[] concat​(String[]... arrays)
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(String[] array,
                                                 String searchedText)
      • unmodifiableList

        @SafeVarargs
        public static final <T> List<T> unmodifiableList​(T... args)
      • newLinkedHashSet

        public static <E> Set<E> newLinkedHashSet​(E... elements)
      • tryToLoadClassForName

        public static Class tryToLoadClassForName​(String name)
      • getContextClassLoader

        public static ClassLoader getContextClassLoader()
      • getCurrentClassLoader

        public static ClassLoader getCurrentClassLoader​(Class clazz)
      • getUnproxiedClass

        public static Class getUnproxiedClass​(Class currentClass)
        NOTE: copied from DeltaSpike
        Parameters:
        currentClass - current class
        Returns:
        class of the real implementation
      • isProxiedClass

        public static boolean isProxiedClass​(Class currentClass)
        NOTE: copied from DeltaSpike Analyses if the given class is a generated proxy class
        Parameters:
        currentClass - current class
        Returns:
        true if the given class is a known proxy class, false otherwise
      • md5Hex

        public static String md5Hex​(byte[] bytes)
      • toCapitalCase

        public static String toCapitalCase​(String value)
        Converts a sting to capital case even counting Unicode characters.
         thisIsMyString = This Is My String
         ThisIsATest = This Is A Test
         helloWorld = Hello World
         
        Parameters:
        value - the value to capital case
        Returns:
        the returned value in capital case or empty string if blank
      • getFieldRecursive

        public static Field getFieldRecursive​(Class<?> clazz,
                                              String name)