Beispiel #1
0
        public static bool Intersect(ComparatorSet <T> left, List <ComparatorSet <T> > right)
        {
            bool result = false;

            right.ForEach(r => result |= Intersect(left, r));
            return(result);
        }
Beispiel #2
0
        public static bool Intersect(ComparatorSet <T> cs1, ComparatorSet <T> cs2)
        {
            if (!ComparatorSetIsValidRange(cs1))
            {
                throw new ArgumentException("Invalid comparator set for range.", "cs1");
            }
            if (!ComparatorSetIsValidRange(cs2))
            {
                throw new ArgumentException("Invalid comparator set for range.", "cs2");
            }
            if (cs1.Count == 1 && cs2.Count == 1)
            {
                return(Intersect(cs1[0], cs2[0]));
            }
            else if (cs1.Count == 1 && cs2.Count == 2)
            {
                return(Satisfies(cs1[0].Version, cs2));
            }
            else if (cs1.Count == 2 && cs2.Count == 1)
            {
                return(Satisfies(cs2[0].Version, cs1));
            }

            else if (cs2.Count == 2 && cs2.Count == 2)
            {
                return(cs1.ToInterval().Intersect(cs2.ToInterval()));
            }
            else
            {
                throw new ArgumentOutOfRangeException("Can't convert comparator sets to range.");
            }
        }
Beispiel #3
0
 public static bool ComparatorSetIsValidRange(ComparatorSet <T> cs)
 {
     if ((cs.Count == 1) && cs[0].Operator == ExpressionType.Equal)
     {
         return(true);
     }
     else if (cs.Count == 2)
     {
         foreach (Comparator <T> c in cs)
         {
             if (!ValidRangeOperators.Contains(c.Operator))
             {
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #4
0
 public static BinaryExpression GetBinaryExpression(T left, ComparatorSet <T> right)
 {
     if (right.Count == 0)
     {
         return(GetBinaryExpression(ExpressionType.Equal, left, left));
     }
     else
     {
         BinaryExpression c = null;
         foreach (Comparator <T> r in right)
         {
             if (c == null)
             {
                 c = GetBinaryExpression(r.Operator, left, r.Version);
             }
             else
             {
                 c = Expression.AndAlso(c, GetBinaryExpression(r.Operator, left, r.Version));
             }
         }
         return(c);
     }
 }
Beispiel #5
0
 public static bool Satisfies(T v, ComparatorSet <T> s)
 {
     return(InvokeBinaryExpression(GetBinaryExpression(v, s)));
 }