- java.lang.Object
-
- org.github.gestalt.config.utils.RecordUtils
-
public final class RecordUtils extends java.lang.ObjectLarge parts of this code is borrowed from ...Utility methods for record serialization, using MethodHandles.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ObjectcomponentValue(java.lang.Object recordObject, RecComponent recordComponent)Retrieves the value of the record component for the given record object.static <T> TinvokeCanonicalConstructor(java.lang.Class<T> recordType, RecComponent[] recordComponents, java.lang.Object[] args)Invokes the canonical constructor of a record class with the given argument values.static booleanisRecord(java.lang.Class<?> type)Returns true if, and only if, the given class is a record class.static <T> RecComponent[]recordComponents(java.lang.Class<T> type, java.util.Comparator<RecComponent> comparator)Returns an ordered array of the record components for the given record class.
-
-
-
Method Detail
-
isRecord
public static boolean isRecord(java.lang.Class<?> type)
Returns true if, and only if, the given class is a record class.- Parameters:
type- class type- Returns:
- if this class is a record
-
recordComponents
public static <T> RecComponent[] recordComponents(java.lang.Class<T> type, java.util.Comparator<RecComponent> comparator)
Returns an ordered array of the record components for the given record class. The order is imposed by the given comparator. If the given comparator is null, the order is that of the record components in the record attribute of the class file.- Type Parameters:
T- This is the type of the record- Parameters:
type- class typecomparator- how to sort the records- Returns:
- the record components
-
componentValue
public static java.lang.Object componentValue(java.lang.Object recordObject, RecComponent recordComponent)Retrieves the value of the record component for the given record object.- Parameters:
recordObject- record object to get its valuesrecordComponent- components or records- Returns:
- record components
-
invokeCanonicalConstructor
public static <T> T invokeCanonicalConstructor(java.lang.Class<T> recordType, RecComponent[] recordComponents, java.lang.Object[] args)Invokes the canonical constructor of a record class with the given argument values.- Type Parameters:
T- This is the type of the record- Parameters:
recordType- type of recordrecordComponents- record componentsargs- objects used to create the record- Returns:
- the record created
-
-