Class LangUtils

java.lang.Object
org.primefaces.util.LangUtils

public class LangUtils extends Object
  • Field Details

    • EMPTY_OBJECT_ARRAY

      public static final Object[] EMPTY_OBJECT_ARRAY
  • Method Details

    • isEmpty

      public static boolean isEmpty(String value)
    • isNotEmpty

      public static boolean isNotEmpty(String value)
    • 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

      @SafeVarargs public static <T> Set<T> concat(Set<T>... sets)
    • concat

      @SafeVarargs public static <T> List<T> concat(List<T>... lists)
    • concat

      public static String[] concat(String[] array1, String[] array2)
    • 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)
    • isClassAvailable

      public static boolean isClassAvailable(String name)
    • tryToLoadClassForName

      public static <T> Class<T> tryToLoadClassForName(String name)
    • tryToLoadMethodForName

      public static Method tryToLoadMethodForName(Class<?> clazz, String name, Class<?>... args)
    • loadClassForName

      public static <T> Class<T> loadClassForName(String name) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • 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
    • getTypeFromCollectionProperty

      public static Class<?> getTypeFromCollectionProperty(Object base, String property)
      Determines the type of the generic collection via the getter. ATTENTION: This method is not designed to cover all possible (edge-)cases. For all full implementation look into something like https://github.com/spring-projects/spring-framework/blob/master/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java
      Parameters:
      base - Object which contains the collection-property as getter.
      property - Name of the collection-property.
      Returns:
      Type of the objects within the collection-property. (eg List<String> -> String)
    • 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
    • isNumeric

      public static boolean isNumeric(String str)

      Checks whether the given String is a parsable number.

      Parsable numbers include those Strings understood by Integer.parseInt(String), Long.parseLong(String), Float.parseFloat(String) or Double.parseDouble(String). This method can be used instead of catching ParseException when calling one of those methods.

      Hexadecimal and scientific notations are not considered parsable.

      Null and empty String will return false.

      Parameters:
      str - the String to check.
      Returns:
      true if the string is a parsable number.
      Since:
      3.4