View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
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 org.xnap.util;
21  
22  
23  
24  /***
25   * Represents the progress of a transfer.
26   */
27  public class Progress implements Comparable
28  {
29  
30      //--- Constant(s) ---
31  
32      //--- Data field(s) ---
33  
34      private long rate;
35      private long size;
36      private long transferred;
37  
38      //--- Constructor(s) ---
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      //--- Method(s) ---
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  }