using System; using System.Collections.Generic; namespace TomatenMusic.Util { class PageManager { private List Items; private int PageSize; public PageManager(List allItems, int pageSize) { this.Items = allItems; this.PageSize = pageSize; } public List GetPage(int page) { if (page <= GetTotalPages() && page > 0) { List onPage = new List(); page--; int lowerBound = page * PageSize; int upperBound = Math.Min(lowerBound + PageSize, Items.Count); for (int i = lowerBound; i < upperBound; i++) { onPage.Add(Items[i]); } return onPage; } else return new List(); } public void AddItem(T Item) { if (Items.Contains(Item)) { return; } Items.Add(Item); } public void RemoveItem(T Item) { if (Items.Contains(Item)) Items.Remove(Item); } public int GetTotalPages() { int totalPages = (int)Math.Ceiling((double)Items.Count / PageSize); return totalPages; } public List GetContents() { return Items; } } }