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>
,java.io.Serializable
,java.lang.Cloneable
- Direct Known Subclasses:
FinderWithIdSupport
,PersonFinderImpl2a
,PersonFinderImpl2b
,SimpleFinderSupport
public class HierarchicFinderSupport<T,F extends Finder<T>> extends java.lang.Object implements Finder<T>
A support class for implementing aFinder
. Subclasses only need to implement thecomputeResults()
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 theFinder
with extra methods, please use the simplifiedSimpleFinderSupport
.- Author:
- Fabrizio Giudici
- See Also:
- Serialized Form
- 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 Modifier and Type Field Description protected int
firstResult
protected int
maxResults
-
Constructor Summary
Constructors Modifier Constructor Description protected
HierarchicFinderSupport()
Default constructor.protected
HierarchicFinderSupport(HierarchicFinderSupport<T,F> other, java.lang.Object holder)
Clone constructor for subclasses.protected
HierarchicFinderSupport(java.lang.String name)
Creates an instance with the given name (that will be used for diagnostics).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description HierarchicFinderSupport<T,F>
clone()
Deprecated.protected F
clone(java.lang.Object override)
Deprecated.UseclonedWith(Object)
instead.protected F
clonedWith(java.lang.Object override)
Create a clone of this object calling the special copy constructor by reflection.protected java.util.List<T>
computeNeededResults()
Subclasses can implement this method where *only the requested* raw results must be retrieved.protected java.util.List<T>
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.F
from(int firstResult)
Tells theFinder
that only a subset of found items will be returned, starting from the given position.protected static <U> U
getSource(java.lang.Class<? extends U> type, U other, java.lang.Object override)
A utility method used by the copy constructor (see general documentation).F
max(int maxResults)
Tells theFinder
that only a maximum number of found items will be returned.<U> Finder<U>
ofType(java.lang.Class<U> type)
Tells theFinder
that the specified type of results is expected.java.util.List<T>
results()
Performs the search and returns the found items.F
sort(Finder.SortCriterion criterion)
Tells theFinder
that results will be sorted according to the given criterion, in ascending direction.F
sort(Finder.SortCriterion criterion, Finder.SortDirection direction)
Tells theFinder
that results will be sorted according to the given criterion and direction.F
withContext(java.lang.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, from, iterator, max, optionalFirstResult, optionalResult, result, stream
-
-
-
-
Constructor Detail
-
HierarchicFinderSupport
protected HierarchicFinderSupport(@Nonnull java.lang.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 java.lang.Object holder)
Clone constructor for subclasses.- Parameters:
other
- the other instance to cloneholder
- the holder object
-
-
Method Detail
-
clone
@Nonnull public final HierarchicFinderSupport<T,F> clone()
Deprecated.This method throws an exception since aFinder
extending this class must be cloned withclonedWith(Object)
.- Overrides:
clone
in classjava.lang.Object
- See Also:
clonedWith(Object)
-
clonedWith
@Nonnull protected F clonedWith(@Nonnull java.lang.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 java.lang.Object override)
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
@Nonnull public F from(@Nonnegative int firstResult)
Tells theFinder
that only a subset of found items will be returned, starting from the given position.
-
max
@Nonnull public F max(@Nonnegative int maxResults)
Tells theFinder
that only a maximum number of found items will be returned.
-
withContext
@Nonnull public F withContext(@Nonnull java.lang.Object context)
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
@Nonnull public <U> Finder<U> ofType(@Nonnull java.lang.Class<U> type)
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
@Nonnull public final F sort(@Nonnull Finder.SortCriterion criterion)
Tells theFinder
that results will be sorted according to the given criterion, in ascending direction.
-
results
@Nonnull public java.util.List<T> 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
@Nonnull protected java.util.List<T> computeResults()
Subclasses can implement this method where *all* the raw results must be actually retrieved.- Returns:
- the unprocessed results
-
computeNeededResults
@Nonnull protected java.util.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 java.lang.Class<? extends U> type, @Nonnull U other, @Nonnull java.lang.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
-
-