/// <summary> /// Parse the database file. /// </summary> /// <param name="reader"></param> /// <returns></returns> private void LoadDatabase(TextReader reader) { itemList = new List <NamedPoint>(); string line; while ((line = reader.ReadLine()) != null) { AddAndKeepSorted(NamedPoint.Parse(line)); } CheckListSize(); }
private void AddAndKeepSorted(NamedPoint newItem) { // Add the newItem while keeping the list sorted for (int i = 0; i < itemList.Count; i++) { if (newItem.CompareTo(itemList[i]) < 0) { // The newItem is smaller, so insert it before item i itemList.Insert(i, newItem); // Found a place to put newItem, so stop processing return; } } // Didn't find a place to put newItem, so add it to the end if (itemList.Count < MAX_SIZE) { itemList.Add(newItem); } }
public void AddItem(NamedPoint newItem) { AddAndKeepSorted(newItem); CheckListSize(); SaveData(); }
/// <summary> /// Add a new item to the data /// </summary> /// <param name="name"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> public void AddItem(string name, int x, int y) { NamedPoint newItem = new NamedPoint(name, x, y); AddItem(newItem); }