2 * Reactor - TorrentState.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.reactor.states;
20 import java.util.Iterator;
21 import java.util.List;
23 import net.pterodactylus.reactor.State;
24 import net.pterodactylus.reactor.states.TorrentState.TorrentFile;
26 import com.google.common.collect.Lists;
29 * {@link State} that contains information about an arbitrary number of torrent
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class TorrentState extends AbstractState implements Iterable<TorrentFile> {
36 /** The torrent files. */
37 private final List<TorrentFile> files = Lists.newArrayList();
44 * Adds a torrent file to this state.
47 * The torrent file to add
50 public TorrentState addTorrentFile(TorrentFile torrentFile) {
51 files.add(torrentFile);
63 public Iterator<TorrentFile> iterator() {
64 return files.iterator();
75 public String toString() {
76 return String.format("%s[files=%s]", getClass().getSimpleName(), files);
80 * Container for torrent file data.
82 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
84 public static class TorrentFile {
86 /** The name of the file. */
87 private final String name;
89 /** The size of the file. */
90 private final String size;
92 /** The magnet URI of the file. */
93 private final String magnetUri;
95 /** The download URI of the file. */
96 private final String downloadUri;
99 * Creates a new torrent file.
102 * The name of the file
104 * The size of the file
106 * The magnet URI of the file
108 * The download URI of the file
110 public TorrentFile(String name, String size, String magnetUri, String downloadUri) {
113 this.magnetUri = magnetUri;
114 this.downloadUri = downloadUri;
122 * Returns the name of the file.
124 * @return The name of the file
126 public String name() {
131 * Returns the size of the file. The returned size may included
132 * non-numeric information, such as units (e. g. “860.46 MB”).
134 * @return The size of the file
136 public String size() {
141 * Returns the magnet URI of the file.
143 * @return The magnet URI of the file
145 public String magnetUri() {
150 * Returns the download URI of the file.
152 * @return The download URI of the file
154 public String downloadUri() {
166 public String toString() {
167 return String.format("%s(%s,%s,%s)", name(), size(), magnetUri(), downloadUri());