Class PriorityAsSupport

  • All Implemented Interfaces:
    it.tidalwave.util.As

    public class PriorityAsSupport
    extends it.tidalwave.util.spi.AsSupport
    implements it.tidalwave.util.As
    A specialisation of AsSupport that deals with multiple roles of the same type by prioritising them; they are ordered from most relevant to least relevant (where relevance is associated to specialisation, that is most specialised roles, or roles associated via @DciRole to most specialised datum classes, are most relevant). FIXME: could be seen as a replacement to AsSupport?
    Author:
    Fabrizio Giudici
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  PriorityAsSupport.RoleProvider  
      • Nested classes/interfaces inherited from interface it.tidalwave.util.As

        it.tidalwave.util.As.Defaults, it.tidalwave.util.As.NotFoundBehaviour<T extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T as​(java.lang.Class<T> type)
      Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned.
      <T> T as​(java.lang.Class<T> type, it.tidalwave.util.As.NotFoundBehaviour<T> notFoundBehaviour)
      Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned.
      <T> java.util.Collection<T> asMany​(java.lang.Class<T> type)
      Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned.
      <T> java.util.Optional<T> maybeAs​(java.lang.Class<T> type)
      Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface it.tidalwave.util.As

        asOptional
    • Constructor Detail

      • PriorityAsSupport

        public PriorityAsSupport​(java.lang.Object owner)
      • PriorityAsSupport

        public PriorityAsSupport​(@Nonnull
                                 java.lang.Object owner,
                                 @Nonnull
                                 java.util.Collection<java.lang.Object> rolesOrFactories)
      • PriorityAsSupport

        public PriorityAsSupport​(@Nonnull
                                 java.lang.Object owner,
                                 @Nonnull
                                 PriorityAsSupport.RoleProvider additionalRoleProvider,
                                 @Nonnull
                                 java.util.Collection<java.lang.Object> rolesOrFactories)
    • Method Detail

      • as

        @Nonnull
        public <T> T as​(@Nonnull
                        java.lang.Class<T> type)
        Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned. See asMany(java.lang.Class) for further details.
        Specified by:
        as in interface it.tidalwave.util.As
        Overrides:
        as in class it.tidalwave.util.spi.AsSupport
        See Also:
        asMany(java.lang.Class)
      • as

        @Nonnull
        public <T> T as​(@Nonnull
                        java.lang.Class<T> type,
                        @Nonnull
                        it.tidalwave.util.As.NotFoundBehaviour<T> notFoundBehaviour)
        Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned. See asMany(java.lang.Class) for further details.
        Specified by:
        as in interface it.tidalwave.util.As
        Overrides:
        as in class it.tidalwave.util.spi.AsSupport
        See Also:
        asMany(java.lang.Class)
      • maybeAs

        @Nonnull
        public <T> java.util.Optional<T> maybeAs​(@Nonnull
                                                 java.lang.Class<T> type)
        Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned. See asMany(java.lang.Class) for further details.
        Specified by:
        maybeAs in interface it.tidalwave.util.As
        See Also:
        asMany(java.lang.Class)
      • asMany

        @Nonnull
        public <T> java.util.Collection<T> asMany​(@Nonnull
                                                  java.lang.Class<T> type)
        Returned roles can be associated both to this type and to the delegate; the one with the higher priority is returned. The ones associated to this type come with higher priority (this makes sense, being this class a decorator, specific roles could be associated to it). But given that the default implementation of asMany() doesn't guarantee ant order (see TFT-192) there's something to take care of. Currently this method contains some hardwired priority logics.
        Specified by:
        asMany in interface it.tidalwave.util.As
        Overrides:
        asMany in class it.tidalwave.util.spi.AsSupport