remove $Id$ keyword
[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  */
33 public class PeerListResult extends HighLevelResult implements Iterable<Peer> {
34
35         /** The list of peers. */
36         private final List<Peer> peers = new ArrayList<Peer>();
37
38         /**
39          * Package-private constructor.
40          * 
41          * @param identifier
42          *            The identifier of the request
43          */
44         PeerListResult(String identifier) {
45                 super(identifier);
46         }
47
48         /**
49          * Adds a peer to the list.
50          * 
51          * @param peer
52          *            The peer to add
53          */
54         void addPeer(Peer peer) {
55                 peers.add(peer);
56         }
57
58         /**
59          * {@inheritDoc}
60          */
61         public Iterator<Peer> iterator() {
62                 return peers.iterator();
63         }
64
65         /**
66          * Returns the peer at the given index.
67          * 
68          * @param index
69          *            The index of the peer
70          * @return The peer
71          * @see java.util.List#get(int)
72          */
73         public Peer get(int index) {
74                 return peers.get(index);
75         }
76
77         /**
78          * Returns the size of the peer list.
79          * 
80          * @return The size of the peer list
81          * @see java.util.List#size()
82          */
83         public int size() {
84                 return peers.size();
85         }
86
87 }