jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r169151 - /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator
Date Sun, 08 May 2005 19:27:33 GMT
Author: jukka
Date: Sun May  8 12:27:32 2005
New Revision: 169151

URL: http://svn.apache.org/viewcvs?rev=169151&view=rev
Log:
JCR-EXT: Cleaned up, documented and extended the array iterator classes.

Modified:
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayIterator.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeIterator.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeTypeIterator.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayPropertyIterator.java

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayIterator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayIterator.java?rev=169151&r1=169150&r2=169151&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayIterator.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayIterator.java
Sun May  8 12:27:32 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.iterator;
 
+import java.util.NoSuchElementException;
+
 import javax.jcr.RangeIterator;
 
 /**
@@ -24,54 +26,92 @@
  * implements the RangeIterator functionality for an underlying array
  * of objects. Used as the base class for the type-specific iterator
  * classes defined in this package.
- * 
- * @author Jukka Zitting
  */
-public class ArrayIterator implements RangeIterator {
+class ArrayIterator implements RangeIterator {
 
     /** The current iterator position. */
     private int position;
-    
+
     /** The underlying array of objects. */
-    private Object[] array;
-    
+    private final Object[] array;
+
     /**
      * Creates an iterator for the given array of objects.
-     * 
+     *
      * @param array the objects to iterate
      */
-    public ArrayIterator(Object[] array) {
+    protected ArrayIterator(Object[] array) {
         this.position = 0;
         this.array = array;
     }
-    
-    /** {@inheritDoc} */
+
+    /**
+     * Checks whether there are more elements in the array.
+     *
+     * @return <code>true</code> if more elements are available,
+     *         <code>false</code> otherwise
+     * @see Iterator#hasNext()
+     */
     public boolean hasNext() {
         return (position < array.length);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Returns the next array element and advances the array position.
+     *
+     * @return next element
+     * @see Iterator#next()
+     */
     public Object next() {
         return array[position++];
     }
 
-    /** {@inheritDoc} */
-    public void remove() {
+    /**
+     * Element removal is not supported.
+     *
+     * @throws UnsupportedOperationException always thrown
+     * @see Iterator#remove()
+     */
+    public void remove() throws UnsupportedOperationException {
         throw new UnsupportedOperationException();
     }
 
-    /** {@inheritDoc} */
-    public void skip(long items) {
-        position += items;
+    /**
+     * Advances the array position the given number of elements.
+     *
+     * @param items number of items to skip
+     * @throws IllegalArgumentException if the given number of items is negative
+     * @throws NoSuchElementException if skipping past the end of the array
+     * @see RangeIterator#skip(long)
+     */
+    public void skip(long items)
+            throws IllegalArgumentException, NoSuchElementException {
+        if (items < 0) {
+            throw new IllegalArgumentException("Negative number of items");
+        } else if (position + items < array.length) {
+            position += items;
+        } else {
+            throw new NoSuchElementException("No more elements in the array");
+        }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Returns the length of the array.
+     *
+     * @return array length
+     * @see RangeIterator#getSize()
+     */
     public long getSize() {
         return array.length;
     }
 
-    /** {@inheritDoc} */
-    public long getPos() {
+    /**
+     * Returns the current array position
+     *
+     * @return array position
+     * @see RangeIterator#getPosition()
+     */
+    public long getPosition() {
         return position;
     }
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeIterator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeIterator.java?rev=169151&r1=169150&r2=169151&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeIterator.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeIterator.java
Sun May  8 12:27:32 2005
@@ -16,29 +16,41 @@
  */
 package org.apache.jackrabbit.iterator;
 
+import java.util.Collection;
+
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 
 /**
  * Array implementation of the JCR
  * {@link javax.jcr.NodeIterator NodeIterator} interface.
- * This class is used by the JCR-RMI client adapters to convert
- * node arrays to iterators.
- * 
- * @author Jukka Zitting
  */
 public class ArrayNodeIterator extends ArrayIterator implements NodeIterator {
-    
+
     /**
      * Creates an iterator for the given array of nodes.
-     * 
+     *
      * @param nodes the nodes to iterate
      */
     public ArrayNodeIterator(Node[] nodes) {
         super(nodes);
     }
-    
-    /** {@inheritDoc} */
+
+    /**
+     * Creates an iterator for the given collection of nodes.
+     *
+     * @param nodes the nodes to iterate
+     */
+    public ArrayNodeIterator(Collection nodes) {
+        this((Node[]) nodes.toArray(new Node[nodes.size()]));
+    }
+
+    /**
+     * Returns the next node in the array.
+     *
+     * @return next node
+     * @see NodeIterator#nextNode()
+     */
     public Node nextNode() {
         return (Node) next();
     }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeTypeIterator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeTypeIterator.java?rev=169151&r1=169150&r2=169151&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeTypeIterator.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayNodeTypeIterator.java
Sun May  8 12:27:32 2005
@@ -6,7 +6,7 @@
  * 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
+ *      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,
@@ -16,30 +16,42 @@
  */
 package org.apache.jackrabbit.iterator;
 
+import java.util.Collection;
+
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.NodeTypeIterator;
 
 /**
  * Array implementation of the JCR
  * {@link javax.jcr.NodeTypeIterator NodeTypeIterator} interface.
- * This class is used by the JCR-RMI client adapters to convert
- * node type arrays to iterators.
- * 
- * @author Jukka Zitting
  */
 public class ArrayNodeTypeIterator extends ArrayIterator implements
         NodeTypeIterator {
-    
+
     /**
      * Creates an iterator for the given array of node types.
-     * 
+     *
      * @param types the node types to iterate
      */
     public ArrayNodeTypeIterator(NodeType[] types) {
         super(types);
     }
 
-    /** {@inheritDoc} */
+    /**
+     * Creates an iterator for the given collection of node types.
+     *
+     * @param types the node types to iterate
+     */
+    public ArrayNodeTypeIterator(Collection types) {
+        this((NodeType[]) types.toArray(new NodeType[types.size()]));
+    }
+
+    /**
+     * Returns the next node type in the array.
+     *
+     * @return next node type
+     * @see NodeTypeIterator#nextNodeType()
+     */
     public NodeType nextNodeType() {
         return (NodeType) next();
     }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayPropertyIterator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayPropertyIterator.java?rev=169151&r1=169150&r2=169151&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayPropertyIterator.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/iterator/ArrayPropertyIterator.java
Sun May  8 12:27:32 2005
@@ -16,30 +16,42 @@
  */
 package org.apache.jackrabbit.iterator;
 
+import java.util.Collection;
+
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
 
 /**
  * Array implementation of the JCR
  * {@link javax.jcr.PropertyIterator PropertyIterator} interface.
- * This class is used by the JCR-RMI client adapters to convert
- * property arrays to iterators.
- * 
- * @author Jukka Zitting
  */
 public class ArrayPropertyIterator extends ArrayIterator
         implements PropertyIterator {
-    
+
     /**
      * Creates an iterator for the given array of properties.
-     * 
+     *
      * @param properties the properties to iterate
      */
     public ArrayPropertyIterator(Property[] properties) {
         super(properties);
     }
-    
-    /** {@inheritDoc} */
+
+    /**
+     * Creates an iterator for the given collection of properties.
+     *
+     * @param properties the properties to iterate
+     */
+    public ArrayPropertyIterator(Collection properties) {
+        this((Property[]) properties.toArray(new Property[properties.size()]));
+    }
+
+    /**
+     * Returns the next property in the array.
+     *
+     * @return next property
+     * @see PropertyIterator#nextProperty()
+     */
     public Property nextProperty() {
         return (Property) next();
     }



Mime
View raw message