- java.lang.Object
-
- org.praxislive.code.userapi.Ref.Provider
-
public abstract static class Ref.Provider extends Object
Providers initialize Ref instances so that the underlying value can be used directly as the injected field type.A default provider covers some basic types, or a custom handler type may be set in
Inject#handler()
. A custom handler must have a public, no-arg constructor which registers initializers.
-
-
Constructor Summary
Constructors Constructor Description Provider()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Ref.Provider
getDefault()
Get the default provider.<T> Ref.Initializer<T>
initializerFor(Class<T> type)
Acquire the initializer for the given type.boolean
isSupportedType(Class<?> type)
Check if this handler supports the provided type.protected <T> void
provide(Class<T> type, Supplier<? extends T> constructor)
Register a constructor for the given type.protected <T> void
provide(Class<T> type, Supplier<? extends T> constructor, Consumer<? super T> disposer)
Register a constructor and disposer for the given type.protected <T> void
register(Class<T> type, Ref.Initializer<? extends T> initializer)
Register an initializer to configure a Ref for the given type.Set<Class<?>>
supportedTypes()
The set of types supported by this handler.
-
-
-
Method Detail
-
initializerFor
public final <T> Ref.Initializer<T> initializerFor(Class<T> type)
Acquire the initializer for the given type.- Type Parameters:
T
- generic type- Parameters:
type
- type- Returns:
- initializer for type, or null if not supported
-
supportedTypes
public final Set<Class<?>> supportedTypes()
The set of types supported by this handler.- Returns:
- supported types
-
isSupportedType
public final boolean isSupportedType(Class<?> type)
Check if this handler supports the provided type.- Parameters:
type
- type- Returns:
- supported
-
register
protected final <T> void register(Class<T> type, Ref.Initializer<? extends T> initializer)
Register an initializer to configure a Ref for the given type. The initializer should initialize the Ref, as well as add dispose or other handlers as required.- Type Parameters:
T
- generic type- Parameters:
type
- typeinitializer
- initializer for type
-
provide
protected final <T> void provide(Class<T> type, Supplier<? extends T> constructor)
Register a constructor for the given type. This is a shortcut method to register an initializer, equivalent to registeringr -> r.init(constructor)
. The reference will use the default disposer that handlesAutoCloseable
- see documentation ofRef
.- Type Parameters:
T
- generic type- Parameters:
type
- typeconstructor
- constructor for type
-
provide
protected final <T> void provide(Class<T> type, Supplier<? extends T> constructor, Consumer<? super T> disposer)
Register a constructor and disposer for the given type. This is a shortcut method to register an initializer, equivalent to registeringr -> r.init(constructor).onDispose(disposer)
.- Type Parameters:
T
- generic type- Parameters:
type
- typeconstructor
- constructor for typedisposer
- disposer for type
-
getDefault
public static Ref.Provider getDefault()
Get the default provider. The default provider supports fields of type List, Map and Set, via ArrayList, LinkedHashMap and LinkedHashSet respectively.- Returns:
- default provider
-
-