Class HierarchicFinderSupport<T,F extends Finder<T>>

java.lang.Object
it.tidalwave.util.spi.HierarchicFinderSupport<T,F>
All Implemented Interfaces:
Finder<T>, Serializable, Cloneable
Direct Known Subclasses:
FinderWithIdSupport, SimpleFinderSupport

public class HierarchicFinderSupport<T,F extends Finder<T>> extends Object implements Finder<T>
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:
Status: draft API
  • Field Details

    • firstResult

      @Nonnegative protected final int firstResult
    • maxResults

      @Nonnegative protected final int maxResults
  • Constructor Details

    • HierarchicFinderSupport

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

      protected HierarchicFinderSupport()
      Default constructor.
    • HierarchicFinderSupport

      protected HierarchicFinderSupport(@Nonnull HierarchicFinderSupport<T,F> other, @Nonnull Object holder)
      Clone constructor for subclasses.
      Parameters:
      other - the other instance to clone
      holder - the holder object
  • Method Details

    • clone

      @Nonnull public final HierarchicFinderSupport<T,F> clone()
      Deprecated.
      This method throws an exception since a Finder extending this class must be cloned with clonedWith(Object).
      Overrides:
      clone in class Object
      See Also:
    • clonedWith

      @Nonnull protected F clonedWith(@Nonnull Object override)
      Create a clone of this object calling the special copy constructor by reflection.
      Parameters:
      override - the override object
      Returns:
      the clone
    • clone

      @Nonnull @Deprecated protected F clone(@Nonnull Object override)
      Deprecated.
      Use clonedWith(Object) instead.
      Create a clone of this object calling the special clone constructor by reflection.
      Parameters:
      override - the override object
      Returns:
      the clone
    • from

      @Nonnull public F 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<T>
      Parameters:
      firstResult - the index of the first result to return
      Returns:
      the Finder
    • max

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

      @Nonnull public F 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<T>
      Parameters:
      context - the context
      Returns:
      the Finder
    • ofType

      @Nonnull public <U> Finder<U> ofType(@Nonnull Class<U> type)
      Tells the Finder that the specified type of results is expected.
      Specified by:
      ofType in interface Finder<T>
      Type Parameters:
      U - the static type
      Parameters:
      type - the dynamic type
      Returns:
      the Finder
    • sort

      @Nonnull public F sort(@Nonnull Finder.SortCriterion criterion, @Nonnull Finder.SortDirection direction)
      Tells the Finder that results will be sorted according to the given criterion and direction.
      Specified by:
      sort in interface Finder<T>
      Parameters:
      criterion - the sort criterion
      direction - the sort direction
      Returns:
      the Finder
    • sort

      @Nonnull public final F sort(@Nonnull Finder.SortCriterion criterion)
      Tells the Finder that results will be sorted according to the given criterion, in ascending direction.
      Specified by:
      sort in interface Finder<T>
      Parameters:
      criterion - the sort criterion
      Returns:
      the Finder
    • results

      @Nonnull public List<T> results()
      Performs the search and returns the found items.
      Specified by:
      results in interface Finder<T>
      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<T>
      Returns:
      the count of found items
    • computeResults

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

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

      @Nonnull protected static <U> U getSource(@Nonnull Class<? extends U> type, @Nonnull U other, @Nonnull Object override)
      A utility method used by the copy constructor (see general documentation). If the override object is strictly of the specified type, it is returned; otherwise the other object is returned.
      Type Parameters:
      U - the static type of the source
      Parameters:
      type - the dynamic type of the source
      other - the other finder
      override - the holder object
      Returns:
      the override or other