All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.abubusoft.kripton.android.sqlite.PaginatedResult Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright 2015, 2017 Francesco Benincasa ([email protected]).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.abubusoft.kripton.android.sqlite;

import java.util.List;

/**
 * 

* Allow to manage SQL result pages with LIMIT clause. *

* *

* See here for more info. *

* * @author Francesco Benincasa ([email protected]) * @param the element type */ public abstract class PaginatedResult { /** * Instantiates a new paginated result. */ protected PaginatedResult() { initialized=false; } /** The initialized. */ protected boolean initialized; /** The first row. */ protected int firstRow; /** The list. */ protected List list; /** The page size. */ protected int pageSize; /** * Execute. * * @return the list */ public abstract List execute(); /** * First row. * * @return the int */ public int firstRow() { return firstRow; } /** * Next page. * * @return true, if successful */ public boolean nextPage() { if (initialized) { firstRow += pageSize; } else { initialized=true; } return execute().size()>0; } /** * Goto page. * * @param page the page * @return true, if successful */ public boolean gotoPage(int page) { firstRow = pageSize * page ; if (firstRow<0) { firstRow=0; return false; } return execute().size()>0; } /** * Previous page. * * @return true, if successful */ public boolean previousPage() { firstRow -= pageSize; if (firstRow < -1) firstRow = -1; return execute().size()>0; } /** * Checks for next. * * @return true, if successful */ public boolean hasNext() { return list.size()>0; } /** * List. * * @return the list */ public List list() { return list; } /** * Page size. * * @return the int */ public int pageSize() { return pageSize; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy