Class Reflections


  • public class Reflections
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Reflections()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Optional<?> getUnwrappedEnumValue​(java.lang.Class<?> clazz, java.lang.Object instance)
      Extracts the underlying value from an enum wrapper instance if the class follows the enum wrapper pattern.
      static boolean isEnumWrapper​(java.lang.Class<?> clazz)
      Checks if the given class is an enum wrapper.
      static boolean isEnumWrapper​(java.lang.Object obj)
      Checks if the given object is an instance of an enum wrapper class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Reflections

        public Reflections()
    • Method Detail

      • getUnwrappedEnumValue

        public static java.util.Optional<?> getUnwrappedEnumValue​(java.lang.Class<?> clazz,
                                                                  java.lang.Object instance)
        Extracts the underlying value from an enum wrapper instance if the class follows the enum wrapper pattern.

        An enum wrapper is a class that emulates enum behavior but can handle unknown values without runtime errors. This pattern is commonly used for API responses where new enum values might be added over time.

        The method validates that the class follows the enum wrapper pattern by checking for:

        • A static factory method of(String) or of(Integer) that returns the class type
        • An instance method value() returning String or Integer
        • At least one public static final field of the same class type (predefined constants)

        If all validation passes, the method invokes the value() method on the provided instance and returns the result.

        Parameters:
        clazz - the class to examine for enum wrapper pattern
        instance - the instance of the enum wrapper class from which to extract the value
        Returns:
        Optional<?> containing the extracted value (String or Integer) if the class follows the enum wrapper pattern and the value extraction succeeds, Optional.empty() otherwise
      • isEnumWrapper

        public static boolean isEnumWrapper​(java.lang.Class<?> clazz)
        Checks if the given class is an enum wrapper.

        An enum wrapper is a class that emulates enum behavior but can handle unknown values without runtime errors. This pattern is commonly used for API responses where new enum values might be added over time.

        The method validates that the class follows the enum wrapper pattern by checking for:

        • A static factory method of(String) or of(Integer) that returns the class type
        • An instance method value() returning String or Integer
        • At least one public static final field of the same class type (predefined constants)
        Parameters:
        clazz - the class to examine for enum wrapper pattern
        Returns:
        true if the class is an enum wrapper, false otherwise
      • isEnumWrapper

        public static boolean isEnumWrapper​(java.lang.Object obj)
        Checks if the given object is an instance of an enum wrapper class.
        Parameters:
        obj - the object to check
        Returns:
        true if the object is an instance of an enum wrapper class, false otherwise