Package it.tidalwave.util.spi
Class AsSupport
- java.lang.Object
-
- it.tidalwave.util.spi.AsSupport
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface it.tidalwave.util.As
As.Defaults, As.NotFoundBehaviour<T>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tas(Class<T> type)Returns an adapter to this object of the specified type.<T> Tas(Class<T> type, As.NotFoundBehaviour<T> notFoundBehaviour)Returns an adapter to this object of the specified type.<T> Collection<T>asMany(Class<T> type)Searches for multiple adapters of the given type and returns them.
-
-
-
Constructor Detail
-
AsSupport
protected AsSupport()
Constructor for use in subclassing.
-
AsSupport
public AsSupport(@Nonnull Object owner, @Nonnull Object... rolesOrFactories)
Constructor for use in composition. In addition to the mandatory owner, it's possible to pass a collection of pre-instantiated roles, or instances ofRoleFactorythat will be invoked to create additional roles.- Parameters:
owner- the ownerrolesOrFactories- a collection of roles or factories for roles
-
-
Method Detail
-
as
@Nonnull public <T> T as(@Nonnull Class<T> type)
Returns an adapter to this object of the specified type. If the implementation can find multiple compliant adapters, only one will be returned.
-
as
@Nonnull public <T> T as(@Nonnull Class<T> type, @Nonnull As.NotFoundBehaviour<T> notFoundBehaviour)
Returns an adapter to this object of the specified type. If the implementation can find multiple compliant adapters, only one will be returned. If no adapter is found, the result provided by the given default behaviour will be returned. First, local roles are probed; then the owner, in case it directly implements the required role; at last, the delegate is invoked.
-
asMany
@Nonnull public <T> Collection<T> asMany(@Nonnull Class<T> type)
Searches for multiple adapters of the given type and returns them. The list contains all the relevant local roles, as well as those retrieved by the delegate, in this order.
-
-