Compare() public method

public Compare ( Object a, Object b ) : int
a Object
b Object
return int
Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public int CompareTo(
            object other)
        {
            Comparer comparer = new Comparer( System.Globalization.CultureInfo.CurrentCulture );

            Vertex otherVertex = (Vertex) other;

            return comparer.Compare(
                _key,
                otherVertex._key );
        }
Exemplo n.º 4
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);
        }
            internal int Compare(Graphic x, Graphic y)
            {
                var o1 = x.Attributes[Field];                 // get primitive value
                var o2 = y.Attributes[Field];                 // get primitive value

                if (isDynamicCodedValue)
                {
                    o1 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, x, dynamicCodedValueSource);
                    o2 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, y, dynamicCodedValueSource);
                }
                if (isCodedValue || isTypeIDField)
                {
                    o1 = CodedValueSources.CodedValueNameLookup(Field, x, codedValueSources);
                    o2 = CodedValueSources.CodedValueNameLookup(Field, y, codedValueSources);
                }

                return(comparer.Compare(o1, o2));                // compare primitives
            }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
0
            internal int Compare(Graphic x, Graphic y)
            {
                var o1 = x.Attributes[Field];                 // get primitive value
                var o2 = y.Attributes[Field];                 // get primitive value

                if (o1 == null && o2 == null)
                {
                    return(0);
                }
                else if (o1 != null && o2 == null)
                {
                    return(1);
                }
                else if (o1 == null && o2 != null)
                {
                    return(-1);
                }

                var type = NonNullableType(DataType);

                var t1 = o1.GetType();
                var t2 = o2.GetType();

                if (type == typeof(DateTime))
                {
                    if (t1 != type && t2 != type)
                    {
                        return(0);
                    }
                    if (t1 != type && t2 == type)
                    {
                        return(-1);
                    }
                    if (t1 == type && t2 != type)
                    {
                        return(1);
                    }
                }
                else
                {
                    if (t1 != type)
                    {
                        o1 = Convert.ChangeType(o1, type);
                    }
                    if (t2 != type)
                    {
                        o2 = Convert.ChangeType(o2, type);
                    }
                }

                if (isDynamicCodedValue)
                {
                    o1 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, x, dynamicCodedValueSource);
                    o2 = DynamicCodedValueSource.CodedValueNameLookup(TypeIDField, Field, y, dynamicCodedValueSource);
                }
                else if (isCodedValue || isTypeIDField)
                {
                    o1 = CodedValueSources.CodedValueNameLookup(Field, x, codedValueSources);
                    o2 = CodedValueSources.CodedValueNameLookup(Field, y, codedValueSources);
                }

                return(comparer.Compare(o1, o2));                // compare primitives
            }
Exemplo n.º 9
0
            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;
            }
Exemplo n.º 10
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;
        }
Exemplo n.º 11
0
		public void Constructor ()
		{
			Comparer c = new Comparer (CultureInfo.InvariantCulture);
			Assert.IsTrue (c.Compare ("a", "A") < 0);
		}