public void AddExample(Multistroke p) { string catName = Category.ParseName(p.Name); if (this.ContainsKey(p.User)) { // if this user is in the collection, and has some samples in this category already... if (this[p.User].ContainsKey(catName)) { Dictionary <string, Category> forUser = this[p.User]; Category cat = (Category)forUser[catName]; cat.AddExample(p); // if the category has been made before, just add to it } else // create new category { Dictionary <string, Category> forUser = this[p.User]; forUser.Add(catName, new Category(catName, p)); } } else // create new user { Dictionary <string, Category> forUser = new Dictionary <string, Category>(); forUser.Add(catName, new Category(catName, p)); this.Add(p.User, forUser); } }
public void AddExample(Multistroke p) // changed to Multistroke, Lisa 1/5/2008 { bool success = true; try { // first, ensure that p's name is right string name = ParseName(p.Name); if (name != _name) { throw new ArgumentException("Prototype name does not equal the name of the category to which it was added."); } // second, ensure that it doesn't already exist for (int i = 0; i < _prototypes.Count; i++) { Multistroke p0 = _prototypes[i]; // Lisa 15/2/008 if (p0.Name == p.Name) { throw new ArgumentException("Prototype name was added more than once to its category."); } } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); success = false; } if (success) { _prototypes.Add(p); } }
public Category(string name, List <Multistroke> examples) { _name = name; _prototypes = new List <Multistroke>(examples.Count); for (int i = 0; i < examples.Count; i++) { Multistroke p = (Multistroke)examples[i]; AddExample(p); } }
// sorts in descending order of Score public int CompareTo(object obj) { if (obj is Multistroke) { Multistroke ms = (Multistroke)obj; return(Name.CompareTo(ms.Name)); } else { throw new ArgumentException("object is not a Multistroke"); } }
// changed to store Multistrokes instead of Gestures, Lisa 1/5/2008 public Category(string name, Multistroke firstExample) //Gesture firstExample) { _name = name; _prototypes = new List <Multistroke>(); AddExample(firstExample); }