You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CellEvaluationFrame.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.formula;
  16. import java.util.HashSet;
  17. import java.util.Set;
  18. import org.apache.poi.ss.formula.eval.ValueEval;
  19. /**
  20. * Stores details about the current evaluation of a cell.<br>
  21. */
  22. final class CellEvaluationFrame {
  23. private final FormulaCellCacheEntry _cce;
  24. private final Set<CellCacheEntry> _sensitiveInputCells;
  25. private FormulaUsedBlankCellSet _usedBlankCellGroup;
  26. public CellEvaluationFrame(FormulaCellCacheEntry cce) {
  27. _cce = cce;
  28. _sensitiveInputCells = new HashSet<>();
  29. }
  30. public CellCacheEntry getCCE() {
  31. return _cce;
  32. }
  33. public String toString() {
  34. StringBuffer sb = new StringBuffer(64);
  35. sb.append(getClass().getName()).append(" [");
  36. sb.append("]");
  37. return sb.toString();
  38. }
  39. /**
  40. * @param inputCell a cell directly used by the formula of this evaluation frame
  41. */
  42. public void addSensitiveInputCell(CellCacheEntry inputCell) {
  43. _sensitiveInputCells.add(inputCell);
  44. }
  45. /**
  46. * @return never <code>null</code>, (possibly empty) array of all cells directly used while
  47. * evaluating the formula of this frame.
  48. */
  49. private CellCacheEntry[] getSensitiveInputCells() {
  50. int nItems = _sensitiveInputCells.size();
  51. if (nItems < 1) {
  52. return CellCacheEntry.EMPTY_ARRAY;
  53. }
  54. CellCacheEntry[] result = new CellCacheEntry[nItems];
  55. _sensitiveInputCells.toArray(result);
  56. return result;
  57. }
  58. public void addUsedBlankCell(EvaluationWorkbook evalWorkbook, int bookIndex, int sheetIndex, int rowIndex, int columnIndex) {
  59. if (_usedBlankCellGroup == null) {
  60. _usedBlankCellGroup = new FormulaUsedBlankCellSet();
  61. }
  62. _usedBlankCellGroup.addCell(evalWorkbook, bookIndex, sheetIndex, rowIndex, columnIndex);
  63. }
  64. public void updateFormulaResult(ValueEval result) {
  65. _cce.updateFormulaResult(result, getSensitiveInputCells(), _usedBlankCellGroup);
  66. }
  67. }