package net.pterodactylus.rhynodge.states;
import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@JsonProperty
private List<TorrentFile> files = Lists.newArrayList();
+ /**
+ * Creates a new torrent state without torrent files.
+ */
+ public TorrentState() {
+ this(Collections.<TorrentFile> emptySet());
+ }
+
+ /**
+ * Creates a new torrent state containing the given torrent files.
+ *
+ * @param torrentFiles
+ * The torrent files
+ */
+ public TorrentState(Collection<TorrentFile> torrentFiles) {
+ files.addAll(torrentFiles);
+ }
+
//
// ACCESSORS
//
/**
+ * Returns all torrent files of this state.
+ *
+ * @return All torrent files of this state
+ */
+ public Collection<TorrentFile> torrentFiles() {
+ return Collections.unmodifiableList(files);
+ }
+
+ /**
* Adds a torrent file to this state.
*
* @param torrentFile
/**
* Returns the magnet URI of the file.
*
- * @return The magnet URI of the file
+ * @return The magnet URI of the file, or {@code null} if there is no
+ * magnet URI for this torrent file
*/
public String magnetUri() {
return magnetUri;
/**
* Returns the download URI of the file.
*
- * @return The download URI of the file
+ * @return The download URI of the file, or {@code null} if there is no
+ * download URI for this torrent file
*/
public String downloadUri() {
return downloadUri;
List<NameValuePair> parameters = URLEncodedUtils.parse(magnetUri.substring("magnet:?".length()), Charset.forName("UTF-8"));
for (NameValuePair parameter : parameters) {
if (parameter.getName().equals("xt")) {
- return parameter.getValue();
+ return parameter.getValue().toLowerCase();
}
}
return null;