001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.server.users;
020
021import java.io.Serializable;
022import java.util.Calendar;
023import java.util.Date;
024
025
026/**
027 * This class stores the information about one active user
028 *
029 * @author Samuel Campos <samuelcampos@ua.pt>
030 */
031public class UserON implements Serializable {
032    private int userID;
033    private String username;
034    private String host;
035
036    private Date loginTime;
037
038    //private User userfer;
039
040    public UserON(int userID, String username, String host){
041        this.userID = userID;
042        this.username = username;
043        this.host = host;
044
045        loginTime = new Date();
046    }
047
048    /**
049     * @return the username
050     */
051    public String getUsername() {
052        return username;
053    }
054
055    /**
056     * @return the userID
057     */
058    public int getUserID() {
059        return userID;
060    }
061
062    /**
063     * @return the host
064     */
065    public String getHost() {
066        return host;
067    }
068
069    public Date getLoginTime(){
070        return loginTime;
071    }
072
073
074    @Override
075    public boolean equals(Object other) {
076        if (other == null || other.getClass() != getClass()) {
077            return false;
078        }
079
080        if (other == this) {
081            return true;
082        }
083
084        UserON tmp = (UserON) other;
085
086        if (userID == tmp.userID && username.equals(tmp.username) && host.equals(tmp.host)) {
087            return true;
088        }
089
090        return false;
091    }
092
093    @Override
094    public String toString(){
095        Calendar cal = Calendar.getInstance();
096        Calendar cal2 = Calendar.getInstance();
097        cal.setTime(loginTime);
098        cal2.setTime(new Date());
099
100        long milliseconds1 = cal.getTimeInMillis();
101        long milliseconds2 = cal2.getTimeInMillis();
102
103        long diff = milliseconds2 - milliseconds1;
104
105        long diffHours = diff / (60 * 60 * 1000);
106        diff = diff % (60 * 60 * 1000);
107        long diffMinutes = diff / (60 * 1000);
108        diff = diff % (60 * 1000);
109        long diffSeconds = diff / 1000;
110
111        return host + " - " + username + ", Login Time: " + diffHours + ":" + diffMinutes + ":" + diffSeconds ;
112    }
113    
114}