/*
 * Decompiled with CFR 0.152.
 */
package com.l7tech.server.identity.ldap;

import com.l7tech.server.identity.ldap.LdapUtils;

class h {
    private final StringBuilder a = new StringBuilder(200);
    private int b = 0;
    private int c = -1;
    private static final String[] d;

    h() {
    }

    public void or() {
        this.a(d[2]);
    }

    public void and() {
        this.a(d[0]);
    }

    public void end() {
        if (this.b > 0) {
            if (this.c == this.a.length() - 2) {
                this.a.delete(this.c, this.a.length());
            } else {
                this.a.append(")");
            }
            --this.b;
        }
    }

    public void objectClass(String string) {
        this.attrEquals(d[1], string);
    }

    public void attrPresent(String string) {
        this.a(string, "=", "*");
    }

    public void attrEquals(String string, String string2) {
        this.a(string, "=", LdapUtils.filterEscape(string2));
    }

    public void attrEqualsUnsafe(String string, String string2) {
        this.a(string, "=", string2);
    }

    public void expression(String string) {
        this.a.append("(");
        this.a.append(string);
        this.a.append(")");
    }

    public String buildFilter() {
        while (this.b > 0) {
            this.a.append(")");
            --this.b;
        }
        return this.a.toString();
    }

    public String toString() {
        return this.a.toString();
    }

    public boolean isEmpty() {
        return this.a.length() == 0;
    }

    private void a(String string) {
        this.c = this.a.length();
        this.a.append(string);
        ++this.b;
    }

    private void a(String string, String string2, String string3) {
        this.a.append("(");
        this.a.append(LdapUtils.filterEscape(string));
        this.a.append(string2);
        this.a.append(string3);
        this.a.append(")");
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "\u0001n\u000bF*?a\u001d:aE)&w\u0002\u00014";
        int n3 = "\u0001n\u000bF*?a\u001d:aE)&w\u0002\u00014".length();
        int n4 = 2;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = h.a(76, h.b(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                d = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x4E);
        }
        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 -> 101;
                    case 1 -> 4;
                    case 2 -> 25;
                    case 3 -> 72;
                    case 4 -> 50;
                    case 5 -> 2;
                    default -> 78;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

