public void Clear() { items.Clear(); Index = 0; OnQueueChange?.Invoke(this, null); OnQueueIndexChange?.Invoke(this, null); }
public bool TryPrevious() { if (0 == Index) { return(false); } --Index; OnQueueChange?.Invoke(this, null); OnQueueIndexChange?.Invoke(this, null); return(true); }
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); }
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); }
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); }
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); }