PagingIterator.java
1.07 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.cq.projects.impl.util;
import java.util.Iterator;
public class PagingIterator<E>
implements Iterator<E> {
private Iterator<E> it;
private Integer offset;
private Integer limit;
private int limitCounter = 0;
public PagingIterator(Iterator<E> it, Integer offset, Integer limit) {
this.it = it;
this.offset = offset;
this.limit = limit;
this.doOffset();
}
private void doOffset() {
if (this.offset == null) {
return;
}
for (int i = 0; i < this.offset && this.it.hasNext(); ++i) {
this.it.next();
}
}
@Override
public boolean hasNext() {
if (this.limit == null || this.limit < 0) {
return this.it.hasNext();
}
return this.limitCounter < this.limit && this.it.hasNext();
}
@Override
public E next() {
E next = this.it.next();
++this.limitCounter;
return next;
}
@Override
public void remove() {
this.it.remove();
}
}