package com.mongodb.jee;

import java.util.Iterator;

import com.mongodb.DBCursor;
import com.mongodb.DBObject;

public class PageResult {

	private final Iterable<DBObject> items;
	private final int fromItemIndex;
	private final int toItemIndex;
	private final int totalItems;

	public PageResult(DBCursor cursor, int fromItemIndex, int toItemIndex) {
		this(cursor.skip(fromItemIndex).limit(toItemIndex - fromItemIndex + 1),
				fromItemIndex, toItemIndex, cursor.count());
	}

	public PageResult(Iterable<DBObject> items, int fromItemIndex, int toItemIndex,
			int totalItems) {
		this.items = items;
		this.fromItemIndex = fromItemIndex;
		this.toItemIndex = toItemIndex;
		this.totalItems = totalItems;
	}

	public Iterable<DBObject> getItems() {
		return items;
	}

	public int getTotalItems() {
		return totalItems;
	}

	public int getFromItemIndex() {
		return fromItemIndex;
	}

	public int getToItemIndex() {
		return toItemIndex;
	}
}

@@ -1,57 +1,730 @@
-package com.mongodb.jee;%0D%0A%0D%0Aimport java.util.Iterator
+/**%0D%0A * Copyright (C) 2012 Angelo Zerr %3Cangelo.zerr@gmail.com%3E and Pascal Leclercq %3Cpascal.leclercq@gmail.com%3E%0D%0A * %0D%0A * %3Cp/%3E%0D%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0D%0A * you may not use this file except in compliance with the License.%0D%0A * You may obtain a copy of the License at%0D%0A * %3Cp/%3E%0D%0A * http://www.apache.org/licenses/LICENSE-2.0%0D%0A * %3Cp/%3E%0D%0A * Unless required by applicable law or agreed to in writing, software%0D%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0A * See the License for the specific language governing permissions and%0D%0A * limitations under the License.%0D%0A */%0D%0Apackage com.mongodb.jee
 ;%0D%0A%0D
@@ -786,16 +786,68 @@
 ect;%0D%0A%0D%0A
+/**%0D%0A * %0D%0A * Simple Pojo of page result.%0D%0A * %0D%0A */%0D%0A
 public c
@@ -1272,33 +1272,37 @@
 t fromItemIndex,
- 
+%0D%0A%09%09%09
 int toItemIndex,
@@ -1297,29 +1297,25 @@
 toItemIndex,
-%0D%0A%09%09%09
+ 
 int totalIte
@@ -1462,193 +1462,470 @@
 %0A%0D%0A%09
-public Iterable%3CDBObject%3E getItems() %7B%0D%0A%09%09return items;%0D%0A%09%7D%0D%0A%0D%0A%09public int getTotalItems() %7B%0D%0A%09%09return totalItems;%0D%0A%09%7D%0D%0A%0D%0A%09public int getFromItemIndex() %7B%0D%0A%09%09return fromItemIndex;%0D%0A%09%7D%0D%0A
+/**%0D%0A%09 * Returns the paginated items.%0D%0A%09 * %0D%0A%09 * @return%0D%0A%09 */%0D%0A%09public Iterable%3CDBObject%3E getItems() %7B%0D%0A%09%09return items;%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * Return the total items.%0D%0A%09 * %0D%0A%09 * @return%0D%0A%09 */%0D%0A%09public int getTotalItems() %7B%0D%0A%09%09return totalItems;%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * Returns the from item index of the page.%0D%0A%09 * %0D%0A%09 * @return%0D%0A%09 */%0D%0A%09public int getFromItemIndex() %7B%0D%0A%09%09return fromItemIndex;%0D%0A%09%7D%0D%0A%0D%0A%09/**%0D%0A%09 * Returns the to item index of the page.%0D%0A%09 * %0D%0A%09 * @return%0D%0A%09 */
 %0D%0A%09p

Add cooments for page result.