/// <summary> /// A helper method to obtain all direct and indirect cells that named cell depends on. /// Used for finding circular dependency in graph. /// </summary> /// <param name="name">Named cell</param> /// <returns>Set of all direct and indirect cells on which "name"'s value depends on</returns> private ISet <string> GetAllDependents(string name) { HashSet <string> AllDependents = new HashSet <string>(); AllDependents.Add(name); if (!Graph.HasDependents(name)) { return(AllDependents); } GetDependentsRecursive(name, AllDependents); return(AllDependents); }
protected override IEnumerable <string> GetDirectDependents(string name) { // Check for any Dependents to begin with if (depGraph.HasDependents(name)) { return(depGraph.GetDependents(name)); } // Otherwise we return a new empty list return(new List <string>()); }
/// <inheritdoc/> /// <param name="name">The name of the cell that is the dependee of all cells returned.</param> /// <returns>Enumeration of direct dependents of given cell</returns> protected override IEnumerable <string> GetDirectDependents(string name) { //If the cell does not have dependents, do not return anything if (!dg.HasDependents(name)) { yield break; } //Otherwise, enumerate each dependent else { foreach (String n in dg.GetDependents(name)) { yield return(n); } } }
/// <summary> /// If name is null, throws an ArgumentNullException. /// /// Otherwise, if name isn't a valid cell name, throws an InvalidNameException. /// /// Otherwise, returns an enumeration, without duplicates, of the names of all cells whose /// values depend directly on the value of the named cell. In other words, returns /// an enumeration, without duplicates, of the names of all cells that contain /// formulas containing name. /// /// For example, suppose that /// A1 contains 3 /// B1 contains the formula A1 * A1 /// C1 contains the formula B1 + A1 /// D1 contains the formula B1 - C1 /// The direct dependents of A1 are B1 and C1 /// </summary> protected override IEnumerable <string> GetDirectDependents(string name) { CheckParameters(name); HashSet <string> list = new HashSet <string>(); // Make sure the named cell has any dependent before adding it to the list // Otherwise, return an empty list. if (graph.HasDependents(name)) { foreach (string dependent in graph.GetDependents(name)) { list.Add(dependent); } } return(list); }
/// <summary> /// Helper method which makes use of the already implmented GetCellsToRecalculate to find all the dependencies. /// </summary> /// <param name="name">The cell whose dependencies we are to find</param> /// <returns>The cells dependents</returns> private List <string> getDependents(string name) { List <string> listToReturn = new List <string>() { }; if (dependencies.HasDependents(name)) { foreach (string x in this.GetCellsToRecalculate(name)) { listToReturn.Add(x); } } else { listToReturn.Add(name); } return(listToReturn); }
/// <summary> /// way of getting the direct dependents of a given cell. Helper method for getCellsToRecalculate /// </summary> /// <param name="name">Cell name</param> /// <returns>Direct Dependents</returns> protected override IEnumerable <string> GetDirectDependents(string name) { if (name == null) { throw new ArgumentNullException(); } if (!couldBeAVariable(name)) { throw new InvalidNameException(); } HashSet <string> dependents = new HashSet <string>(); //to hold all the direct dependents if (dg.HasDependents(name)) { foreach (string el in dg.GetDependents(name)) { dependents.Add(el); } } return(dependents); }
protected override ISet <String> SetCellContents(String name, Formula formula) { //EXCEPTION HANDELING\\ if (System.String.IsNullOrWhiteSpace(name)) { throw new InvalidNameException(); } if (!isValid(name)) { throw new InvalidNameException(); } if (formula == null) { throw new ArgumentNullException(); } this.temp = new HashSet <string>(); foreach (string s in formula.GetVariables()) //GET ALL THE VARIABLES FROM THE FORMULA AND ADD THEM TO A SET { if (!isValid(s)) { throw new FormulaFormatException("One or more variables names do not follow the proper syntax expected"); } this.temp.Add(s); } foreach (string s in this.temp) //TRACK DEPENDENCIES { if (ssDep.HasDependents(s)) { foreach (string ss in ssDep.GetDependents(s)) { if (ss == s || ss == name) { throw new CircularException(); } } } ssDep.AddDependency(name, s); } Cell v; if (Cells.TryGetValue(name, out v)) //Get the right cell { if (v.Content is Formula) { Formula check = (Formula)v.Content; foreach (string s in check.GetVariables()) { ssDep.RemoveDependency(name, s); //Remove old dependencies } } } ISet <string> set = Set(name, formula); foreach (string s in set) //Recalculate Cells that depend on new cells content { calculateV(s); } return(set); }