Ejemplo n.º 1
0
        public bool Equals(UidInterval p)
        {
            // If parameter is null return false:
            if ((object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return((From == p.From) && (To == p.To));
        }
Ejemplo n.º 2
0
        public void AddUnhandledInterval(UidInterval newInterval)
        {
            var newIntervals = new List <UidInterval>();

            var intersectionMinFrom      = newInterval.From;
            var intersectionMaxTo        = newInterval.To;
            var intersectionWasAddedFlag = false;

            foreach (var interval in _unhandledIntervals)
            {
                if (interval.From > newInterval.To)
                {
                    newIntervals.Add(interval);
                }
                else if (interval.To < newInterval.From)
                {
                    if (!intersectionWasAddedFlag)
                    {
                        intersectionWasAddedFlag = true;
                        newIntervals.Add(new UidInterval(intersectionMinFrom, intersectionMaxTo));
                    }
                    newIntervals.Add(interval);
                }
                else
                {
                    intersectionMinFrom = Math.Min(intersectionMinFrom, interval.From);
                    intersectionMaxTo   = Math.Max(intersectionMaxTo, interval.To);
                }
            }

            if (!intersectionWasAddedFlag)
            {
                newIntervals.Add(new UidInterval(intersectionMinFrom, intersectionMaxTo));
            }

            _unhandledIntervals = newIntervals;
        }
Ejemplo n.º 3
0
        public void AddHandledInterval(UidInterval newInterval)
        {
            var newIntervals = new List <UidInterval>();

            foreach (var interval in _unhandledIntervals)
            {
                if (interval.To < newInterval.From || interval.From > newInterval.To)
                {
                    newIntervals.Add(interval);
                }
                else
                {
                    if (interval.To > newInterval.To)
                    {
                        newIntervals.Add(new UidInterval(newInterval.To + 1, interval.To));
                    }
                    if (interval.From < newInterval.From)
                    {
                        newIntervals.Add(new UidInterval(interval.From, newInterval.From - 1));
                    }
                }
            }
            _unhandledIntervals = newIntervals;
        }