
com.evrythng.commons.Pagination Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of evrythng-commons Show documentation
Show all versions of evrythng-commons Show documentation
Public common EVRYTHNG classes.
/*
* (c) Copyright 2013 EVRYTHNG Ltd London / Zurich
* www.evrythng.com
*/
package com.evrythng.commons;
import com.evrythng.commons.domain.Size;
import com.evrythng.commons.domain.SortOrder;
/**
* Class to hold zero-based pagination information.
*
* This class is thread-safe.
* This class is immutable.
*
* @author Michel Yerly (my)
**/
public final class Pagination {
private final int page;
private final int perPage;
private final int offset; // denormalized
public Pagination(int page, int perPage) {
super();
this.page = page;
this.perPage = perPage;
this.offset = page * perPage;
}
public final int getPage() {
return page;
}
public final int getPageOneBased() {
return page + 1;
}
public final int getPerPage() {
return perPage;
}
public final int getOffset() {
return offset;
}
@Override
public String toString() {
return String.format("Pagination [page=%s, perPage=%s, offset=%s]", page, perPage, offset);
}
public Integer token() {
return page;
}
public Size size() {
return Size.of(getPageOneBased());
}
public SortOrder sortOrder() {
return SortOrder.descending();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy