001/* 002 * flattr4j - A Java library for Flattr 003 * 004 * Copyright (C) 2014 Richard "Shred" Körber 005 * http://flattr4j.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License / GNU Lesser 009 * General Public License as published by the Free Software Foundation, 010 * either version 3 of the License, or (at your option) any later version. 011 * 012 * Licensed under the Apache License, Version 2.0 (the "License"); 013 * you may not use this file except in compliance with the License. 014 * 015 * This program is distributed in the hope that it will be useful, 016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 018 */ 019package org.shredzone.flattr4j.async; 020 021import org.shredzone.flattr4j.FlattrService; 022 023/** 024 * A {@link FlattrCallable} that allows pagination. 025 * 026 * @author Iulius Gutberlet 027 * @author Richard "Shred" Körber 028 */ 029public abstract class PaginatedFlattrCallable<R> extends AbstractFlattrCallable<R> { 030 031 private Integer count; 032 private Integer page; 033 034 /** 035 * The number of entries per page. {@code null} defaults to 30 entries. 036 */ 037 public void setCount(Integer count) { this.count = count; } 038 public Integer getCount() { return count; } 039 040 /** 041 * Page number (counted from 1), or {@code null} to turn off paging. 042 */ 043 public void setPage(Integer page) { this.page = page; } 044 public Integer getPage() { return page; } 045 046 /** 047 * Calls the appropriate method at the service and returns the result. 048 * 049 * @param service 050 * Preconfigured {@link FlattrService} to be invoked 051 * @param count 052 * Number of elements per page, or {@code null} 053 * @param page 054 * Page number, or {@code null} 055 * @return Result returned from the Flattr method. 056 */ 057 public abstract R call(FlattrService service, Integer count, Integer page) throws Exception; //NOSONAR: accept all exceptions 058 059 @Override 060 public R call(FlattrService service) throws Exception { 061 return call(service, count, page); 062 } 063 064}