You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2003/10/26 02:56:06 UTC
cvs commit: cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search LuceneCocoonPager.java
vgritsenko 2003/10/25 17:56:06
Modified: src/blocks/lucene/java/org/apache/cocoon/components/search
LuceneCocoonPager.java
Log:
cleanup
Revision Changes Path
1.3 +26 -78 cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search/LuceneCocoonPager.java
Index: LuceneCocoonPager.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search/LuceneCocoonPager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LuceneCocoonPager.java 11 Mar 2003 17:44:21 -0000 1.2
+++ LuceneCocoonPager.java 26 Oct 2003 00:56:05 -0000 1.3
@@ -66,45 +66,34 @@
*/
public class LuceneCocoonPager implements ListIterator
{
-
/**
- *Description of the Field
- *
- * @since
+ * Default count of hits per page.
*/
public final static int COUNT_OF_HITS_PER_PAGE_DEFAULT = 5;
+
/**
- *Description of the Field
- *
- * @since
+ * Default starting index
*/
public final static int HITS_INDEX_START_DEFAULT = 0;
/**
- * current index of hit to return by next()
- *
- * @since
+ * Current index of hit to return by next()
*/
int hitsIndex = HITS_INDEX_START_DEFAULT;
/**
- * maximum count of hits to return by next(), and previous()
- *
- * @since
+ * Maximum count of hits to return by next(), and previous()
*/
int countOfHitsPerPage = COUNT_OF_HITS_PER_PAGE_DEFAULT;
/**
- * hits to iterate upon
- *
- * @since
+ * Hits to iterate upon
*/
private Hits hits;
/**
* @param hits Description of Parameter
- * @since
*/
public LuceneCocoonPager(Hits hits) {
setHits(hits);
@@ -112,18 +101,16 @@
/**
- *Constructor for the LuceneCocoonPager object
- *
- * @since
+ * Constructor for the LuceneCocoonPager object
*/
- public LuceneCocoonPager() { }
+ public LuceneCocoonPager() {
+ }
/**
- *Sets the hits attribute of the LuceneCocoonPager object
+ * Sets the hits attribute of the LuceneCocoonPager object
*
* @param hits The new hits value
- * @since
*/
public void setHits(Hits hits) {
this.hits = hits;
@@ -135,10 +122,12 @@
* Set count of hits displayed per single page
*
* @param countOfHitsPerPage The new countOfHitsPerPage value
- * @since
*/
public void setCountOfHitsPerPage(int countOfHitsPerPage) {
this.countOfHitsPerPage = countOfHitsPerPage;
+ if (this.countOfHitsPerPage <= 0) {
+ this.countOfHitsPerPage = 1;
+ }
}
@@ -146,7 +135,6 @@
* Get starting index for retrieving hits
*
* @param start_index The new startIndex value
- * @since
*/
public void setStartIndex(int start_index) {
this.hitsIndex = start_index;
@@ -158,7 +146,6 @@
* specified element (optional operation).
*
* @param o Description of Parameter
- * @since
*/
public void set(Object o) {
throw new UnsupportedOperationException();
@@ -169,7 +156,6 @@
* Get count of hits
*
* @return The count of hits
- * @since
*/
public int getCountOfHits() {
return hits.length();
@@ -179,7 +165,6 @@
* Get count of hits displayed per single page
*
* @return The countOfHitsPerPage value
- * @since
*/
public int getCountOfHitsPerPage() {
return this.countOfHitsPerPage;
@@ -189,7 +174,6 @@
* Caluclate count of pages for displaying all hits
*
* @return The countOfPages value
- * @since
*/
public int getCountOfPages() {
int count_of_pages = hits.length() / this.countOfHitsPerPage;
@@ -205,56 +189,45 @@
* Set starting index for retrieving hits
*
* @return The startIndex value
- * @since
*/
public int getStartIndex() {
return this.hitsIndex;
}
-
/**
* Inserts the specified element into the list (optional operation).
*
* @param o Description of Parameter
* @exception UnsupportedOperationException Description of Exception
- * @since
*/
public void add(Object o) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
-
/**
* Returns true if this list iterator has more elements when traversing
* the list in the forward direction.
*
* @return Description of the Returned Value
- * @since
*/
public boolean hasNext() {
- boolean has_next = hitsIndex < hits.length();
- return has_next;
+ return hitsIndex < hits.length();
}
-
/**
* Returns true if this list iterator has more elements when traversing
* the list in the reverse direction.
*
* @return Description of the Returned Value
- * @since
*/
public boolean hasPrevious() {
- boolean has_previous = hitsIndex > countOfHitsPerPage;
- return has_previous;
+ return hitsIndex > countOfHitsPerPage;
}
-
/**
* Returns the next element in the list.
*
* @return Description of the Returned Value
- * @since
*/
public Object next() {
ArrayList hitsPerPageList = new ArrayList();
@@ -262,10 +235,9 @@
if (hitsIndex < endIndex) {
while (hitsIndex < endIndex) {
try {
- HitWrapper hit_wrapper = new HitWrapper(
- hits.score(hitsIndex),
- hits.doc(hitsIndex));
- hitsPerPageList.add(hit_wrapper);
+ HitWrapper hit = new HitWrapper(hits.score(hitsIndex),
+ hits.doc(hitsIndex));
+ hitsPerPageList.add(hit);
} catch (IOException ioe) {
throw new NoSuchElementException("no more hits: " + ioe.getMessage());
}
@@ -277,25 +249,20 @@
return hitsPerPageList;
}
-
/**
* Returns the index of the element that would be returned by a
* subsequent call to next.
*
* @return Description of the Returned Value
- * @since
*/
public int nextIndex() {
- int next_index = Math.min(hitsIndex, hits.length());
- return next_index;
+ return Math.min(hitsIndex, hits.length());
}
-
/**
* Returns the previous element in the list.
*
* @return Description of the Returned Value
- * @since
*/
public Object previous() {
ArrayList hitsPerPageList = new ArrayList();
@@ -306,10 +273,9 @@
if (startIndex < endIndex) {
while (startIndex < endIndex) {
try {
- HitWrapper hit_wrapper = new HitWrapper(
- hits.score(startIndex),
- hits.doc(startIndex));
- hitsPerPageList.add(hit_wrapper);
+ HitWrapper hit = new HitWrapper(hits.score(startIndex),
+ hits.doc(startIndex));
+ hitsPerPageList.add(hit);
} catch (IOException ioe) {
throw new NoSuchElementException("no more hits: " + ioe.getMessage());
}
@@ -322,89 +288,71 @@
return hitsPerPageList;
}
-
/**
* Returns the index of the element that would be returned by a
* subsequent call to previous.
*
* @return Description of the Returned Value
- * @since
*/
public int previousIndex() {
- int previous_index = Math.max(0, hitsIndex - 2 * countOfHitsPerPage);
- return previous_index;
+ return Math.max(0, hitsIndex - 2 * countOfHitsPerPage);
}
-
/**
* Removes from the list the last element that was returned by next or
* previous (optional operation).
- *
- * @since
*/
public void remove() {
throw new UnsupportedOperationException();
}
-
/**
* A helper class encapsulating found document, and its score
*
* @author <a href="mailto:berni_huber@a1.net">Bernhard Huber</a>
* @version CVS $Id$
*/
- public static class HitWrapper
- {
+ public static class HitWrapper {
float score;
Document document;
-
/**
* Constructor for the HitWrapper object
*
* @param score Description of Parameter
* @param document Description of Parameter
- * @since
*/
public HitWrapper(float score, Document document) {
this.document = document;
this.score = score;
}
-
/**
* Gets the document attribute of the HitWrapper object
*
* @return The document value
- * @since
*/
public Document getDocument() {
return document;
}
-
/**
* Gets the score attribute of the HitWrapper object
*
* @return The score value
- * @since
*/
public float getScore() {
return score;
}
-
/**
* Gets the field attribute of the HitWrapper object
*
* @param field Description of Parameter
* @return The field value
- * @since
*/
public String getField(String field) {
return document.get(field);
}
}
-
}
-