ResourceIterator.java
1.17 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
*/
package com.day.cq.wcm.commons;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.sling.api.resource.Resource;
public class ResourceIterator<T>
implements Iterator<T> {
private T next;
private final Iterator<Resource> base;
private final Class<T> adapterType;
public ResourceIterator(Iterator<Resource> base, Class<T> adapterType) {
this.base = base;
this.adapterType = adapterType;
this.seek();
}
private T seek() {
T prev = this.next;
this.next = null;
while (this.base.hasNext() && this.next == null) {
this.next = this.base.next().adaptTo(this.adapterType);
}
return prev;
}
@Override
public boolean hasNext() {
return this.next != null;
}
@Override
public T next() {
if (this.next == null) {
throw new NoSuchElementException();
}
return this.seek();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}