Beispiel #1
0
        private static Value GreaterThan(Comparison comparison)
        {
            switch (comparison.innerEnumValue)
            {
            case Comparison.InnerEnum.GREATER_THAN:
                return(TRUE);

            case Comparison.InnerEnum.GREATER_THAN_AND_EQUAL:
            case Comparison.InnerEnum.EQUAL:
            case Comparison.InnerEnum.SMALLER_THAN_AND_EQUAL:
            case Comparison.InnerEnum.SMALLER_THAN:
                return(FALSE);

            case Comparison.InnerEnum.UNDEFINED:
                return(NO_VALUE);

            default:
                throw new InternalException(comparison + " is not a known comparison", null);
            }
        }
Beispiel #2
0
        private Comparison Cmp(AnyValue v1, AnyValue v2, bool ternary)
        {
            Debug.Assert(v1 != null && v2 != null, "null values are not supported, use NoValue.NO_VALUE instead");

            // NO_VALUE is bigger than all other values, need to check for that up
            // front
            if (v1 == v2)
            {
                return(Comparison.Equal);
            }
            if (v1 == Values.NO_VALUE)
            {
                return(Comparison.GreaterThan);
            }
            if (v2 == Values.NO_VALUE)
            {
                return(Comparison.SmallerThan);
            }

            // We must handle sequences as a special case, as they can be both storable and virtual
            bool isSequence1 = v1.SequenceValue;
            bool isSequence2 = v2.SequenceValue;

            if (isSequence1 && isSequence2)
            {
                return(Comparison.from(CompareSequences(( SequenceValue )v1, ( SequenceValue )v2)));
            }
            else if (isSequence1)
            {
                return(Comparison.from(CompareSequenceAndNonSequence(( SequenceValue )v1, v2)));
            }
            else if (isSequence2)
            {
                return(Comparison.from(-CompareSequenceAndNonSequence(( SequenceValue )v2, v1)));
            }

            // Handle remaining AnyValues
            bool isValue1 = v1 is Value;
            bool isValue2 = v2 is Value;

            int x = Boolean.compare(isValue1, isValue2);

            if (x == 0)
            {
                //noinspection ConstantConditions
                // Do not turn this into ?-operator
                if (isValue1)
                {
                    if (ternary)
                    {
                        return(_valueComparator.ternaryCompare(( Value )v1, ( Value )v2));
                    }
                    else
                    {
                        return(Comparison.from(_valueComparator.Compare(( Value )v1, ( Value )v2)));
                    }
                }
                else
                {
                    // This returns int
                    return(Comparison.from(CompareVirtualValues(( VirtualValue )v1, ( VirtualValue )v2)));
                }
            }
            return(Comparison.from(x));
        }