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 final class 
    A type reference for roles that can be used in place of a class literal, especially when roles with generics are used.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    as(As.Type<? extends T> type)
    Returns a role for this object of the specified type.
    default <T> T
    as(Class<? extends T> type)
    Returns an adapter to this object of the specified type.
    default <T> Collection<T>
    asMany(As.Type<? extends T> type)
    Returns the requested role or an empty Optional.
    <T> Collection<T>
    asMany(Class<? extends T> type)
    Searches for multiple adapters of the given type and returns them.
    static As
    forObject(Object object)
    Creates an As implementation delegate for the given object (or returns the object itself if it is the default implementation of As).
    static As
    forObject(Object object, Object role)
    Creates an As implementation delegate for the given object.
    static As
    forObject(Object object, Collection<Object> roles)
    Creates an As implementation delegate for the given object.
    default <T> Optional<T>
    maybeAs(As.Type<? extends T> type)
    Returns the requested role or an empty Optional.
    <T> Optional<T>
    maybeAs(Class<? extends T> type)
    Returns the requested role or an empty Optional.
    static <T> As.Type<T>
    type(Class<?> type)
    Creates a role type reference.
  • Method Details

    • forObject

      @Nonnull static As forObject(@Nonnull Object object)
      Creates an As implementation delegate for the given object (or returns the object itself if it is the default implementation of As).
      Parameters:
      object - the object
      Returns:
      the implementation
      Since:
      3.2-ALPHA-12
    • forObject

      @Nonnull static As forObject(@Nonnull Object object, @Nonnull Object role)
      Creates an As implementation delegate for the given object. It accepts a single pre-instantiated role, or a RoleFactory that will be invoked to create additional roles.
      Parameters:
      object - the object
      role - the role or RoleFactory
      Returns:
      the implementation
      Since:
      3.2-ALPHA-13
    • forObject

      @Nonnull static As forObject(@Nonnull Object object, @Nonnull Collection<Object> roles)
      Creates an As implementation delegate for the given object. It accepts a collection of pre-instantiated roles, or instances of RoleFactory that will be invoked to create additional roles.
      Parameters:
      object - the object
      roles - roles or RoleFactory instances
      Returns:
      the implementation
      Since:
      3.2-ALPHA-13
    • as

      @Nonnull default <T> T as(@Nonnull Class<? extends 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
    • maybeAs

      @Nonnull <T> Optional<T> maybeAs(@Nonnull Class<? extends T> type)
      Returns the requested role or an empty Optional.
      Type Parameters:
      T - the static type
      Parameters:
      type - the dynamic type
      Returns:
      the optional role
      Since:
      3.2-ALPHA-3
    • asMany

      @Nonnull <T> Collection<T> asMany(@Nonnull Class<? extends 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 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<? extends 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> Optional<T> maybeAs(@Nonnull As.Type<? extends T> type)
      Returns the requested role or an empty Optional.
      Type Parameters:
      T - the static type
      Parameters:
      type - the type reference
      Returns:
      the optional role
      Since:
      3.2-ALPHA-12
    • asMany

      @Nonnull default <T> Collection<T> asMany(@Nonnull As.Type<? extends T> type)
      Returns the requested role or an empty Optional.
      Type Parameters:
      T - the static type
      Parameters:
      type - the type reference
      Returns:
      the roles
      Since:
      3.2-ALPHA-12