001/* 002 * flattr4j - A Java library for Flattr 003 * 004 * Copyright (C) 2012 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.model; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.shredzone.flattr4j.connector.FlattrObject; 025 026/** 027 * Contains the search result. 028 * <p> 029 * This class is not threadsafe. 030 * 031 * @author Richard "Shred" Körber 032 * @since 2.0 033 */ 034public class SearchResult extends Resource { 035 private static final long serialVersionUID = -3762044230769599498L; 036 037 private transient ArrayList<Thing> result = null; 038 039 /** 040 * Creates a new {@link SearchResult}. 041 */ 042 public SearchResult(FlattrObject data) { 043 super(data); 044 } 045 046 /** 047 * Returns the total number of results. 048 */ 049 public int getTotalCount() { 050 return data.getInt("total_items"); 051 } 052 053 /** 054 * Returns the number of items. 055 */ 056 public int getItemCount() { 057 return data.getInt("items"); 058 } 059 060 /** 061 * Returns the current page. 062 */ 063 public int getPage() { 064 return data.getInt("page"); 065 } 066 067 /** 068 * Returns the result list of {@link Thing}. 069 */ 070 public List<Thing> getThings() { 071 if (result == null) { 072 List<FlattrObject> objects = data.getObjects("things"); 073 result = new ArrayList<Thing>(objects.size()); 074 for (FlattrObject obj : objects) { 075 result.add(new Thing(obj)); 076 } 077 } 078 return result; 079 } 080 081}