Class PodamUtils


  • public abstract class PodamUtils
    extends Object
    PODAM Utilities class.
    Since:
    1.0.0
    Author:
    mtedone
    • Field Detail

      • NICE_ASCII_CHARACTERS

        public static final char[] NICE_ASCII_CHARACTERS
        An array of valid String characters
      • LOG

        private static final org.slf4j.Logger LOG
        The application logger.
    • Constructor Detail

      • PodamUtils

        public PodamUtils()
    • Method Detail

      • getField

        public static Field getField​(Class<?> pojoClass,
                                     String attributeName)
        It returns a Field matching the attribute name or null if a field was not found.
        Parameters:
        pojoClass - The class supposed to contain the field
        attributeName - The field name
        Returns:
        a Field matching the attribute name or null if a field was not found.
      • getFieldValue

        public static <T> T getFieldValue​(Object pojo,
                                          String attributeName)
        It returns an value for a Field matching the attribute name or null if a field was not found.
        Type Parameters:
        T - The type of field to be returned
        Parameters:
        pojo - The class supposed to contain the field
        attributeName - The field name
        Returns:
        an instance of Field matching the attribute name or null if a field was not found.
      • getFieldValueWithGetter

        public static <T> T getFieldValueWithGetter​(Object pojo,
                                                    String attributeName)
        It returns an value from getter for a Field matching the attribute name or null if a field was not found.
        Type Parameters:
        T - The type of field to be returned
        Parameters:
        pojo - The class supposed to contain the field
        attributeName - The field name
        Returns:
        an instance of Field matching the attribute name or null if a field was not found.
      • selectLatestMethod

        public static Method selectLatestMethod​(Set<Method> methods)
        Searches among set of a class'es methods and selects the one defined in the most specific descend of the hierarchy tree
        Parameters:
        methods - a set of methods to choose from
        Returns:
        the selected method
      • getAttributeAnnotations

        public static List<Annotation> getAttributeAnnotations​(Field attribute,
                                                               Method... methods)
        Given the attribute and setter it combines annotations from them or an empty collection if no custom annotations were found
        Parameters:
        attribute - The class attribute
        methods - List of setters and getter to check annotations
        Returns:
        all annotations for the attribute
      • getNiceCharacter

        public static Character getNiceCharacter()
        Generates random character from set valid for identifiers in Java language
        Returns:
        random character suitable for identifier
      • getLongInRange

        public static long getLongInRange​(long minValue,
                                          long maxValue)
        It returns a long/Long value between min and max value (included).
        Parameters:
        minValue - The minimum value for the returned value
        maxValue - The maximum value for the returned value
        Returns:
        A long/Long value between min and max value (included).
      • getIntegerInRange

        public static int getIntegerInRange​(int minValue,
                                            int maxValue)
        It returns a random int/Integer value between min and max value (included).
        Parameters:
        minValue - The minimum value for the returned value
        maxValue - The maximum value for the returned value
        Returns:
        An int/Integer value between min and max value (included).
      • getDoubleInRange

        public static double getDoubleInRange​(double minValue,
                                              double maxValue)
        It returns a double/Double value between min and max value (included).
        Parameters:
        minValue - The minimum value for the returned value
        maxValue - The maximum value for the returned value
        Returns:
        A double/Double value between min and max value (included)
      • primitiveToBoxedType

        public static Class<?> primitiveToBoxedType​(Class<?> primitiveType)
        Finds boxed type for a primitive type
        Parameters:
        primitiveType - Primitive type to find boxed type for
        Returns:
        A boxed type or the same type, if original type was not primitive