KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > master > UploaderPosition


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD 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 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.master;
19
20 /**
21  * @author mog
22  * @version $Id: UploaderPosition.java,v 1.5 2004/02/10 00:03:07 mog Exp $
23  */

24 public class UploaderPosition implements Comparable JavaDoc {
25     long bytes;
26     int files;
27     String JavaDoc username;
28     long xfertime;
29
30     public UploaderPosition(
31         String JavaDoc username,
32         long bytes,
33         int files,
34         long xfertime) {
35         this.username = username;
36         this.bytes = bytes;
37         this.files = files;
38         this.xfertime = xfertime;
39     }
40
41     public int compareTo(Object JavaDoc o) {
42         return compareTo((UploaderPosition) o);
43     }
44
45     /** Sorts in reverse order so that the biggest shows up first.
46      * @see java.lang.Comparable#compareTo(java.lang.Object)
47      */

48     public int compareTo(UploaderPosition o) {
49         long thisVal = getBytes();
50         long anotherVal = o.getBytes();
51         return (thisVal < anotherVal ? 1 : (thisVal == anotherVal ? 0 : -1));
52     }
53
54     /* (non-Javadoc)
55      * @see java.lang.Object#equals(java.lang.Object)
56      */

57     public boolean equals(Object JavaDoc obj) {
58         //if(obj instanceof String && obj.equals(getUsername())) return true;
59
if (!(obj instanceof UploaderPosition))
60             return false;
61         UploaderPosition other = (UploaderPosition) obj;
62         return getUsername().equals(other.getUsername());
63     }
64     public long getBytes() {
65         return this.bytes;
66     }
67     public int getFiles() {
68         return this.files;
69     }
70
71     public String JavaDoc getUsername() {
72         return username;
73     }
74     public long getXferspeed() {
75         if (getXfertime() == 0)
76             return 0;
77         return (long) ((long) getBytes() / ((long) getXfertime() / 1000.0));
78     }
79
80     public long getXfertime() {
81         return xfertime;
82     }
83
84     public int hashCode() {
85         return getUsername().hashCode();
86     }
87     public void updateBytes(long bytes) {
88         this.bytes += bytes;
89     }
90     public void updateFiles(int files) {
91         this.files += files;
92     }
93     public void updateXfertime(long xfertime) {
94         this.xfertime += xfertime;
95     }
96 }
97
Popular Tags