-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event.java
74 lines (63 loc) · 1.76 KB
/
Event.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
/**
* CSCI 6341/ Final Project: Automatic Crossroads Control and Management
* Author: Ismayil Hasanov, Yubo Tsai, Han Wang
* Date : Apr 25 2017
* Description: Event class
*/
class Event implements Comparable {
public static int ARRIVAL = 1;
public static int DEPARTURE = 2;
public static int RIGHT = 0;
public static int STRAIGHT = 1;
public static int LEFT = 2;
int type = -1; // Arrival or departure.
double eventTime; // When it occurs.
int fromLane = -1;
int direction = -1;
int carID = -1;
public Event(double eventTime, int type, int fromLane, int carID, int direction)
{
this.eventTime = eventTime;
this.type = type;
this.fromLane = fromLane;
this.carID = carID;
this.direction = direction;
}
public int compareTo(Object obj)
{
Event e = (Event) obj;
if (eventTime < e.eventTime) {
return -1;
}
else if (eventTime > e.eventTime) {
return 1;
}
else {
return 0;
}
}
public boolean equals(Object obj)
{
return (compareTo(obj) == 0);
}
public String toString()
{
String strType = "departure";
if (type == 1) {
strType = "arrival";
}
String strDirection = "right";
if (direction == 1) {
strDirection = "straight";
} else if (direction == 2) {
strDirection = "left";
}
return "[Event]: carID="+carID+" time="+eventTime+" lane="+fromLane+" type="+strType+" direction="+strDirection;
}
}