it.tidalwave.util.spi
Class FinderSupport<Type,ExtendedFinder extends Finder<Type>>

Package class diagram package FinderSupport
java.lang.Object
  extended by it.tidalwave.util.spi.FinderSupport<Type,ExtendedFinder>
All Implemented Interfaces:
Finder<Type>, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Composite.EmptyFinder, SimpleFinderSupport

public abstract class FinderSupport<Type,ExtendedFinder extends Finder<Type>>
extends java.lang.Object
implements Finder<Type>, java.lang.Cloneable

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.

Version:
$Id$
Author:
Fabrizio Giudici
See Also:
Serialized Form
Status: draft API

Nested Class Summary
 
Nested classes/interfaces inherited from interface it.tidalwave.util.Finder
Finder.FilterSortCriterion<Type>, Finder.SortCriterion, Finder.SortDirection
 
Field Summary
protected  int firstResult
           
protected  int maxResults
           
protected  java.util.List<it.tidalwave.util.spi.FinderSupport.Sorter<Type>> sorters
           
 
Constructor Summary
protected FinderSupport()
           
protected FinderSupport(java.lang.String name)
          Creates an instance with the given name (that will be used for diagnostics).
 
Method Summary
 FinderSupport<Type,ExtendedFinder> clone()
          Clones this object.
protected abstract  java.util.List<? extends Type> computeResults()
          Subclasses must implement this method where raw results are 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>
Finder<AnotherType>
ofType(java.lang.Class<AnotherType> type)
          
 Type result()
          Performs the search assuming that it will return a single item and returns it.
 java.util.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.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

firstResult

@Nonnegative
protected int firstResult

maxResults

@Nonnegative
protected int maxResults

sorters

@Nonnull
protected java.util.List<it.tidalwave.util.spi.FinderSupport.Sorter<Type>> sorters
Constructor Detail

FinderSupport

protected FinderSupport(@Nonnull
                        java.lang.String name)
Creates an instance with the given name (that will be used for diagnostics).

Parameters:
name - the name

FinderSupport

protected FinderSupport()
Method Detail

clone

@Nonnull
public FinderSupport<Type,ExtendedFinder> clone()
Clones this object. This operation is called whenever a parameter-setting method is called in fluent-interface style.

Overrides:
clone in class java.lang.Object
Returns:
the cloned object

from

@Nonnull
public ExtendedFinder from(@Nonnegative
                                   int firstResult)
Tells the Finder that only a subset of found items will be returned, starting from the given position.

Specified by:
from in interface Finder<Type>
Returns:
the Finder

max

@Nonnull
public ExtendedFinder max(@Nonnegative
                                  int maxResults)
Tells the Finder that only a maximum number of found items will be returned.

Specified by:
max in interface Finder<Type>
Returns:
the Finder

ofType

@Nonnull
public <AnotherType> Finder<AnotherType> ofType(@Nonnull
                                                        java.lang.Class<AnotherType> type)

Specified by:
ofType in interface Finder<Type>
Returns:
the Finder

sort

@Nonnull
public ExtendedFinder sort(@Nonnull
                                   Finder.SortCriterion criterion,
                                   @Nonnull
                                   Finder.SortDirection direction)
Tells the Finder that results will be sorted according to the given criterion and direction.

Specified by:
sort in interface Finder<Type>
Parameters:
criterion - the sort criterion
direction - the sort direction
Returns:
the Finder

sort

@Nonnull
public final ExtendedFinder sort(@Nonnull
                                         Finder.SortCriterion criterion)
Tells the Finder that results will be sorted according to the given criterion, in ascending direction.

Specified by:
sort in interface Finder<Type>
Parameters:
criterion - the sort criterion
Returns:
the Finder

result

@Nonnull
public Type result()
            throws NotFoundException
Performs the search assuming that it will return a single item and returns it. This method fails if the search returns more than one single item.

Specified by:
result in interface Finder<Type>
Returns:
the found item
Throws:
NotFoundException - if the search didn't find anything

firstResult

@Nonnull
public Type firstResult()
                 throws NotFoundException
Performs the search and returns only the first found item.

Specified by:
firstResult in interface Finder<Type>
Returns:
the first found item
Throws:
NotFoundException - if the search didn't find anything

results

@Nonnull
public java.util.List<? extends Type> results()
Performs the search and returns the found items.

Specified by:
results in interface Finder<Type>
Returns:
the searched items

count

@Nonnegative
public int count()
Performs the search and returns the count of found items.

Specified by:
count in interface Finder<Type>
Returns:
the count of found items

toString

@Nonnull
public java.lang.String toString()

Overrides:
toString in class java.lang.Object

computeResults

@Nonnull
protected abstract java.util.List<? extends Type> computeResults()
Subclasses must implement this method where raw results are actually retrieved.

Returns:
the unprocessed results


Copyright © 2009-2011 Tidalwave s.a.s.. All Rights Reserved.