Example #1
0
        public int CompareTo(IVariant other)
        {
            if (ID == null ||
                Info == null ||
                Filter == null ||
                RefBase == null ||
                AltBase == null)
            {
                return(-1);
            }

            if (other == null ||
                other.ID == null ||
                other.Info == null ||
                other.Filter == null ||
                other.RefBase == null ||
                other.AltBase == null)
            {
                return(1);
            }

            int compareResult = base.CompareTo(other);

            if (compareResult != 0)
            {
                return(compareResult);
            }
            compareResult = ID.CompareTo(other.ID);
            if (compareResult != 0)
            {
                return(compareResult);
            }
            compareResult = Quality.CompareTo(other.Quality);
            if (compareResult != 0)
            {
                return(compareResult);
            }
            compareResult = Filter.CompareTo(other.Filter);
            if (compareResult != 0)
            {
                return(compareResult);
            }
            compareResult = Info.CompareTo(other.Info);
            if (compareResult != 0)
            {
                return(compareResult);
            }
            compareResult = (string.Join("", RefBase)).CompareTo(string.Join("", other.RefBase));
            if (compareResult != 0)
            {
                return(compareResult);
            }
            return((string.Join("", AltBase)).CompareTo(string.Join("", other.AltBase)));
        }
Example #2
0
            public override int Compare(SortObject x, SortObject y)
            {
                IRelic leftRelic  = x.mObj as IRelic;
                IRelic rightRelic = y.mObj as IRelic;

                if ((leftRelic != null) && (rightRelic != null))
                {
                    return(leftRelic.Age.CompareTo(rightRelic.Age));
                }

                Quality leftQuality  = GetQuality(x.mObj);
                Quality rightQuality = GetQuality(y.mObj);

                return(leftQuality.CompareTo(rightQuality));
            }
Example #3
0
        /// <summary>
        /// Sorts the selector in precedence order according to the content negotiation rules from the relevant RFCs.
        /// </summary>
        /// <param name="other">Selector to compare against.</param>
        /// <returns></returns>
        public int CompareTo(MimeTypeSelector other)
        {
            if (other == null)
            {
                // We're always greater than a null
                return(-1);
            }

            if (_isInvalid)
            {
                if (other.IsInvalid)
                {
                    // If both invalid use order
                    return(Order.CompareTo(other.Order));
                }
                else
                {
                    // Invalid types are less than valid types
                    return(1);
                }
            }
            else if (other.IsInvalid)
            {
                // Valid types are greater than invalid types
                return(-1);
            }

            if (_isAny)
            {
                if (other.IsAny)
                {
                    // If both Any use quality
                    int c = -1 * Quality.CompareTo(other.Quality);
                    if (c == 0)
                    {
                        // If same quality use order
                        c = Order.CompareTo(other.Order);
                    }
                    return(c);
                }
                else
                {
                    // Any is less than range/specific type
                    return(1);
                }
            }
            else if (_isRange)
            {
                if (other.IsAny)
                {
                    // Range types are greater than Any
                    return(-1);
                }
                else if (other.IsRange)
                {
                    // If both Range use quality
                    int c = -1 * Quality.CompareTo(other.Quality);
                    if (c == 0)
                    {
                        // If same quality use order
                        c = Order.CompareTo(other.Order);
                    }
                    return(c);
                }
                else
                {
                    // Range is less that specific type
                    return(1);
                }
            }
            else
            {
                if (other.IsAny || other.IsRange)
                {
                    // Specific types are greater than Any/Range
                    return(-1);
                }
                else
                {
                    // Both specific so use quality
                    int c = -1 * Quality.CompareTo(other.Quality);
                    if (c == 0)
                    {
                        // If same quality use order
                        c = Order.CompareTo(other.Order);
                    }
                    return(c);
                }
            }
        }