com.faunos.util.io.file
Class Traverser

java.lang.Object
  extended by com.faunos.util.io.file.Traverser
All Implemented Interfaces:
Runnable

public class Traverser
extends Object
implements Runnable

A depth-first, directory structure traverser. The traverser implements an Euler traversal of the directory structure (generalized for tree nodes with arbitrary number of children). As it traverses the structure, an instance fires pre-order and post-order events along the way.

This class is not safe under concurrent access.

Author:
Babak Farhang
See Also:
TraverseListener, Euler Traversal

Constructor Summary
Traverser(File root)
          Creates a new instance with the given root file (usually a directory).
Traverser(File root, TraverseListener listener, FileFilter filter, Comparator<File> siblingOrder)
          Creates a new instance with the given root file (usually a directory).
 
Method Summary
 void run()
          Performs the traversal over the directory structure.
 void setFilter(FileFilter filter)
          Sets the filter used to determine whether files will be visited.
 void setListener(TraverseListener listener)
          Sets the listener for the traversal.
 void setSiblingOrder(Comparator<File> siblingOrder)
          Sets the comparator used to determine the order in which files in a same directory get visited.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Traverser

public Traverser(File root)
Creates a new instance with the given root file (usually a directory).


Traverser

public Traverser(File root,
                 TraverseListener listener,
                 FileFilter filter,
                 Comparator<File> siblingOrder)
Creates a new instance with the given root file (usually a directory).

Method Detail

setListener

public void setListener(TraverseListener listener)
Sets the listener for the traversal.


setFilter

public void setFilter(FileFilter filter)
Sets the filter used to determine whether files will be visited.


setSiblingOrder

public void setSiblingOrder(Comparator<File> siblingOrder)
Sets the comparator used to determine the order in which files in a same directory get visited.


run

public void run()
Performs the traversal over the directory structure. Pre- and post-order events are fired to the listener, if any.

This method may only be invoked once. Otherwise, an exception is thrown.

Specified by:
run in interface Runnable
Throws:
IndexOutOfBoundsException - if invoked more than once


SourceForge.net Logo