whitespace changes: replaced tabs with 4 spaces

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711862 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2015-11-01 23:30:48 +00:00
parent 8b6cef3b79
commit adcc71257a

View File

@ -44,20 +44,20 @@ public final class FormulaShifter {
Sheet Sheet
} }
/** /**
* Extern sheet index of sheet where moving is occurring, * Extern sheet index of sheet where moving is occurring,
* used for updating HSSF style 3D references * used for updating HSSF style 3D references
*/ */
private final int _externSheetIndex; private final int _externSheetIndex;
/** /**
* Sheet name of the sheet where moving is occurring, * Sheet name of the sheet where moving is occurring,
* used for updating XSSF style 3D references on row shifts. * used for updating XSSF style 3D references on row shifts.
*/ */
private final String _sheetName; private final String _sheetName;
private final int _firstMovedIndex; private final int _firstMovedIndex;
private final int _lastMovedIndex; private final int _lastMovedIndex;
private final int _amountToMove; private final int _amountToMove;
private final int _srcSheetIndex; private final int _srcSheetIndex;
private final int _dstSheetIndex; private final int _dstSheetIndex;
@ -69,22 +69,22 @@ public final class FormulaShifter {
* *
* For example, this will be called on {@link org.apache.poi.hssf.usermodel.HSSFSheet#shiftRows(int, int, int)} } * For example, this will be called on {@link org.apache.poi.hssf.usermodel.HSSFSheet#shiftRows(int, int, int)} }
*/ */
private FormulaShifter(int externSheetIndex, String sheetName, int firstMovedIndex, int lastMovedIndex, int amountToMove) { private FormulaShifter(int externSheetIndex, String sheetName, int firstMovedIndex, int lastMovedIndex, int amountToMove) {
if (amountToMove == 0) { if (amountToMove == 0) {
throw new IllegalArgumentException("amountToMove must not be zero"); throw new IllegalArgumentException("amountToMove must not be zero");
} }
if (firstMovedIndex > lastMovedIndex) { if (firstMovedIndex > lastMovedIndex) {
throw new IllegalArgumentException("firstMovedIndex, lastMovedIndex out of order"); throw new IllegalArgumentException("firstMovedIndex, lastMovedIndex out of order");
} }
_externSheetIndex = externSheetIndex; _externSheetIndex = externSheetIndex;
_sheetName = sheetName; _sheetName = sheetName;
_firstMovedIndex = firstMovedIndex; _firstMovedIndex = firstMovedIndex;
_lastMovedIndex = lastMovedIndex; _lastMovedIndex = lastMovedIndex;
_amountToMove = amountToMove; _amountToMove = amountToMove;
_mode = ShiftMode.Row; _mode = ShiftMode.Row;
_srcSheetIndex = _dstSheetIndex = -1; _srcSheetIndex = _dstSheetIndex = -1;
} }
/** /**
* Create an instance for shifting sheets. * Create an instance for shifting sheets.
@ -100,45 +100,45 @@ public final class FormulaShifter {
_mode = ShiftMode.Sheet; _mode = ShiftMode.Sheet;
} }
public static FormulaShifter createForRowShift(int externSheetIndex, String sheetName, int firstMovedRowIndex, int lastMovedRowIndex, int numberOfRowsToMove) { public static FormulaShifter createForRowShift(int externSheetIndex, String sheetName, int firstMovedRowIndex, int lastMovedRowIndex, int numberOfRowsToMove) {
return new FormulaShifter(externSheetIndex, sheetName, firstMovedRowIndex, lastMovedRowIndex, numberOfRowsToMove); return new FormulaShifter(externSheetIndex, sheetName, firstMovedRowIndex, lastMovedRowIndex, numberOfRowsToMove);
} }
public static FormulaShifter createForSheetShift(int srcSheetIndex, int dstSheetIndex) { public static FormulaShifter createForSheetShift(int srcSheetIndex, int dstSheetIndex) {
return new FormulaShifter(srcSheetIndex, dstSheetIndex); return new FormulaShifter(srcSheetIndex, dstSheetIndex);
} }
@Override @Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(getClass().getName()); sb.append(getClass().getName());
sb.append(" ["); sb.append(" [");
sb.append(_firstMovedIndex); sb.append(_firstMovedIndex);
sb.append(_lastMovedIndex); sb.append(_lastMovedIndex);
sb.append(_amountToMove); sb.append(_amountToMove);
return sb.toString(); return sb.toString();
} }
/** /**
* @param ptgs - if necessary, will get modified by this method * @param ptgs - if necessary, will get modified by this method
* @param currentExternSheetIx - the extern sheet index of the sheet that contains the formula being adjusted * @param currentExternSheetIx - the extern sheet index of the sheet that contains the formula being adjusted
* @return <code>true</code> if a change was made to the formula tokens * @return <code>true</code> if a change was made to the formula tokens
*/ */
public boolean adjustFormula(Ptg[] ptgs, int currentExternSheetIx) { public boolean adjustFormula(Ptg[] ptgs, int currentExternSheetIx) {
boolean refsWereChanged = false; boolean refsWereChanged = false;
for(int i=0; i<ptgs.length; i++) { for(int i=0; i<ptgs.length; i++) {
Ptg newPtg = adjustPtg(ptgs[i], currentExternSheetIx); Ptg newPtg = adjustPtg(ptgs[i], currentExternSheetIx);
if (newPtg != null) { if (newPtg != null) {
refsWereChanged = true; refsWereChanged = true;
ptgs[i] = newPtg; ptgs[i] = newPtg;
} }
} }
return refsWereChanged; return refsWereChanged;
} }
private Ptg adjustPtg(Ptg ptg, int currentExternSheetIx) { private Ptg adjustPtg(Ptg ptg, int currentExternSheetIx) {
switch(_mode){ switch(_mode){
case Row: case Row:
return adjustPtgDueToRowMove(ptg, currentExternSheetIx); return adjustPtgDueToRowMove(ptg, currentExternSheetIx);
case Sheet: case Sheet:
@ -222,175 +222,175 @@ public final class FormulaShifter {
return updatedPtg; return updatedPtg;
} }
private Ptg rowMoveRefPtg(RefPtgBase rptg) { private Ptg rowMoveRefPtg(RefPtgBase rptg) {
int refRow = rptg.getRow(); int refRow = rptg.getRow();
if (_firstMovedIndex <= refRow && refRow <= _lastMovedIndex) { if (_firstMovedIndex <= refRow && refRow <= _lastMovedIndex) {
// Rows being moved completely enclose the ref. // Rows being moved completely enclose the ref.
// - move the area ref along with the rows regardless of destination // - move the area ref along with the rows regardless of destination
rptg.setRow(refRow + _amountToMove); rptg.setRow(refRow + _amountToMove);
return rptg; return rptg;
} }
// else rules for adjusting area may also depend on the destination of the moved rows // else rules for adjusting area may also depend on the destination of the moved rows
int destFirstRowIndex = _firstMovedIndex + _amountToMove; int destFirstRowIndex = _firstMovedIndex + _amountToMove;
int destLastRowIndex = _lastMovedIndex + _amountToMove; int destLastRowIndex = _lastMovedIndex + _amountToMove;
// ref is outside source rows // ref is outside source rows
// check for clashes with destination // check for clashes with destination
if (destLastRowIndex < refRow || refRow < destFirstRowIndex) { if (destLastRowIndex < refRow || refRow < destFirstRowIndex) {
// destination rows are completely outside ref // destination rows are completely outside ref
return null; return null;
} }
if (destFirstRowIndex <= refRow && refRow <= destLastRowIndex) { if (destFirstRowIndex <= refRow && refRow <= destLastRowIndex) {
// destination rows enclose the area (possibly exactly) // destination rows enclose the area (possibly exactly)
return createDeletedRef(rptg); return createDeletedRef(rptg);
} }
throw new IllegalStateException("Situation not covered: (" + _firstMovedIndex + ", " + throw new IllegalStateException("Situation not covered: (" + _firstMovedIndex + ", " +
_lastMovedIndex + ", " + _amountToMove + ", " + refRow + ", " + refRow + ")"); _lastMovedIndex + ", " + _amountToMove + ", " + refRow + ", " + refRow + ")");
} }
private Ptg rowMoveAreaPtg(AreaPtgBase aptg) { private Ptg rowMoveAreaPtg(AreaPtgBase aptg) {
int aFirstRow = aptg.getFirstRow(); int aFirstRow = aptg.getFirstRow();
int aLastRow = aptg.getLastRow(); int aLastRow = aptg.getLastRow();
if (_firstMovedIndex <= aFirstRow && aLastRow <= _lastMovedIndex) { if (_firstMovedIndex <= aFirstRow && aLastRow <= _lastMovedIndex) {
// Rows being moved completely enclose the area ref. // Rows being moved completely enclose the area ref.
// - move the area ref along with the rows regardless of destination // - move the area ref along with the rows regardless of destination
aptg.setFirstRow(aFirstRow + _amountToMove); aptg.setFirstRow(aFirstRow + _amountToMove);
aptg.setLastRow(aLastRow + _amountToMove); aptg.setLastRow(aLastRow + _amountToMove);
return aptg; return aptg;
} }
// else rules for adjusting area may also depend on the destination of the moved rows // else rules for adjusting area may also depend on the destination of the moved rows
int destFirstRowIndex = _firstMovedIndex + _amountToMove; int destFirstRowIndex = _firstMovedIndex + _amountToMove;
int destLastRowIndex = _lastMovedIndex + _amountToMove; int destLastRowIndex = _lastMovedIndex + _amountToMove;
if (aFirstRow < _firstMovedIndex && _lastMovedIndex < aLastRow) { if (aFirstRow < _firstMovedIndex && _lastMovedIndex < aLastRow) {
// Rows moved were originally *completely* within the area ref // Rows moved were originally *completely* within the area ref
// If the destination of the rows overlaps either the top // If the destination of the rows overlaps either the top
// or bottom of the area ref there will be a change // or bottom of the area ref there will be a change
if (destFirstRowIndex < aFirstRow && aFirstRow <= destLastRowIndex) { if (destFirstRowIndex < aFirstRow && aFirstRow <= destLastRowIndex) {
// truncate the top of the area by the moved rows // truncate the top of the area by the moved rows
aptg.setFirstRow(destLastRowIndex+1); aptg.setFirstRow(destLastRowIndex+1);
return aptg; return aptg;
} else if (destFirstRowIndex <= aLastRow && aLastRow < destLastRowIndex) { } else if (destFirstRowIndex <= aLastRow && aLastRow < destLastRowIndex) {
// truncate the bottom of the area by the moved rows // truncate the bottom of the area by the moved rows
aptg.setLastRow(destFirstRowIndex-1); aptg.setLastRow(destFirstRowIndex-1);
return aptg; return aptg;
} }
// else - rows have moved completely outside the area ref, // else - rows have moved completely outside the area ref,
// or still remain completely within the area ref // or still remain completely within the area ref
return null; // - no change to the area return null; // - no change to the area
} }
if (_firstMovedIndex <= aFirstRow && aFirstRow <= _lastMovedIndex) { if (_firstMovedIndex <= aFirstRow && aFirstRow <= _lastMovedIndex) {
// Rows moved include the first row of the area ref, but not the last row // Rows moved include the first row of the area ref, but not the last row
// btw: (aLastRow > _lastMovedIndex) // btw: (aLastRow > _lastMovedIndex)
if (_amountToMove < 0) { if (_amountToMove < 0) {
// simple case - expand area by shifting top upward // simple case - expand area by shifting top upward
aptg.setFirstRow(aFirstRow + _amountToMove); aptg.setFirstRow(aFirstRow + _amountToMove);
return aptg; return aptg;
} }
if (destFirstRowIndex > aLastRow) { if (destFirstRowIndex > aLastRow) {
// in this case, excel ignores the row move // in this case, excel ignores the row move
return null; return null;
} }
int newFirstRowIx = aFirstRow + _amountToMove; int newFirstRowIx = aFirstRow + _amountToMove;
if (destLastRowIndex < aLastRow) { if (destLastRowIndex < aLastRow) {
// end of area is preserved (will remain exact same row) // end of area is preserved (will remain exact same row)
// the top area row is moved simply // the top area row is moved simply
aptg.setFirstRow(newFirstRowIx); aptg.setFirstRow(newFirstRowIx);
return aptg; return aptg;
} }
// else - bottom area row has been replaced - both area top and bottom may move now // else - bottom area row has been replaced - both area top and bottom may move now
int areaRemainingTopRowIx = _lastMovedIndex + 1; int areaRemainingTopRowIx = _lastMovedIndex + 1;
if (destFirstRowIndex > areaRemainingTopRowIx) { if (destFirstRowIndex > areaRemainingTopRowIx) {
// old top row of area has moved deep within the area, and exposed a new top row // old top row of area has moved deep within the area, and exposed a new top row
newFirstRowIx = areaRemainingTopRowIx; newFirstRowIx = areaRemainingTopRowIx;
} }
aptg.setFirstRow(newFirstRowIx); aptg.setFirstRow(newFirstRowIx);
aptg.setLastRow(Math.max(aLastRow, destLastRowIndex)); aptg.setLastRow(Math.max(aLastRow, destLastRowIndex));
return aptg; return aptg;
} }
if (_firstMovedIndex <= aLastRow && aLastRow <= _lastMovedIndex) { if (_firstMovedIndex <= aLastRow && aLastRow <= _lastMovedIndex) {
// Rows moved include the last row of the area ref, but not the first // Rows moved include the last row of the area ref, but not the first
// btw: (aFirstRow < _firstMovedIndex) // btw: (aFirstRow < _firstMovedIndex)
if (_amountToMove > 0) { if (_amountToMove > 0) {
// simple case - expand area by shifting bottom downward // simple case - expand area by shifting bottom downward
aptg.setLastRow(aLastRow + _amountToMove); aptg.setLastRow(aLastRow + _amountToMove);
return aptg; return aptg;
} }
if (destLastRowIndex < aFirstRow) { if (destLastRowIndex < aFirstRow) {
// in this case, excel ignores the row move // in this case, excel ignores the row move
return null; return null;
} }
int newLastRowIx = aLastRow + _amountToMove; int newLastRowIx = aLastRow + _amountToMove;
if (destFirstRowIndex > aFirstRow) { if (destFirstRowIndex > aFirstRow) {
// top of area is preserved (will remain exact same row) // top of area is preserved (will remain exact same row)
// the bottom area row is moved simply // the bottom area row is moved simply
aptg.setLastRow(newLastRowIx); aptg.setLastRow(newLastRowIx);
return aptg; return aptg;
} }
// else - top area row has been replaced - both area top and bottom may move now // else - top area row has been replaced - both area top and bottom may move now
int areaRemainingBottomRowIx = _firstMovedIndex - 1; int areaRemainingBottomRowIx = _firstMovedIndex - 1;
if (destLastRowIndex < areaRemainingBottomRowIx) { if (destLastRowIndex < areaRemainingBottomRowIx) {
// old bottom row of area has moved up deep within the area, and exposed a new bottom row // old bottom row of area has moved up deep within the area, and exposed a new bottom row
newLastRowIx = areaRemainingBottomRowIx; newLastRowIx = areaRemainingBottomRowIx;
} }
aptg.setFirstRow(Math.min(aFirstRow, destFirstRowIndex)); aptg.setFirstRow(Math.min(aFirstRow, destFirstRowIndex));
aptg.setLastRow(newLastRowIx); aptg.setLastRow(newLastRowIx);
return aptg; return aptg;
} }
// else source rows include none of the rows of the area ref // else source rows include none of the rows of the area ref
// check for clashes with destination // check for clashes with destination
if (destLastRowIndex < aFirstRow || aLastRow < destFirstRowIndex) { if (destLastRowIndex < aFirstRow || aLastRow < destFirstRowIndex) {
// destination rows are completely outside area ref // destination rows are completely outside area ref
return null; return null;
} }
if (destFirstRowIndex <= aFirstRow && aLastRow <= destLastRowIndex) { if (destFirstRowIndex <= aFirstRow && aLastRow <= destLastRowIndex) {
// destination rows enclose the area (possibly exactly) // destination rows enclose the area (possibly exactly)
return createDeletedRef(aptg); return createDeletedRef(aptg);
} }
if (aFirstRow <= destFirstRowIndex && destLastRowIndex <= aLastRow) { if (aFirstRow <= destFirstRowIndex && destLastRowIndex <= aLastRow) {
// destination rows are within area ref (possibly exact on top or bottom, but not both) // destination rows are within area ref (possibly exact on top or bottom, but not both)
return null; // - no change to area return null; // - no change to area
} }
if (destFirstRowIndex < aFirstRow && aFirstRow <= destLastRowIndex) { if (destFirstRowIndex < aFirstRow && aFirstRow <= destLastRowIndex) {
// dest rows overlap top of area // dest rows overlap top of area
// - truncate the top // - truncate the top
aptg.setFirstRow(destLastRowIndex+1); aptg.setFirstRow(destLastRowIndex+1);
return aptg; return aptg;
} }
if (destFirstRowIndex <= aLastRow && aLastRow < destLastRowIndex) { if (destFirstRowIndex <= aLastRow && aLastRow < destLastRowIndex) {
// dest rows overlap bottom of area // dest rows overlap bottom of area
// - truncate the bottom // - truncate the bottom
aptg.setLastRow(destFirstRowIndex-1); aptg.setLastRow(destFirstRowIndex-1);
return aptg; return aptg;
} }
throw new IllegalStateException("Situation not covered: (" + _firstMovedIndex + ", " + throw new IllegalStateException("Situation not covered: (" + _firstMovedIndex + ", " +
_lastMovedIndex + ", " + _amountToMove + ", " + aFirstRow + ", " + aLastRow + ")"); _lastMovedIndex + ", " + _amountToMove + ", " + aFirstRow + ", " + aLastRow + ")");
} }
private static Ptg createDeletedRef(Ptg ptg) { private static Ptg createDeletedRef(Ptg ptg) {
if (ptg instanceof RefPtg) { if (ptg instanceof RefPtg) {
return new RefErrorPtg(); return new RefErrorPtg();
} }
if (ptg instanceof Ref3DPtg) { if (ptg instanceof Ref3DPtg) {
Ref3DPtg rptg = (Ref3DPtg) ptg; Ref3DPtg rptg = (Ref3DPtg) ptg;
return new DeletedRef3DPtg(rptg.getExternSheetIndex()); return new DeletedRef3DPtg(rptg.getExternSheetIndex());
} }
if (ptg instanceof AreaPtg) { if (ptg instanceof AreaPtg) {
return new AreaErrPtg(); return new AreaErrPtg();
} }
if (ptg instanceof Area3DPtg) { if (ptg instanceof Area3DPtg) {
Area3DPtg area3DPtg = (Area3DPtg) ptg; Area3DPtg area3DPtg = (Area3DPtg) ptg;
return new DeletedArea3DPtg(area3DPtg.getExternSheetIndex()); return new DeletedArea3DPtg(area3DPtg.getExternSheetIndex());
} }
if (ptg instanceof Ref3DPxg) { if (ptg instanceof Ref3DPxg) {
Ref3DPxg pxg = (Ref3DPxg)ptg; Ref3DPxg pxg = (Ref3DPxg)ptg;
return new Deleted3DPxg(pxg.getExternalWorkbookNumber(), pxg.getSheetName()); return new Deleted3DPxg(pxg.getExternalWorkbookNumber(), pxg.getSheetName());
@ -400,6 +400,6 @@ public final class FormulaShifter {
return new Deleted3DPxg(pxg.getExternalWorkbookNumber(), pxg.getSheetName()); return new Deleted3DPxg(pxg.getExternalWorkbookNumber(), pxg.getSheetName());
} }
throw new IllegalArgumentException("Unexpected ref ptg class (" + ptg.getClass().getName() + ")"); throw new IllegalArgumentException("Unexpected ref ptg class (" + ptg.getClass().getName() + ")");
} }
} }