Package org.fryske_akademy
Class Util
- java.lang.Object
-
- org.fryske_akademy.Util
-
public class Util extends Object
- Author:
- eduard
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanbothNullOrEmpty(String s, String t)static ThrowabledeepestCause(Throwable t)you can set log level to fine to see the original stacktrace in the log.static EnumfindInClass(Class clazz, String e)Look for methods with return type enum, whose simple class is the first part of the argument string, look for the enum constant whose name is the last part of the argument string.static List<String>formatConstraintException(jakarta.validation.ConstraintViolationException cve)static <T> TgetBean(Class<T> clazz, Annotation... qualifiers)find a bean programmatically in CDI provider, can be used if you need one in an unmanaged situation.static <T> TgetBean(Class<T> clazz, String name)find a bean programmatically in CDI provider, can be used if you need one in an unmanaged situation.static EnumgetEnumWithValue(Object objectWithEnums)look for a method returning an enum, call it, if the value isn't null return it.static booleanhasSetterForEnumString(String t, Object objectWithEnums)look for a setter ignoring case for a string in the form "enum simple class"."enum name", return true if it is found.static booleanisIndex(String input, char c, int pos)Fast method to check if a char is at a certain position in a string.static List<Enum>listEnums(Class clazz)look for all methods whose return type is an enum and add all constants to the result.static booleannullOrEmpty(String s)static <T> TsetEnum(Enum e, T objectWithEnums)Look for a setter for the enum in the object, call it and return the object.static <T> TsetEnumsFromString(String inputString, T objectWithEnums)parse a string containing enums the form "enum simple class"."enum name" separated by space, look for the right setter in the Object class and call the setter.static Stringsplit(String toSplit, int index)Callssplit(java.lang.String, int, boolean)with false.static Stringsplit(String toSplit, int index, boolean ignorePatternAfterIndex)Callsplit(java.lang.String, java.lang.String, int, boolean)with ": ?" as regex.static Stringsplit(String toSplit, String regex, int index, boolean ignorePatternAfterIndex)split a string on regex and return the requested index, or null.static StringtoString(Enum e)return "enum simple class"."enum name"static StringtoString(List<Enum> l)return "[" +toString(java.lang.Enum)for each enum + "]"
-
-
-
Method Detail
-
setEnumsFromString
public static <T> T setEnumsFromString(String inputString, T objectWithEnums)
parse a string containing enums the form "enum simple class"."enum name" separated by space, look for the right setter in the Object class and call the setter. Case is ignored.- Parameters:
inputString- space separated inputStrng, containing "enum simple class"."enum name"objectWithEnums-- Throws:
IllegalArgumentException- when no setter has been called for an enum string
-
hasSetterForEnumString
public static boolean hasSetterForEnumString(String t, Object objectWithEnums)
look for a setter ignoring case for a string in the form "enum simple class"."enum name", return true if it is found.- Parameters:
t-objectWithEnums-- Returns:
-
setEnum
public static <T> T setEnum(Enum e, T objectWithEnums)
Look for a setter for the enum in the object, call it and return the object.- Type Parameters:
T-- Parameters:
e-objectWithEnums-- Returns:
- Throws:
IllegalArgumentException- when no setter has been called for the enum
-
getEnumWithValue
public static Enum getEnumWithValue(Object objectWithEnums)
look for a method returning an enum, call it, if the value isn't null return it.- Parameters:
objectWithEnums-- Returns:
-
listEnums
public static List<Enum> listEnums(Class clazz)
look for all methods whose return type is an enum and add all constants to the result.- Parameters:
clazz-- Returns:
-
findInClass
public static Enum findInClass(Class clazz, String e)
Look for methods with return type enum, whose simple class is the first part of the argument string, look for the enum constant whose name is the last part of the argument string. Case is ignored.- Parameters:
clazz-e- string in the form "enum simple class"."enum name"- Returns:
-
toString
public static String toString(Enum e)
return "enum simple class"."enum name"- Parameters:
e-- Returns:
-
toString
public static String toString(List<Enum> l)
return "[" +toString(java.lang.Enum)for each enum + "]"- Parameters:
l-- Returns:
-
split
public static String split(String toSplit, int index)
Callssplit(java.lang.String, int, boolean)with false.- Parameters:
toSplit-index-- Returns:
-
split
public static String split(String toSplit, int index, boolean ignorePatternAfterIndex)
Callsplit(java.lang.String, java.lang.String, int, boolean)with ": ?" as regex.- Parameters:
toSplit-index-ignorePatternAfterIndex-- Returns:
-
split
public static String split(String toSplit, String regex, int index, boolean ignorePatternAfterIndex)
split a string on regex and return the requested index, or null. Can be used to find an entity using a readable user representation of an entity such as "netherlands: franeker", or "netherlands: franeker: center".- Parameters:
toSplit-index-ignorePatternAfterIndex- when true, occurring patterns after index will be ignored, so the return value will be the rest of the input string.- Returns:
-
deepestCause
public static Throwable deepestCause(Throwable t)
you can set log level to fine to see the original stacktrace in the log.- Parameters:
t-- Returns:
-
isIndex
public static boolean isIndex(String input, char c, int pos)
Fast method to check if a char is at a certain position in a string.- Parameters:
input-c-pos-- Returns:
-
getBean
public static <T> T getBean(Class<T> clazz, Annotation... qualifiers)
find a bean programmatically in CDI provider, can be used if you need one in an unmanaged situation.- Type Parameters:
T-- Parameters:
clazz-qualifiers- required, if needed extendAnnotationLiteralimplementing your qualifier and instantiate that.- Returns:
-
getBean
public static <T> T getBean(Class<T> clazz, String name)
find a bean programmatically in CDI provider, can be used if you need one in an unmanaged situation.- Type Parameters:
T-- Parameters:
clazz-name- the name of the bean to lookup- Returns:
-
formatConstraintException
public static List<String> formatConstraintException(jakarta.validation.ConstraintViolationException cve)
-
nullOrEmpty
public static boolean nullOrEmpty(String s)
-
-