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

com.jdroid.java.search.PagedResult Maven / Gradle / Ivy

The newest version!
package com.jdroid.java.search;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.jdroid.java.collections.Lists;

/**
 * Represents a list result in a paginated API call.
 * 
 * @param  The list item.
 */
public class PagedResult {
	
	private Boolean lastPage;
	private List results;
	
	public PagedResult(List results, Boolean lastPage) {
		this.results = results;
		this.lastPage = lastPage;
	}
	
	/**
	 * @param lastPage Whether the paginates list contains the last page or not.
	 */
	public PagedResult(Boolean lastPage) {
		this(Lists.newArrayList(), lastPage);
	}
	
	public PagedResult(List results) {
		this(results, true);
	}
	
	public PagedResult() {
		this(true);
	}
	
	/**
	 * Adds a result item to the list.
	 * 
	 * @param result The result to add.
	 */
	public void addResult(T result) {
		results.add(result);
	}
	
	/**
	 * Adds result items to the list.
	 * 
	 * @param results The results to add.
	 */
	public void addResults(Collection results) {
		this.results.addAll(results);
	}
	
	/**
	 * @return the results
	 */
	public List getResults() {
		return results;
	}
	
	public void sortResults(Comparator comparator) {
		Collections.sort(results, comparator);
	}
	
	/**
	 * @return the lastPage
	 */
	public boolean isLastPage() {
		return lastPage;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy