Class AsSupport

  • All Implemented Interfaces:
    As

    public class AsSupport
    extends java.lang.Object
    implements As
    Author:
    Fabrizio Giudici
    • 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
    • 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 a RoleFactory that will be invoked to create additional roles.
        Parameters:
        owner - the owner
        role - the role or RoleFactory
        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 of RoleFactory that will be invoked to create additional roles.
        Parameters:
        owner - the owner
        roles - roles or RoleFactory 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.
        Specified by:
        as in interface As
        Type Parameters:
        T - the static type
        Parameters:
        type - the dynamic type
        Returns:
        the adapter
      • 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.
        Specified by:
        as in interface As
        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
      • 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.
        Specified by:
        asMany in interface As
        Type Parameters:
        T - the static type
        Parameters:
        type - the dynamic type
        Returns:
        a collection of adapters, possibly empty