Module it.tidalwave.util
Package it.tidalwave.util.spi
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
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface it.tidalwave.util.Finder
Finder.InMemorySortCriterion<U>, Finder.SortCriterion, Finder.SortDirection -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.protectedHierarchicFinderSupport(HierarchicFinderSupport<T, F> other, Object holder) Clone constructor for subclasses.protectedCreates an instance with the given name (that will be used for diagnostics). -
Method Summary
Modifier and TypeMethodDescriptionfinal HierarchicFinderSupport<T, F> clone()Deprecated.protected FDeprecated.protected FclonedWith(Object override) Create a clone of this object calling the special copy constructor by reflection.Subclasses can implement this method where *only the requested* raw results must be retrieved.Subclasses can implement this method where *all* the raw results must be actually retrieved.intcount()Performs the search and returns the count of found items.from(int firstResult) Tells theFinderthat only a subset of found items will be returned, starting from the given position.protected static <U> UA utility method used by the copy constructor (see general documentation).max(int maxResults) Tells theFinderthat only a maximum number of found items will be returned.<U> Finder<U> Tells theFinderthat the specified type of results is expected.results()Performs the search and returns the found items.final Fsort(Finder.SortCriterion criterion) Tells theFinderthat results will be sorted according to the given criterion, in ascending direction.sort(Finder.SortCriterion criterion, Finder.SortDirection direction) Tells theFinderthat results will be sorted according to the given criterion and direction.withContext(Object context) Tells theFinderthat results should be created with the given context.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface it.tidalwave.util.Finder
firstResult, forEach, from, from, iterator, max, max, optionalFirstResult, optionalResult, result, stream
-
Field Details
-
firstResult
protected final int firstResult -
maxResults
protected final int maxResults
-
-
Constructor Details
-
HierarchicFinderSupport
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 cloneholder- the holder object
-
-
Method Details
-
clone
Deprecated.This method throws an exception since aFinderextending this class must be cloned withclonedWith(Object). -
clonedWith
Create a clone of this object calling the special copy constructor by reflection.- Parameters:
override- the override object- Returns:
- the clone
-
clone
Deprecated.UseclonedWith(Object)instead.Create a clone of this object calling the special clone constructor by reflection.- Parameters:
override- the override object- Returns:
- the clone
-
from
Tells theFinderthat only a subset of found items will be returned, starting from the given position. -
max
Tells theFinderthat only a maximum number of found items will be returned. -
withContext
Tells theFinderthat results should be created with the given context. This method can be called multiple times; contexts are accumulated.- Specified by:
withContextin interfaceFinder<T>- Parameters:
context- the context- Returns:
- the
Finder
-
ofType
Tells theFinderthat the specified type of results is expected. -
sort
@Nonnull public F sort(@Nonnull Finder.SortCriterion criterion, @Nonnull Finder.SortDirection direction) Tells theFinderthat results will be sorted according to the given criterion and direction. -
sort
Tells theFinderthat results will be sorted according to the given criterion, in ascending direction. -
results
Performs the search and returns the found items. -
count
public int count()Performs the search and returns the count of found items. -
computeResults
Subclasses can implement this method where *all* the raw results must be actually retrieved.- Returns:
- the unprocessed results
-
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 sourceother- the other finderoverride- the holder object- Returns:
- the override or other
-
clonedWith(Object)instead.