jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r522141 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/
Date Sun, 25 Mar 2007 02:00:16 GMT
Author: jukka
Date: Sat Mar 24 19:00:14 2007
New Revision: 522141

URL: http://svn.apache.org/viewvc?view=rev&rev=522141
Log:
JCR-742: Added a set of generic JCR iterator classes at org.apache.jackrabbit.commons.iterator

Added:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventListenerIteratorAdapter.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeIteratorAdapter.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/PropertyIteratorAdapter.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorAdapter.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorDecorator.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RowIteratorAdapter.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/VersionIteratorAdapter.java
  (with props)

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.RangeIterator;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+
+/**
+ * Adapter class for turning {@link RangeIterator}s or {@link Iterator}s
+ * into {@link EventIterator}s. 
+ */
+public class EventIteratorAdapter extends RangeIteratorDecorator
+		implements EventIterator {
+
+	/**
+	 * Creates an adapter for the given {@link RangeIterator}.
+	 *
+	 * @param iterator iterator of {@link Event}s
+	 */
+	public EventIteratorAdapter(RangeIterator iterator) {
+		super(iterator);
+	}
+
+	/**
+	 * Creates an adapter for the given {@link Iterator}.
+	 *
+	 * @param iterator iterator of {@link Event}s.
+	 */
+	public EventIteratorAdapter(Iterator iterator) {
+		super(new RangeIteratorAdapter(iterator));
+	}
+
+	/**
+	 * Creates an iterator for the given collection.
+	 *
+	 * @param collection collection of {@link Event}s
+	 */
+	public EventIteratorAdapter(Collection collection) {
+		super(new RangeIteratorAdapter(collection));
+	}
+
+	//-------------------------------------------------------< EventIterator >
+
+	/**
+	 * Returns the next event.
+	 *
+	 * @return next event
+	 * @throws NoSuchElementException if there is no next event
+	 */
+	public Event nextEvent() throws NoSuchElementException {
+		return (Event) next();
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventListenerIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventListenerIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventListenerIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventListenerIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.RangeIterator;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.EventListenerIterator;
+
+/**
+ * Adapter class for turning {@link RangeIterator}s or {@link Iterator}s
+ * into {@link EventListenerIterator}s. 
+ */
+public class EventListenerIteratorAdapter extends RangeIteratorDecorator
+		implements EventListenerIterator {
+
+	/**
+	 * Creates an adapter for the given {@link RangeIterator}.
+	 *
+	 * @param iterator iterator of {@link EventListener}s
+	 */
+	public EventListenerIteratorAdapter(RangeIterator iterator) {
+		super(iterator);
+	}
+
+	/**
+	 * Creates an adapter for the given {@link Iterator}.
+	 *
+	 * @param iterator iterator of {@link EventListener}s
+	 */
+	public EventListenerIteratorAdapter(Iterator iterator) {
+		super(new RangeIteratorAdapter(iterator));
+	}
+
+	/**
+	 * Creates an iterator for the given collection.
+	 *
+	 * @param collection collection of {@link EventListener}s
+	 */
+	public EventListenerIteratorAdapter(Collection collection) {
+		super(new RangeIteratorAdapter(collection));
+	}
+
+	//-----------------------------------------------< EventListenerIterator >
+
+	/**
+	 * Returns the next event listener.
+	 *
+	 * @return next event listener
+	 * @throws NoSuchElementException if there is no next event listener
+	 */
+	public EventListener nextEventListener() {
+		return (EventListener) next();
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventListenerIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RangeIterator;
+
+/**
+ * Adapter class for turning {@link RangeIterator}s or {@link Iterator}s
+ * into {@link NodeIterator}s. 
+ */
+public class NodeIteratorAdapter extends RangeIteratorDecorator
+		implements NodeIterator {
+
+	/**
+	 * Creates an adapter for the given {@link RangeIterator}.
+	 *
+	 * @param iterator iterator of {@link Node}s
+	 */
+	public NodeIteratorAdapter(RangeIterator iterator) {
+		super(iterator);
+	}
+
+	/**
+	 * Creates an adapter for the given {@link Iterator}.
+	 *
+	 * @param iterator iterator of {@link Node}s
+	 */
+	public NodeIteratorAdapter(Iterator iterator) {
+		super(new RangeIteratorAdapter(iterator));
+	}
+
+	/**
+	 * Creates an iterator for the given collection.
+	 *
+	 * @param collection collection of {@link Node}s
+	 */
+	public NodeIteratorAdapter(Collection collection) {
+		super(new RangeIteratorAdapter(collection));
+	}
+
+	//--------------------------------------------------------< NodeIterator >
+
+	/**
+	 * Returns the next node.
+	 *
+	 * @return next node
+	 * @throws NoSuchElementException if there is no next node
+	 */
+	public Node nextNode() throws NoSuchElementException {
+		return (Node) next();
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.RangeIterator;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
+
+/**
+ * Adapter class for turning {@link RangeIterator}s or {@link Iterator}s
+ * into {@link NodeTypeIterator}s. 
+ */
+public class NodeTypeIteratorAdapter extends RangeIteratorDecorator
+		implements NodeTypeIterator {
+
+	/**
+	 * Creates an adapter for the given {@link RangeIterator}.
+	 *
+	 * @param iterator iterator of {@link NodeType}s
+	 */
+	public NodeTypeIteratorAdapter(RangeIterator iterator) {
+		super(iterator);
+	}
+
+	/**
+	 * Creates an adapter for the given {@link Iterator}.
+	 *
+	 * @param iterator iterator of {@link NodeType}s
+	 */
+	public NodeTypeIteratorAdapter(Iterator iterator) {
+		super(new RangeIteratorAdapter(iterator));
+	}
+
+	/**
+	 * Creates an iterator for the given collection.
+	 *
+	 * @param collection collection of {@link NodeType}s
+	 */
+	public NodeTypeIteratorAdapter(Collection collection) {
+		super(new RangeIteratorAdapter(collection));
+	}
+
+	//----------------------------------------------------< NodeTypeIterator >
+
+	/**
+	 * Returns the next node type.
+	 *
+	 * @return next node type
+	 * @throws NoSuchElementException if there is no next node type
+	 */
+	public NodeType nextNodeType() throws NoSuchElementException {
+		return (NodeType) next();
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/PropertyIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/PropertyIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/PropertyIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/PropertyIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RangeIterator;
+
+/**
+ * Adapter class for turning {@link RangeIterator}s or {@link Iterator}s
+ * into {@link PropertyIterator}s. 
+ */
+public class PropertyIteratorAdapter extends RangeIteratorDecorator
+		implements PropertyIterator {
+
+	/**
+	 * Creates an adapter for the given {@link RangeIterator}.
+	 *
+	 * @param iterator iterator of {@link Property} instances
+	 */
+	public PropertyIteratorAdapter(RangeIterator iterator) {
+		super(iterator);
+	}
+
+	/**
+	 * Creates an adapter for the given {@link Iterator}.
+	 *
+	 * @param iterator iterator of {@link Property} instances
+	 */
+	public PropertyIteratorAdapter(Iterator iterator) {
+		super(new RangeIteratorAdapter(iterator));
+	}
+
+	/**
+	 * Creates an iterator for the given collection.
+	 *
+	 * @param collection collection of {@link Property} instances
+	 */
+	public PropertyIteratorAdapter(Collection collection) {
+		super(new RangeIteratorAdapter(collection));
+	}
+
+	//----------------------------------------------------< PropertyIterator >
+
+	/**
+	 * Returns the next property.
+	 *
+	 * @return next property
+	 * @throws NoSuchElementException if there is no next property
+	 */
+	public Property nextProperty() {
+		return (Property) next();
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/PropertyIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.RangeIterator;
+
+/**
+ * Adapter for turning normal {@link Iterator}s into {@link RangeIterator}s.
+ * This helper class is used by the adapter classes in this package to
+ * implement the JCR iterator interfaces on top of normal Java iterators.
+ */
+public class RangeIteratorAdapter implements RangeIterator {
+
+	/**
+	 * The adapted iterator instance.
+	 */
+	private final Iterator iterator;
+
+	/**
+	 * Number of elements in the adapted iterator, or -1 if unknown.
+	 */
+	private long size;
+
+	/**
+	 * Current position of the iterator.
+	 */
+	private long position;
+
+	/**
+	 * Creates an adapter for the given iterator of the given size.
+	 *
+	 * @param iterator adapted iterator
+	 * @param size size of the iterator, or -1 if unknown
+	 */
+	public RangeIteratorAdapter(Iterator iterator, long size) {
+		this.iterator = iterator;
+		this.size = size;
+		this.position = 0;
+	}
+
+	/**
+	 * Creates an adapter for the given iterator of unknown size.
+	 *
+	 * @param iterator adapted iterator
+	 */
+	public RangeIteratorAdapter(Iterator iterator) {
+		this(iterator, -1);
+	}
+
+	/**
+	 * Creates a {@link RangeIterator} for the given collection.
+	 *
+	 * @param collection the collection to iterate
+	 */
+	public RangeIteratorAdapter(Collection collection) {
+		this(collection.iterator(), collection.size());
+	}
+
+	//-------------------------------------------------------< RangeIterator >
+
+	/**
+	 * Returns the current position of the iterator.
+	 *
+	 * @return iterator position
+	 */
+	public long getPosition() {
+		return position;
+	}
+
+	/**
+	 * Returns the size of the iterator.
+	 *
+	 * @return iterator size, or -1 if unknown
+	 */
+	public long getSize() {
+		return size;
+	}
+
+	/**
+	 * Skips the given number of elements.
+	 *
+	 * @param n number of elements to skip
+	 * @throws IllegalArgumentException if n is negative
+	 * @throws NoSuchElementException if skipped past the last element
+	 */
+	public void skip(long n)
+			throws IllegalArgumentException, NoSuchElementException {
+		if (n < 0) {
+			throw new IllegalArgumentException("skip(" + n + ")");
+		}
+		for (long i = 0; i < n; i++) {
+			next();
+		}
+	}
+
+	//------------------------------------------------------------< Iterator >
+
+	/**
+	 * Checks if this iterator has more elements. If there are no more
+	 * elements and the size of the iterator is unknown, then the size is
+	 * set to the current position. 
+	 *
+	 * @return <code>true</code> if this iterator has more elements,
+	 *         <code>false</code> otherwise
+	 */
+	public boolean hasNext() {
+		if (iterator.hasNext()) {
+			return true;
+		} else {
+			if (size == -1) {
+				size = position;
+			}
+			return false;
+		}
+	}
+
+	/**
+	 * Returns the next element in this iterator and advances the iterator
+	 * position. If there are no more elements and the size of the iterator
+	 * is unknown, then the size is set to the current position.
+	 *
+	 * @return next element
+	 * @throws NoSuchElementException if there are no more elements
+	 */
+	public Object next() throws NoSuchElementException {
+		try {
+			Object next = iterator.next();
+			position++;
+			return next;
+		} catch (NoSuchElementException e) {
+			if (size == -1) {
+				size = position;
+			}
+			throw e;
+		}
+	}
+
+	/**
+	 * Removes the previously retrieved element. Decreases the current
+	 * position and size of this iterator.
+	 *
+	 * @throws UnsupportedOperationException if removes are not permitted
+	 * @throws IllegalStateException if there is no previous element to remove
+	 */
+	public void remove()
+			throws UnsupportedOperationException, IllegalStateException {
+		iterator.remove();
+		position--;
+		if (size != -1) {
+			size--;
+		}
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorDecorator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorDecorator.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorDecorator.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorDecorator.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.NoSuchElementException;
+
+import javax.jcr.RangeIterator;
+
+/**
+ * Base class for decorating {@link RangeIterator}s.
+ */
+public class RangeIteratorDecorator implements RangeIterator {
+
+	/**
+	 * The decorated iterator.
+	 */
+	private final RangeIterator iterator;
+
+	/**
+	 * Creates a decorated iterator. Protected since this class is only
+	 * useful when subclassed.
+	 *
+	 * @param iterator the iterator to be decorated
+	 */
+	protected RangeIteratorDecorator(RangeIterator iterator) {
+		this.iterator = iterator;
+	}
+
+	//-------------------------------------------------------< RangeIterator >
+
+	/**
+	 * Delegated to the underlying iterator.
+	 *
+	 * @return iterator position
+	 */
+	public long getPosition() {
+		return iterator.getPosition();
+	}
+
+	/**
+	 * Delegated to the underlying iterator.
+	 *
+	 * @return iterator size
+	 */
+	public long getSize() {
+		return iterator.getSize();
+	}
+
+	/**
+	 * Delegated to the underlying iterator.
+	 *
+	 * @param n number of elements to skip
+	 * @throws NoSuchElementException if skipped past the last element
+	 */
+	public void skip(long n) throws NoSuchElementException {
+		iterator.skip(n);
+	}
+
+	//------------------------------------------------------------< Iterator >
+
+	/**
+	 * Delegated to the underlying iterator.
+	 *
+	 * @return <code>true</code> if the iterator has more elements,
+	 *         <code>false</code> otherwise
+	 */
+	public boolean hasNext() {
+		return iterator.hasNext();
+	}
+
+	/**
+	 * Delegated to the underlying iterator.
+	 *
+	 * @return next element
+	 * @throws NoSuchElementException if there are no more elements
+	 */
+	public Object next() throws NoSuchElementException {
+		return iterator.next();
+	}
+
+	/**
+	 * Delegated to the underlying iterator.
+	 *
+	 * @throws UnsupportedOperationException if the operation is not supported
+	 * @throws IllegalStateException if there is no element to be removed
+	 */
+	public void remove()
+			throws UnsupportedOperationException, IllegalStateException {
+		iterator.remove();
+	}
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RangeIteratorDecorator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RowIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RowIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RowIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RowIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.RangeIterator;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
+
+/**
+ * Adapter class for turning {@link RangeIterator}s or {@link Iterator}s
+ * into {@link RowIterator}s. 
+ */
+public class RowIteratorAdapter extends RangeIteratorDecorator
+		implements RowIterator {
+
+	/**
+	 * Creates an adapter for the given {@link RangeIterator}.
+	 *
+	 * @param iterator iterator of {@link Row}s
+	 */
+	public RowIteratorAdapter(RangeIterator iterator) {
+		super(iterator);
+	}
+
+	/**
+	 * Creates an adapter for the given {@link Iterator}.
+	 *
+	 * @param iterator iterator of {@link Row}s
+	 */
+	public RowIteratorAdapter(Iterator iterator) {
+		super(new RangeIteratorAdapter(iterator));
+	}
+
+	/**
+	 * Creates an iterator for the given collection.
+	 *
+	 * @param collection collection of {@link Row}s
+	 */
+	public RowIteratorAdapter(Collection collection) {
+		super(new RangeIteratorAdapter(collection));
+	}
+
+	//---------------------------------------------------------< RowIterator >
+
+	/**
+	 * Returns the next row.
+	 *
+	 * @return next row
+	 * @throws NoSuchElementException if there is no next row
+	 */
+	public Row nextRow() {
+		return (Row) next();
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/RowIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/VersionIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/VersionIteratorAdapter.java?view=auto&rev=522141
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/VersionIteratorAdapter.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/VersionIteratorAdapter.java
Sat Mar 24 19:00:14 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.commons.iterator;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.jcr.RangeIterator;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionIterator;
+
+/**
+ * Adapter class for turning {@link RangeIterator}s or {@link Iterator}s
+ * into {@link VersionIterator}s. 
+ */
+public class VersionIteratorAdapter extends RangeIteratorDecorator
+		implements VersionIterator {
+
+	/**
+	 * Creates an adapter for the given {@link RangeIterator}.
+	 *
+	 * @param iterator iterator of {@link Version}s
+	 */
+	public VersionIteratorAdapter(RangeIterator iterator) {
+		super(iterator);
+	}
+
+	/**
+	 * Creates an adapter for the given {@link Iterator}.
+	 *
+	 * @param iterator iterator of {@link Version}s
+	 */
+	public VersionIteratorAdapter(Iterator iterator) {
+		super(new RangeIteratorAdapter(iterator));
+	}
+
+	/**
+	 * Creates an iterator for the given collection.
+	 *
+	 * @param collection collection of {@link Version}s
+	 */
+	public VersionIteratorAdapter(Collection collection) {
+		super(new RangeIteratorAdapter(collection));
+	}
+
+	//-----------------------------------------------------< VersionIterator >
+
+	/**
+	 * Returns the next version.
+	 *
+	 * @return next version
+	 * @throws NoSuchElementException if there is no next version
+	 */
+	public Version nextVersion() {
+		return (Version) next();
+	}
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/VersionIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message