Class FinderSupport<TYPE,​EXTENDED_FINDER extends Finder<TYPE>>

  • All Implemented Interfaces:
    Finder<TYPE>, Serializable, Cloneable
    Direct Known Subclasses:
    SimpleFinderSupport

    public class FinderSupport<TYPE,​EXTENDED_FINDER extends Finder<TYPE>>
    extends Object
    implements Finder<TYPE>, Cloneable
    A support class for implementing a Finder. Subclasses only need to implement the computeResults() method where raw results are retrieved (with raw we mean that they shouldn't be filtered or sorted, as post-processing will be performed by this class) and a clone constructor. If you don't need to extend the Finder with extra methods, please use the simplified SimpleFinderSupport.
    Author:
    Fabrizio Giudici
    See Also:
    Serialized Form
    Status: draft API
    • Constructor Detail

      • FinderSupport

        protected FinderSupport​(@Nonnull
                                String name)
        Creates an instance with the given name (that will be used for diagnostics).
        Parameters:
        name - the name
      • FinderSupport

        protected FinderSupport()
        Default constructor.
    • Method Detail

      • from

        @Nonnull
        public EXTENDED_FINDER from​(@Nonnegative
                                    int firstResult)
        Tells the Finder that only a subset of found items will be returned, starting from the given position.
        Specified by:
        from in interface Finder<TYPE>
        Parameters:
        firstResult - the index of the first result to return
        Returns:
        the Finder
      • max

        @Nonnull
        public EXTENDED_FINDER max​(@Nonnegative
                                   int maxResults)
        Tells the Finder that only a maximum number of found items will be returned.
        Specified by:
        max in interface Finder<TYPE>
        Parameters:
        maxResults - the max number of results to return
        Returns:
        the Finder
      • withContext

        @Nonnull
        public EXTENDED_FINDER withContext​(@Nonnull
                                           Object context)
        Tells the Finder that results should be created with the given context. This method can be called multiple times; contexts are accumulated.
        Specified by:
        withContext in interface Finder<TYPE>
        Parameters:
        context - the context
        Returns:
        the Finder
      • ofType

        @Nonnull
        public <ANOTHER_TYPE> Finder<ANOTHER_TYPE> ofType​(@Nonnull
                                                          Class<ANOTHER_TYPE> type)
        Tells the Finder that the specified type of results is expected.
        Specified by:
        ofType in interface Finder<TYPE>
        Parameters:
        type - the expected type of results
        Returns:
        the Finder
      • result

        @Nonnull
        public TYPE result()
                    throws NotFoundException
        Performs the search assuming that it will return a single item and returns it. This method fails if the search returns more than one single item.
        Specified by:
        result in interface Finder<TYPE>
        Returns:
        the found item
        Throws:
        NotFoundException - if the search didn't find anything
      • results

        @Nonnull
        public List<? extends TYPE> results()
        Performs the search and returns the found items.
        Specified by:
        results in interface Finder<TYPE>
        Returns:
        the searched items
      • count

        @Nonnegative
        public int count()
        Performs the search and returns the count of found items.
        Specified by:
        count in interface Finder<TYPE>
        Returns:
        the count of found items
      • computeResults

        @Nonnull
        protected List<? extends TYPE> computeResults()
        Subclasses can implement this method where *all* the raw results must be actually retrieved.
        Returns:
        the unprocessed results
      • computeNeededResults

        @Nonnull
        protected List<? extends TYPE> computeNeededResults()
        Subclasses can implement this method where *only the requested* raw results must be retrieved.
        Returns:
        the unprocessed results