Class Util


  • public class Util
    extends Object
    Author:
    eduard
    • Constructor Detail

      • Util

        public Util()
    • 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:
      • 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 extend AnnotationLiteral implementing 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​(javax.validation.ConstraintViolationException cve)
      • nullOrEmpty

        public static boolean nullOrEmpty​(String s)
      • bothNullOrEmpty

        public static boolean bothNullOrEmpty​(String s,
                                              String t)