Example #1
0
 public void Clear()
 {
     items.Clear();
     Index = 0;
     OnQueueChange?.Invoke(this, null);
     OnQueueIndexChange?.Invoke(this, null);
 }
Example #2
0
 public bool TryPrevious()
 {
     if (0 == Index)
     {
         return(false);
     }
     --Index;
     OnQueueChange?.Invoke(this, null);
     OnQueueIndexChange?.Invoke(this, null);
     return(true);
 }
Example #3
0
        public bool TryNext()
        {
            if (Index == items.Count)
            {
                return(false);
            }

            if (++Index != items.Count)
            {
                OnQueueChange?.Invoke(this, null);
                OnQueueIndexChange?.Invoke(this, null);
                return(true);
            }
            return(false);
        }
Example #4
0
        public bool Skip(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException("count too small");
            }

            int targetIndex = Index + count;

            if (!Tools.IsBetween(targetIndex, 0, items.Count))
            {
                throw new ArgumentException("count too large");
            }

            Index = targetIndex;
            OnQueueChange?.Invoke(this, null);
            OnQueueIndexChange?.Invoke(this, null);
            return(Index != items.Count);
        }
Example #5
0
        public void Remove(int at)
        {
            if (!Tools.IsBetweenExcludingUpper(at, 0, items.Count))
            {
                throw new ArgumentException();
            }
            if (Index == at)
            {
                throw new InvalidOperationException("Can't remove the current item");
            }

            items.RemoveAt(at);
            if (at < Index)
            {
                --Index;
                OnQueueIndexChange?.Invoke(this, null);
            }

            OnQueueChange?.Invoke(this, null);
        }
Example #6
0
        public void RemoveRange(int from, int to)
        {
            if (!Tools.IsBetweenExcludingUpper(from, 0, items.Count) ||
                !Tools.IsBetweenExcludingUpper(to, 0, items.Count) || to < from)
            {
                throw new ArgumentException();
            }
            if (Tools.IsBetween(Index, from, to))
            {
                throw new InvalidOperationException("Can't remove the current item");
            }

            int count = to - from + 1;

            items.RemoveRange(from, count);
            if (to < Index)
            {
                Index -= count;
                OnQueueIndexChange?.Invoke(this, null);
            }

            OnQueueChange?.Invoke(this, null);
        }