fr.ouestfrance.querydsl.postgrest.model.RangeResponse Maven / Gradle / Ivy
The newest version!
package fr.ouestfrance.querydsl.postgrest.model;
import java.util.List;
/**
* Postgrest range response
*
* @param type of the page
* @param data Elements returned
* @param range Range returned (first returned, last returned, total elements)
*/
public record RangeResponse(List data, HeaderRange range) {
/**
* Create a range response from a list of elements
*
* @param items elements
* @param type of the elements
* @return range response
*/
@SafeVarargs
public static RangeResponse of(T... items) {
return new RangeResponse<>(List.of(items), null);
}
/**
* Retrieve total elements from range response
*
* @return total elements
*/
public long getTotalElements() {
return (range != null) ? range.getTotalElements() : data.size();
}
/**
* Retrieve page size from range response
*
* @return page size
*/
public int getPageSize() {
if (range != null) {
return range.getLimit() - range.getOffset() + 1;
}
return data.isEmpty() ? 1 : data.size();
}
}