class ResourceListController {

    public PaginationResult<T> applyPagingToList(List<T> resources, PaginationOptions<T> paginationOptions) throws PaginationParameterException {
        if(resources.size() == 0) {
            if(paginationOptions.getPageNumber() == 0) {
                return new PaginationResult<>(resources, 0, paginationOptions);
            } else {
                throw new PaginationParameterException(PAGINATION_PARAMETER_EXCEPTION_MESSAGE);
            }
        }
        List<T> sortedResources = this.sortList(resources, paginationOptions.getSortComparator());

        int fromIndex = paginationOptions.getOffset();
        int toIndex = paginationOptions.getPageEndIndex();
        if(fromIndex >= sortedResources.size()) {
            throw new PaginationParameterException(PAGINATION_PARAMETER_EXCEPTION_MESSAGE);
        } else if (toIndex > sortedResources.size()) {
            toIndex = sortedResources.size();
        }
        return new PaginationResult<>(sortedResources.subList(fromIndex, toIndex), sortedResources.size(), paginationOptions);
    }

}