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.flattr;
020
021import java.util.List;
022
023import org.shredzone.flattr4j.FlattrService;
024import org.shredzone.flattr4j.async.FlattrCallable;
025import org.shredzone.flattr4j.async.PaginatedFlattrCallable;
026import org.shredzone.flattr4j.model.Flattr;
027import org.shredzone.flattr4j.model.ThingId;
028import org.shredzone.flattr4j.model.UserId;
029
030/**
031 * {@link FlattrCallable} for invoking {@link FlattrService#getFlattrs(ThingId)} or
032 * {@link FlattrService#getFlattrs(UserId)}
033 *
034 * @author Iulius Gutberlet
035 * @author Richard "Shred" Körber
036 */
037public class GetFlattrsMethod extends PaginatedFlattrCallable<List<Flattr>> {
038
039    private ThingId thingId;
040    private UserId userId;
041
042    public GetFlattrsMethod() {
043        // default constructor
044    }
045
046    public GetFlattrsMethod(ThingId thingId) {
047        setThingId(thingId);
048    }
049
050    public GetFlattrsMethod(UserId userId) {
051        setUserId(userId);
052    }
053
054    public ThingId getThingId()                 { return thingId; }
055    public void setThingId(ThingId thingId) {
056        this.thingId = thingId;
057        this.userId = null;
058    }
059
060    public UserId getUserId()                   { return userId; }
061    public void setUserId(UserId userId) {
062        this.userId = userId;
063        this.thingId = null;
064    }
065
066    @Override
067    public List<Flattr> call(FlattrService service, Integer count, Integer page)
068        throws Exception {
069        if (thingId != null) {
070            return service.getFlattrs(thingId, count, page);
071        } else {
072            return service.getFlattrs(userId, count, page);
073        }
074    }
075
076}