add identifier to all requests
[jFCPlib.git] / src / net / pterodactylus / fcp / highlevel / PeerListResult.java
1 /*
2  * jFCPlib-high-level-client - PeerListResult.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.Iterator;
24 import java.util.List;
25
26 import net.pterodactylus.fcp.Peer;
27
28 /**
29  * The result of a {@link HighLevelClient#getPeers()} operation.
30  * 
31  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
32  * @version $Id$
33  */
34 public class PeerListResult extends HighLevelResult implements Iterable<Peer> {
35
36         /** The list of peers. */
37         private final List<Peer> peers = new ArrayList<Peer>();
38
39         /**
40          * Package-private constructor.
41          * 
42          * @param identifier
43          *            The identifier of the request
44          */
45         PeerListResult(String identifier) {
46                 super(identifier);
47         }
48
49         /**
50          * Adds a peer to the list.
51          * 
52          * @param peer
53          *            The peer to add
54          */
55         void addPeer(Peer peer) {
56                 peers.add(peer);
57         }
58
59         /**
60          * {@inheritDoc}
61          */
62         public Iterator<Peer> iterator() {
63                 return peers.iterator();
64         }
65
66         /**
67          * Returns the peer at the given index.
68          * 
69          * @param index
70          *            The index of the peer
71          * @return The peer
72          * @see java.util.List#get(int)
73          */
74         public Peer get(int index) {
75                 return peers.get(index);
76         }
77
78         /**
79          * Returns the size of the peer list.
80          * 
81          * @return The size of the peer list
82          * @see java.util.List#size()
83          */
84         public int size() {
85                 return peers.size();
86         }
87
88 }