]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.jcr/src/org/argeo/jcr/CollectionNodeIterator.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.jcr
;
18 import java
.util
.Collection
;
19 import java
.util
.Iterator
;
20 import java
.util
.NoSuchElementException
;
22 import javax
.jcr
.Node
;
23 import javax
.jcr
.NodeIterator
;
25 /** Wraps a collection of nodes in order to read it as a {@link NodeIterator} */
26 public class CollectionNodeIterator
implements NodeIterator
{
27 private final Long collectionSize
;
28 private final Iterator
<Node
> iterator
;
29 private Integer position
= 0;
31 public CollectionNodeIterator(Collection
<Node
> nodes
) {
33 this.collectionSize
= (long) nodes
.size();
34 this.iterator
= nodes
.iterator();
37 public void skip(long skipNum
) {
39 throw new IllegalArgumentException(
40 "Skip count has to be positive: " + skipNum
);
42 for (long i
= 0; i
< skipNum
; i
++) {
44 throw new NoSuchElementException("Last element past (position="
45 + getPosition() + ")");
50 public long getSize() {
51 return collectionSize
;
54 public long getPosition() {
58 public boolean hasNext() {
59 return iterator
.hasNext();
62 public Object
next() {
66 public void remove() {
70 public Node
nextNode() {
71 Node node
= iterator
.next();