Class LangUtils
- java.lang.Object
-
- org.primefaces.util.LangUtils
-
public class LangUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Object[]EMPTY_OBJECT_ARRAY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]concat(String[]... arrays)static String[]concat(String[] array1, String[] array2)static <T> List<T>concat(List<T>... lists)static <T> Set<T>concat(Set<T>... sets)static booleancontains(Object[] array, Object object)static booleancontainsIgnoreCase(String[] array, String searchedText)static intcountMatches(String str, char ch)Counts how many times the char appears in the given string.static ClassLoadergetContextClassLoader()static ClassLoadergetCurrentClassLoader(Class clazz)static Class<?>getTypeFromCollectionProperty(Object base, String property)Determines the type of the generic collection via the getter.static ClassgetUnproxiedClass(Class currentClass)NOTE: copied from DeltaSpikestatic booleanisNotBlank(String value)static booleanisNumeric(String str)Checks whether the given String is a parsable number.static booleanisProxiedClass(Class currentClass)NOTE: copied from DeltaSpike Analyses if the given class is a generated proxy classstatic booleanisValueBlank(String str)static booleanisValueEmpty(String value)static ClassloadClassForName(String name)static Stringmd5Hex(byte[] bytes)static <E> Set<E>newLinkedHashSet(E... elements)static Stringsubstring(String str, int start, int end)Gets a substring from the specified String avoiding exceptions.static StringtoCapitalCase(String value)Converts a sting to capital case even counting Unicode characters.static ClasstryToLoadClassForName(String name)static <T> List<T>unmodifiableList(T... args)
-
-
-
Field Detail
-
EMPTY_OBJECT_ARRAY
public static final Object[] EMPTY_OBJECT_ARRAY
-
-
Method Detail
-
isValueEmpty
public static boolean isValueEmpty(String value)
-
isValueBlank
public static boolean isValueBlank(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
nullor empty ("") String input returns0.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 nullch- 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
ncharacters from the end of the String.The returned substring starts with the character in the
startposition and ends before theendposition. All position counting is zero-based -- i.e., to start at the beginning of the string usestart = 0. Negative start and end positions can be used to specify offsets relative to the end of the String.If
startis not strictly to the left ofend, "" 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 nullstart- the position to start from, negative means count back from the end of the String by this many charactersend- 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,
nullif null String input
-
concat
@SafeVarargs public static <T> Set<T> concat(Set<T>... sets)
-
concat
@SafeVarargs public static <T> List<T> concat(List<T>... lists)
-
unmodifiableList
@SafeVarargs public static final <T> List<T> unmodifiableList(T... args)
-
newLinkedHashSet
public static <E> Set<E> newLinkedHashSet(E... elements)
-
loadClassForName
public static Class 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)orDouble.parseDouble(String). This method can be used instead of catchingParseExceptionwhen calling one of those methods.Hexadecimal and scientific notations are not considered parsable.
Nulland empty String will returnfalse.- Parameters:
str- the String to check.- Returns:
trueif the string is a parsable number.- Since:
- 3.4
-
-