Class LangUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]static String[]static <T> List<T>static <T> Set<T>static booleanstatic booleancontainsIgnoreCase(String[] array, String searchedText) static intcountMatches(String str, char ch) Counts how many times the char appears in the given string.static ClassLoaderstatic 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 booleanstatic booleanisClassAvailable(String name) static booleanstatic booleanisNotBlank(String value) static booleanisNotEmpty(String value) static booleanChecks 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 <T> Class<T>loadClassForName(String name) static Stringmd5Hex(byte[] bytes) static <E> Set<E>newLinkedHashSet(E... elements) static StringGets a substring from the specified String avoiding exceptions.static StringtoCapitalCase(String value) Converts a sting to capital case even counting Unicode characters.static <T> Class<T>tryToLoadClassForName(String name) static MethodtryToLoadMethodForName(Class<?> clazz, String name, Class<?>... args) static final <T> List<T>unmodifiableList(T... args)
-
Field Details
-
EMPTY_OBJECT_ARRAY
-
-
Method Details
-
isEmpty
-
isNotEmpty
-
isBlank
-
isNotBlank
-
countMatches
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
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
-
contains
-
concat
-
concat
-
concat
-
concat
-
containsIgnoreCase
-
unmodifiableList
-
newLinkedHashSet
-
isClassAvailable
-
tryToLoadClassForName
-
tryToLoadMethodForName
-
loadClassForName
- Throws:
ClassNotFoundException
-
getContextClassLoader
-
getCurrentClassLoader
-
getUnproxiedClass
NOTE: copied from DeltaSpike- Parameters:
currentClass- current class- Returns:
- class of the real implementation
-
isProxiedClass
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
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
-
toCapitalCase
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
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
-