/*
 * MessageType.java
 *
 * Created on April 29, 2005, 2:45 PM
 */

package DDMT.core.misc;

/**
 *
 * @author  jk3
 */
public class MessageType implements EventType {
    
    //sender's number
    private int sender;
    
    //recievers number
    private int reciever;
    
    //body of the message
    private String text;
    
    //Time the message was recieved
    private double recievedTime;
    
    /** Creates a new instance of MessageType */
    public MessageType(int s, int r, String t, double recievedT) {
        sender = s;
        reciever = r;
        text = t;
        recievedTime = recievedT;
    }
    
    /** Method that will identiry whether this event has anything to do with that node **/
    public boolean involves(int number) {
        if( sender == number || reciever == number )
            return true;
        return false;
    }
    
    /** Method to get the time that this event took place **/
    public double getTime()
    {
        return recievedTime;
    }
    
    /** Method to print the event **/
    public String print() {
        return "Time: "+recievedTime+": Message from: "+sender+" To: "+reciever + " :: "+text;
    }
    
    public int Compare(EventType event) {
        if( event.getTime() > recievedTime)
        {
            return -1;
        }else
        {
            return 1;
        }
    }
    
    /** Check if this event happened in a specific time period **/
    public boolean happenedDuring(double startTime, double endTime) {
        if( recievedTime < endTime && recievedTime > startTime )
            return true;
        return false;
    }
    
}
