fd1de34b3a06b8cb6ad29ffc7331c87fd673935b
[jFCPlib.git] / src / net / pterodactylus / fcp / highlevel / RequestListResult.java
1 /*
2  * jFCPlib-high-level-client - RequestListResult.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.fcp.highlevel;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.List;
26
27 /**
28  * The request list results lists all currently running requests on a node.
29  * 
30  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
31  * @version $Id$
32  */
33 public class RequestListResult extends HighLevelResult implements Iterable<RequestResult> {
34
35         /** The request results. */
36         private List<RequestResult> requestResults = Collections.synchronizedList(new ArrayList<RequestResult>());
37
38         /**
39          * Creates a new request list result.
40          * 
41          * @param identifier
42          *            The identifier of the request
43          */
44         RequestListResult(String identifier) {
45                 super(identifier);
46         }
47
48         /**
49          * Adds a request result.
50          * 
51          * @param requestResult
52          *            The request result to add
53          */
54         void addRequestResult(RequestResult requestResult) {
55                 requestResults.add(requestResult);
56         }
57
58         /**
59          * {@inheritDoc}
60          */
61         public Iterator<RequestResult> iterator() {
62                 return requestResults.iterator();
63         }
64
65         /**
66          * Returns the request result at the given index.
67          * 
68          * @param index
69          *            The index of the request result
70          * @return The request result
71          */
72         public RequestResult get(int index) {
73                 return requestResults.get(index);
74         }
75
76         /**
77          * Returns the number of request results in this request list.
78          * 
79          * @return The number of request results
80          */
81         public int size() {
82                 return requestResults.size();
83         }
84
85 }