org.entityfs.util.dirdiff
Class DirectoryTreeDifferentiator

java.lang.Object
  extended by org.entityfs.util.dirdiff.DirectoryTreeDifferentiator
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
DirectoryTreeSynchronizer

public class DirectoryTreeDifferentiator
extends Object
implements Runnable

This is a recursive DirectoryDifferentiator that is used for analyzing differences between a master directory hierarchy and a target directory hierarchy. When the client calls run(), it creates a DirectoryDifferentiator to analyze the differences between the master and the target directory. After doing so, it calls itself recursively for each subdirectory of the master directory that has a corresponding subdirectory in the target directory. iterates over every child entity in the master directory and tries to find a matching entity in the target directory using a EntityMatchStrategy. After iterating, it calls its UnmatchedTargetEntityStrategy for each unmatched entity in the target directory, and then its UnmatchedMasterEntityStrategy for each unmatched entity in the master directory.

Since:
1.0
Author:
Karl Gustafsson
See Also:
DirectoryDifferentiator

Constructor Summary
DirectoryTreeDifferentiator(DirectoryView master, DirectoryView target, EntityMatchStrategy ems, UnmatchedTargetEntityStrategy utes, UnmatchedMasterEntityStrategy umes)
          Create a new differentiator that will analyze the differences between two directory hierarchies recursively.
 
Method Summary
protected  Pair<DirectoryView> getSubdirectoryPair(DirectoryView master, DirectoryView dir, DirectoryView target)
          Get a Pair of a master subdirectory and a target subdirectory if the supplied master subdirectory has a matching target subdirectory.
 void run()
          Run the differentiator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectoryTreeDifferentiator

public DirectoryTreeDifferentiator(DirectoryView master,
                                   DirectoryView target,
                                   EntityMatchStrategy ems,
                                   UnmatchedTargetEntityStrategy utes,
                                   UnmatchedMasterEntityStrategy umes)
                            throws NullPointerException
Create a new differentiator that will analyze the differences between two directory hierarchies recursively.

Parameters:
master - The root of the master directory hierarchy.
target - The root of the target directory hierarchy.
ems - The strategy object that is used to see if an entity in a master directory has a matching entity in a target directory.
utes - The strategy object that is used to handle each entity in a target directory that does not have a matching entity in its corresponding master directory.
umes - The strategy object that is used to handle each entity in a master directory that does not have a matching entity in its corresponding target directory.
Throws:
NullPointerException - If any of the arguments is null.
Method Detail

getSubdirectoryPair

protected Pair<DirectoryView> getSubdirectoryPair(DirectoryView master,
                                                  DirectoryView dir,
                                                  DirectoryView target)
Get a Pair of a master subdirectory and a target subdirectory if the supplied master subdirectory has a matching target subdirectory. If not, return null.

This implementation returns a directory pair if there is a subdirectory of the same name as the master subdirectory in the target directory. Subclasses may override this to change this behavior.

Parameters:
master - The master directory. Locked for reading.
dir - The master directory subdirectory to search for a match for.
target - The target directory. Locked for writing.
Returns:
A directory pair (master subdirectory, target subdirectory) if there is a target subdirectory that matches the master subdirectory. Otherwise, null is returned.

run

public void run()
Run the differentiator.

Specified by:
run in interface Runnable