org.entityfs.util.itr
Class DepthFirstIteratorImpl

java.lang.Object
  extended by org.entityfs.util.itr.AbstractIterator<T,U>
      extended by org.entityfs.util.itr.DepthFirstIteratorImpl
All Implemented Interfaces:
Iterator<EntityView>, DepthFirstIterator<EntityView>

public class DepthFirstIteratorImpl
extends AbstractIterator<T,U>

Standard implementation of DepthFirstIterator for EntityView :s.

EntityFS iterators are not thread safe. Don't use them concurrently from several threads without synchronizing access to them.

Since:
1.0
Author:
Karl Gustafsson
See Also:
DepthLastIteratorImpl

Constructor Summary
DepthFirstIteratorImpl(EntityListable dv, boolean returnThis)
          Create a new depth-first iterator.
DepthFirstIteratorImpl(EntityListable dv, Filter<? super EntityView> filter, boolean returnThis)
          Create a new depth-first iterator.
 
Method Summary
protected  org.entityfs.util.itr.DepthFirstIteratorContextImpl createChildIteratorContext(EntityView dv, org.entityfs.util.itr.DepthFirstIteratorContextImpl parentContext)
           
protected  EntityView getObjectForRootDirectory(DirectoryView rootDirectory)
          Get an object to return from the iterator for the root directory of the recursive iteration.
protected  boolean testAndSetNext()
           
 
Methods inherited from class org.entityfs.util.itr.AbstractIterator
getContextStack, getFilter, hasNext, next, remove, setNext, testAndSetNextChildEntity, testAndSetNextSubdirectory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Iterator
hasNext, next, remove
 

Constructor Detail

DepthFirstIteratorImpl

public DepthFirstIteratorImpl(EntityListable dv,
                              Filter<? super EntityView> filter,
                              boolean returnThis)
Create a new depth-first iterator. The iterator will only return entities that pass the supplied filter.

Parameters:
dv - The start directory for the iteration. If returnThis is true, this must be a DirectoryView (such as a Directory.
filter - The filter that entities must pass to be returned from the iterator. The iterator will not visit subdirectories that does not pass this filter.
returnThis - Should the start directory be returned as the last entity from the iterator (if it passes the filter)?

DepthFirstIteratorImpl

public DepthFirstIteratorImpl(EntityListable dv,
                              boolean returnThis)
Create a new depth-first iterator.

Parameters:
dv - The start directory for the iteration. If returnThis is true, this must be a DirectoryView (such as a Directory.
returnThis - Should the start directory be returned as the last entity from the iterator?
Method Detail

createChildIteratorContext

protected org.entityfs.util.itr.DepthFirstIteratorContextImpl createChildIteratorContext(EntityView dv,
                                                                                         org.entityfs.util.itr.DepthFirstIteratorContextImpl parentContext)
Specified by:
createChildIteratorContext in class AbstractIterator<org.entityfs.util.itr.DepthFirstIteratorContextImpl,EntityView>

getObjectForRootDirectory

protected EntityView getObjectForRootDirectory(DirectoryView rootDirectory)
Get an object to return from the iterator for the root directory of the recursive iteration. This is only called if DepthFirstIteratorContext.testAndClearShouldReturnThis() returns true for the current context.

Parameters:
rootDirectory - The root directory of the iteration.

testAndSetNext

protected final boolean testAndSetNext()
Specified by:
testAndSetNext in class AbstractIterator<T extends org.entityfs.util.itr.DepthFirstIteratorContext<U>,U>