SearchQuery.java 2.22 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
package fi.codecrew.moya.utilities;

import java.io.Serializable;

public class SearchQuery implements Serializable {

	public static enum QuerySortOrder {
		UNSORTED, ASCENDING, DESCENDING
	}

	private static final long serialVersionUID = -8777921789916093938L;
	private int page = 0;
	private int pagesize = 20;
	private String sort = null;
	private String search = null;
	private QuerySortOrder sortDirection = QuerySortOrder.UNSORTED;

	public SearchQuery()
	{
		super();
	}

	public SearchQuery(int page, int pagesize, String sort, String search, QuerySortOrder direction) {
		super();
		this.page = page;
		this.pagesize = pagesize;
		this.sort = sort;
		this.search = search;
		this.sortDirection = direction;
	}

	public int getFirstElement() {
		return page * pagesize;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		if (page < 0) {
			this.page = 0;
		} else
		{
			this.page = page;
		}
	}

	public int getPagesize() {

		return pagesize;
	}

	public void setPagesize(int pagesize) {
		if (pagesize < 1)
			pagesize = 20;
		else
			this.pagesize = pagesize;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public void addPage(Integer count) {
		if (count != null) {
			page += count;
		}
	}

	public QuerySortOrder getSortDirection() {
		return sortDirection;
	}

	public void setSortDirection(QuerySortOrder sortDirection) {
		this.sortDirection = sortDirection;
	}

}