forked from DannaGuo/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey.java
More file actions
76 lines (63 loc) · 1.44 KB
/
Key.java
File metadata and controls
76 lines (63 loc) · 1.44 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
67
68
69
70
71
72
73
74
75
76
package org.tron.common.storage;
import org.apache.commons.lang3.ArrayUtils;
import java.util.Arrays;
public class Key {
private static int MAX_KEY_LENGTH = 32;
private static int MIN_KEY_LENGTH = 1;
/**
* data could not be null
*/
private byte[] data = new byte[0];
/**
*
* @param data
*/
public Key(byte[] data) {
if (data != null && data.length != 0) {
this.data = new byte[data.length];
System.arraycopy(data, 0, this.data, 0, data.length);
}
}
/**
*
* @param key
*/
private Key(Key key) {
this.data = new byte[key.getData().length];
System.arraycopy(key.getData(), 0, this.data, 0, this.data.length);
}
/**
*
* @return
*/
public Key clone() {
return new Key(this);
}
/**
*
* @return
*/
public byte[] getData() {
return data;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Key key = (Key) o;
if (Arrays.equals(key.getData(), this.data)) return true;
return false;
}
@Override
public int hashCode() {
return data != null ? ArrayUtils.hashCode(data) : 0;
}
/**
*
* @param data
* @return
*/
public static Key create(byte[] data) {
return new Key(data);
}
}