-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
55 lines (48 loc) · 1.24 KB
/
Event.java
File metadata and controls
55 lines (48 loc) · 1.24 KB
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
/**
* Represents a collision between a particle and another particle, or a particle and a wall.
*/
public class Event implements Comparable<Event> {
private double _timeOfEvent;
private double _timeEventCreated;
private Particle p1;
private Particle p2;
private Wall wall;
/**
* @param timeOfEvent the time when the collision will take place
* @param timeEventCreated the time when the event was first instantiated and added to the queue
*/
public Event (double timeOfEvent, double timeEventCreated) {
_timeOfEvent = timeOfEvent;
_timeEventCreated = timeEventCreated;
}
@Override
/**
* Compares two Events based on their event times. Since you are implementing a maximum heap,
* this method assumes that the event with the smaller event time should receive higher priority.
*/
public int compareTo (Event e) {
if (_timeOfEvent < e._timeOfEvent) {
return +1;
} else if (_timeOfEvent == e._timeOfEvent) {
return 0;
} else {
return -1;
}
}
/* Getters */
public double getTimeOfEvent () {
return _timeOfEvent;
}
public double getTimeEventCreated () {
return _timeEventCreated;
}
public Particle getP1() {
return p1;
}
public Particle getP2() {
return p2;
}
public Wall getWall() {
return wall;
}
}