/
Range.java
61 lines (39 loc) · 1.17 KB
/
Range.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
package org.jgroups.util;
import java.io.DataInput;
import java.io.DataOutput;
public class Range implements SizeStreamable, Comparable<Range> {
public long low=-1; // first msg to be retransmitted
public long high=-1; // last msg to be retransmitted
/** For externalization */
public Range() {
}
public Range(long low, long high) {
this.low=low; this.high=high;
}
public String toString() {
return "[" + low + " : " + high + ']';
}
public int compareTo(Range other) {
if(low == other.low && high == other.high)
return 0;
return low < other.low? -1 : 1;
}
public int hashCode() {
return (int)low;
}
public boolean equals(Object obj) {
Range other=(Range)obj;
return compareTo(other) == 0;
}
public void writeTo(DataOutput out) throws Exception {
Bits.writeLongSequence(low, high, out);
}
public void readFrom(DataInput in) throws Exception {
long[] seqnos=Bits.readLongSequence(in);
low=seqnos[0];
high=seqnos[1];
}
public int serializedSize() {
return Bits.size(low, high);
}
}