public class FinderSupport<TYPE,EXTENDED_FINDER extends Finder<TYPE>> extends Object implements Finder<TYPE>, Cloneable
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
.Finder.FilterSortCriterion<TYPE>, Finder.SortCriterion, Finder.SortDirection
Modifier | Constructor and Description |
---|---|
protected |
FinderSupport()
Default constructor.
|
protected |
FinderSupport(FinderSupport<TYPE,EXTENDED_FINDER> other,
Object override)
Clone constructor for subclasses.
|
protected |
FinderSupport(String name)
Creates an instance with the given name (that will be used for diagnostics).
|
Modifier and Type | Method and Description |
---|---|
FinderSupport<TYPE,EXTENDED_FINDER> |
clone()
Deprecated.
|
protected EXTENDED_FINDER |
clone(Object override) |
protected List<? extends TYPE> |
computeNeededResults()
Subclasses can implement this method where *only the requested* raw results must be retrieved.
|
protected List<? extends TYPE> |
computeResults()
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.
|
static <T> Finder<T> |
emptyFinder()
Returns an empty
Finder . |
TYPE |
firstResult()
Performs the search and returns only the first found item.
|
EXTENDED_FINDER |
from(int firstResult)
Tells the
Finder that only a subset of found items will be returned, starting from the given position. |
protected static <T> T |
getSource(Class<T> clazz,
T other,
Object override) |
EXTENDED_FINDER |
max(int maxResults)
Tells the
Finder that only a maximum number of found items will be returned. |
<ANOTHER_TYPE> |
ofType(Class<ANOTHER_TYPE> type)
Tells the
Finder that the specified type of results is expected. |
TYPE |
result()
Performs the search assuming that it will return a single item and returns it.
|
List<? extends TYPE> |
results()
Performs the search and returns the found items.
|
EXTENDED_FINDER |
sort(Finder.SortCriterion criterion)
Tells the
Finder that results will be sorted according to the given criterion, in ascending direction. |
EXTENDED_FINDER |
sort(Finder.SortCriterion criterion,
Finder.SortDirection direction)
Tells the
Finder that results will be sorted according to the given criterion and direction. |
EXTENDED_FINDER |
withContext(Object context)
Tells the
Finder that results should be created with the given context. |
protected FinderSupport(@Nonnull String name)
name
- the nameprotected FinderSupport()
protected FinderSupport(@Nonnull FinderSupport<TYPE,EXTENDED_FINDER> other, @Nonnull Object override)
@Nonnull public static <T> Finder<T> emptyFinder()
Finder
.T
- the type of the Finder
Finder
@Nonnull protected static <T> T getSource(Class<T> clazz, @Nonnull T other, @Nonnull Object override)
@Nonnull public final FinderSupport<TYPE,EXTENDED_FINDER> clone()
@Nonnull protected EXTENDED_FINDER clone(@Nonnull Object override)
@Nonnull public EXTENDED_FINDER from(@Nonnegative int firstResult)
Finder
that only a subset of found items will be returned, starting from the given position.@Nonnull public EXTENDED_FINDER max(@Nonnegative int maxResults)
Finder
that only a maximum number of found items will be returned.@Nonnull public EXTENDED_FINDER withContext(@Nonnull Object context)
Finder
that results should be created with the given context. This method can be called
multiple times; contexts are accumulated.withContext
in interface Finder<TYPE>
context
- the contextFinder
@Nonnull public <ANOTHER_TYPE> Finder<ANOTHER_TYPE> ofType(@Nonnull Class<ANOTHER_TYPE> type)
Finder
that the specified type of results is expected.@Nonnull public EXTENDED_FINDER sort(@Nonnull Finder.SortCriterion criterion, @Nonnull Finder.SortDirection direction)
Finder
that results will be sorted according to the given criterion and direction.@Nonnull public final EXTENDED_FINDER sort(@Nonnull Finder.SortCriterion criterion)
Finder
that results will be sorted according to the given criterion, in ascending direction.@Nonnull public TYPE result() throws NotFoundException
result
in interface Finder<TYPE>
NotFoundException
- if the search didn't find anything@Nonnull public TYPE firstResult() throws NotFoundException
firstResult
in interface Finder<TYPE>
NotFoundException
- if the search didn't find anything@Nonnull public List<? extends TYPE> results()
@Nonnegative public int count()
@Nonnull protected List<? extends TYPE> computeResults()
Copyright © 2009–2016 Tidalwave s.a.s. (http://tidalwave.it). All rights reserved.