internal void CategorizePropEntries() { if (this.Children.Count > 0) { GridEntry[] dest = new GridEntry[this.Children.Count]; this.Children.CopyTo(dest, 0); if ((base.PropertySort & PropertySort.Categorized) != PropertySort.NoSort) { Hashtable hashtable = new Hashtable(); for (int i = 0; i < dest.Length; i++) { GridEntry entry = dest[i]; if (entry != null) { string propertyCategory = entry.PropertyCategory; ArrayList list = (ArrayList)hashtable[propertyCategory]; if (list == null) { list = new ArrayList(); hashtable[propertyCategory] = list; } list.Add(entry); } } ArrayList list2 = new ArrayList(); IDictionaryEnumerator enumerator = hashtable.GetEnumerator(); while (enumerator.MoveNext()) { ArrayList list3 = (ArrayList)enumerator.Value; if (list3 != null) { string key = (string)enumerator.Key; if (list3.Count > 0) { GridEntry[] array = new GridEntry[list3.Count]; list3.CopyTo(array, 0); try { list2.Add(new CategoryGridEntry(base.ownerGrid, this, key, array)); continue; } catch { continue; } } } } dest = new GridEntry[list2.Count]; list2.CopyTo(dest, 0); StringSorter.Sort(dest); base.ChildCollection.Clear(); base.ChildCollection.AddRange(dest); } } }
public void Sort_a_empty_Resulted_empty_a() { List <string> list = new List <string> { "a", "" }; List <string> sortedList = new List <string> { "", "a" }; StringSorter stringSorter = new StringSorter(list); list = stringSorter.Sort().ToList(); CollectionAssert.AreEqual(list, sortedList); }
public void Sort_ba_aa_bb_ab_Resulted_aa_ab_ba_bb() { List <string> list = new List <string> { "ba", "aa", "bb", "ab" }; List <string> sortedList = new List <string> { "aa", "ab", "ba", "bb" }; StringSorter stringSorter = new StringSorter(list); list = stringSorter.Sort().ToList(); CollectionAssert.AreEqual(list, sortedList); }
public void Sort_c_b_a_d_Resulted_a_b_c_d() { List <string> list = new List <string> { "c", "b", "a", "d" }; List <string> sortedList = new List <string> { "a", "b", "c", "d" }; StringSorter stringSorter = new StringSorter(list); list = stringSorter.Sort().ToList(); CollectionAssert.AreEqual(list, sortedList); }
static void SortRun() { List <string> list = new List <string> { "Zebra", //a 1 "Lion", // i 7 "Tiger", //e i 3 "Tiger", //4 "", //0 "Elephent", //e (e)h 2 "Mouse", //e m 6 "Monkey" //e k 5 }; StringSorter sorter = new StringSorter(list); List <string> sortedList = sorter.Sort().ToList(); foreach (var item in sortedList) { Console.WriteLine(item); } }
internal void CategorizePropEntries() { if (Children.Count > 0) { GridEntry[] childEntries = new GridEntry[this.Children.Count]; this.Children.CopyTo(childEntries, 0); if ((this.PropertySort & PropertySort.Categorized) != 0) { // first, walk through all the entires and // group them by their category by adding // them to a hashtable of arraylists. // Hashtable bins = new Hashtable(); for (int i = 0; i < childEntries.Length; i++) { GridEntry pe = childEntries[i]; Debug.Assert(pe != null); if (pe != null) { string category = pe.PropertyCategory; ArrayList bin = (ArrayList)bins[category]; if (bin == null) { bin = new ArrayList(); bins[category] = bin; } bin.Add(pe); } } // now walk through the hashtable // and create a categorygridentry for each // category that holds all the properties // of that category. // ArrayList propList = new ArrayList(); IDictionaryEnumerator enumBins = (IDictionaryEnumerator)bins.GetEnumerator(); while (enumBins.MoveNext()) { ArrayList bin = (ArrayList)enumBins.Value; if (bin != null) { string category = (string)enumBins.Key; if (bin.Count > 0) { GridEntry[] rgpes = new GridEntry[bin.Count]; bin.CopyTo(rgpes, 0); try { propList.Add(new CategoryGridEntry(this.ownerGrid, this, category, rgpes)); } catch { } } } } childEntries = new GridEntry[propList.Count]; propList.CopyTo(childEntries, 0); StringSorter.Sort(childEntries); ChildCollection.Clear(); ChildCollection.AddRange(childEntries); } } }
static void Main(string[] args) { string[] sorted = StringSorter.Sort(args); System.Console.WriteLine(string.Join(",", sorted)); }