-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHash.java
More file actions
47 lines (37 loc) · 927 Bytes
/
Hash.java
File metadata and controls
47 lines (37 loc) · 927 Bytes
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
/**
* A Wrapper for byte[] with some helping functions
* to determine validity.
*/
public class Hash {
//fields------------------------------------
private byte[] data;
//constructor-------------------------------
public Hash(byte[] data) {
this.data = data;
}
//Methods-----------------------------------
public byte[] getData() {
return this.data;
}
public boolean isValid() {
for (int i = 0; i < 3; i++) {
if (this.data[i] != 0) {
return false;
}
}
return true;
}
public String toString() {
String retString = new String();
for (int i = 0; i < this.data.length; i++) {
byte b = this.data[i];
int thing = Byte.toUnsignedInt(b);
retString += String.format("%x", thing);
}
return retString;
}
public boolean equals(Hash other) {
String str = this.toString();
return (str.equals(other.toString()));
}
}