package co.phoenixlab.dn.dngearsim.utils.version;

import java.security.MessageDigest;
import java.util.Objects;

public class VersionHashPair {

    private static final byte[] EMPTY_DIGEST = new byte[32];

    /**
     * Version number, to be interpreted using
     */
    private int version;
    private byte[] hash;

    public VersionHashPair() {
        version = 0;
        hash = EMPTY_DIGEST;
    }

    public VersionHashPair(int version, byte[] hash) {
        this.version = version;
        this.hash = hash;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public byte[] getHash() {
        return hash;
    }

    public void setHash(byte[] hash) {
        this.hash = hash;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        VersionHashPair that = (VersionHashPair) o;
        return version == that.version &&
                MessageDigest.isEqual(hash, that.hash);
    }

    @Override
    public int hashCode() {
        return Objects.hash(version, hash);
    }

    public boolean isVersionHigherThan(VersionHashPair other) {
        return Integer.compareUnsigned(version, other.version) > 0;
    }

}

@@ -1387,10 +1387,1365 @@
 %0A    %7D%0A%0A
+    @Override%0A    public String toString() %7B%0A        return Versions.toString(version) + %22,%22 + hashToString(hash);%0A    %7D%0A%0A    public static VersionHashPair parse(String s) throws NumberFormatException %7B%0A        VersionHashPair pair = new VersionHashPair();%0A        pair.fromString(s);%0A        return pair;%0A    %7D%0A%0A    public void fromString(String s) %7B%0A        if (s == null %7C%7C s.isEmpty()) %7B%0A            throw new NumberFormatException(%22empty string%22);%0A        %7D%0A        String%5B%5D split = s.split(%22,%22);%0A        if (split.length != 2) %7B%0A            throw new NumberFormatException(s);%0A        %7D%0A        setVersion(Versions.parseVersion(split%5B0%5D));%0A        setHash(hashStringToByteArray(split%5B1%5D));%0A    %7D%0A%0A    private static String hashToString(byte%5B%5D hash) %7B%0A        assert hash.length %25 4 == 0 : %22Hash size must be multiple of 4%22;%0A        StringBuilder builder = new StringBuilder();%0A        for (int i = 0; i %3C hash.length; i += 4) %7B%0A            builder.append(String.format(%22%2502X%22, hash%5Bi%5D));%0A            builder.append(String.format(%22%2502X%22, hash%5Bi + 1%5D));%0A            builder.append(String.format(%22%2502X%22, hash%5Bi + 2%5D));%0A            builder.append(String.format(%22%2502X%22, hash%5Bi + 3%5D));%0A        %7D%0A        return builder.toString();%0A    %7D%0A%0A    private static byte%5B%5D hashStringToByteArray(String hashStr) %7B%0A        //  TODO%0A        return new byte%5B0%5D;%0A    %7D%0A
 %7D%0A

Add to/from string for VersionHashPair