FileDocCategorySizeDatePackage
Directory.javaAPI DocApache Ant 1.705122Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional.ssh

Directory

public class Directory extends Object
A helper object for Scp representing a directory in a file system.

Fields Summary
private File
directory
private ArrayList
childDirectories
private ArrayList
files
private Directory
parent
Constructors Summary
public Directory(File directory)
Constructor for a Directory.

param
directory a directory.

        this(directory,  null);
    
public Directory(File directory, Directory parent)
Constructor for a Directory.

param
directory a directory
param
parent a parent Directory

        this.parent = parent;
        this.childDirectories = new ArrayList();
        this.files = new ArrayList();
        this.directory = directory;
    
Methods Summary
public voidaddDirectory(org.apache.tools.ant.taskdefs.optional.ssh.Directory directory)
Add a directory to the child directories.

param
directory a Directory

        if (!childDirectories.contains(directory)) {
            childDirectories.add(directory);
        }
    
public voidaddFile(java.io.File file)
Add a file to the list of files.

param
file a file to add

        files.add(file);
    
public java.util.IteratordirectoryIterator()
Get an iterator over the child Directories.

return
an iterator

        return childDirectories.iterator();
    
public booleanequals(java.lang.Object obj)
The equality method. This checks if the directory field is the same.

param
obj the object to compare to
return
true if this object has an equal directory field as the other object

        if (obj == this) {
            return true;
        }

        if (!(obj instanceof Directory)) {
            return false;
        }

        Directory d = (Directory) obj;

        return this.directory.equals(d.directory);
    
public intfileSize()
Get the number of files in the files attribute.

return
the number of files

        return files.size();
    
public java.util.IteratorfilesIterator()
Get an iterator over the files.

return
an iterator

        return files.iterator();
    
public org.apache.tools.ant.taskdefs.optional.ssh.DirectorygetChild(java.io.File dir)
Get a child directory of this directory.

param
dir the directory to look for
return
the child directory, or null if not found

        for (int i = 0; i < childDirectories.size(); i++) {
            Directory current = (Directory) childDirectories.get(i);
            if (current.getDirectory().equals(dir)) {
                return current;
            }
        }

        return null;
    
public java.io.FilegetDirectory()
Get the directory file.

return
the directory file

        return directory;
    
public org.apache.tools.ant.taskdefs.optional.ssh.DirectorygetParent()
Get the parent Directory.

return
the parent Directory.

        return parent;
    
public java.lang.String[]getPath()
Get the path components of this directory.

return
the path components as an array of strings.

        return getPath(directory.getAbsolutePath());
    
public static java.lang.String[]getPath(java.lang.String thePath)
Convert a file path to an array of path components. This uses File.sepatator to split the file path string.

param
thePath the file path string to convert
return
an array of path components

        StringTokenizer tokenizer = new StringTokenizer(thePath,
                File.separator);
        String[] path = new String[ tokenizer.countTokens() ];

        int i = 0;
        while (tokenizer.hasMoreTokens()) {
            path[i] = tokenizer.nextToken();
            i++;
        }

        return path;
    
public inthashCode()
The hashcode method.

return
the hash code of the directory field

        return directory.hashCode();
    
public booleanisRoot()
Is this a root Directory?

return
true if there is no parent Directory

        return parent == null;