public CellCacheEntry[] GetCacheEntries()
        {

            FormulaCellCacheEntry[] result = new FormulaCellCacheEntry[_formulaEntriesByCell.Count];
            _formulaEntriesByCell.Values.CopyTo(result,0);
            return result;
        }
 /**
  * Notifies this evaluation tracker that evaluation of the specified cell Is
  * about To start.<br/>
  *
  * In the case of a <c>true</c> return code, the caller should
  * continue evaluation of the specified cell, and also be sure To call
  * <c>endEvaluate()</c> when complete.<br/>
  *
  * In the case of a <c>null</c> return code, the caller should
  * return an evaluation result of
  * <c>ErrorEval.CIRCULAR_REF_ERROR</c>, and not call <c>endEvaluate()</c>.
  * <br/>
  * @return <c>false</c> if the specified cell is already being evaluated
  */
 public bool StartEvaluate(FormulaCellCacheEntry cce)
 {
     if (cce == null)
     {
         throw new ArgumentException("cellLoc must not be null");
     }
     if (_currentlyEvaluatingCells.Contains(cce))
     {
         return false;
     }
     _currentlyEvaluatingCells.Add(cce);
     _evaluationFrames.Add(new CellEvaluationFrame(cce));
     return true;
 }
Beispiel #3
0
        public void TestBasicCellCacheEntry()
        {
            CellCacheEntry pcce = new PlainValueCellCacheEntry(new NumberEval(42.0));
            ValueEval      ve   = pcce.GetValue();

            Assert.AreEqual(42, ((NumberEval)ve).NumberValue, 0.0);

            FormulaCellCacheEntry fcce = new FormulaCellCacheEntry();

            fcce.UpdateFormulaResult(new NumberEval(10.0), CellCacheEntry.EMPTY_ARRAY, null);

            ve = fcce.GetValue();
            Assert.AreEqual(10, ((NumberEval)ve).NumberValue, 0.0);
        }
 public void Add(CellCacheEntry cce)
 {
     if (_size * 3 >= _arr.Length * 2)
     {
         // re-Hash
         FormulaCellCacheEntry[] prevArr = _arr;
         FormulaCellCacheEntry[] newArr = new FormulaCellCacheEntry[4 + _arr.Length * 3 / 2]; // grow 50%
         for (int i = 0; i < prevArr.Length; i++)
         {
             FormulaCellCacheEntry prevCce = _arr[i];
             if (prevCce != null)
             {
                 AddInternal(newArr, prevCce);
             }
         }
         _arr = newArr;
     }
     if (AddInternal(_arr, cce))
     {
         _size++;
     }
 }
 public FormulaCellCacheEntry[] ToArray()
 {
     int nItems = _size;
     if (nItems < 1)
     {
         return FormulaCellCacheEntry.EMPTY_ARRAY;
     }
     FormulaCellCacheEntry[] result = new FormulaCellCacheEntry[nItems];
     int j = 0;
     for (int i = 0; i < _arr.Length; i++)
     {
         FormulaCellCacheEntry cce = _arr[i];
         if (cce != null)
         {
             result[j++] = cce;
         }
     }
     if (j != nItems)
     {
         throw new InvalidOperationException("size mismatch");
     }
     return result;
 }
        public bool Remove(CellCacheEntry cce)
        {
            FormulaCellCacheEntry[] arr = _arr;

            if (_size * 3 < _arr.Length && _arr.Length > 8)
            {
                // re-Hash
                bool found = false;
                FormulaCellCacheEntry[] prevArr = _arr;
                FormulaCellCacheEntry[] newArr = new FormulaCellCacheEntry[_arr.Length / 2]; // shrink 50%
                for (int i = 0; i < prevArr.Length; i++)
                {
                    FormulaCellCacheEntry prevCce = _arr[i];
                    if (prevCce != null)
                    {
                        if (prevCce == cce)
                        {
                            found = true;
                            _size--;
                            // skip it
                            continue;
                        }
                        AddInternal(newArr, prevCce);
                    }
                }
                _arr = newArr;
                return found;
            }
            // else - usual case
            // delete single element (without re-Hashing)

            int startIx = cce.GetHashCode() % arr.Length;

            // note - can't exit loops upon finding null because of potential previous deletes
            for (int i = startIx; i < arr.Length; i++)
            {
                FormulaCellCacheEntry item = arr[i];
                if (item == cce)
                {
                    // found it
                    arr[i] = null;
                    _size--;
                    return true;
                }
            }
            for (int i = 0; i < startIx; i++)
            {
                FormulaCellCacheEntry item = arr[i];
                if (item == cce)
                {
                    // found it
                    arr[i] = null;
                    _size--;
                    return true;
                }
            }
            return false;
        }
Beispiel #7
0
        public void AddConsumingCell(FormulaCellCacheEntry cellLoc)
        {
            _consumingCells.Add(cellLoc);

        }
Beispiel #8
0
 public void ClearConsumingCell(FormulaCellCacheEntry cce)
 {
     if (!_consumingCells.Remove(cce))
     {
         throw new InvalidOperationException("Specified formula cell is not consumed by this cell");
     }
 }
 public void Put(IEvaluationCell cell, FormulaCellCacheEntry entry)
 {
     _formulaEntriesByCell[cell.IdentityKey] = entry;
 }
Beispiel #10
0
        public void NotifyUpdateCell(int bookIndex, int sheetIndex, IEvaluationCell cell)
        {
            FormulaCellCacheEntry fcce = _formulaCellCache.Get(cell);

            int rowIndex = cell.RowIndex;
            int columnIndex = cell.ColumnIndex;
            Loc loc = new Loc(bookIndex, sheetIndex, cell.RowIndex, cell.ColumnIndex);
            PlainValueCellCacheEntry pcce = _plainCellCache.Get(loc);

            if (cell.CellType == LF.Utils.NPOI.SS.UserModel.CellType.FORMULA)
            {
                if (fcce == null)
                {
                    fcce = new FormulaCellCacheEntry();

                    if (pcce == null)
                    {
                        if (_evaluationListener != null)
                        {
                            _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                    columnIndex, cell, fcce);
                        }
                        UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                    }
                    _formulaCellCache.Put(cell, fcce);
                }
                else
                {
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    fcce.ClearFormulaEntry();
                }
                if (pcce == null)
                {
                    // was formula cell before - no Change of type
                }
                else
                {
                    // changing from plain cell To formula cell
                    pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    _plainCellCache.Remove(loc);
                }
            }
            else
            {
                ValueEval value = WorkbookEvaluator.GetValueFromNonFormulaCell(cell);
                if (pcce == null)
                {
                    if (value != BlankEval.instance)
                    {
                        pcce = new PlainValueCellCacheEntry(value);
                        if (fcce == null)
                        {
                            if (_evaluationListener != null)
                            {
                                _evaluationListener.OnChangeFromBlankValue(sheetIndex, rowIndex,
                                        columnIndex, cell, pcce);
                            }
                            UpdateAnyBlankReferencingFormulas(bookIndex, sheetIndex, rowIndex, columnIndex);
                        }
                        _plainCellCache.Put(loc, pcce);
                    }
                }
                else
                {
                    if (pcce.UpdateValue(value))
                    {
                        pcce.RecurseClearCachedFormulaResults(_evaluationListener);
                    }
                    if (value == BlankEval.instance)
                    {
                        _plainCellCache.Remove(loc);
                    }
                }
                if (fcce == null)
                {
                    // was plain cell before - no Change of type
                }
                else
                {
                    // was formula cell before - now a plain value
                    _formulaCellCache.Remove(cell);
                    fcce.SetSensitiveInputCells(null);
                    fcce.RecurseClearCachedFormulaResults(_evaluationListener);
                }
            }
        }
Beispiel #11
0
        public FormulaCellCacheEntry GetOrCreateFormulaCellEntry(IEvaluationCell cell)
        {            
            FormulaCellCacheEntry result = _formulaCellCache.Get(cell);
            if (result == null)
            {

                result = new FormulaCellCacheEntry();
                _formulaCellCache.Put(cell, result);
            }
            return result;
        }
Beispiel #12
0
 public void ProcessEntry(FormulaCellCacheEntry entry)
 {
     entry.NotifyUpdatedBlankCell(bsk, rowIndex, columnIndex, evaluationListener);
 }
 public CellEvaluationFrame(FormulaCellCacheEntry cce)
 {
     _cce = cce;
     _sensitiveInputCells = new ArrayList();
 }