// Creates a new Row Element, and adds this to sorted list of row elements (provided it is unique) public void addElement(int devYear, float value) { RowElement elem = new RowElement(devYear, value); if (!rowElements.Exists(e => e.getDevYear() == elem.getDevYear())) { rowElements.Add(elem); // After a new element is added, the list is re-sorted in ascending order of Dev Years rowElements.Sort((x, y) => x.getDevYear().CompareTo(y.getDevYear())); } }
// Converts incremental row data -> cummulative row data public void convert() { // Initialises new list of Row Elements List <RowElement> cRowElements = new List <RowElement>(); float prev = 0; float next = 0; // For each element in row, clone with a new cummulated value (adding the previous value) // Add this cloned element to the new sorted "cummulative" list of row elements for (int i = 0; i < rowElements.Count; i++) { next = rowElements[i].getValue() + prev; RowElement elem = new RowElement(rowElements[i].getDevYear(), next); cRowElements.Add(elem); rowElements.Sort((x, y) => x.getDevYear().CompareTo(y.getDevYear())); prev = next; } // Replace old "incremental" list with new "cummulative" list rowElements = cRowElements; }