Package it.tidalwave.util
Interface As
-
public interface As
Objects implementing this interface can provide am adapter of the required type. The adapter can be found with a variety of approaches that depend on the implementation. This capability can be used to implement a design based on the Data, Context and Interaction pattern (DCI). For further details, please look at the project website, where a tutorial is available.- Author:
- Fabrizio Giudici
- Status: stable API
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
As.Defaults
Deprecated.static interface
As.NotFoundBehaviour<T>
Deprecated.static class
As.Type<T>
A type reference for roles that can be used in place of a class literal, especially when roles with generics are used.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default <T> T
as(As.Type<T> type)
Returns a role for this object of the specified type.default <T> T
as(java.lang.Class<T> type)
Returns an adapter to this object of the specified type.default <T> T
as(java.lang.Class<T> type, As.NotFoundBehaviour<T> notFoundBehaviour)
Deprecated.default <T> java.util.Collection<T>
asMany(As.Type<T> type)
Returns the requested role or an emptyOptional
.<T> java.util.Collection<T>
asMany(java.lang.Class<T> type)
Searches for multiple adapters of the given type and returns them.static As
forObject(java.lang.Object object)
Creates anAs
implementation delegate for the given object (or returns the object itself if it is the default implementation ofAs
).static As
forObject(java.lang.Object object, java.lang.Object role)
Creates anAs
implementation delegate for the given object.static As
forObject(java.lang.Object object, java.util.Collection<java.lang.Object> roles)
Creates anAs
implementation delegate for the given object.default <T> java.util.Optional<T>
maybeAs(As.Type<T> type)
Returns the requested role or an emptyOptional
.<T> java.util.Optional<T>
maybeAs(java.lang.Class<T> type)
Returns the requested role or an emptyOptional
.static <T> As.Type<T>
type(java.lang.Class<?> type)
Creates a role type reference.
-
-
-
Method Detail
-
forObject
@Nonnull static As forObject(@Nonnull java.lang.Object object)
Creates anAs
implementation delegate for the given object (or returns the object itself if it is the default implementation ofAs
).- Parameters:
object
- the object- Returns:
- the implementation
- Since:
- 3.2-ALPHA-12
-
forObject
@Nonnull static As forObject(@Nonnull java.lang.Object object, @Nonnull java.lang.Object role)
Creates anAs
implementation delegate for the given object. It accepts a single pre-instantiated role, or aRoleFactory
that will be invoked to create additional roles.- Parameters:
object
- the objectrole
- the role orRoleFactory
- Returns:
- the implementation
- Since:
- 3.2-ALPHA-13
-
forObject
@Nonnull static As forObject(@Nonnull java.lang.Object object, @Nonnull java.util.Collection<java.lang.Object> roles)
Creates anAs
implementation delegate for the given object. It accepts a collection of pre-instantiated roles, or instances ofRoleFactory
that will be invoked to create additional roles.- Parameters:
object
- the objectroles
- roles orRoleFactory
instances- Returns:
- the implementation
- Since:
- 3.2-ALPHA-13
-
as
@Nonnull default <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.- Type Parameters:
T
- the static type- Parameters:
type
- the dynamic type- Returns:
- the adapter
- Throws:
AsException
- if no adapter is found
-
as
@Nonnull @Deprecated default <T> T as(@Nonnull java.lang.Class<T> type, @Nonnull As.NotFoundBehaviour<T> notFoundBehaviour)
Deprecated.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.- Type Parameters:
T
- the static type- Parameters:
type
- the dynamic typenotFoundBehaviour
- the behaviour to apply when an adapter is not found- Returns:
- the adapter
-
maybeAs
@Nonnull <T> java.util.Optional<T> maybeAs(@Nonnull java.lang.Class<T> type)
Returns the requested role or an emptyOptional
.- Type Parameters:
T
- the static type- Parameters:
type
- the dynamic type- Returns:
- the optional role
- Since:
- 3.2-ALPHA-3
-
asMany
@Nonnull <T> java.util.Collection<T> asMany(@Nonnull java.lang.Class<T> type)
Searches for multiple adapters of the given type and returns them.- Type Parameters:
T
- the static type- Parameters:
type
- the dynamic type- Returns:
- a collection of adapters, possibly empty
-
type
@Nonnull static <T> As.Type<T> type(@Nonnull java.lang.Class<?> type)
Creates a role type reference.- Type Parameters:
T
- the static type- Parameters:
type
- the dynamic type- Returns:
- the type reference
- Since:
- 3.2-ALPHA-12
-
as
@Nonnull default <T> T as(@Nonnull As.Type<T> type)
Returns a role for this object of the specified type. If the implementation can find multiple compliant roles, only one will be returned.- Type Parameters:
T
- the static type- Parameters:
type
- the type reference- Returns:
- the role
- Since:
- 3.2-ALPHA-12
-
maybeAs
@Nonnull default <T> java.util.Optional<T> maybeAs(@Nonnull As.Type<T> type)
Returns the requested role or an emptyOptional
.- Type Parameters:
T
- the static type- Parameters:
type
- the type reference- Returns:
- the optional role
- Since:
- 3.2-ALPHA-12
-
asMany
@Nonnull default <T> java.util.Collection<T> asMany(@Nonnull As.Type<T> type)
Returns the requested role or an emptyOptional
.- Type Parameters:
T
- the static type- Parameters:
type
- the type reference- Returns:
- the roles
- Since:
- 3.2-ALPHA-12
-
-