package jxl.biff.formula;

import common.Assert;
import common.Logger;
import jxl.SheetSettings;
import jxl.biff.CellReferenceHelper;
import jxl.biff.IntegerHelper;

/* JADX INFO: loaded from: classes.dex */
public class Area extends Operand implements ParsedThing {
    public static /* synthetic */ Class class$jxl$biff$formula$Area;
    private static Logger logger;
    private int columnFirst;
    private boolean columnFirstRelative;
    private int columnLast;
    private boolean columnLastRelative;
    private int rowFirst;
    private boolean rowFirstRelative;
    private int rowLast;
    private boolean rowLastRelative;

    static {
        Class clsClass$ = class$jxl$biff$formula$Area;
        if (clsClass$ == null) {
            clsClass$ = class$("jxl.biff.formula.Area");
            class$jxl$biff$formula$Area = clsClass$;
        }
        logger = Logger.getLogger(clsClass$);
    }

    public Area() {
    }

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

    @Override // jxl.biff.formula.Operand, jxl.biff.formula.ParseItem
    public void adjustRelativeCellReferences(int i2, int i3) {
        if (this.columnFirstRelative) {
            this.columnFirst += i2;
        }
        if (this.columnLastRelative) {
            this.columnLast += i2;
        }
        if (this.rowFirstRelative) {
            this.rowFirst += i3;
        }
        if (this.rowLastRelative) {
            this.rowLast += i3;
        }
    }

    @Override // jxl.biff.formula.Operand, jxl.biff.formula.ParseItem
    public void columnInserted(int i2, int i3, boolean z) {
        if (z) {
            int i4 = this.columnFirst;
            if (i3 <= i4) {
                this.columnFirst = i4 + 1;
            }
            int i5 = this.columnLast;
            if (i3 <= i5) {
                this.columnLast = i5 + 1;
            }
        }
    }

    @Override // jxl.biff.formula.Operand, jxl.biff.formula.ParseItem
    public void columnRemoved(int i2, int i3, boolean z) {
        if (z) {
            int i4 = this.columnFirst;
            if (i3 < i4) {
                this.columnFirst = i4 - 1;
            }
            int i5 = this.columnLast;
            if (i3 <= i5) {
                this.columnLast = i5 - 1;
            }
        }
    }

    @Override // jxl.biff.formula.ParseItem
    public byte[] getBytes() {
        byte[] bArr = new byte[9];
        bArr[0] = !useAlternateCode() ? Token.AREA.getCode() : Token.AREA.getCode2();
        IntegerHelper.getTwoBytes(this.rowFirst, bArr, 1);
        IntegerHelper.getTwoBytes(this.rowLast, bArr, 3);
        int i2 = this.columnFirst;
        if (this.rowFirstRelative) {
            i2 |= 32768;
        }
        if (this.columnFirstRelative) {
            i2 |= 16384;
        }
        IntegerHelper.getTwoBytes(i2, bArr, 5);
        int i3 = this.columnLast;
        if (this.rowLastRelative) {
            i3 |= 32768;
        }
        if (this.columnLastRelative) {
            i3 |= 16384;
        }
        IntegerHelper.getTwoBytes(i3, bArr, 7);
        return bArr;
    }

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

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

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

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

    @Override // jxl.biff.formula.ParseItem
    public void getString(StringBuffer stringBuffer) {
        CellReferenceHelper.getCellReference(this.columnFirst, this.rowFirst, stringBuffer);
        stringBuffer.append(':');
        CellReferenceHelper.getCellReference(this.columnLast, this.rowLast, stringBuffer);
    }

    @Override // jxl.biff.formula.ParseItem
    public void handleImportedCellReferences() {
    }

    @Override // jxl.biff.formula.ParsedThing
    public int read(byte[] bArr, int i2) {
        this.rowFirst = IntegerHelper.getInt(bArr[i2], bArr[i2 + 1]);
        this.rowLast = IntegerHelper.getInt(bArr[i2 + 2], bArr[i2 + 3]);
        int i3 = IntegerHelper.getInt(bArr[i2 + 4], bArr[i2 + 5]);
        this.columnFirst = i3 & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT;
        this.columnFirstRelative = (i3 & 16384) != 0;
        this.rowFirstRelative = (i3 & 32768) != 0;
        int i4 = IntegerHelper.getInt(bArr[i2 + 6], bArr[i2 + 7]);
        this.columnLast = i4 & SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT;
        this.columnLastRelative = (i4 & 16384) != 0;
        this.rowLastRelative = (i4 & 32768) != 0;
        return 8;
    }

    @Override // jxl.biff.formula.Operand, jxl.biff.formula.ParseItem
    public void rowInserted(int i2, int i3, boolean z) {
        int i4;
        if (z && (i4 = this.rowLast) != 65535) {
            int i5 = this.rowFirst;
            if (i3 <= i5) {
                this.rowFirst = i5 + 1;
            }
            if (i3 <= i4) {
                this.rowLast = i4 + 1;
            }
        }
    }

    @Override // jxl.biff.formula.Operand, jxl.biff.formula.ParseItem
    public void rowRemoved(int i2, int i3, boolean z) {
        int i4;
        if (z && (i4 = this.rowLast) != 65535) {
            int i5 = this.rowFirst;
            if (i3 < i5) {
                this.rowFirst = i5 - 1;
            }
            if (i3 <= i4) {
                this.rowLast = i4 - 1;
            }
        }
    }

    public void setRangeData(int i2, int i3, int i4, int i5, boolean z, boolean z2, boolean z3, boolean z4) {
        this.columnFirst = i2;
        this.columnLast = i3;
        this.rowFirst = i4;
        this.rowLast = i5;
        this.columnFirstRelative = z;
        this.columnLastRelative = z2;
        this.rowFirstRelative = z3;
        this.rowLastRelative = z4;
    }

    public Area(String str) {
        int iIndexOf = str.indexOf(":");
        Assert.verify(iIndexOf != -1);
        String strSubstring = str.substring(0, iIndexOf);
        String strSubstring2 = str.substring(iIndexOf + 1);
        this.columnFirst = CellReferenceHelper.getColumn(strSubstring);
        this.rowFirst = CellReferenceHelper.getRow(strSubstring);
        this.columnLast = CellReferenceHelper.getColumn(strSubstring2);
        this.rowLast = CellReferenceHelper.getRow(strSubstring2);
        this.columnFirstRelative = CellReferenceHelper.isColumnRelative(strSubstring);
        this.rowFirstRelative = CellReferenceHelper.isRowRelative(strSubstring);
        this.columnLastRelative = CellReferenceHelper.isColumnRelative(strSubstring2);
        this.rowLastRelative = CellReferenceHelper.isRowRelative(strSubstring2);
    }
}
