public abstract class FinderSupport<Type,ExtendedFinder 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 and Type | Field and Description |
---|---|
protected int |
firstResult |
protected int |
maxResults |
protected List<it.tidalwave.util.spi.FinderSupport.Sorter<Type>> |
sorters |
Modifier | Constructor and Description |
---|---|
protected |
FinderSupport() |
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,ExtendedFinder> |
clone()
Clones this object.
|
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.
|
Type |
firstResult()
Performs the search and returns only the first found item.
|
ExtendedFinder |
from(int firstResult)
Tells the
Finder that only a subset of found items will be returned, starting from the given position. |
ExtendedFinder |
max(int maxResults)
Tells the
Finder that only a maximum number of found items will be returned. |
<AnotherType> |
ofType(Class<AnotherType> 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.
|
ExtendedFinder |
sort(Finder.SortCriterion criterion)
Tells the
Finder that results will be sorted according to the given criterion, in ascending direction. |
ExtendedFinder |
sort(Finder.SortCriterion criterion,
Finder.SortDirection direction)
Tells the
Finder that results will be sorted according to the given criterion and direction. |
@Nonnegative protected int firstResult
@Nonnegative protected int maxResults
protected FinderSupport(@Nonnull String name)
name
- the nameprotected FinderSupport()
@Nonnull public FinderSupport<Type,ExtendedFinder> clone()
@Nonnull public ExtendedFinder from(@Nonnegative int firstResult)
Finder
that only a subset of found items will be returned, starting from the given position.@Nonnull public ExtendedFinder max(@Nonnegative int maxResults)
Finder
that only a maximum number of found items will be returned.@Nonnull public <AnotherType> Finder<AnotherType> ofType(@Nonnull Class<AnotherType> type)
Finder
that the specified type of results is expected.@Nonnull public ExtendedFinder 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 ExtendedFinder 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–2015 Tidalwave s.a.s. (http://tidalwave.it). All rights reserved.