-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
65 lines (61 loc) · 1.77 KB
/
Event.java
File metadata and controls
65 lines (61 loc) · 1.77 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
56
57
58
59
60
61
62
63
64
65
/**
* Represents a collision between a particle and another particle, or a particle
* and a wall.
*/
public class Event implements Comparable<Event> {
double _timeOfEvent;
double _timeEventCreated;
Particle particle1;
Particle particle2;
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;
}
/**
* @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
* @param p1 particle 1
* @param p2 particle 2
*/
public Event(double timeOfEvent, double timeEventCreated, Particle p1, Particle p2) {
_timeOfEvent = timeOfEvent;
_timeEventCreated = timeEventCreated;
particle1 = p1;
particle2 = p2;
}
/**
* particle-wall collision constructor
*
* @param timeOfEvent
* @param timeEventCreated
* @param p1 particle 1
**/
public Event(double timeOfEvent, double timeEventCreated, Particle p, Wall w) {
_timeOfEvent = timeOfEvent;
_timeEventCreated = timeEventCreated;
particle1 = p;
wall = w;
}
@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;
}
}
}