forked from DNAProject/DNA-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIntBase.java
More file actions
66 lines (56 loc) · 1.52 KB
/
Copy pathUIntBase.java
File metadata and controls
66 lines (56 loc) · 1.52 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
66
package DNA;
import java.io.IOException;
import java.nio.*;
import java.util.Arrays;
import DNA.IO.*;
public abstract class UIntBase implements Serializable {
protected byte[] data_bytes;
protected UIntBase(int bytes, byte[] value) {
if (value == null) {
this.data_bytes = new byte[bytes];
return;
}
if (value.length != bytes) {
throw new IllegalArgumentException();
}
this.data_bytes = value;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (!(obj instanceof UIntBase)) {
return false;
}
UIntBase other = (UIntBase) obj;
return Arrays.equals(this.data_bytes, other.data_bytes);
}
@Override
public int hashCode() {
return ByteBuffer.wrap(data_bytes).order(ByteOrder.LITTLE_ENDIAN).getInt();
}
public byte[] toArray() {
return data_bytes;
}
/**
* 转为16进制字符串
* @return 返回16进制字符串
*/
@Override
public String toString() {
// return Helper.toHexString(Helper.reverse(data_bytes));
return Helper.toHexString(data_bytes);
}
@Override
public void serialize(BinaryWriter writer) throws IOException {
writer.write(data_bytes);
}
@Override
public void deserialize(BinaryReader reader) throws IOException {
reader.read(data_bytes);
}
}