Package com.google.genai.gaos.utils
Class Reflections
java.lang.Object
com.google.genai.gaos.utils.Reflections
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<?>getUnwrappedEnumValue(Class<?> clazz, Object instance) Extracts the underlying value from an enum wrapper instance if the class follows the enum wrapper pattern.static booleanisEnumWrapper(Class<?> clazz) Checks if the given class is an enum wrapper.static booleanisEnumWrapper(Object obj) Checks if the given object is an instance of an enum wrapper class.
-
Constructor Details
-
Reflections
public Reflections()
-
-
Method Details
-
getUnwrappedEnumValue
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)orof(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 patterninstance- 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
- A static factory method
-
isEnumWrapper
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)orof(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
- A static factory method
-
isEnumWrapper
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
-