-
Notifications
You must be signed in to change notification settings - Fork 7
/
Race.java
65 lines (58 loc) · 1.9 KB
/
Race.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
package com.ercatcher.RaceDetector;
public abstract class Race<E, M> {
public E getWriteEvent() {
return writeEvent;
}
public E getReadEvent() {
return readEvent;
}
public M getMemoryId() {
return memoryId;
}
private E writeEvent;
private E readEvent;
private M memoryId;
protected boolean writeWrite=false;
public boolean isWW(){
return writeWrite;
}
Race(E writeEvent, E readEvent, M memoryId){
this.writeEvent = writeEvent;
this.readEvent = readEvent;
this.memoryId = memoryId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
if(isWW()){
result = prime * result + (writeEvent.hashCode()+readEvent.hashCode());
}
else{
result = prime * result + writeEvent.hashCode();
result = prime * result + readEvent.hashCode();
}
result = prime * result + memoryId.hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Race other = (Race) obj;
if(isWW()){
return this.memoryId.equals(other.memoryId)
&& ((this.writeEvent.equals(other.writeEvent) && this.readEvent.equals(other.readEvent))
|| (this.writeEvent.equals(other.readEvent) && this.readEvent.equals(other.writeEvent)));
}
return this.writeEvent.equals(other.writeEvent) && this.readEvent.equals(other.readEvent) && this.memoryId.equals(other.memoryId);
}
@Override
public String toString() {
return String.format("Write Event: %s Read Event: %s, Memory Id: %s", writeEvent.toString(), readEvent.toString(), memoryId.toString());
}
}