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
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated 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.
      default <T> java.util.Optional<T> asOptional​(java.lang.Class<T> type)
      Deprecated.
      default <T> java.util.Optional<T> maybeAs​(java.lang.Class<T> type)
      Returns the requested role or an empty Optional.
    • 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 type
        notFoundBehaviour - 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 empty Optional.
        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.
        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