public bool IsValid(T toCheck)
        {
            if (MinimumSet)
            {
                var comparison = Minimum.CompareTo(toCheck);

                if (comparison < 0)
                {
                    return(true);
                }
                if (IncludeMinimumEqual && comparison == 0)
                {
                    return(true);
                }
            }

            if (MaximumSet)
            {
                var comparison = Maximum.CompareTo(toCheck);

                if (comparison > 0)
                {
                    return(false);
                }
                if (IncludeMaximumEqual && comparison == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public int CompareTo(Range <T> range)
        {
            if (Value.CompareTo(range.Value) != 0)
            {
                return(Value.CompareTo(range.Value));
            }

            if (Minimum.CompareTo(range.Minimum) != 0)
            {
                return(Minimum.CompareTo(range.Minimum));
            }

            if (Maximum.CompareTo(range.Maximum) != 0)
            {
                return(Maximum.CompareTo(range.Maximum));
            }

            if (MinimumBoundary != range.MinimumBoundary)
            {
                return(MinimumBoundary.CompareTo(range.Minimum));
            }

            if (MaximumBoundary != range.MaximumBoundary)
            {
                return(MaximumBoundary.CompareTo(range.MaximumBoundary));
            }

            return(0);
        }
Exemplo n.º 3
0
        protected override bool ConditionApplies(ModelInstance root)
        {
            object value = root[Property];

            if (value == null || (value is double && double.IsNaN((double)value)))
            {
                return(false);
            }

            // min <= value <= max
            // CompareTo = 0: equal, >0: instance > value
            if (Minimum != null && Maximum != null)
            {
                return(Minimum.CompareTo(value) > 0 && Maximum.CompareTo(value) < 0);
            }
            else if (Minimum != null)
            {
                return(Minimum.CompareTo(value) > 0);
            }
            else if (Maximum != null)
            {
                return(Maximum.CompareTo(value) < 0);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
 public bool Equals(Range <T> range)
 {
     return((Value.CompareTo(range.Value) == 0) &&
            (Minimum.CompareTo(range.Minimum) == 0) &&
            (Maximum.CompareTo(range.Maximum) == 0) &&
            (MinimumBoundary == range.MinimumBoundary) &&
            (MaximumBoundary == range.MaximumBoundary));
 }
Exemplo n.º 5
0
        public bool IsOverlapping(IRange <T> other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Maximum.CompareTo(other.Minimum) >= 0 && Minimum.CompareTo(other.Maximum) <= 0);
        }
Exemplo n.º 6
0
 public int CompareTo(T item)
 {
     if (Minimum.CompareTo(item) > 0)
     {
         return(-1);
     }
     if (Maximum.CompareTo(item) < 0)
     {
         return(1);
     }
     return(0);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Updates the maximum value in the range if the proposed value is greater than the current maximum value.
 /// </summary>
 /// <param name="proposedMax">New candidate value for the maximum.</param>
 public void UpdateMaximum(T proposedMax)
 {
     if (_maxValid)
     {
         if (Maximum.CompareTo(proposedMax) < 0)
         {
             Maximum = proposedMax;
         }
     }
     else
     {
         Maximum = proposedMax;
     }
 }
Exemplo n.º 8
0
        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            base.OnPreviewTextInput(e);

            if (e.Handled)
            {
                return;
            }

            if (e.Text == "-")
            {
                e.Handled = true;
                int newCaretIndex;

                if (Text.StartsWith("-") && (this.IsInitial(MaximumProperty) || Maximum.CompareTo(default(T)) >= 0))
                {
                    newCaretIndex = Math.Max(0, CaretIndex - 1);
                    Text          = Text.Substring(1);
                }
                else if ((this.IsInitial(MinimumProperty) || Minimum.CompareTo(default(T)) < 0))
                {
                    newCaretIndex = CaretIndex + 1;
                    Text          = Text.Insert(0, "-");
                }
                else
                {
                    ShowNotification();
                    return;
                }

                CaretIndex = newCaretIndex;
            }
            else if (e.Text == DECIMAL_SEPARATOR)
            {
                if (Text.Contains(DECIMAL_SEPARATOR))
                {
                    e.Handled = true;
                    ShowNotification();
                }
                else if (Text == string.Empty)
                {
                    e.Handled  = true;
                    Text       = "0" + DECIMAL_SEPARATOR;
                    CaretIndex = Text.Length;
                }
            }
        }
Exemplo n.º 9
0
        protected override bool ConditionApplies(ModelInstance root)
        {
            int value = root.GetList((ModelReferenceProperty)Property).Count;

            if (Minimum > 0 && Maximum > 0)
            {
                return(Minimum.CompareTo(value) > 0 && Maximum.CompareTo(value) < 0);
            }
            else if (Minimum > 0)
            {
                return(Minimum.CompareTo(value) > 0);
            }
            else if (Maximum > 0)
            {
                return(Maximum.CompareTo(value) < 0);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Checks to see if this range overlaps another range (inclusive)
 /// </summary>
 /// <param name="other">The other range to compare to</param>
 /// <returns>True if the other range in any way overlaps this range, false otherwise</returns>
 public bool IsOverlapping(DoubleRange other)
 {
     return(Maximum.CompareTo(other.Minimum) >= 0 && Minimum.CompareTo(other.Maximum) <= 0);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Checks to see if this range is a proper sub range of another range (inclusive)
 /// </summary>
 /// <param name="other">The other range to compare to</param>
 /// <returns>True if this range is fully enclosed by the other range, false otherwise</returns>
 public bool IsSubRange(DoubleRange other)
 {
     return(Maximum.CompareTo(other.Maximum) <= 0 && Minimum.CompareTo(other.Minimum) >= 0);
 }