com.faunos.util.io.file
Class FileSystemTraverser

java.lang.Object
  extended by com.faunos.util.tree.AbstractTraverser<File>
      extended by com.faunos.util.io.file.FileSystemTraverser
All Implemented Interfaces:
Runnable

public class FileSystemTraverser
extends AbstractTraverser<File>

A depth-first, directory structure traverser.

This class is not safe under concurrent access.

Author:
Babak Farhang
See Also:
TraverseListener, Euler Traversal

Constructor Summary
FileSystemTraverser(File root)
          Creates a new instance with the given root file (usually a directory).
FileSystemTraverser(File root, TraverseListener<File> listener, FileFilter filter, Comparator<File> siblingOrder)
          Creates a new instance with the given root file (usually a directory).
 
Method Summary
protected  File[] getChildren(File node)
          Returns the files in the given directory node, applying this instance's filter, if any.
 FileFilter getFilter()
          Returns the filter used to determine whether files will be visited.
protected  boolean hasChildren(File node)
          Returns true is the specified file node is a directory.
 void setFilter(FileFilter filter)
          Sets the filter used to determine whether files will be visited.
static void visitPostorder(File root, Visitor<File> visitor, FileFilter filter)
          Visits the root file, and if a directory, and traverses the directory structure, firing post-order events along the way.
static void visitPostorder(File root, Visitor<File> visitor, FileFilter filter, Comparator<File> siblingOrder)
          Visits the root file, and if a directory, and traverses the directory structure, firing post-order events along the way.
static void visitPreorder(File root, Visitor<File> visitor, FileFilter filter)
          Visits the root file, and if a directory, and traverses the directory structure, firing pre-order events along the way.
static void visitPreorder(File root, Visitor<File> visitor, FileFilter filter, Comparator<File> siblingOrder)
          Visits the root file, and if a directory, and traverses the directory structure, firing pre-order events along the way.
 
Methods inherited from class com.faunos.util.tree.AbstractTraverser
getListener, getSiblingOrder, run, setListener, setSiblingOrder, visitPostorder, visitPreorder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemTraverser

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


FileSystemTraverser

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

Method Detail

visitPreorder

public static void visitPreorder(File root,
                                 Visitor<File> visitor,
                                 FileFilter filter)
Visits the root file, and if a directory, and traverses the directory structure, firing pre-order events along the way. Ordinary files in a same directory are visited before subdirectories.

Parameters:
root - the root of the directory structure (must exist)
visitor - the callback interface invoked on traversal
filter - optional file filter (may be null)

visitPreorder

public static void visitPreorder(File root,
                                 Visitor<File> visitor,
                                 FileFilter filter,
                                 Comparator<File> siblingOrder)
Visits the root file, and if a directory, and traverses the directory structure, firing pre-order events along the way.

Parameters:
root - the root of the directory structure (must exist)
visitor - the callback interface invoked on traversal
filter - optional file filter (may be null)
siblingOrder - determines the order files in a same directory get visited. If null, the files' natural ordering is used.

visitPostorder

public static void visitPostorder(File root,
                                  Visitor<File> visitor,
                                  FileFilter filter)
Visits the root file, and if a directory, and traverses the directory structure, firing post-order events along the way. Ordinary files in a same directory are visited after subdirectories.

Parameters:
root - the root of the directory structure (must exist)
visitor - the callback interface invoked on traversal
filter - optional file filter (may be null)

visitPostorder

public static void visitPostorder(File root,
                                  Visitor<File> visitor,
                                  FileFilter filter,
                                  Comparator<File> siblingOrder)
Visits the root file, and if a directory, and traverses the directory structure, firing post-order events along the way.

Parameters:
root - the root of the directory structure (must exist)
visitor - the callback interface invoked on traversal
filter - optional file filter (may be null)
siblingOrder - determines the order files in a same directory get visited. If null, the files' natural ordering is used.

setFilter

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


getFilter

public FileFilter getFilter()
Returns the filter used to determine whether files will be visited. May be null.


getChildren

protected File[] getChildren(File node)
Returns the files in the given directory node, applying this instance's filter, if any.

Specified by:
getChildren in class AbstractTraverser<File>
Returns:
an array of child nodes, possibly empty; never null.

hasChildren

protected boolean hasChildren(File node)
Returns true is the specified file node is a directory.

Specified by:
hasChildren in class AbstractTraverser<File>


SourceForge.net Logo