/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.util; import xbn.XBNObject; import xbn.output.Outputter; import java.io.FileFilter; /**
Configuration for a DirScan. See DirScan
Source code: DSConfig.java
0.8.2b
@version 0.9b
@author Jeff Epstein, http://sourceforge.net/projects/xbnjava
**/
public class DSConfig extends XBNObject {
private int iLvlsMxDpth = -1;
private boolean bIgnoreDirs = false;
private boolean bFilesFirst = false;
private FileFilter ff = null;
private Outputter optrDbg = null;
/**
Create a DSConfig.
Equal to DSConfig(-1)
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, false)
Create a DSConfig.
Equal to DSConfig(-1, b_ignoreDirs)
Create a DSConfig.
Equal to DSConfig(-1, file_filter)
Note: To set file_filter to null, use either (FileFilter)null
or use this constructor instead.
Create a DSConfig.
Equal to DSConfig(-1, optr_dbg)
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, b_ignoreDirs, false)
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, false, file_filter)
Note: To set file_filter to null, use either (FileFilter)null
or use this constructor instead.
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, false, optr_dbg)
Create a DSConfig.
Equal to DSConfig(-1, b_ignoreDirs, b_filesFirst)
Create a DSConfig.
Equal to DSConfig(-1, b_ignoreDirs, file_filter)
Note: To set file_filter to null, use either (FileFilter)null
or use this constructor instead.
Create a DSConfig.
Equal to DSConfig(-1, b_ignoreDirs, optr_dbg)
Create a DSConfig.
Equal to DSConfig(-1, file_filter, optr_dbg)
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, b_ignoreDirs, b_filesFirst, (new Outputter()))
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, b_ignoreDirs, false, file_filter)
Note: To set file_filter to null, use either (FileFilter)null
or use this constructor instead.
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, b_ignoreDirs, false, optr_dbg)
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, false, file_filter, optr_dbg)
Create a DSConfig.
Equal to DSConfig(-1, b_ignoreDirs, file_filter, optr_dbg)
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, b_ignoreDirs, b_filesFirst, file_filter, (new Outputter()))
Note: To set file_filter to null, use either (FileFilter)null
or use this constructor instead.
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, b_ignoreDirs, b_filesFirst, null, optr_dbg)
Create a DSConfig.
Equal to DSConfig(-1, b_ignoreDirs, b_filesFirst, file_filter, optr_dbg)
Create a DSConfig.
Equal to DSConfig(i_lvlsMaxDepth, b_ignoreDirs, false, file_filter, optr_dbg)
Create a DSConfig.
@param i_lvlsMaxDepth The maximum number of levels to analyze. May not be less than -1. See getLvlsMaxDepth. @param b_ignoreDirs If true, then directories are suppressed from the resulting Vector. Note that files within those directories are included, as long as the directory is accepted by file_filter. If this is set to true, then b_filesFirst is overwritten to false. See doIgnoreDirs @param b_filesFirst If true, then files are listed before directories. If false, then ordering is as normally provided by File.listFiles. When b_ignoreDirs equals true, this parameter is overwritten to equal false. When b_ignoreDirs equals false andoptr_dbg.isOn()
equals true, the value of this parameter is overwritten to be true. See areFilesFirst
@param file_filter The FileFilter to scan through. See getFileFilter
@param optr_dbg The Outputter to use for debugging output May not be null. When this is on and b_ignoreDirs equals false, then b_filesFirst is overwritten to equal true. See getOptrDbg.
**/
public DSConfig(int i_lvlsMaxDepth, boolean b_ignoreDirs, boolean b_filesFirst, FileFilter file_filter, Outputter optr_dbg) {
if(i_lvlsMaxDepth < -1) {
throwAX("constructor: i_lvlsMaxDepth (" + i_lvlsMaxDepth + ") must be greater than -2.");
}
throwAXIfNull(optr_dbg, "optr_dbg", sCNSTR);
iLvlsMxDpth = i_lvlsMaxDepth;
bIgnoreDirs = b_ignoreDirs;
ff = file_filter;
optrDbg = optr_dbg;
if(b_ignoreDirs) {
bFilesFirst = false;
} else if(optrDbg.isOn()) { //b_ignoreDirs equals false
bFilesFirst = true;
} else {
bFilesFirst = b_filesFirst;
}
}
/**
At a maximum, how many sub-directory levels should be analyzed?.
Given this directory structure, where dir0
is the base directory:
dir0
file01.txt
dir1
file11.txt
dir11
file111.txt
If this function returns... | ...then is this analyzed? | |||||
dir0 |
file01.txt |
dir1 |
file11.txt |
dir111 |
file111.txt |
|
-1 (meaning all) | Yes | Yes | Yes | Yes | Yes | Yes |
0 | Yes | no | no | no | no | no |
1 | Yes | Yes | Yes | no | no | no |
2 | Yes | Yes | Yes | Yes | Yes | no |
3 | Yes | Yes | Yes | Yes | Yes | Yes |
5 | Yes | Yes | Yes | Yes | Yes | Yes |
10 | Yes | Yes | Yes | Yes | Yes | Yes |
Are directories included suppressed from the resulting Vector?. See DirScan.getVector.
Note that files within those directories are included, as long as the directory is accepted by file_filter.
@return b_ignoreDirs exactly as provided to the constructor. **/ public final boolean doIgnoreDirs() { return bIgnoreDirs; } /**Get the base directory.
The reason for listing files first is because it makes the debugging output clear. It is more efficient when this equals false (when files are not listed first).
@return b_filesFirst exactly as provided to the constructor (given the documented exceptions). **/ public final boolean areFilesFirst() { return bFilesFirst; } /**Get the FileFilter scan through.
@return file_filter exactly as provided to the constructor. **/ public final FileFilter getFileFilter() { return ff; } /**Get the Outputter for debugging output.
@return optr_dbg exactly as provided to the constructor. **/ public final Outputter getOptrDbg() { return optrDbg; } /**Get some information about this DSConfig.
**/ public final String toString() { return this.getClass().getName() + ": getLvlsMaxDepth()=" + getLvlsMaxDepth() + ", doIgnoreDirs()=" + doIgnoreDirs() + ", areFilesFirst()=" + areFilesFirst() + ", getFileFilter()=[" + getFileFilter() + "], getOptrDbg()=[" + getOptrDbg() + "]"; } }