1 | |
package liquibase.change; |
2 | |
|
3 | |
import liquibase.util.MD5Util; |
4 | |
|
5 | |
import java.io.InputStream; |
6 | |
|
7 | |
public class CheckSum { |
8 | |
private int version; |
9 | |
private String checksum; |
10 | |
|
11 | 345 | private CheckSum(String checksum, int version) { |
12 | 345 | this.checksum = checksum; |
13 | 345 | this.version = version; |
14 | 345 | } |
15 | |
|
16 | |
public static CheckSum parse(String checksumValue) { |
17 | 18 | if (checksumValue == null) { |
18 | 0 | return null; |
19 | |
} |
20 | 18 | if (checksumValue.matches("^\\d:.*")) { |
21 | 4 | return new CheckSum(checksumValue.substring(2), Integer.valueOf(checksumValue.substring(0, 1))); |
22 | |
} else { |
23 | 14 | return new CheckSum(checksumValue, 1); |
24 | |
} |
25 | |
} |
26 | |
|
27 | |
public static int getCurrentVersion() { |
28 | 387 | return 3; |
29 | |
} |
30 | |
|
31 | |
public static CheckSum compute(String valueToChecksum) { |
32 | 320 | return new CheckSum(MD5Util.computeMD5(valueToChecksum), getCurrentVersion()); |
33 | |
} |
34 | |
|
35 | |
public static CheckSum compute(InputStream stream) { |
36 | 7 | return new CheckSum(MD5Util.computeMD5(stream), getCurrentVersion()); |
37 | |
} |
38 | |
|
39 | |
@Override |
40 | |
public String toString() { |
41 | 598 | return version + ":" + this.checksum; |
42 | |
} |
43 | |
|
44 | |
public int getVersion() { |
45 | 33 | return version; |
46 | |
} |
47 | |
|
48 | |
@Override |
49 | |
public int hashCode() { |
50 | 1 | return toString().hashCode(); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public boolean equals(Object obj) { |
55 | 6 | return obj instanceof CheckSum && this.toString().equals(obj.toString()); |
56 | |
} |
57 | |
} |