1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.util;
21
22
23
24 /***
25 * Represents the progress of a transfer.
26 */
27 public class Progress implements Comparable
28 {
29
30
31
32
33
34 private long rate;
35 private long size;
36 private long transferred;
37
38
39
40 public Progress(long size, long transferred)
41 {
42 this.size = size;
43 this.transferred = transferred;
44 }
45
46 public Progress()
47 {
48 this(-1, -1);
49 }
50
51
52
53 /***
54 * Use a higher precission to make a difference between 0 progress and 0.5.
55 */
56 public int compareTo(Object o)
57 {
58 return (int)(getPercent() - ((Progress)o).getPercent());
59 }
60
61 public double getPercent()
62 {
63 return (size <= 0 || transferred <= 0)
64 ? 0 : ((double)(transferred * 100) / size);
65 }
66 /***
67 * Returns the current rate.
68 */
69 public long getRate()
70 {
71 return rate;
72 }
73
74 public void setRate(long rate)
75 {
76 this.rate = rate;
77 }
78
79 public long getSize()
80 {
81 return size;
82 }
83
84 public long getTransferred()
85 {
86 return transferred;
87 }
88
89 }