Record Class DelegateTypeAdapterFactory
java.lang.Object
java.lang.Record
eu.cloudnetservice.driver.impl.document.gson.DelegateTypeAdapterFactory
- Record Components:
typeSupportChecker- the check predicate if a type is supported by this factory.delegateFactory- the delegated function to construct the actual type adapter.
- All Implemented Interfaces:
com.google.gson.TypeAdapterFactory
record DelegateTypeAdapterFactory(@NonNull Predicate<Class<?>> typeSupportChecker, @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory)
extends Record
implements com.google.gson.TypeAdapterFactory
A type adapter factory implementation that first validates that the correct type can be provided by it and then calls
the given delegate function, passing the target gson instance to it.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe field for thedelegateFactoryrecord component.The field for thetypeSupportCheckerrecord component. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> @Nullable com.google.gson.TypeAdapter<T> Returns the value of thedelegateFactoryrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static @NonNull com.google.gson.TypeAdapterFactoryhierarchyFactory(@NonNull Class<?> baseClass, @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory) Constructs a new factory that validates that the requested type is somewhere in the hierarchy of the given base type before calling the delegate function.static @NonNull com.google.gson.TypeAdapterFactorystandardFactory(@NonNull Class<?> baseClass, @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory) Constructs a new factory that validates that the requested type is exactly the given base type before calling the delegate function.final StringtoString()Returns a string representation of this record class.Returns the value of thetypeSupportCheckerrecord component.
-
Field Details
-
typeSupportChecker
The field for thetypeSupportCheckerrecord component. -
delegateFactory
@NonNull private final @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactoryThe field for thedelegateFactoryrecord component.
-
-
Constructor Details
-
DelegateTypeAdapterFactory
DelegateTypeAdapterFactory(@NonNull @NonNull Predicate<Class<?>> typeSupportChecker, @NonNull @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory) Creates an instance of aDelegateTypeAdapterFactoryrecord class.- Parameters:
typeSupportChecker- the value for thetypeSupportCheckerrecord componentdelegateFactory- the value for thedelegateFactoryrecord component
-
-
Method Details
-
standardFactory
@NonNull public static @NonNull com.google.gson.TypeAdapterFactory standardFactory(@NonNull @NonNull Class<?> baseClass, @NonNull @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory) Constructs a new factory that validates that the requested type is exactly the given base type before calling the delegate function.- Parameters:
baseClass- the base class that the requested type must be equal to.delegateFactory- the delegate factory to call when a type factory should be created.- Returns:
- a type adapter factory that validates that the exact type is requested before constructing the adapter.
- Throws:
NullPointerException- if the given base type or delegate factory is null.
-
hierarchyFactory
@NonNull public static @NonNull com.google.gson.TypeAdapterFactory hierarchyFactory(@NonNull @NonNull Class<?> baseClass, @NonNull @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory) Constructs a new factory that validates that the requested type is somewhere in the hierarchy of the given base type before calling the delegate function.- Parameters:
baseClass- the base class that the requested type must be in the hierarchy of.delegateFactory- the delegate factory to call when a type factory should be created.- Returns:
- a type adapter factory that validates that a hierarchy type is requested before constructing the adapter.
- Throws:
NullPointerException- if the given base type or delegate factory is null.
-
create
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
typeSupportChecker
Returns the value of thetypeSupportCheckerrecord component.- Returns:
- the value of the
typeSupportCheckerrecord component
-
delegateFactory
@NonNull public @NonNull Function<com.google.gson.Gson, com.google.gson.TypeAdapter<?>> delegateFactory()Returns the value of thedelegateFactoryrecord component.- Returns:
- the value of the
delegateFactoryrecord component
-