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 Deprecated 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 boolean
contains(Object[] array, Object object)
static boolean
containsIgnoreCase(String[] array, String searchedText)
static int
countMatches(String str, char ch)
Counts how many times the char appears in the given string.static ClassLoader
getContextClassLoader()
static ClassLoader
getCurrentClassLoader(Class clazz)
static Field
getField(Class<?> clazz, String name)
static Field
getFieldRecursive(Class<?> clazz, String name)
static Class<?>
getTypeFromCollectionProperty(Object base, String property)
Determines the type of the generic collection via the getter.static Class
getUnproxiedClass(Class currentClass)
NOTE: copied from DeltaSpikestatic boolean
isBlank(String str)
static boolean
isEmpty(String value)
static boolean
isNotBlank(String value)
static boolean
isNotEmpty(String value)
static boolean
isNumeric(String str)
Checks whether the given String is a parsable number.static boolean
isProxiedClass(Class currentClass)
NOTE: copied from DeltaSpike Analyses if the given class is a generated proxy classstatic boolean
isValueBlank(String str)
Deprecated.static boolean
isValueEmpty(String value)
Deprecated.static Class
loadClassForName(String name)
static String
md5Hex(byte[] bytes)
static <E> Set<E>
newLinkedHashSet(E... elements)
static String
substring(String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.static String
toCapitalCase(String value)
Converts a sting to capital case even counting Unicode characters.static Class
tryToLoadClassForName(String name)
static <T> List<T>
unmodifiableList(T... args)
-
-
-
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 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
n
characters from the end of the String.The returned substring starts with the character in the
start
position and ends before theend
position. 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
start
is 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,
null
if 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 catchingParseException
when calling one of those methods.Hexadecimal and scientific notations are not considered parsable.
Null
and empty String will returnfalse
.- Parameters:
str
- the String to check.- Returns:
true
if the string is a parsable number.- Since:
- 3.4
-
-