Class IntrospectionUtil


  • public class IntrospectionUtil
    extends Object
    General introspection utilities
    • Method Detail

      • hasMultipleValues

        public static boolean hasMultipleValues​(Class clazz)
        Figure out if field represents multiple values
        Parameters:
        clazz - Field to evaluate
        Returns:
        true if field is an array or collection
      • getCollectionComponentType

        public static Class<?> getCollectionComponentType​(Field field)
        Determine if the field is a list or array and return its component type if so.
        Parameters:
        field - Field to evaluate
        Returns:
        List/Array component type or field type if not a list or array
      • isPrimitive

        public static boolean isPrimitive​(Field field)
        A primitive field is one which is a single or array/list of primitive values.
        Parameters:
        field - Field to evaluate
        Returns:
        true if primitive or list/array of primitive values
      • isSimple

        public static boolean isSimple​(Field field)
        A simple field is either primitive, an enumeration, or a string.
        Parameters:
        field - Field to evaluate
        Returns:
        true if primitive, an enumeration, or a string
      • createObject

        public static Optional<Object> createObject​(Class c)
        Try any available public constructors to create an object. Return the first successful attempt.
        Parameters:
        c - Class to use
        Returns:
        Optional object if successful, otherwise empty optional.
      • getDeclaredValue

        public static Optional<Object> getDeclaredValue​(AccessibleObject field)
        Determine the declared (default) value of a field; if a method is provided then an Empty optional is returned Note: This assumes that there is a public no-parameter constructor for the declaring object, otherwise this will return an empty optional.
        Parameters:
        field - Field to evaluate
        Returns:
        Optional with value if any found, otherwise empty optional is returned