1d6e91fcd73cd7b381122595dc4e91ae70bbaf4a
[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          * Adds a peer to the list.
41          * 
42          * @param peer
43          *            The peer to add
44          */
45         void addPeer(Peer peer) {
46                 peers.add(peer);
47         }
48
49         /**
50          * {@inheritDoc}
51          */
52         public Iterator<Peer> iterator() {
53                 return peers.iterator();
54         }
55
56         /**
57          * Returns the peer at the given index.
58          * 
59          * @param index
60          *            The index of the peer
61          * @return The peer
62          * @see java.util.List#get(int)
63          */
64         public Peer get(int index) {
65                 return peers.get(index);
66         }
67
68         /**
69          * Returns the size of the peer list.
70          * 
71          * @return The size of the peer list
72          * @see java.util.List#size()
73          */
74         public int size() {
75                 return peers.size();
76         }
77
78 }