Author: oheger
Date: Fri Feb 7 20:31:59 2014
New Revision: 1565790
URL: http://svn.apache.org/r1565790
Log:
Adapted ConfigurationNodeIteratorBase.
This class is now able to provide a NodeHandler to its sub classes. Some
functionality related to the iteration has now to be implemented by sub
classes.
Modified:
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/xpath/ConfigurationNodeIteratorBase.java
Modified:
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/xpath/ConfigurationNodeIteratorBase.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/xpath/ConfigurationNodeIteratorBase.java?rev=1565790&r1=1565789&r2=1565790&view=diff
==============================================================================
---
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/xpath/ConfigurationNodeIteratorBase.java
(original)
+++
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/xpath/ConfigurationNodeIteratorBase.java
Fri Feb 7 20:31:59 2014
@@ -16,9 +16,7 @@
*/
package org.apache.commons.configuration.tree.xpath;
-import java.util.List;
-
-import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.tree.NodeHandler;
import org.apache.commons.jxpath.ri.model.NodeIterator;
import org.apache.commons.jxpath.ri.model.NodePointer;
@@ -33,18 +31,13 @@ import org.apache.commons.jxpath.ri.mode
* </p>
*
* @since 1.3
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html">Commons
- * Configuration team</a>
* @version $Id$
+ * @param <T> the type of the nodes this iterator deals with
*/
-abstract class ConfigurationNodeIteratorBase implements NodeIterator
+abstract class ConfigurationNodeIteratorBase<T> implements NodeIterator
{
/** Stores the parent node pointer. */
- private NodePointer parent;
-
- /** Stores the list with the sub nodes. */
- private List<ConfigurationNode> subNodes;
+ private final ConfigurationNodePointer<T> parent;
/** Stores the current position. */
private int position;
@@ -53,7 +46,7 @@ abstract class ConfigurationNodeIterator
private int startOffset;
/** Stores the reverse flag. */
- private boolean reverse;
+ private final boolean reverse;
/**
* Creates a new instance of {@code ConfigurationNodeIteratorBase}
@@ -62,7 +55,8 @@ abstract class ConfigurationNodeIterator
* @param parent the parent pointer
* @param reverse the reverse flag
*/
- protected ConfigurationNodeIteratorBase(NodePointer parent, boolean
reverse)
+ protected ConfigurationNodeIteratorBase(ConfigurationNodePointer<T> parent,
+ boolean reverse)
{
this.parent = parent;
this.reverse = reverse;
@@ -102,7 +96,7 @@ abstract class ConfigurationNodeIterator
return null;
}
- return createNodePointer(subNodes.get(positionToIndex(getPosition())));
+ return createNodePointer(positionToIndex(getPosition()));
}
/**
@@ -110,12 +104,23 @@ abstract class ConfigurationNodeIterator
*
* @return the parent node pointer
*/
- protected NodePointer getParent()
+ protected ConfigurationNodePointer<T> getParent()
{
return parent;
}
/**
+ * Returns the node handler for the managed nodes. This is a convenience
+ * method.
+ *
+ * @return the node handler
+ */
+ protected NodeHandler<T> getNodeHandler()
+ {
+ return getParent().getNodeHandler();
+ }
+
+ /**
* Returns the start offset of the iteration.
*
* @return the start offset
@@ -145,29 +150,25 @@ abstract class ConfigurationNodeIterator
}
/**
- * Initializes the list of sub nodes for the iteration. This method must be
- * called during initialization phase.
+ * Returns the maximum position for this iterator.
*
- * @param nodes the list with the sub nodes
+ * @return the maximum allowed position
*/
- protected void initSubNodeList(List<ConfigurationNode> nodes)
+ protected int getMaxPosition()
{
- subNodes = nodes;
- if (reverse)
- {
- setStartOffset(subNodes.size());
- }
+ return reverse ? getStartOffset() + 1 : size() - getStartOffset();
}
/**
- * Returns the maximum position for this iterator.
+ * Returns the index in the data list for the given position. This method
+ * also checks the reverse flag.
*
- * @return the maximum allowed position
+ * @param pos the position (1-based)
+ * @return the corresponding list index
*/
- protected int getMaxPosition()
+ protected int positionToIndex(int pos)
{
- return reverse ? getStartOffset() + 1 : subNodes.size()
- - getStartOffset();
+ return (reverse ? 1 - pos : pos - 1) + getStartOffset();
}
/**
@@ -175,23 +176,15 @@ abstract class ConfigurationNodeIterator
* method is called by {@code getNodePointer()}. Derived classes
* must create the correct pointer object.
*
- * @param node the current configuration node
+ * @param position the current position in the iteration
* @return the node pointer
*/
- protected NodePointer createNodePointer(ConfigurationNode node)
- {
- return new ConfigurationNodePointer(getParent(), node);
- }
+ protected abstract NodePointer createNodePointer(int position);
/**
- * Returns the index in the data list for the given position. This method
- * also checks the reverse flag.
+ * Returns the number of elements in this iteration.
*
- * @param pos the position (1-based)
- * @return the corresponding list index
+ * @return the number of elements
*/
- protected int positionToIndex(int pos)
- {
- return (reverse ? 1 - pos : pos - 1) + getStartOffset();
- }
+ protected abstract int size();
}