Example #1
0
        public int CompareTo(object obj)
        {
            if (obj.GetType() != typeof(Transition))
            {
                return(-1);
            }

            Transition other = obj as Transition;

            int c1 = From.CompareTo(other.From);
            int c2 = To.CompareTo(other.To);

            if (c1 == c2 && c2 == 0)
            {
                return(0);
            }

            if (c1 < 0 || c1 > 0)
            {
                return(c1);
            }

            if (c2 < 0 || c2 > 0)
            {
                return(c2);
            }

            return(0);
        }
Example #2
0
 public bool Contains(T value)
 {
     if (From.CompareTo(To) <= 0)
     {
         return(From.CompareTo(value) <= 0 && value.CompareTo(To) <= 0);
     }
     return(To.CompareTo(value) <= 0 && value.CompareTo(From) <= 0);
 }
Example #3
0
        public int CompareTo(TimeSlot other)
        {
            if (From == other.From)
            {
                return(To.CompareTo(other.To));
            }

            return(From.CompareTo(other.From));
        }
Example #4
0
        public int CompareTo(CharRange other)
        {
            int c = From.CompareTo(other.From);

            if (c == 0)
            {
                return(To.CompareTo(other.To));
            }
            return(c);
        }
Example #5
0
        /// <summary>
        /// Compares the value of this instance to a specified FuzzyDateRange value and returns an integer
        /// that indicates whether this instance is earlier than, the same as, or later than the
        /// specified FuzzyDateRange value.
        /// </summary>
        /// <param name="value">The object to compare to the current instance.</param>
        /// <returns>A signed number indicating the relative values of this instance and the value parameter.</returns>
        public int CompareTo(FuzzyDateRange value)
        {
            var fromCompare = From.CompareTo(value.From);

            if (fromCompare != 0)
            {
                return(fromCompare);
            }

            return(To.CompareTo(value.To));
        }
 private void Validate()
 {
     if (From == null || To == null)
     {
         throw new Exceptions.ValidationException("Start date and/or End date is null!");
     }
     if (From.CompareTo(To) > 0)
     {
         throw new Exceptions.ValidationException("Start date should be before End date!");
     }
 }
Example #7
0
 /// <summary>
 /// Return if are between from an To
 /// </summary>
 /// <param name="o">Object</param>
 public bool ItsValid(T o)
 {
     if (From.CompareTo(o) <= 0 && To.CompareTo(o) >= 0)
     {
         if (Excludes.Contains(o))
         {
             return(false);
         }
         return(true);
     }
     return(false);
 }
Example #8
0
            public int CompareTo(object obj)
            {
                if (!(obj is TransitCondition))
                {
                    return(-1);
                }
                var o       = (TransitCondition)obj;
                var isEqual = From.CompareTo(o.From) == 0 &&
                              From.CompareTo(o.From) == 0 &&
                              From.CompareTo(o.From) == 0;

                return(isEqual ? 0 : 1);
            }
Example #9
0
        /// <summary>
        /// String representation
        /// </summary>
        public override string ToString()
        {
            string ex = "";

            if (Excludes != null)
            {
                ex = string.Join(",", Excludes);
            }

            return
                ((From.CompareTo(To) == 0 ? From.ToString() : From.ToString() + " - " + To.ToString())
                 + (ex == "" ? "" : "![" + ex + "]"));
        }
Example #10
0
        public int CompareTo(T other)
        {
            if (To.CompareTo(other) < 0)
            {
                return(-1);
            }

            if (From.CompareTo(other) > 0)
            {
                return(1);
            }

            return(0);
        }
Example #11
0
        private bool IsInLeftBoundary(TValue value)
        {
            switch (LeftBoundaryType)
            {
            case IntervalBoundaryType.Open:
                return(From.CompareTo(value) < 0);

            case IntervalBoundaryType.Closed:
                return(From.CompareTo(value) <= 0);

            default:
                throw new NotImplementedException($"Handling {LeftBoundaryType.GetType().FullName}.{LeftBoundaryType} is not implemented.");
            }
        }
Example #12
0
 /// <summary>
 /// Returns -1 if this range's From is less than the other, 1 if greater.
 /// If both are equal, To is compared, 1 if greater, -1 if less.
 /// 0 if both ranges are equal.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns></returns>
 public int CompareTo(Range <T> other)
 {
     if (From.CompareTo(other.From) < 0)
     {
         return(-1);
     }
     if (From.CompareTo(other.From) > 0)
     {
         return(1);
     }
     if (To.CompareTo(other.To) < 0)
     {
         return(-1);
     }
     return(To.CompareTo(other.To) > 0 ? 1 : 0);
 }
Example #13
0
    public int CompareTo(SpriteLease other)
    {
        if (ReferenceEquals(this, other))
        {
            return(0);
        }
        if (other is null)
        {
            return(1);
        }
        var fromComparison = From.CompareTo(other.From);

        if (fromComparison != 0)
        {
            return(fromComparison);
        }
        return(To.CompareTo(other.To));
    }
Example #14
0
        public int CompareTo(Edge <T> other)
        {
            int result = 0;

            //Don't compare weights unless both edges have a weight
            if (other.weight != double.PositiveInfinity && this.weight != double.PositiveInfinity)
            {
                result = Weight.CompareTo(other.Weight);
            }

            //What if the edges have the same weight
            if (result == 0)
            {
                result = From.CompareTo(other.From);
                if (result == 0)
                {
                    result = To.CompareTo(other.To);
                }
            }
            return(result);
        }
Example #15
0
        // Needed for IMemoryCache equality check
        public bool Equals([AllowNull] VyQuery other)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            var toEqual = To.CompareTo(other.To);

            if (toEqual != 0)
            {
                return(false);
            }

            var fromEqual = From.CompareTo(other.From);

            if (fromEqual != 0)
            {
                return(false);
            }

            // Don't compare time of day.
            var queryTime    = DateTime.Parse(Time);
            var queryTimeDay = new DateTime(queryTime.Year, queryTime.Month, queryTime.Day);

            var compareToTime    = DateTime.Parse(other.Time);
            var compareToTimeDay = new DateTime(compareToTime.Year, compareToTime.Month, compareToTime.Day);

            var timeEqual = queryTimeDay.CompareTo(compareToTimeDay);

            if (timeEqual != 0)
            {
                return(false);
            }
            return(true);
        }
Example #16
0
        public override string ToString()
        {
            int comparison = From.CompareTo(To);

            if (comparison == 0)
            {
                //From == To
                return(From.ToString());
            }
            else if (comparison < 0)
            {
                //From < To
                StringBuilder sb = new StringBuilder();
                if (IsFromInclusive)
                {
                    sb.Append('[');
                }
                else
                {
                    sb.Append('(');
                }

                sb.Append(From.ToString()).Append(", ").Append(To.ToString());
                if (IsToInclusive)
                {
                    sb.Append(']');
                }
                else
                {
                    sb.Append(')');
                }
                return(sb.ToString());
            }
            else
            {
                return($"Invalid Range: {From} is greater than {To}");
            }
        }
Example #17
0
        /// <summary>
        /// Gets the length of this range. For a date range, use the TimeOfDay property of the returned date time.
        /// </summary>
        public T GetLength()
        {
            if (From.CompareTo(To) > 0)
            {
                throw new InvalidOperationException("'from' should be smaller than or equal to 'To' value in a range.");
            }

            var    fromValue = (object)From;
            var    toValue   = (object)To;
            object result;

            if (typeof(T) == typeof(int))
            {
                result = (int)toValue - (int)fromValue;
            }
            else if (typeof(T) == typeof(double))
            {
                result = (double)toValue - (double)fromValue;
            }
            else if (typeof(T) == typeof(long))
            {
                result = (long)toValue - (long)fromValue;
            }
            else if (typeof(T) == typeof(decimal))
            {
                result = (decimal)toValue - (decimal)fromValue;
            }
            else if (typeof(T) == typeof(DateTime))
            {
                result = new DateTime(1900, 1, 1).Add((DateTime)toValue - (DateTime)fromValue);
            }
            else
            {
                throw new NotSupportedException("GetLength() is not supported on type: " + typeof(T).FullName);
            }

            return((T)result);
        }
Example #18
0
 /// <summary>
 /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
 /// </summary>
 /// <param name="other">An object to compare with this instance.</param>
 /// <returns>
 /// Returns -1 if this range's From is less than the other, 1 if greater. If both are equal, To is compared, 1 if greater, -1 if less. 0 if both ranges are equal.
 /// </returns>
 public int CompareTo(Range <T> other)
 {
     if (From.CompareTo(other.From) < 0)
     {
         return(-1);
     }
     else if (From.CompareTo(other.From) > 0)
     {
         return(1);
     }
     else if (To.CompareTo(other.To) < 0)
     {
         return(-1);
     }
     else if (To.CompareTo(other.To) > 0)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
Example #19
0
        public int CompareTo(RentalBO other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            var idComparison = Id.CompareTo(other.Id);

            if (idComparison != 0)
            {
                return(idComparison);
            }
            var fromComparison = From.CompareTo(other.From);

            if (fromComparison != 0)
            {
                return(fromComparison);
            }
            return(To.CompareTo(other.To));
        }
Example #20
0
        public int CompareTo(Interval <T> other)
        {
            if (From.CompareTo(other.From) < 0)
            {
                return(-1);
            }

            if (From.CompareTo(other.From) > 0)
            {
                return(1);
            }

            if (To.CompareTo(other.To) < 0)
            {
                return(1);
            }

            if (To.CompareTo(other.To) > 0)
            {
                return(-1);
            }

            return(0);
        }
Example #21
0
 public bool HasIntersectionWith(Range <T> second)
 {
     return(From.CompareTo(second.From) <= 0 && To.CompareTo(second.To) >= 0 ||
            From.CompareTo(second.From) <= 0 && To.CompareTo(second.From) > 0 ||
            From.CompareTo(second.To) < 0 && To.CompareTo(second.To) >= 0);
 }
Example #22
0
 public int CompareTo(RangeBase <TRangeType> other)
 {
     return(From.CompareTo(other?.From));
 }
Example #23
0
 public bool Contains(T t)
 {
     return(From.CompareTo(t) <= 0 && To.CompareTo(t) > 0);
 }
Example #24
0
 public bool Contains(T point)
 {
     return(From.CompareTo(point) <= 0 &&
            To.CompareTo(point) >= 0);
 }
Example #25
0
        /// <summary>
        /// Sammenlikner to TimePeriode objekter for sortering
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public int CompareTo(TimePeriod other)
        {
            var result = From.CompareTo(other.From);

            return(result != 0 ? result : To.CompareTo(other.To));
        }
Example #26
0
 public bool Content(T obj)
 {
     return(From.CompareTo(obj) <= 0 && To.CompareTo(obj) >= 0);
 }
Example #27
0
 public bool Contains(Interval <T> other)
 {
     return(From.CompareTo(other.From) <= 0 &&
            To.CompareTo(other.To) >= 0);
 }
Example #28
0
 public bool Overlaps(IRange <T> other)
 {
     return(From.CompareTo(other.To) == -1 && To.CompareTo(other.From) == 1);
 }
Example #29
0
 public V Other(V either)
 {
     return(From.CompareTo(either) == 0 ? To : From);
 }
Example #30
0
 public bool Overlaps(Interval <T> other)
 {
     return(From.CompareTo(other.To) <= 0 &&
            To.CompareTo(other.From) >= 0);
 }