package jxl.biff;

import common.Logger;
import d.b.a.a.a;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Iterator;
import jxl.WorkbookSettings;
import jxl.biff.formula.ExternalSheet;
import jxl.biff.formula.FormulaException;
import jxl.biff.formula.FormulaParser;

/* JADX INFO: loaded from: classes.dex */
public class DVParser {
    public static final DVType ANY;
    public static final Condition BETWEEN;
    public static final DVType DATE;
    public static final DVType DECIMAL;
    private static DecimalFormat DECIMAL_FORMAT;
    private static int EMPTY_CELLS_ALLOWED_MASK;
    public static final Condition EQUAL;
    public static final DVType FORMULA;
    public static final Condition GREATER_EQUAL;
    public static final Condition GREATER_THAN;
    public static final ErrorStyle INFO;
    public static final DVType INTEGER;
    public static final Condition LESS_EQUAL;
    public static final Condition LESS_THAN;
    public static final DVType LIST;
    public static final Condition NOT_BETWEEN;
    public static final Condition NOT_EQUAL;
    private static int SHOW_ERROR_MASK;
    private static int SHOW_PROMPT_MASK;
    public static final ErrorStyle STOP;
    private static int STRING_LIST_GIVEN_MASK;
    private static int SUPPRESS_ARROW_MASK;
    public static final DVType TEXT_LENGTH;
    public static final DVType TIME;
    public static final ErrorStyle WARNING;
    public static /* synthetic */ Class class$jxl$biff$DVParser;
    private static Logger logger;
    private int column1;
    private int column2;
    private Condition condition;
    private boolean emptyCellsAllowed;
    private ErrorStyle errorStyle;
    private String errorText;
    private String errorTitle;
    private FormulaParser formula1;
    private String formula1String;
    private FormulaParser formula2;
    private String formula2String;
    private String promptText;
    private String promptTitle;
    private int row1;
    private int row2;
    private boolean showError;
    private boolean showPrompt;
    private boolean stringListGiven;
    private boolean suppressArrow;
    private DVType type;

    public static class Condition {
        private static Condition[] types = new Condition[0];
        private MessageFormat format;
        private int value;

        public Condition(int i2, String str) {
            this.value = i2;
            this.format = new MessageFormat(str);
            Condition[] conditionArr = types;
            Condition[] conditionArr2 = new Condition[conditionArr.length + 1];
            types = conditionArr2;
            System.arraycopy(conditionArr, 0, conditionArr2, 0, conditionArr.length);
            types[conditionArr.length] = this;
        }

        public static Condition getCondition(int i2) {
            Condition condition = null;
            int i3 = 0;
            while (true) {
                Condition[] conditionArr = types;
                if (i3 >= conditionArr.length || condition != null) {
                    break;
                }
                if (conditionArr[i3].value == i2) {
                    condition = conditionArr[i3];
                }
                i3++;
            }
            return condition;
        }

        public String getConditionString(String str, String str2) {
            return this.format.format(new String[]{str, str2});
        }

        public int getValue() {
            return this.value;
        }
    }

    public static class DVType {
        private static DVType[] types = new DVType[0];
        private String desc;
        private int value;

        public DVType(int i2, String str) {
            this.value = i2;
            this.desc = str;
            DVType[] dVTypeArr = types;
            DVType[] dVTypeArr2 = new DVType[dVTypeArr.length + 1];
            types = dVTypeArr2;
            System.arraycopy(dVTypeArr, 0, dVTypeArr2, 0, dVTypeArr.length);
            types[dVTypeArr.length] = this;
        }

        public static DVType getType(int i2) {
            DVType dVType = null;
            int i3 = 0;
            while (true) {
                DVType[] dVTypeArr = types;
                if (i3 >= dVTypeArr.length || dVType != null) {
                    break;
                }
                if (dVTypeArr[i3].value == i2) {
                    dVType = dVTypeArr[i3];
                }
                i3++;
            }
            return dVType;
        }

        public String getDescription() {
            return this.desc;
        }

        public int getValue() {
            return this.value;
        }
    }

    public static class ErrorStyle {
        private static ErrorStyle[] types = new ErrorStyle[0];
        private int value;

        public ErrorStyle(int i2) {
            this.value = i2;
            ErrorStyle[] errorStyleArr = types;
            ErrorStyle[] errorStyleArr2 = new ErrorStyle[errorStyleArr.length + 1];
            types = errorStyleArr2;
            System.arraycopy(errorStyleArr, 0, errorStyleArr2, 0, errorStyleArr.length);
            types[errorStyleArr.length] = this;
        }

        public static ErrorStyle getErrorStyle(int i2) {
            ErrorStyle errorStyle = null;
            int i3 = 0;
            while (true) {
                ErrorStyle[] errorStyleArr = types;
                if (i3 >= errorStyleArr.length || errorStyle != null) {
                    break;
                }
                if (errorStyleArr[i3].value == i2) {
                    errorStyle = errorStyleArr[i3];
                }
                i3++;
            }
            return errorStyle;
        }

        public int getValue() {
            return this.value;
        }
    }

    static {
        Class clsClass$ = class$jxl$biff$DVParser;
        if (clsClass$ == null) {
            clsClass$ = class$("jxl.biff.DVParser");
            class$jxl$biff$DVParser = clsClass$;
        }
        logger = Logger.getLogger(clsClass$);
        ANY = new DVType(0, "any");
        INTEGER = new DVType(1, "int");
        DECIMAL = new DVType(2, "dec");
        LIST = new DVType(3, "list");
        DATE = new DVType(4, "date");
        TIME = new DVType(5, "time");
        TEXT_LENGTH = new DVType(6, "strlen");
        FORMULA = new DVType(7, "form");
        STOP = new ErrorStyle(0);
        WARNING = new ErrorStyle(1);
        INFO = new ErrorStyle(2);
        BETWEEN = new Condition(0, "{0} <= x <= {1}");
        NOT_BETWEEN = new Condition(1, "!({0} <= x <= {1}");
        EQUAL = new Condition(2, "x == {0}");
        NOT_EQUAL = new Condition(3, "x != {0}");
        GREATER_THAN = new Condition(4, "x > {0}");
        LESS_THAN = new Condition(5, "x < {0}");
        GREATER_EQUAL = new Condition(6, "x >= {0}");
        LESS_EQUAL = new Condition(7, "x <= {0}");
        STRING_LIST_GIVEN_MASK = 128;
        EMPTY_CELLS_ALLOWED_MASK = 256;
        SUPPRESS_ARROW_MASK = 512;
        SHOW_PROMPT_MASK = 262144;
        SHOW_ERROR_MASK = 524288;
        DECIMAL_FORMAT = new DecimalFormat("#.#");
    }

    /* JADX WARN: Removed duplicated region for block: B:39:0x00ad  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00af  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00bb  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00c9  */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00d8  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00da  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00e6  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x00f4  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0103  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x0105  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x0111  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x016c  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0186  */
    /* JADX WARN: Removed duplicated region for block: B:67:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public DVParser(byte[] r15, jxl.biff.formula.ExternalSheet r16, jxl.biff.WorkbookMethods r17, jxl.WorkbookSettings r18) throws jxl.biff.formula.FormulaException {
        /*
            Method dump skipped, instruction units count: 414
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: jxl.biff.DVParser.<init>(byte[], jxl.biff.formula.ExternalSheet, jxl.biff.WorkbookMethods, jxl.WorkbookSettings):void");
    }

    public static /* synthetic */ Class class$(String str) {
        try {
            return Class.forName(str);
        } catch (ClassNotFoundException e2) {
            throw new NoClassDefFoundError(e2.getMessage());
        }
    }

    public byte[] getData() {
        FormulaParser formulaParser = this.formula1;
        byte[] bytes = formulaParser != null ? formulaParser.getBytes() : new byte[0];
        FormulaParser formulaParser2 = this.formula2;
        byte[] bytes2 = formulaParser2 != null ? formulaParser2.getBytes() : new byte[0];
        byte[] bArr = new byte[(this.errorText.length() * 2) + (this.promptText.length() * 2) + (this.errorTitle.length() * 2) + (this.promptTitle.length() * 2) + 4 + 2 + 2 + 2 + 2 + bytes.length + 2 + bytes2.length + 2 + 4 + 10];
        int value = this.type.getValue() | 0 | (this.errorStyle.getValue() << 4) | (this.condition.getValue() << 20);
        if (this.stringListGiven) {
            value |= STRING_LIST_GIVEN_MASK;
        }
        if (this.emptyCellsAllowed) {
            value |= EMPTY_CELLS_ALLOWED_MASK;
        }
        if (this.suppressArrow) {
            value |= SUPPRESS_ARROW_MASK;
        }
        if (this.showPrompt) {
            value |= SHOW_PROMPT_MASK;
        }
        if (this.showError) {
            value |= SHOW_ERROR_MASK;
        }
        IntegerHelper.getFourBytes(value, bArr, 0);
        IntegerHelper.getTwoBytes(this.promptTitle.length(), bArr, 4);
        StringHelper.getUnicodeBytes(this.promptTitle, bArr, 6);
        int iH = a.H(this.promptTitle, 2, 6);
        IntegerHelper.getTwoBytes(this.errorTitle.length(), bArr, iH);
        int i2 = iH + 2;
        StringHelper.getUnicodeBytes(this.errorTitle, bArr, i2);
        int iH2 = a.H(this.errorTitle, 2, i2);
        IntegerHelper.getTwoBytes(this.promptText.length(), bArr, iH2);
        int i3 = iH2 + 2;
        StringHelper.getUnicodeBytes(this.promptText, bArr, i3);
        int iH3 = a.H(this.promptText, 2, i3);
        IntegerHelper.getTwoBytes(this.errorText.length(), bArr, iH3);
        int i4 = iH3 + 2;
        StringHelper.getUnicodeBytes(this.errorText, bArr, i4);
        int iH4 = a.H(this.errorText, 2, i4);
        IntegerHelper.getTwoBytes(bytes.length, bArr, iH4);
        int i5 = iH4 + 4;
        System.arraycopy(bytes, 0, bArr, i5, bytes.length);
        int length = i5 + bytes.length;
        IntegerHelper.getTwoBytes(bytes2.length, bArr, length);
        int i6 = length + 4;
        System.arraycopy(bytes2, 0, bArr, i6, bytes2.length);
        int length2 = i6 + bytes2.length;
        IntegerHelper.getTwoBytes(1, bArr, length2);
        int i7 = length2 + 2;
        IntegerHelper.getTwoBytes(this.row1, bArr, i7);
        int i8 = i7 + 2;
        IntegerHelper.getTwoBytes(this.row2, bArr, i8);
        int i9 = i8 + 2;
        IntegerHelper.getTwoBytes(this.column1, bArr, i9);
        IntegerHelper.getTwoBytes(this.column2, bArr, i9 + 2);
        return bArr;
    }

    public int getFirstColumn() {
        return this.column1;
    }

    public int getFirstRow() {
        return this.row1;
    }

    public int getLastColumn() {
        return this.column2;
    }

    public int getLastRow() {
        return this.row2;
    }

    public String getValidationFormula() throws FormulaException {
        if (this.type == LIST) {
            return this.formula1.getFormula();
        }
        String formula = this.formula1.getFormula();
        FormulaParser formulaParser = this.formula2;
        String formula2 = formulaParser != null ? formulaParser.getFormula() : null;
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(this.condition.getConditionString(formula, formula2));
        stringBuffer.append("; x ");
        stringBuffer.append(this.type.getDescription());
        return stringBuffer.toString();
    }

    public void insertColumn(int i2) {
        FormulaParser formulaParser = this.formula1;
        if (formulaParser != null) {
            formulaParser.columnInserted(0, i2, true);
        }
        FormulaParser formulaParser2 = this.formula2;
        if (formulaParser2 != null) {
            formulaParser2.columnInserted(0, i2, true);
        }
        int i3 = this.column1;
        if (i3 >= i2) {
            this.column1 = i3 + 1;
        }
        int i4 = this.column2;
        if (i4 >= i2) {
            this.column2 = i4 + 1;
        }
    }

    public void insertRow(int i2) {
        FormulaParser formulaParser = this.formula1;
        if (formulaParser != null) {
            formulaParser.rowInserted(0, i2, true);
        }
        FormulaParser formulaParser2 = this.formula2;
        if (formulaParser2 != null) {
            formulaParser2.rowInserted(0, i2, true);
        }
        int i3 = this.row1;
        if (i3 >= i2) {
            this.row1 = i3 + 1;
        }
        int i4 = this.row2;
        if (i4 >= i2) {
            this.row2 = i4 + 1;
        }
    }

    public void removeColumn(int i2) {
        FormulaParser formulaParser = this.formula1;
        if (formulaParser != null) {
            formulaParser.columnRemoved(0, i2, true);
        }
        FormulaParser formulaParser2 = this.formula2;
        if (formulaParser2 != null) {
            formulaParser2.columnRemoved(0, i2, true);
        }
        int i3 = this.column1;
        if (i3 > i2) {
            this.column1 = i3 - 1;
        }
        int i4 = this.column2;
        if (i4 >= i2) {
            this.column2 = i4 - 1;
        }
    }

    public void removeRow(int i2) {
        FormulaParser formulaParser = this.formula1;
        if (formulaParser != null) {
            formulaParser.rowRemoved(0, i2, true);
        }
        FormulaParser formulaParser2 = this.formula2;
        if (formulaParser2 != null) {
            formulaParser2.rowRemoved(0, i2, true);
        }
        int i3 = this.row1;
        if (i3 > i2) {
            this.row1 = i3 - 1;
        }
        int i4 = this.row2;
        if (i4 >= i2) {
            this.row2 = i4 - 1;
        }
    }

    public void setCell(int i2, int i3, ExternalSheet externalSheet, WorkbookMethods workbookMethods, WorkbookSettings workbookSettings) throws FormulaException {
        this.row1 = i3;
        this.row2 = i3;
        this.column1 = i2;
        this.column2 = i2;
        FormulaParser formulaParser = new FormulaParser(this.formula1String, externalSheet, workbookMethods, workbookSettings);
        this.formula1 = formulaParser;
        formulaParser.parse();
        if (this.formula2String != null) {
            FormulaParser formulaParser2 = new FormulaParser(this.formula2String, externalSheet, workbookMethods, workbookSettings);
            this.formula2 = formulaParser2;
            formulaParser2.parse();
        }
    }

    public DVParser(Collection collection) {
        this.type = LIST;
        this.errorStyle = STOP;
        this.condition = BETWEEN;
        this.stringListGiven = true;
        this.emptyCellsAllowed = true;
        this.suppressArrow = false;
        this.showPrompt = true;
        this.showError = true;
        this.promptTitle = "\u0000";
        this.errorTitle = "\u0000";
        this.promptText = "\u0000";
        this.errorText = "\u0000";
        if (collection.size() == 0) {
            logger.warn("no validation strings - ignoring");
        }
        Iterator it = collection.iterator();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append('\"');
        stringBuffer.append(it.next().toString());
        while (it.hasNext()) {
            stringBuffer.append((char) 0);
            stringBuffer.append(' ');
            stringBuffer.append(it.next().toString());
        }
        stringBuffer.append('\"');
        this.formula1String = stringBuffer.toString();
    }

    public DVParser(String str) {
        this.type = LIST;
        this.errorStyle = STOP;
        this.condition = BETWEEN;
        this.stringListGiven = false;
        this.emptyCellsAllowed = true;
        this.suppressArrow = false;
        this.showPrompt = true;
        this.showError = true;
        this.promptTitle = "\u0000";
        this.errorTitle = "\u0000";
        this.promptText = "\u0000";
        this.errorText = "\u0000";
        this.formula1String = str;
    }

    public DVParser(int i2, int i3, int i4, int i5) {
        this.type = LIST;
        this.errorStyle = STOP;
        this.condition = BETWEEN;
        this.stringListGiven = false;
        this.emptyCellsAllowed = true;
        this.suppressArrow = false;
        this.showPrompt = true;
        this.showError = true;
        this.promptTitle = "\u0000";
        this.errorTitle = "\u0000";
        this.promptText = "\u0000";
        this.errorText = "\u0000";
        StringBuffer stringBuffer = new StringBuffer();
        CellReferenceHelper.getCellReference(i2, i3, stringBuffer);
        stringBuffer.append(':');
        CellReferenceHelper.getCellReference(i4, i5, stringBuffer);
        this.formula1String = stringBuffer.toString();
    }

    public DVParser(double d2, double d3, Condition condition) {
        this.type = DECIMAL;
        this.errorStyle = STOP;
        this.condition = condition;
        this.stringListGiven = false;
        this.emptyCellsAllowed = true;
        this.suppressArrow = false;
        this.showPrompt = true;
        this.showError = true;
        this.promptTitle = "\u0000";
        this.errorTitle = "\u0000";
        this.promptText = "\u0000";
        this.errorText = "\u0000";
        this.formula1String = DECIMAL_FORMAT.format(d2);
        if (Double.isNaN(d3)) {
            return;
        }
        this.formula2String = DECIMAL_FORMAT.format(d3);
    }

    public DVParser(DVParser dVParser) {
        this.type = dVParser.type;
        this.errorStyle = dVParser.errorStyle;
        this.condition = dVParser.condition;
        this.stringListGiven = dVParser.stringListGiven;
        this.emptyCellsAllowed = dVParser.emptyCellsAllowed;
        this.suppressArrow = dVParser.suppressArrow;
        this.showPrompt = dVParser.showPrompt;
        this.showError = dVParser.showError;
        this.promptTitle = dVParser.promptTitle;
        this.promptText = dVParser.promptText;
        this.errorTitle = dVParser.errorTitle;
        this.errorText = dVParser.errorText;
        try {
            this.formula1String = dVParser.formula1.getFormula();
            FormulaParser formulaParser = dVParser.formula2;
            this.formula2String = formulaParser != null ? formulaParser.getFormula() : null;
        } catch (FormulaException e2) {
            Logger logger2 = logger;
            StringBuffer stringBufferZ = a.z("Cannot parse validation formula:  ");
            stringBufferZ.append(e2.getMessage());
            logger2.warn(stringBufferZ.toString());
        }
    }
}
