예제 #1
0
        public int Compare(MultiKeyUntyped firstValues, MultiKeyUntyped secondValues)
        {
            if (firstValues.Count != _isDescendingValues.Length || secondValues.Count != _isDescendingValues.Length)
            {
                throw new ArgumentException("Incompatible size MultiKey sizes for comparison");
            }

            for (int i = 0; i < firstValues.Count; i++)
            {
                var valueOne     = firstValues.Get(i);
                var valueTwo     = secondValues.Get(i);
                var isDescending = _isDescendingValues[i];

                if (!_stringTypedValue[i])
                {
                    int comparisonResult = MultiKeyComparator.CompareValues(valueOne, valueTwo, isDescending);
                    if (comparisonResult != 0)
                    {
                        return(comparisonResult);
                    }
                }
                else
                {
                    int comparisonResult = MultiKeyComparator.CompareValues(valueOne, valueTwo, isDescending, _stringComparison);
                    if (comparisonResult != 0)
                    {
                        return(comparisonResult);
                    }
                }
            }

            // Make the comparator compatible with equals
            return(!Equals(firstValues, secondValues) ? -1 : 0);
        }
예제 #2
0
        public static IComparer <object> GetComparator(
            ExprEvaluator[] sortCriteriaEvaluators,
            bool isSortUsingCollator,
            bool[] isDescendingValues)
        {
            // determine string-type sorting
            var hasStringTypes = false;
            var stringTypes    = new bool[sortCriteriaEvaluators.Length];

            int count = 0;

            foreach (ExprEvaluator node in sortCriteriaEvaluators)
            {
                if (node.ReturnType == typeof(string))
                {
                    hasStringTypes     = true;
                    stringTypes[count] = true;
                }
                count++;
            }

            if (sortCriteriaEvaluators.Length > 1)
            {
                if ((!hasStringTypes) || (!isSortUsingCollator))
                {
                    var comparatorMK = new MultiKeyComparator(isDescendingValues);
                    return(new MultiKeyCastingComparator(comparatorMK));
                }
                else
                {
                    var comparatorMk = new MultiKeyCollatingComparator(isDescendingValues, stringTypes);
                    return(new MultiKeyCastingComparator(comparatorMk));
                }
            }
            else
            {
                if ((!hasStringTypes) || (!isSortUsingCollator))
                {
                    return(new ObjectComparator(isDescendingValues[0]));
                }
                else
                {
                    return(new ObjectCollatingComparator(isDescendingValues[0]));
                }
            }
        }
예제 #3
0
 public int Compare(Object firstValue, Object secondValue)
 {
     return(MultiKeyComparator.CompareValues(firstValue, secondValue, _isDescendingValue));
 }