forked from mattsemar/dsp-bulldozer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPager.cs
More file actions
54 lines (42 loc) · 1.16 KB
/
Pager.cs
File metadata and controls
54 lines (42 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
namespace Bulldozer
{
public class Pager<T>
{
public List<T> _items;
public int PageNum;
public int PageSize = 25;
public Pager(List<T> items, int pageSize = 10)
{
PageSize = pageSize;
_items = new List<T>(items);
}
public int Count => _items.Count;
public void Reset()
{
PageNum = 0;
}
public void Next()
{
PageNum++;
}
public bool IsFirst() => PageNum == 0;
public (int startIndex, int endIndex) GetIndexes()
{
var beginNdx = PageNum * PageSize;
return (PageNum * PageSize, Math.Min(beginNdx + PageSize, _items.Count));
}
public List<T> GetPage()
{
var (startIndex, endIndex) = GetIndexes();
return _items.GetRange(startIndex, endIndex - startIndex);
}
public bool HasNext() => _items.Count > GetIndexes().endIndex;
public bool IsEmpty() => _items.Count == 0;
public void Previous()
{
PageNum--;
}
}
}