-
Notifications
You must be signed in to change notification settings - Fork 15
/
TransactionId.java
43 lines (33 loc) · 928 Bytes
/
TransactionId.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
package simpledb;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;
/**
* TransactionId is a class that contains the identifier of a transaction.
*/
public class TransactionId implements Serializable {
public static TransactionId of(long id) { // newly-defined
return new TransactionId(id);
}
private static final long serialVersionUID = 1L;
static AtomicLong counter = new AtomicLong(0);
final long myid;
public TransactionId() {
myid = counter.getAndIncrement();
}
private TransactionId(long myid) { // newly-defined
this.myid = myid;
}
public long getId() {
return myid;
}
public boolean equals(Object o) { // revised
if (!(o instanceof TransactionId)) {
return false;
} else {
return ((TransactionId) o).myid == myid;
}
}
public int hashCode() {
return (int) myid;
}
}