private List <TabularItemNode> Sort(CacheFieldNode cacheField, SharedItemsCollection cacheItems) { // Sort the fields according to their types. IComparer <string> comparer = null; if (this.TabularDataNode.CustomListSort && cacheField.IsDateGrouping) { if (cacheField.FieldGroup.GroupBy == PivotFieldDateGrouping.Months) { comparer = new MonthComparer(); } else if (cacheField.FieldGroup.GroupBy == PivotFieldDateGrouping.Days) { comparer = new DayComparer(); } } else { comparer = new NaturalComparer(); } // Sort the slicer cache items. if (this.TabularDataNode.SortOrder == SortOrder.Descending) { return(this.TabularDataNode.Items.OrderByDescending(t => cacheItems[t.AtomIndex].Value, comparer).ToList()); } return(this.TabularDataNode.Items.OrderBy(t => cacheItems[t.AtomIndex].Value, comparer).ToList()); }
public static void Main() { IComparer <Test> cmp = new NaturalComparer <Test> (); Test a = new Test(); Test b = new Test(); cmp.Compare(a, b); }
public void Test01() { var r1 = NaturalComparer.Compare("_qwerty", "0qwerty", StringComparison.InvariantCulture); Assert.True(r1 < 0); var r2 = NaturalComparer.Ordinal.Compare("[qwerty", "_qwerty"); Assert.True(r2 < 0); }
static void Test1() { Console.WriteLine("----Test1"); IComparer <Test> cmp = new NaturalComparer <Test>(); Test a = new Test(); Test b = new Test(); cmp.Compare(a, b); Console.WriteLine("ok"); }
public void GenericC() { SCG.IComparer <dbl> h = new NaturalComparer <dbl>(); dbl s = new dbl(3.4); dbl t = new dbl(3.4); dbl u = new dbl(7.4); Assert.AreEqual(0, h.Compare(s, t)); Assert.IsTrue(h.Compare(s, u) < 0); }
/// <summary> /// Sort a list of File objects by SystemID, SourceID, Game, and Name (in order) /// </summary> /// <param name="roms">List of File objects representing the roms to be sorted</param> /// <param name="norename">True if files are not renamed, false otherwise</param> /// <returns>True if it sorted correctly, false otherwise</returns> public static bool Sort(ref List <DatItem> roms, bool norename) { roms.Sort(delegate(DatItem x, DatItem y) { try { NaturalComparer nc = new NaturalComparer(); if (x.SystemID == y.SystemID) { if (x.SourceID == y.SourceID) { if (x.MachineName == y.MachineName) { if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk)) { if (Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name))) { return(nc.Compare(Path.GetFileName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Utilities.RemovePathUnsafeCharacters(y.Name)))); } return(nc.Compare(Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Utilities.RemovePathUnsafeCharacters(y.Name)))); } else if ((x.ItemType == ItemType.Rom || x.ItemType == ItemType.Disk) && (y.ItemType != ItemType.Rom && y.ItemType != ItemType.Disk)) { return(-1); } else if ((x.ItemType != ItemType.Rom && x.ItemType != ItemType.Disk) && (y.ItemType == ItemType.Rom || y.ItemType == ItemType.Disk)) { return(1); } else { if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name)) { return(nc.Compare(Path.GetFileName(x.Name), Path.GetFileName(y.Name))); } return(nc.Compare(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name))); } } return(nc.Compare(x.MachineName, y.MachineName)); } return(norename ? nc.Compare(x.MachineName, y.MachineName) : x.SourceID - y.SourceID); } return(norename ? nc.Compare(x.MachineName, y.MachineName) : x.SystemID - y.SystemID); } catch (Exception) { // Absorb the error return(0); } }); return(true); }
/// <summary> /// Helper function for SplitByLevel to sort the input game names /// </summary> /// <param name="a">First string to compare</param> /// <param name="b">Second string to compare</param> /// <returns>-1 for a coming before b, 0 for a == b, 1 for a coming after b</returns> private static int SplitByLevelSort(string a, string b) { NaturalComparer nc = new NaturalComparer(); int adeep = a.Count(c => c == '/' || c == '\\'); int bdeep = b.Count(c => c == '/' || c == '\\'); if (adeep == bdeep) { return(nc.Compare(a, b)); } return(adeep - bdeep); }
public int Compare(IDataObject x, IDataObject y) { var result = x.Type.Sort.CompareTo(y.Type.Sort); if (result != 0) { return(result); } result = NaturalComparer.Compare(x.DisplayName, y.DisplayName); if (result != 0) { return(_direction * result); } return(_direction * (x.GetHashCode() - y.GetHashCode())); }
public int DoCompare(NodeViewModel x, NodeViewModel y) { var result = x.Type.Sort.CompareTo(y.Type.Sort); if (result != 0) { return(result); } result = NaturalComparer.Compare(x.Title, y.Title); if (result != 0) { return(_direction * result); } return(_direction * (x.GetHashCode() - y.GetHashCode())); }
public StringParser(NaturalComparer naturalComparer) { mNaturalComparer = naturalComparer; }
// Handles drag/drop onto timeline void LayoutInsert(Rect rect) { Event e = Event.current; if ((e.type == EventType.DragUpdated || e.type == EventType.DragPerform) && rect.Contains(e.mousePosition)) { if (System.Array.Exists(DragAndDrop.objectReferences, item => item is Sprite || item is Texture2D)) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; int closestFrame = MousePosToInsertFrameIndex(rect); LayoutInsertFramesLine(rect, closestFrame); m_dragDropHovering = true; if (e.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); List <Sprite> sprites = new List <Sprite>(); foreach (Object obj in DragAndDrop.objectReferences) { if (obj is Sprite) { sprites.Add(obj as Sprite); } else if (obj is Texture2D) { // Grab all sprites associated with a texture, add to list string path = AssetDatabase.GetAssetPath(obj); Object[] assets = AssetDatabase.LoadAllAssetRepresentationsAtPath(path); foreach (Object subAsset in assets) { if (subAsset is Sprite) { sprites.Add((Sprite)subAsset); } } } } // Sort sprites by name and insert using (NaturalComparer comparer = new NaturalComparer()) { sprites.Sort((a, b) => comparer.Compare(a.name, b.name)); } InsertFrames(sprites.ToArray(), closestFrame); } } } // The indicator won't update while drag/dropping becuse it's not active, so we hack it using this flag if (m_dragDropHovering && rect.Contains(e.mousePosition)) { int closestFrame = MousePosToInsertFrameIndex(rect); LayoutInsertFramesLine(rect, closestFrame); } else { m_dragDropHovering = false; } if (e.type == EventType.DragExited) { m_dragDropHovering = false; } }
private static void DoTest(string left, string right, ComparerEquality expectedResult, NaturalComparer comparer) { var result = comparer.Compare(left, right); switch (expectedResult) { case ComparerEquality.LessThan: Assert.True(result <= (int)expectedResult, $"Result: {result} Expected Result: {expectedResult}({(int)expectedResult})"); break; case ComparerEquality.Equal: Assert.True(result == (int)expectedResult, $"Result: {result} Expected Result: {expectedResult}({(int)expectedResult})"); break; case ComparerEquality.GreaterThan: Assert.True(result >= (int)expectedResult, $"Result: {result} Expected Result: {expectedResult}({(int)expectedResult})"); break; default: throw new ArgumentOutOfRangeException(nameof(expectedResult), expectedResult, null); } }
public void TestCompare(string left, string right, ComparerEquality expectedResult, NaturalComparerOptions options = NaturalComparerOptions.None) { var comparer = new NaturalComparer(options); DoTest(left, right, expectedResult, comparer); }