Package org.fryske_akademy
Class Util
java.lang.Object
org.fryske_akademy.Util
- Author:
- eduard
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanbothNullOrEmpty(String s, String t) static Throwableyou 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.formatConstraintException(jakarta.validation.ConstraintViolationException cve) static <T> Tfind a bean programmatically in CDI provider by name, 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 booleanFast method to check if a char is at a certain position in a string.look for all methods whose return type is an enum and add all constants to the result.static booleanstatic <T> TLook 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 StringCallssplit(java.lang.String, int, boolean)with false.static StringCallsplit(java.lang.String, java.lang.String, int, boolean)with ": ?" as regex.static Stringsplit a string on regex and return the requested index, or null.static Stringreturn "enum simple class"."enum name"static Stringreturn "[" +toString(java.lang.Enum)for each enum + "]"
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
setEnumsFromString
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
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
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
look for a method returning an enum, call it, if the value isn't null return it.- Parameters:
objectWithEnums-- Returns:
-
listEnums
look for all methods whose return type is an enum and add all constants to the result.- Parameters:
clazz-- Returns:
-
findInClass
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
return "enum simple class"."enum name"- Parameters:
e-- Returns:
-
toString
return "[" +toString(java.lang.Enum)for each enum + "]"- Parameters:
l-- Returns:
-
split
Callssplit(java.lang.String, int, boolean)with false.- Parameters:
toSplit-index-- Returns:
-
split
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
you can set log level to fine to see the original stacktrace in the log.- Parameters:
t-- Returns:
-
isIndex
Fast method to check if a char is at a certain position in a string.- Parameters:
input-c-pos-- Returns:
-
getBean
find a bean programmatically in CDI provider by name, can be used if you need one in an unmanaged situation. PreferInstance.select(Class, Annotation...).- Type Parameters:
T-- Parameters:
clazz-name- the name of the bean to lookup- Returns:
-
formatConstraintException
-
nullOrEmpty
-
bothNullOrEmpty
-