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>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AsSupport()
Constructor for use in subclassing.AsSupport(java.lang.Object owner)
Constructor for use in composition.AsSupport(java.lang.Object owner, java.lang.Object role)
Constructor for use in composition.AsSupport(java.lang.Object owner, java.util.Collection<java.lang.Object> roles)
Constructor for use in composition.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
as(java.lang.Class<T> type)
Returns an adapter to this object of the specified type.<T> T
as(java.lang.Class<T> type, As.NotFoundBehaviour<T> notFoundBehaviour)
Returns an adapter to this object of the specified type.<T> java.util.Collection<T>
asMany(java.lang.Class<T> type)
Searches for multiple adapters of the given type and returns them.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface it.tidalwave.util.As
asOptional, maybeAs
-
-
-
-
Constructor Detail
-
AsSupport
protected AsSupport()
Constructor for use in subclassing.
-
AsSupport
public AsSupport(@Nonnull java.lang.Object owner)
Constructor for use in composition.- Parameters:
owner
- the owner- Since:
- 3.2-ALPHA-3 (refactored)
-
AsSupport
public AsSupport(@Nonnull java.lang.Object owner, @Nonnull java.lang.Object role)
Constructor for use in composition. In addition to the mandatory owner, it accepts a single pre-instantiated role, or aRoleFactory
that will be invoked to create additional roles.- Parameters:
owner
- the ownerrole
- the role orRoleFactory
- Since:
- 3.2-ALPHA-3
-
AsSupport
public AsSupport(@Nonnull java.lang.Object owner, @Nonnull java.util.Collection<java.lang.Object> roles)
Constructor for use in composition. In addition to the mandatory owner, it accepts a collection of pre-instantiated roles, or instances ofRoleFactory
that will be invoked to create additional roles.- Parameters:
owner
- the ownerroles
- roles orRoleFactory
instances- Since:
- 3.2-ALPHA-3 (refactored)
-
-
Method Detail
-
as
@Nonnull public <T> T as(@Nonnull java.lang.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 java.lang.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> java.util.Collection<T> asMany(@Nonnull java.lang.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.
-
-