001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package net.sf.drftpd.master;
019:
020: /**
021: * @author mog
022: * @version $Id: UploaderPosition.java 820 2004-11-26 04:54:18Z mog $
023: */
024: public class UploaderPosition implements Comparable {
025: long _bytes;
026: int _files;
027: String _username;
028: long _xfertime;
029:
030: public UploaderPosition(String username, long bytes, int files,
031: long xfertime) {
032: _username = username;
033: _bytes = bytes;
034: _files = files;
035: _xfertime = xfertime;
036: }
037:
038: public int compareTo(Object o) {
039: return compareTo((UploaderPosition) o);
040: }
041:
042: /** Sorts in reverse order so that the biggest shows up first.
043: * @see java.lang.Comparable#compareTo(java.lang.Object)
044: */
045: public int compareTo(UploaderPosition o) {
046: long this Val = getBytes();
047: long anotherVal = o.getBytes();
048:
049: return ((this Val < anotherVal) ? 1
050: : ((this Val == anotherVal) ? 0 : (-1)));
051: }
052:
053: /* (non-Javadoc)
054: * @see java.lang.Object#equals(java.lang.Object)
055: */
056: public boolean equals(Object obj) {
057: //if(obj instanceof String && obj.equals(getUsername())) return true;
058: if (!(obj instanceof UploaderPosition)) {
059: return false;
060: }
061:
062: UploaderPosition other = (UploaderPosition) obj;
063:
064: return getUsername().equals(other.getUsername());
065: }
066:
067: public long getBytes() {
068: return _bytes;
069: }
070:
071: public int getFiles() {
072: return _files;
073: }
074:
075: public String getUsername() {
076: return _username;
077: }
078:
079: public long getXferspeed() {
080: if (getXfertime() == 0) {
081: return 0;
082: }
083:
084: return (long) (getBytes() / (getXfertime() / 1000.0));
085: }
086:
087: public long getXfertime() {
088: return _xfertime;
089: }
090:
091: public int hashCode() {
092: return getUsername().hashCode();
093: }
094:
095: public void updateBytes(long bytes) {
096: _bytes += bytes;
097: }
098:
099: public void updateFiles(int files) {
100: _files += files;
101: }
102:
103: public void updateXfertime(long xfertime) {
104: _xfertime += xfertime;
105: }
106: }
|