|
|
|
@ -86,7 +86,7 @@ public final class Torrent {
@@ -86,7 +86,7 @@ public final class Torrent {
|
|
|
|
|
cal.set(1900, Calendar.DECEMBER, 31); |
|
|
|
|
this.dateDone = cal.getTime(); |
|
|
|
|
} else if (eta == -1 || eta == -2) { |
|
|
|
|
// UNknown eta: move to the top of the list
|
|
|
|
|
// Unknown eta: move to the top of the list
|
|
|
|
|
this.dateDone = new Date(Long.MAX_VALUE); |
|
|
|
|
} else { |
|
|
|
|
Calendar cal = Calendar.getInstance(); |
|
|
|
@ -97,4 +97,212 @@ public final class Torrent {
@@ -97,4 +97,212 @@ public final class Torrent {
|
|
|
|
|
this.error = error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public long id() { |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String hash() { |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String name() { |
|
|
|
|
return name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public TorrentStatus statusCode() { |
|
|
|
|
return statusCode; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String locationDir() { |
|
|
|
|
return locationDir; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int rateDownload() { |
|
|
|
|
return rateDownload; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int rateUpload() { |
|
|
|
|
return rateUpload; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int seedersConnected() { |
|
|
|
|
return seedersConnected; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int seedersKnown() { |
|
|
|
|
return seedersKnown; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int leechersConnected() { |
|
|
|
|
return leechersConnected; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int leechersKnown() { |
|
|
|
|
return leechersKnown; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public long eta() { |
|
|
|
|
return eta; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public long downloadedEver() { |
|
|
|
|
return downloadedEver; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public long uploadedEver() { |
|
|
|
|
return uploadedEver; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public long totalSize() { |
|
|
|
|
return totalSize; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public float partDone() { |
|
|
|
|
return partDone; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public float available() { |
|
|
|
|
return available; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String label() { |
|
|
|
|
return label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Date dateAdded() { |
|
|
|
|
return dateAdded; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Date dateDone() { |
|
|
|
|
return dateDone; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String error() { |
|
|
|
|
return error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the unique torrent-specific id, which is the torrent's hash or (if not available) the local index number |
|
|
|
|
* @return The torrent's (session-transient) unique id |
|
|
|
|
*/ |
|
|
|
|
public String uniqueId() { |
|
|
|
|
if (this.hash == null) { |
|
|
|
|
return Long.toString(this.id); |
|
|
|
|
} else { |
|
|
|
|
return this.hash; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gives the upload/download seed ratio. |
|
|
|
|
* @return The ratio in range [0,r] |
|
|
|
|
*/ |
|
|
|
|
public double ratio() { |
|
|
|
|
return ((double) uploadedEver) / ((double) downloadedEver); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gives the percentage of the download that is completed |
|
|
|
|
* @return The downloaded percentage in range [0,1] |
|
|
|
|
*/ |
|
|
|
|
public float downloadedPercentage() { |
|
|
|
|
return partDone; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether this torrents is actively downloading or not. |
|
|
|
|
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are not considered actively downloading |
|
|
|
|
* @return True if this torrent is to be treated as being in a downloading state, that is, it is trying to finish a download |
|
|
|
|
*/ |
|
|
|
|
public boolean isDownloading(boolean dormantAsInactive) { |
|
|
|
|
return statusCode == TorrentStatus.DOWNLOADING && (!dormantAsInactive || rateDownload > 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether this torrents is actively seeding or not. |
|
|
|
|
* @param dormantAsInactive If true, dormant (0KB/s, so no data transfer) torrents are not considered actively seeding |
|
|
|
|
* @return True if this torrent is to be treated as being in a seeding state, that is, it is sending data to leechers |
|
|
|
|
*/ |
|
|
|
|
public boolean isSeeding(boolean dormantAsInactive) { |
|
|
|
|
return statusCode == TorrentStatus.SEEDING && (!dormantAsInactive || rateUpload > 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Indicates if the torrent can be paused at this moment |
|
|
|
|
* @return If it can be paused |
|
|
|
|
*/ |
|
|
|
|
public boolean canPause() { |
|
|
|
|
// Can pause when it is downloading or seeding
|
|
|
|
|
return statusCode == TorrentStatus.DOWNLOADING || statusCode == TorrentStatus.SEEDING; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Indicates whether the torrent can be resumed |
|
|
|
|
* @return If it can be resumed |
|
|
|
|
*/ |
|
|
|
|
public boolean canResume() { |
|
|
|
|
// Can resume when it is paused
|
|
|
|
|
return statusCode == TorrentStatus.PAUSED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Indicates if the torrent can be started at this moment |
|
|
|
|
* @return If it can be started |
|
|
|
|
*/ |
|
|
|
|
public boolean canStart() { |
|
|
|
|
// Can start when it is queued
|
|
|
|
|
return statusCode == TorrentStatus.QUEUED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Indicates whether the torrent can be stopped |
|
|
|
|
* @return If it can be stopped |
|
|
|
|
*/ |
|
|
|
|
public boolean canStop() { |
|
|
|
|
// Can stop when it is downloading or seeding or paused
|
|
|
|
|
return statusCode == TorrentStatus.DOWNLOADING || statusCode == TorrentStatus.SEEDING |
|
|
|
|
|| statusCode == TorrentStatus.PAUSED; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Torrent mimicResume() { |
|
|
|
|
return mimicStatus(downloadedPercentage() >= 1 ? TorrentStatus.SEEDING : TorrentStatus.DOWNLOADING); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Torrent mimicPause() { |
|
|
|
|
return mimicStatus(TorrentStatus.PAUSED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Torrent mimicStart() { |
|
|
|
|
return mimicStatus(downloadedPercentage() >= 1 ? TorrentStatus.SEEDING : TorrentStatus.DOWNLOADING); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Torrent mimicStop() { |
|
|
|
|
return mimicStatus(TorrentStatus.QUEUED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Torrent mimicNewLabel(String newLabel) { |
|
|
|
|
return new Torrent(id, hash, name, statusCode, locationDir, rateDownload, rateUpload, seedersConnected, seedersKnown, leechersConnected, |
|
|
|
|
leechersKnown, eta, downloadedEver, uploadedEver, totalSize, partDone, available, newLabel, dateAdded, dateDone, error); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Torrent mimicChecking() { |
|
|
|
|
return mimicStatus(TorrentStatus.CHECKING); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Torrent mimicNewLocation(String newLocation) { |
|
|
|
|
return new Torrent(id, hash, name, statusCode, newLocation, rateDownload, rateUpload, seedersConnected, seedersKnown, leechersConnected, |
|
|
|
|
leechersKnown, eta, downloadedEver, uploadedEver, totalSize, partDone, available, label, dateAdded, dateDone, error); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String toString() { |
|
|
|
|
// (HASH_OR_ID) NAME
|
|
|
|
|
return "(" + uniqueId() + ") " + name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Torrent mimicStatus(TorrentStatus newStatus) { |
|
|
|
|
return new Torrent(id, hash, name, newStatus, locationDir, rateDownload, rateUpload, seedersConnected, seedersKnown, leechersConnected, |
|
|
|
|
leechersKnown, eta, downloadedEver, uploadedEver, totalSize, partDone, available, label, dateAdded, dateDone, error); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|