/// <summary> /// Adds a new tune to the Charge List /// </summary> /// <param name="tuneType">Type of tune</param> /// <param name="notes">Any notes related to the tune</param> public void AddTune(string tuneType, string notes) { for (int i = 0; i < mTuneRecords.Count; ++i) { if (mTuneRecords[i].mTuneType == tuneType) { mTuneRecords[i].mCount += 1; if (notes != string.Empty) { mNotes.Add(notes); } return; } } // Tune type wasn't found in array. Add it TuneRecord tr = new TuneRecord(); tr.mTuneType = tuneType; tr.mCount = 1; mTuneRecords.Add(tr); if (notes != string.Empty) { mNotes.Add(notes); } }
/// <summary> /// Merges two charge lists. For each tune type matching in both the /// charge lists the number of tunes are summed. For any tune type not /// found in both lists a new tune record is added to the one Charge /// List that will be kept. /// </summary> /// <param name="other">Other Charge List to merge from</param> public void MergeChargeLists(ChargeList other) { List<TuneRecord> otherTuneRecords = other.GetTuneRecords(); // Merge notes first mNotes.AddRange(other.GetNotes()); // Merge tune records for (int i = 0; i < otherTuneRecords.Count; ++i) { bool matchFound = false; for (int j = 0; j < mTuneRecords.Count; ++j) { if (otherTuneRecords[i].mTuneType == mTuneRecords[j].mTuneType) { // There is a matching tune type in both the new and old list, merge the counts mTuneRecords[j].mCount += otherTuneRecords[i].mCount; matchFound = true; break; } } if (!matchFound) { // No match for this record was found so just add it to the existing list TuneRecord tr = new TuneRecord(); tr.mTuneType = otherTuneRecords[i].mTuneType; tr.mCount = otherTuneRecords[i].mCount; mTuneRecords.Add(tr); } } }