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: GroupPosition.java 1196 2005-06-23 22:19:18Z zubov $
023: */
024: public class GroupPosition implements Comparable<GroupPosition> {
025: long bytes;
026: int files;
027: String groupname;
028: long xfertime;
029:
030: public GroupPosition(String groupname, long bytes, int files,
031: long xfertime) {
032: this .groupname = groupname;
033: this .bytes = bytes;
034: this .files = files;
035: this .xfertime = xfertime;
036: }
037:
038: /** Sorts in reverse order so that the biggest shows up first.
039: * @see java.lang.Comparable#compareTo(java.lang.Object)
040: */
041: public int compareTo(GroupPosition o) {
042: long this Val = getBytes();
043: long anotherVal = o.getBytes();
044:
045: return ((this Val < anotherVal) ? 1
046: : ((this Val == anotherVal) ? 0 : (-1)));
047: }
048:
049: /* (non-Javadoc)
050: * @see java.lang.Object#equals(java.lang.Object)
051: */
052: public boolean equals(Object obj) {
053: //if(obj instanceof String && obj.equals(getUsername())) return true;
054: if (!(obj instanceof GroupPosition)) {
055: return false;
056: }
057:
058: GroupPosition other = (GroupPosition) obj;
059:
060: return getGroupname().equals(other.getGroupname());
061: }
062:
063: public long getBytes() {
064: return this .bytes;
065: }
066:
067: public int getFiles() {
068: return this .files;
069: }
070:
071: public String getGroupname() {
072: return groupname;
073: }
074:
075: public long getXferspeed() {
076: if (getXfertime() == 0) {
077: return 0;
078: }
079:
080: return (long) (getBytes() / (getXfertime() / 1000.0));
081: }
082:
083: public long getXfertime() {
084: return xfertime;
085: }
086:
087: public int hashCode() {
088: return getGroupname().hashCode();
089: }
090:
091: public void updateBytes(long bytes) {
092: this .bytes += bytes;
093: }
094:
095: public void updateFiles(int files) {
096: this .files += files;
097: }
098:
099: public void updateXfertime(long xfertime) {
100: this.xfertime += xfertime;
101: }
102: }
|