Inheritance: IComparer
 internal SortedSerializableObjectPool(Serializer owner, IList<Type> registeredTypes)
 {
     this._owner = owner;
     this._target = owner.Target;
     this._comparer = new Comparer(System.Globalization.CultureInfo.CurrentCulture);
     this._persistentObjects = new FastSearchDictionary<Guid,GenericWeakReference<ISerializableObject>>(_comparer);
 }
Example #2
0
        /// <summary>
        /// Returns a portion of the list whose keys are greater that the lowerLimit parameter less than the upperLimit parameter.
        /// </summary>
        /// <param name="l">The list where the portion will be extracted.</param>
        /// <param name="limit">The start element of the portion to extract.</param>
        /// <param name="limit">The end element of the portion to extract.</param>
        /// <returns>The portion of the collection.</returns>
        public static System.Collections.SortedList SubMap(System.Collections.SortedList list, System.Object lowerLimit, System.Object upperLimit)
        {
            System.Collections.Comparer   comparer = System.Collections.Comparer.Default;
            System.Collections.SortedList newList  = new System.Collections.SortedList();

            if (list != null)
            {
                if ((list.Count > 0) && (!(lowerLimit.Equals(upperLimit))))
                {
                    int index = 0;
                    while (comparer.Compare(list.GetKey(index), lowerLimit) < 0)
                    {
                        index++;
                    }

                    for (; index < list.Count; index++)
                    {
                        if (comparer.Compare(list.GetKey(index), upperLimit) >= 0)
                        {
                            break;
                        }

                        newList.Add(list.GetKey(index), list[list.GetKey(index)]);
                    }
                }
            }

            return(newList);
        }
Example #3
0
        public bool Check(Data data)
        {
            var firstArgument = _firstArgumentSelector.SelectData(data);
            var secondArgument = _secondArgumentSelector.SelectData(data);

            IComparer comparer = new Comparer(CultureInfo.CurrentCulture);
            int compareResult = comparer.Compare(firstArgument, secondArgument);
            return _checkComparisonResult(compareResult);
        }
Example #4
0
 public static void SearchProducts(Object[] array,string searchBy, Comparer comparer)
 {
     foreach (var item in array)
     {
         if (comparer(item, searchBy))
         {
             Console.WriteLine("Product {0} found.", searchBy);
         }
     }
 }
Example #5
0
        public int CompareTo(
            object other)
        {
            Comparer comparer = new Comparer( System.Globalization.CultureInfo.CurrentCulture );

            Vertex otherVertex = (Vertex) other;

            return comparer.Compare(
                _key,
                otherVertex._key );
        }
Example #6
0
        ////[TestMethod]
        public void TestNamespace()
        {
            string sourceCode =
@"namespace Namespace1
{
    public class Class1
    {
    }
}";
            CsLanguageService languageService = new CsLanguageService();
            CsDocument document1 = languageService.CreateCodeModel(sourceCode, "source1.cs", "test");
            CsDocument document2 = languageService.CreateCodeModel(sourceCode, "source2.cs", "test");

            Comparer comparer = new Comparer();
            comparer.AreEqual(document1, document2);
        }
Example #7
0
        /// <summary>
        /// Returns a portion of the list whose keys are less than the limit object parameter.
        /// </summary>
        /// <param name="l">The list where the portion will be extracted.</param>
        /// <param name="limit">The end element of the portion to extract.</param>
        /// <returns>The portion of the collection whose elements are less than the limit object parameter.</returns>
        public static System.Collections.SortedList HeadMap(System.Collections.SortedList l, System.Object limit)
        {
            System.Collections.Comparer   comparer = System.Collections.Comparer.Default;
            System.Collections.SortedList newList  = new System.Collections.SortedList();

            for (int i = 0; i < l.Count; i++)
            {
                if (comparer.Compare(l.GetKey(i), limit) >= 0)
                {
                    break;
                }

                newList.Add(l.GetKey(i), l[l.GetKey(i)]);
            }

            return(newList);
        }
Example #8
0
        public virtual int CompareTo(
            object other)
        {
            Comparer comparer = new Comparer( System.Globalization.CultureInfo.CurrentCulture );

            Edge otherEdge = (Edge) other;

            int compareResult = comparer.Compare(
                _source,
                otherEdge._source );

            if ( 0 == compareResult )
            {
                comparer.Compare(
                    _sink,
                    otherEdge._sink );
            }

            return compareResult;
        }
Example #9
0
    public static System.Collections.SortedList TailMap(System.Collections.SortedList list, System.Object limit)
    {
        System.Collections.Comparer   comparer = System.Collections.Comparer.Default;
        System.Collections.SortedList newList  = new System.Collections.SortedList();

        if (list != null)
        {
            if (list.Count > 0)
            {
                int index = 0;
                while (comparer.Compare(list.GetKey(index), limit) < 0)
                {
                    index++;
                }

                for (; index < list.Count; index++)
                {
                    newList.Add(list.GetKey(index), list[list.GetKey(index)]);
                }
            }
        }

        return(newList);
    }
Example #10
0
        private static IEnumerable MergeSort(object[] data, Selector s, Comparer c)
        {
            object[] left = SplitArray(data, 0, data.Length / 2 - 1);
            object[] right = SplitArray(data, data.Length / 2, data.Length - 1);

            if (left.Length > 1) MergeSort(left, s, c);
            if (right.Length > 1) MergeSort(right, s, c);

            Merge(left, right, data, s, c);

            return data;
        }
Example #11
0
        private static void Merge(object[] left, object[] right, object[] result, Selector s, Comparer c)
        {
            int i = 0, j = 0, h = 0;

            while (i < left.Length || j < right.Length)
            {
                if (i == left.Length) result[h++] = right[j++];
                else if (j == right.Length) result[h++] = left[i++];
                else if (c(s(left[i]), s(right[j])) < 0)
                {
                    result[h++] = left[i++];
                }
                else
                {
                    result[h++] = right[j++];
                }
            }
        }
Example #12
0
        /// <summary>
        /// Copies the elements from an IEnumerable into an Array of objects. A simple quick sort
        /// is applied to the new list by applying the Selector delegate to each object element and
        /// casting it to IComparable (or a reflected invoke of CompareTo) to perform the comparison.
        /// If a comparison delegate is provided it will be used to perform the comparison.
        /// </summary>
        /// <param name="e">The IEnumerable to copy and process.</param>
        /// <param name="s">The delegate used to select which property in an object should be compared.</param>
        /// <param name="c">The delegate used to perform comparisons on objects during the order.</param>
        /// <returns>A new IEnumerable with elements ordered by the property specified in the selector delegate.</returns>
        public static IEnumerable OrderBy(this IEnumerable e, Selector s, Comparer c)
        {
            ICollection d = e as ICollection;
            object[] data;

            if (null == d)
            {
                var temp = new ArrayList();
                foreach (var o in e)
                    temp.Add(o);
                data = temp.ToArray();

                if (data.Length <= 1)
                    return data;
            }
            else
            {
                if (d.Count <= 1)
                    return d;

                data = new object[d.Count];
                d.CopyTo((object[])data, 0);
            }

            return MergeSort(data, s, c);
        }
            public virtual IEnumerable<BrowseFacet> GetFacets()
            {
                C5.IDictionary<object, BrowseFacet> facetMap;
                if (FacetSpec.FacetSortSpec.OrderValueAsc.Equals(fspec.OrderBy))
                {
                    facetMap = new C5.TreeDictionary<object, BrowseFacet>();
                }
                else
                {
                    facetMap = new C5.HashDictionary<object, BrowseFacet>();
                }

                foreach (IFacetAccessible facetAccessor in this.list)
                {
                    IEnumerator<BrowseFacet> iter = facetAccessor.GetFacets().GetEnumerator();
                    if (facetMap.Count == 0)
                    {
                        while (iter.MoveNext())
                        {
                            BrowseFacet facet = iter.Current;
                            facetMap.Add(facet.Value, facet);
                        }
                    }
                    else
                    {
                        while (iter.MoveNext())
                        {
                            BrowseFacet facet = iter.Current;
                            BrowseFacet existing = facetMap[facet.Value];
                            if (existing == null)
                            {
                                facetMap.Add(facet.Value, facet);
                            }
                            else
                            {
                                existing.HitCount = existing.HitCount + facet.HitCount;
                            }
                        }
                    }
                }

                List<BrowseFacet> list = new List<BrowseFacet>(facetMap.Values);
                // FIXME: we need to reorganize all that stuff with comparators
                Comparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture);
                if (FacetSpec.FacetSortSpec.OrderHitsDesc.Equals(fspec.OrderBy))
                {
                    list.Sort(
                        delegate(BrowseFacet f1, BrowseFacet f2)
                        {
                            int val = f2.HitCount - f1.HitCount;
                            if (val == 0)
                            {
                                val = -(comparer.Compare(f1.Value, f2.Value));
                            }
                            return val;
                        }
                        );
                }
                return list;
            }
Example #14
0
 public void Sort()
 {
     System.Collections.Comparer comp = new System.Collections.Comparer();
     workers.Sort(comp);
 }
 /// <summary>
 /// Construct a CollectionContainsConstraint
 /// </summary>
 /// <param name="expected"></param>
 public AbstractStructureConstraint()
 {
     Comparer = new Comparer(System.Threading.Thread.CurrentThread.CurrentCulture);
 }
Example #16
0
        public virtual int Compare(object x, object y)
        {
            if (x is string)
            {
                return ((string)x).CompareTo((string)y);
            }

            var comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture);
            if (x is int || y is string)
            {
                return comparer.Compare(x, y);
            }

            return -1;
        }
Example #17
0
 private Comparer comparer;// Return the result of comparison.
 public columnSorter()
 {
     col = 0;
     order = SortOrder.None;
     comparer = Comparer.Default;
 }
Example #18
0
 public ComparerImpl(Comparer comparer)
 {
     _comparer = comparer;
 }
Example #19
0
 public List Sort(Comparer comparer)
 {
     if (null == comparer)
     {
         throw new ArgumentNullException("comparer");
     }
     return Sort(new ComparerImpl(comparer));
 }
		void FillMembersComboBox()
		{
			IClass c = GetCurrentSelectedClass();
			if (c != null && lastClassInMembersComboBox != c) {
				lastClassInMembersComboBox = c;
				ArrayList items = new ArrayList();
				bool partialMode = false;
				IClass currentPart = c;
				if (c.IsPartial) {
					CompoundClass cc = c.GetCompoundClass() as CompoundClass;
					if (cc != null) {
						partialMode = true;
						c = cc;
					}
				}
				
				IAmbience ambience = AmbienceService.GetCurrentAmbience();
				ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList | ConversionFlags.ShowParameterList | ConversionFlags.ShowParameterNames;
				
				int lastIndex = 0;
				IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture);
				
				foreach (IMethod m in c.Methods) {
					items.Add(new ComboBoxItem(m, ambience.Convert(m), ClassBrowserIconService.GetIcon(m), partialMode ? currentPart.Methods.Contains(m) : true));
				}
				// use "items.Count - lastIndex" instead of "c.Methods.Count"
				// because it is possible that the number of methods in the class
				// changes while the loop is running (if a compound class is changed
				// from another thread)
				items.Sort(lastIndex, items.Count - lastIndex, comparer);
				lastIndex = items.Count;
				
				foreach (IProperty p in c.Properties) {
					items.Add(new ComboBoxItem(p, ambience.Convert(p), ClassBrowserIconService.GetIcon(p), partialMode ? currentPart.Properties.Contains(p) : true));
				}
				items.Sort(lastIndex, items.Count - lastIndex, comparer);
				lastIndex = items.Count;
				
				foreach (IField f in c.Fields) {
					items.Add(new ComboBoxItem(f, ambience.Convert(f), ClassBrowserIconService.GetIcon(f), partialMode ? currentPart.Fields.Contains(f) : true));
				}
				items.Sort(lastIndex, items.Count - lastIndex, comparer);
				lastIndex = items.Count;
				
				foreach (IEvent evt in c.Events) {
					items.Add(new ComboBoxItem(evt, ambience.Convert(evt), ClassBrowserIconService.GetIcon(evt), partialMode ? currentPart.Events.Contains(evt) : true));
				}
				items.Sort(lastIndex, items.Count - lastIndex, comparer);
				lastIndex = items.Count;
				
				membersComboBox.BeginUpdate();
				membersComboBox.Items.Clear();
				membersComboBox.Items.AddRange(items.ToArray());
				membersComboBox.EndUpdate();
				UpdateMembersComboBox();
			}
		}
 /// <summary>
 /// Constructeur
 /// </summary>
 public SchoolCollectionSorter()
 {
     sortColumn = 0;
     sortOrder = SortOrder.None;
     listViewItemComparer = new Comparer(CultureInfo.CurrentUICulture);
 }
Example #22
0
 internal void AddComparer(object input)
 {
     if (_comparer == null)
         _comparer = input as Comparer;
 }
Example #23
0
 public PermissionTokenKeyComparer()
 {
     _caseSensitiveComparer = new Comparer(CultureInfo.InvariantCulture);
     _info = CultureInfo.InvariantCulture.TextInfo;
 }
Example #24
0
		public void BinarySearch3_EmptyList ()
		{
			Comparer comparer = new Comparer ();
			ArrayList list = new ArrayList ();
			Assert.AreEqual (-1, list.BinarySearch (0, 0, 0, comparer), "BinarySearch");
			// bug 77030 - the comparer isn't called for an empty array/list
			Assert.IsTrue (!comparer.Called, "Called");
		}
 public PermissionTokenKeyComparer(CultureInfo culture)
 {
     _caseSensitiveComparer = new Comparer( culture );
     _info = culture.TextInfo;
 }
Example #26
0
 public void FillTreeNode(TreeNode node, string root)
 {
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     try
     {
         Cursor = Cursors.WaitCursor;
         var text = node.FullPath;
         if (string.CompareOrdinal(text, "\\") == 0)
         {
             text = node.ToString();
         }
         else
         {
             if (string.CompareOrdinal(text.Substring(1, 1), ":") != 0)
             {
                 root = node.Text;
                 text = root + text.Substring(text.IndexOf("\\", StringComparison.Ordinal));
             }
         }
         var directoryInfo = new DirectoryInfo(text);
         var directories = directoryInfo.GetDirectories();
         var comparer = new Comparer(CultureInfo.InvariantCulture);
         Array.Sort(directories, comparer);
         foreach (var current in
             from d in directories
             select new TreeNode(d.Name, 0, 1)
             {
                 Tag = node.Tag.ToString()
             })
         {
             node.Nodes.Add(current);
             current.Nodes.Add("");
         }
         var files = Directory.GetFiles(text, FileExplorerControl.Instance.Filter);
         Array.Sort(files);
         var array = files;
         var array2 = array;
         foreach (var path in array2)
         {
             var treeNode = new TreeNode(Path.GetFileName(path))
             {
                 Tag = node.Tag.ToString()
             };
             var extension = Path.GetExtension(path);
             if (extension != null)
             {
                 var text2 = extension.ToLower();
                 var text3 = text2;
                 // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                 if (text3 == null)
                 {
                     goto IL_260;
                 }
                 if (text3 != ".src")
                 {
                     if (text3 != ".dat")
                     {
                         if (text3 != ".sub")
                         {
                             if (text3 != ".zip")
                             {
                                 goto IL_260;
                             }
                             treeNode.SelectedImageIndex = 6;
                             treeNode.ImageIndex = 6;
                         }
                         else
                         {
                             treeNode.SelectedImageIndex = 6;
                             treeNode.ImageIndex = 6;
                         }
                     }
                     else
                     {
                         treeNode.SelectedImageIndex = 6;
                         treeNode.ImageIndex = 6;
                     }
                 }
                 else
                 {
                     treeNode.SelectedImageIndex = 6;
                     treeNode.ImageIndex = 6;
                 }
                 goto IL_275;
                 IL_260:
                 treeNode.SelectedImageIndex = 6;
                 treeNode.ImageIndex = 6;
             }
             IL_275:
             node.Nodes.Add(treeNode);
         }
         Cursor = Cursors.Default;
     }
     catch (Exception ex)
     {
         var msg = new ErrorMessage("ExplorerClass.FillTreeNode", ex, MessageType.Error);
         Messenger.Default.Send<IMessage>(msg);
         Cursor = Cursors.Default;
     }
 }
Example #27
0
        public static void SortWords(bool accending, bool sortByTranslation)
        {
            Comparer comparer = new Comparer();

            if(accending)
            {
                if(sortByTranslation)
                {
                    comparer.compFunction = comparer.CompareTranslationAccending;
                }
                else
                {
                    comparer.compFunction = comparer.CompareJapaneseAccending;
                }
            }
            else
            {
                if (sortByTranslation)
                {
                    comparer.compFunction = comparer.CompareTranslationDeccending;
                }
                else
                {
                    comparer.compFunction = comparer.CompareJapaneseDeccending;
                }
            }

            Array.Sort(AppData.Words, comparer);
        }
		void FillMembersComboBox()
		{
			IClass c = GetCurrentSelectedClass();
			if (c != null && lastClassInMembersComboBox != c) {
				lastClassInMembersComboBox = c;
				ArrayList items = new ArrayList();
				bool partialMode = false;
				IClass currentPart = c;
				if (c.IsPartial) {
					CompoundClass cc = c.GetCompoundClass() as CompoundClass;
					if (cc != null) {
						partialMode = true;
						c = cc;
					}
				}
				
				lock (c) {
					int lastIndex = 0;
					IComparer comparer = new Comparer(System.Globalization.CultureInfo.InvariantCulture);
					
					foreach (IMethod m in c.Methods) {
						items.Add(new ComboBoxItem(m, m.Name, ClassBrowserIconService.GetIcon(m), partialMode ? currentPart.Methods.Contains(m) : true));
					}
					items.Sort(lastIndex, c.Methods.Count, comparer);
					lastIndex = items.Count;
					
					foreach (IProperty p in c.Properties) {
						items.Add(new ComboBoxItem(p, p.Name, ClassBrowserIconService.GetIcon(p), partialMode ? currentPart.Properties.Contains(p) : true));
					}
					items.Sort(lastIndex, c.Properties.Count, comparer);
					lastIndex = items.Count;
					
					foreach (IField f in c.Fields) {
						items.Add(new ComboBoxItem(f, f.Name, ClassBrowserIconService.GetIcon(f), partialMode ? currentPart.Fields.Contains(f) : true));
					}
					items.Sort(lastIndex, c.Fields.Count, comparer);
					lastIndex = items.Count;
					
					foreach (IEvent evt in c.Events) {
						items.Add(new ComboBoxItem(evt, evt.Name, ClassBrowserIconService.GetIcon(evt), partialMode ? currentPart.Events.Contains(evt) : true));
					}
					items.Sort(lastIndex, c.Events.Count, comparer);
					lastIndex = items.Count;
				}
				
				membersComboBox.BeginUpdate();
				membersComboBox.Items.Clear();
				membersComboBox.Items.AddRange(items.ToArray());
				membersComboBox.EndUpdate();
				UpdateMembersComboBox();
			}
		}
Example #29
0
 /// <summary>
 /// Creates new instance.
 /// </summary>
 public ListViewSorter(ListView list, Comparer[] comparers)
 {
     this.List = list;
     this.Comparers = comparers;
 }
 /// <summary>
 /// set the defaults
 /// </summary>
 public projectSorter()
 {
     currentColumn = 0;
     order = SortOrder.Ascending;
     ObjectCompare = Comparer.Default;
 }
Example #31
0
		public void Constructor ()
		{
			Comparer c = new Comparer (CultureInfo.InvariantCulture);
			Assert.IsTrue (c.Compare ("a", "A") < 0);
		}