]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - jcr/org.argeo.cms.jcr/src/org/argeo/jcr/CollectionNodeIterator.java
3 import java
.util
.Collection
;
4 import java
.util
.Iterator
;
5 import java
.util
.NoSuchElementException
;
8 import javax
.jcr
.NodeIterator
;
10 /** Wraps a collection of nodes in order to read it as a {@link NodeIterator} */
11 public class CollectionNodeIterator
implements NodeIterator
{
12 private final Long collectionSize
;
13 private final Iterator
<Node
> iterator
;
14 private Integer position
= 0;
16 public CollectionNodeIterator(Collection
<Node
> nodes
) {
18 this.collectionSize
= (long) nodes
.size();
19 this.iterator
= nodes
.iterator();
22 public void skip(long skipNum
) {
24 throw new IllegalArgumentException(
25 "Skip count has to be positive: " + skipNum
);
27 for (long i
= 0; i
< skipNum
; i
++) {
29 throw new NoSuchElementException("Last element past (position="
30 + getPosition() + ")");
35 public long getSize() {
36 return collectionSize
;
39 public long getPosition() {
43 public boolean hasNext() {
44 return iterator
.hasNext();
47 public Object
next() {
51 public void remove() {
55 public Node
nextNode() {
56 Node node
= iterator
.next();