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
-
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor.protected
HierarchicFinderSupport
(HierarchicFinderSupport<T, F> other, Object holder) Clone constructor for subclasses.protected
Creates an instance with the given name (that will be used for diagnostics). -
Method Summary
Modifier and TypeMethodDescriptionfinal HierarchicFinderSupport
<T, F> clone()
Deprecated.protected F
Deprecated.protected F
clonedWith
(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.int
count()
Performs the search and returns the count of found items.from
(int firstResult) Tells theFinder
that only a subset of found items will be returned, starting from the given position.protected static <U> U
A utility method used by the copy constructor (see general documentation).max
(int maxResults) Tells theFinder
that only a maximum number of found items will be returned.<U> Finder
<U> Tells theFinder
that the specified type of results is expected.results()
Performs the search and returns the found items.final F
sort
(Finder.SortCriterion criterion) Tells theFinder
that results will be sorted according to the given criterion, in ascending direction.sort
(Finder.SortCriterion criterion, Finder.SortDirection direction) Tells theFinder
that results will be sorted according to the given criterion and direction.withContext
(Object context) Tells theFinder
that results should be created with the given context.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface it.tidalwave.util.Finder
firstResult, forEach, from, from, iterator, max, max, optionalFirstResult, optionalResult, result, stream
-
Field Details
-
firstResult
@Nonnegative protected final int firstResult -
maxResults
@Nonnegative 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 aFinder
extending 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 theFinder
that only a subset of found items will be returned, starting from the given position. -
max
Tells theFinder
that only a maximum number of found items will be returned. -
withContext
Tells theFinder
that results should be created with the given context. This method can be called multiple times; contexts are accumulated.- Specified by:
withContext
in interfaceFinder<T>
- Parameters:
context
- the context- Returns:
- the
Finder
-
ofType
Tells theFinder
that the specified type of results is expected. -
sort
@Nonnull public F sort(@Nonnull Finder.SortCriterion criterion, @Nonnull Finder.SortDirection direction) Tells theFinder
that results will be sorted according to the given criterion and direction. -
sort
Tells theFinder
that results will be sorted according to the given criterion, in ascending direction. -
results
Performs the search and returns the found items. -
count
@Nonnegative 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.