Package it.tidalwave.util
Interface As
-
- All Known Implementing Classes:
AsSupport
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).- Author:
- Fabrizio Giudici
- Status: stable API
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
As.Defaults
static interface
As.NotFoundBehaviour<T>
static class
As.Ref<T>
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default <T> T
as(As.Ref<T> ref)
Returns a role for this object of the specified type.<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.default <T> java.util.Collection<T>
asMany(As.Ref<T> ref)
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.default <T> java.util.Optional<T>
asOptional(java.lang.Class<T> type)
Deprecated.UsemaybeAs(Class)
.default <T> java.util.Optional<T>
maybeAs(As.Ref<T> ref)
Returns the requested role or an emptyOptional
.default <T> java.util.Optional<T>
maybeAs(java.lang.Class<T> type)
Returns the requested role or an emptyOptional
.static <T> As.Ref<T>
ref(java.lang.Class<?> type)
Creates a role type reference.
-
-
-
Method Detail
-
as
@Nonnull <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 <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.- 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 default <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
-
asOptional
@Nonnull @Deprecated default <T> java.util.Optional<T> asOptional(@Nonnull java.lang.Class<T> type)
Deprecated.UsemaybeAs(Class)
.- Type Parameters:
T
- the static type- Parameters:
type
- the dynamic type- Returns:
- the optional role
-
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
-
ref
@Nonnull static <T> As.Ref<T> ref(@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.Ref<T> ref)
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:
ref
- the type reference- Returns:
- the role
- Since:
- 3.2-ALPHA-12
-
maybeAs
@Nonnull default <T> java.util.Optional<T> maybeAs(@Nonnull As.Ref<T> ref)
Returns the requested role or an emptyOptional
.- Type Parameters:
T
- the static type- Parameters:
ref
- the type reference- Returns:
- the optional role
- Since:
- 3.2-ALPHA-12
-
asMany
@Nonnull default <T> java.util.Collection<T> asMany(@Nonnull As.Ref<T> ref)
Returns the requested role or an emptyOptional
.- Type Parameters:
T
- the static type- Parameters:
ref
- the type reference- Returns:
- the roles
- Since:
- 3.2-ALPHA-12
-
-