/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.util.Charsets
 *  com.l7tech.util.HexUtils
 */
package com.l7tech.server.policy;

import com.l7tech.objectmodel.Goid;
import com.l7tech.util.Charsets;
import com.l7tech.util.HexUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class PolicyUniqueIdentifier {
    private final ReadWriteLock a = new ReentrantReadWriteLock();
    private final Goid b;
    private final Integer c;
    private final Map<Goid, Integer> d;
    private String e;
    private static final String[] f;

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public PolicyUniqueIdentifier(Goid goid, Integer n2, Map<Goid, Integer> map) {
        if (goid == null) throw new IllegalArgumentException(f[2] + String.valueOf(goid));
        try {
            if (Goid.isDefault((Goid)goid)) {
                throw new IllegalArgumentException(f[2] + String.valueOf(goid));
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        try {
            if (n2 == null) {
                throw new IllegalArgumentException(f[0]);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        try {
            if (map == null) {
                throw new IllegalArgumentException(f[3]);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        this.b = goid;
        this.c = n2;
        this.d = Collections.unmodifiableMap(new TreeMap<Goid, Integer>(map));
    }

    public Goid getPolicyGoid() {
        return this.b;
    }

    public String getPolicyUniqueIdentifer() {
        String string = null;
        this.a.readLock().lock();
        try {
            string = this.e;
        }
        finally {
            this.a.readLock().unlock();
        }
        if (string == null) {
            this.a.writeLock().lock();
            try {
                string = this.e;
                if (string == null) {
                    string = this.e = this.b();
                }
            }
            finally {
                this.a.writeLock().unlock();
            }
        }
        return string;
    }

    public Map<Goid, Integer> getUsedPoliciesAndVersions(boolean bl2) {
        HashMap<Goid, Integer> hashMap = new HashMap<Goid, Integer>(this.d);
        try {
            if (bl2) {
                hashMap.put(this.b, this.c);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        return hashMap;
    }

    public boolean equals(Object object) {
        block16: {
            try {
                if (this == object) {
                    return true;
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw PolicyUniqueIdentifier.a(illegalArgumentException);
            }
            try {
                try {
                    if (object != null && this.getClass() == object.getClass()) break block16;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw PolicyUniqueIdentifier.a(illegalArgumentException);
                }
                return false;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw PolicyUniqueIdentifier.a(illegalArgumentException);
            }
        }
        PolicyUniqueIdentifier policyUniqueIdentifier = (PolicyUniqueIdentifier)object;
        try {
            if (!Goid.equals((Goid)this.b, (Goid)policyUniqueIdentifier.b)) {
                return false;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        try {
            if (!this.c.equals(policyUniqueIdentifier.c)) {
                return false;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        try {
            if (!this.d.equals(policyUniqueIdentifier.d)) {
                return false;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        return true;
    }

    public int hashCode() {
        int n2;
        try {
            n2 = this.b != null ? this.b.hashCode() : 0;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw PolicyUniqueIdentifier.a(illegalArgumentException);
        }
        int n3 = n2;
        n3 = 31 * n3 + this.c.hashCode();
        n3 = 31 * n3 + this.d.hashCode();
        return n3;
    }

    public String toString() {
        return f[1] + this.a() + "]";
    }

    private String a() {
        StringBuilder stringBuilder = new StringBuilder(128);
        stringBuilder.append(this.b.toHexString());
        stringBuilder.append('|');
        stringBuilder.append(this.c);
        for (Map.Entry<Goid, Integer> entry : this.d.entrySet()) {
            stringBuilder.append(',');
            stringBuilder.append(entry.getKey());
            stringBuilder.append('|');
            stringBuilder.append(entry.getValue());
        }
        return stringBuilder.toString();
    }

    private String b() {
        return HexUtils.hexDump((byte[])HexUtils.getMd5Digest((byte[])this.a().getBytes(Charsets.UTF8)));
    }

    private static IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[4];
                var3_1 = 0;
                var2_2 = "bN8ob!/wS'on6Y\u007fT'r!6\u0016f\u00016c!6\f~M\nBN8ob!,[e\u000f";
                var4_3 = "bN8ob!/wS'on6Y\u007fT'r!6\u0016f\u00016c!6\f~M\nBN8ob!,[e\u000f".length();
                var1_4 = 30;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 65;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = PolicyUniqueIdentifier.a(v0, PolicyUniqueIdentifier.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "$0]\u0018\u0012NbM.D\u0015\u0017D\u007f*1B\u001d^#\u0018-N\u001d.Hj\u0004=R/\u001bUu\u00041E\n^Js\u001e*\u000b\u0017\u0011S&\u000f;\u000b\u0017\u000bKj";
                    var4_3 = "$0]\u0018\u0012NbM.D\u0015\u0017D\u007f*1B\u001d^#\u0018-N\u001d.Hj\u0004=R/\u001bUu\u00041E\n^Js\u001e*\u000b\u0017\u0011S&\u000f;\u000b\u0017\u000bKj".length();
                    var1_4 = 19;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 62;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = PolicyUniqueIdentifier.a(v0, PolicyUniqueIdentifier.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        PolicyUniqueIdentifier.f = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x38);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 83;
                    case 1 -> 96;
                    case 2 -> 21;
                    case 3 -> 71;
                    case 4 -> 64;
                    case 5 -> 25;
                    default -> 56;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

