org.apache.wicket.util.iterator
Class AbstractHierarchyIterator<N,I extends N>

java.lang.Object
  extended by org.apache.wicket.util.iterator.AbstractHierarchyIterator<N,I>
Type Parameters:
I - The type relevant for the iterator. What you expect to get back from next(), e.g. Form.
N - The base type of all nodes, e.g. Component
All Implemented Interfaces:
java.lang.Iterable<I>, java.util.Iterator<I>
Direct Known Subclasses:
AbstractHierarchyIteratorWithFilter

public abstract class AbstractHierarchyIterator<N,I extends N>
extends java.lang.Object
implements java.util.Iterator<I>, java.lang.Iterable<I>

This is a basic iterator for hierarchical structures such as Component hierarchies or HTML markup. It supports child first and parent first traversal and intercepts while moving down or up the hierarchy.

It assume the container class implements Iterable. The leaf nodes don't need to.

Consecutive calls to hasNext() without next() in between, don't move the cursor, but return the same value until next() is called.

Every call to next(), with or without hasNext(), will move the cursor to the next element.

Author:
Juergen Donnerstag

Constructor Summary
AbstractHierarchyIterator(N root)
          Construct.
 
Method Summary
 void dontGoDeeper()
          Assuming we are currently at a container, than ignore all its children and grand-children and continue with the next sibling.
protected abstract  boolean hasChildren(N node)
           
 boolean hasNext()
           
 java.util.Iterator<I> iterator()
           
protected abstract  java.util.Iterator<N> newIterator(N node)
          If node is a container than return an iterator for its children.
 I next()
          Traverse the hierarchy and get the next element
protected  boolean onFilter(N node)
          Gets called for each element within the hierarchy (nodes and leafs)
protected  boolean onTraversalFilter(N node)
          Gets called for each element where hasChildren(Object) return true.
 void remove()
           
 void setChildFirst(boolean childFirst)
           
 void skipRemainingSiblings()
          Skip all remaining siblings and return to the parent node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractHierarchyIterator

public AbstractHierarchyIterator(N root)
Construct.

Parameters:
root -
Method Detail

setChildFirst

public final void setChildFirst(boolean childFirst)
Parameters:
childFirst - If true, than children are visited before their parent is.

hasChildren

protected abstract boolean hasChildren(N node)
Parameters:
node -
Returns:
True, if node is a container and has at least one child.

newIterator

protected abstract java.util.Iterator<N> newIterator(N node)
If node is a container than return an iterator for its children.

Gets only called if hasChildren(Object) return true.

Parameters:
node -
Returns:
container iterator

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<I extends N>

onFilter

protected boolean onFilter(N node)
Gets called for each element within the hierarchy (nodes and leafs)

Parameters:
node -
Returns:
if false, than skip (filter) the element. It'll not stop the iterator from traversing into children though.

onTraversalFilter

protected boolean onTraversalFilter(N node)
Gets called for each element where hasChildren(Object) return true.

Parameters:
node -
Returns:
if false, than do not traverse into the children and grand-children.

next

public I next()
Traverse the hierarchy and get the next element

Specified by:
next in interface java.util.Iterator<I extends N>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<I extends N>

skipRemainingSiblings

public void skipRemainingSiblings()
Skip all remaining siblings and return to the parent node.

Can as well be called within IteratorFilter.onFilter(Object).


dontGoDeeper

public void dontGoDeeper()
Assuming we are currently at a container, than ignore all its children and grand-children and continue with the next sibling.

Can as well be called within IteratorFilter.onFilter(Object).


iterator

public final java.util.Iterator<I> iterator()
Specified by:
iterator in interface java.lang.Iterable<I extends N>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.