net.conquiris.api.search
Class PageResult<T>

java.lang.Object
  extended by net.conquiris.api.search.Result
      extended by net.conquiris.api.search.PageResult<T>
All Implemented Interfaces:
Serializable, Iterable<T>

public final class PageResult<T>
extends Result
implements Iterable<T>

Result representing a page of search results. Results are 0-indexed.

Author:
Andres Rodriguez
See Also:
Serialized Form

Method Summary
static
<T> PageResult<T>
empty()
          Returns the empty page.
 boolean equals(Object obj)
           
static
<T> PageResult<T>
found(int totalHits, float maxScore, long time, int firstResult, List<T> items)
          Constructor.
 T get(int index)
          Return the element in the requested index (relative to the page).
 int getFirstRequestedResult()
          Returns the first requested result index.
 int getFirstResult()
          Returns the first result index.
 List<T> getItems()
          Returns the items in the page (never null.
 int getLastResult()
           
 int hashCode()
           
 boolean isEmpty()
          Returns whether the result is empty.
 Iterator<T> iterator()
           
static
<T> PageResult<T>
notFound(int totalHits, float maxScore, long time, int firstResult)
          Returns a page with no results.
static
<T> PageResult<T>
notFound(long time, int firstResult)
          Returns a page with no results in a query with no results.
 int size()
          Returns the number of elements in the page.
 
Methods inherited from class net.conquiris.api.search.Result
getMaxScore, getTime, getTotalHits
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

empty

public static <T> PageResult<T> empty()
Returns the empty page.

Type Parameters:
T - Item type.
Returns:
The empty apge.

notFound

public static <T> PageResult<T> notFound(int totalHits,
                                         float maxScore,
                                         long time,
                                         int firstResult)
Returns a page with no results.

Parameters:
totalHits - Number of hits.
maxScore - Maximum score.
time - Time taken by the query (ms).
firstResult - First requested result index.

notFound

public static <T> PageResult<T> notFound(long time,
                                         int firstResult)
Returns a page with no results in a query with no results.

Parameters:
time - Time taken by the query (ms).
firstResult - First requested result index.

found

public static <T> PageResult<T> found(int totalHits,
                                      float maxScore,
                                      long time,
                                      int firstResult,
                                      List<T> items)
Constructor.

Parameters:
totalHits - Number of hits.
maxScore - Maximum score.
time - Time taken by the query (ms).
firstResult - First result index.
items - Found items.

getFirstRequestedResult

public int getFirstRequestedResult()
Returns the first requested result index. Will the equal to the first result iff the page is not empty.


getFirstResult

public int getFirstResult()
Returns the first result index.

Throws:
IllegalStateException - if the result is empty.

getLastResult

public int getLastResult()

isEmpty

public boolean isEmpty()
Returns whether the result is empty.


size

public int size()
Returns the number of elements in the page.


getItems

public List<T> getItems()
Returns the items in the page (never null.


get

public T get(int index)
Return the element in the requested index (relative to the page).

Throws:
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>

equals

public boolean equals(Object obj)
Overrides:
equals in class Result

hashCode

public int hashCode()
Overrides:
hashCode in class Result


Copyright © 2012 Derquinse Projects.. All Rights Reserved.