forked from thiennc/Coursera-Blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathByteArrayWrapper.java
executable file
·47 lines (40 loc) · 1.18 KB
/
ByteArrayWrapper.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
import java.util.Arrays;
/** a wrapper for byte array with hashCode and equals function implemented */
public class ByteArrayWrapper {
private byte[] contents;
public ByteArrayWrapper(byte[] b) {
contents = new byte[b.length];
for (int i = 0; i < contents.length; i++)
contents[i] = b[i];
}
public boolean equals(Object other) {
if (other == null) {
return false;
}
if (getClass() != other.getClass()) {
return false;
}
ByteArrayWrapper otherB = (ByteArrayWrapper) other;
byte[] b = otherB.contents;
if (contents == null) {
if (b == null)
return true;
else
return false;
} else {
if (b == null)
return false;
else {
if (contents.length != b.length)
return false;
for (int i = 0; i < b.length; i++)
if (contents[i] != b[i])
return false;
return true;
}
}
}
public int hashCode() {
return Arrays.hashCode(contents);
}
}