org.jutil.io.fileset
Class FileSet

java.lang.Object
  |
  +--org.jutil.io.fileset.FileSet

public class FileSet
extends java.lang.Object

A class of objects that represent a set of files.

A FileSet represents a set of files which satisfy certain criteria. In order for a file to be included, it must satisfy at least one include criterium, and may not satify any exclude criteria.

A criterium consists of a FileSetPredicate, which may have additional criteria embedded in itself. The FileSetPredicate is necessary in order to be able to provide an efficient way for calculating all the files in a FileSet.

This class was inspired by the fileset from Ant.


Inner Class Summary
 class FileSet.FileVisitor
          A class of Visitors that operate on files, and can additionally perform a visit on all elements in its FileSet.
 
Constructor Summary
FileSet()
          Initialize a new FileSet with includes all files. Since the logical or of 0 predicates is false, the new FileSet will initially be empty.
 
Method Summary
 boolean contains(java.io.File file)
          Check whether or not the given file is in this FileSet.
 void exclude(FileSetPredicate predicate)
          Exclude files for which the given filset predicate evaluates to true from this FileSet.
 Or excludePredicate()
          Return the predicate which should evaluate to true for a file in order to be excluded in this FileSet. If you modify the predicates in the returned Or, the behavior of this FileSet will also change because we cannot perform a deep clone without forcing all predicates to implement clone(), which is too much of a burden.
 java.util.Set getFiles()
          Return the files in this FileSet.
 void include(FileSetPredicate predicate)
          Include files for which the given fileset predicate evaluates to true in this FileSet.
 Or includePredicate()
          Return the predicate which should evaluate to true for a file in order to be included in this FileSet. If you modify the predicates in the returned Or, the behavior of this FileSet will also change because we cannot perform a deep clone without forcing all predicates to implement clone(), which is too much of a burden.
static void main(java.lang.String[] args)
           
 void removeExclude(FileSetPredicate predicate)
          Remove the given predicate from the exclude criteria of this FileSet.
 void removeInclude(FileSetPredicate predicate)
          Remove the given predicate from the include criteria of this FileSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSet

public FileSet()

Initialize a new FileSet with includes all files.

Since the logical or of 0 predicates is false, the new FileSet will initially be empty.

Specifications:
public behavior
ensures includePredicate().nbSubPredicates() == 0;
ensures excludePredicate().nbSubPredicates() == 0;
Method Detail

getFiles

public java.util.Set getFiles()
                       throws java.lang.Exception
Return the files in this FileSet.

Specifications:
public behavior
ensures \result != null;
ensures \fresh(\result );
ensures ( \forall Object o; Collections.containsExplicitly(\result ,o); (o instanceof File)&&contains((File)o));
ensures ( \forall File f; contains(f); Collections.containsExplicitly(\result ,f));

include

public void include(FileSetPredicate predicate)

Include files for which the given fileset predicate evaluates to true in this FileSet.

Parameters:
predicate - The predicate that must be added to the include criteria of this FileSet.

Specifications:
public behavior
requires predicate != null;
ensures includePredicate().nbSubPredicates() == \old(includePredicate().nbSubPredicates())+1;
ensures includePredicate().predicateAt(includePredicate().nbSubPredicates()) == predicate;

exclude

public void exclude(FileSetPredicate predicate)

Exclude files for which the given filset predicate evaluates to true from this FileSet.

Parameters:
predicate - The predicate that must be added to the exclude criteria of this FileSet.

Specifications:
public behavior
requires predicate != null;
ensures excludePredicate().nbSubPredicates() == \old(excludePredicate().nbSubPredicates())+1;
ensures excludePredicate().predicateAt(excludePredicate().nbSubPredicates()) == predicate;

removeInclude

public void removeInclude(FileSetPredicate predicate)

Remove the given predicate from the include criteria of this FileSet.

Parameters:
predicate - The predicate to remove from the include criteria

Specifications:
public behavior
ensures ( \forall int i; i > 0&&i < \old(includePredicate().nbSubPredicates()); \old(includePredicate().predicateAt(i)) != predicate ==> (\old(includePredicate().predicateAt(i)) == includePredicate().predicateAt(i-(int)( \num_of int j; j > 0&&j < i; \old(includePredicate().predicateAt(j)) == predicate))));
ensures includePredicate().nbSubPredicates() == \old(includePredicate().nbSubPredicates())-( \num_of int i; i > 0&&i <= \old(includePredicate().nbSubPredicates()); \old(includePredicate().predicateAt(i)) == predicate);

removeExclude

public void removeExclude(FileSetPredicate predicate)

Remove the given predicate from the exclude criteria of this FileSet.

Parameters:
predicate - The predicate to remove from the exclude criteria

Specifications:
public behavior
ensures ( \forall int i; i > 0&&i < \old(excludePredicate().nbSubPredicates()); \old(excludePredicate().predicateAt(i)) != predicate ==> (\old(excludePredicate().predicateAt(i)) == excludePredicate().predicateAt(i-(int)( \num_of int j; j > 0&&j < i; \old(excludePredicate().predicateAt(j)) == predicate))));
ensures excludePredicate().nbSubPredicates() == \old(excludePredicate().nbSubPredicates())-( \num_of int i; i > 0&&i <= \old(excludePredicate().nbSubPredicates()); \old(excludePredicate().predicateAt(i)) == predicate);

contains

public boolean contains(java.io.File file)
                 throws java.lang.Exception
Check whether or not the given file is in this FileSet.

Parameters:
file - To file to be checked.

Specifications:
public behavior
ensures \result == includePredicate().eval(file)&&!excludePredicate().eval(file);

includePredicate

public Or includePredicate()

Return the predicate which should evaluate to true for a file in order to be included in this FileSet.

If you modify the predicates in the returned Or, the behavior of this FileSet will also change because we cannot perform a deep clone without forcing all predicates to implement clone(), which is too much of a burden. Modifying the result itself does not affect this FileSet.

Specifications:
public behavior
ensures \result != null;
ensures \fresh(\result );
ensures ( \forall int i; i > 0&&i <= \result .nbSubPredicates(); \result .predicateAt(i) instanceof FileSetPredicate);

excludePredicate

public Or excludePredicate()

Return the predicate which should evaluate to true for a file in order to be excluded in this FileSet.

If you modify the predicates in the returned Or, the behavior of this FileSet will also change because we cannot perform a deep clone without forcing all predicates to implement clone(), which is too much of a burden. Modifying the result itself does not affect this FileSet.

Specifications:
public behavior
ensures \result != null;
ensures \fresh(\result );
ensures ( \forall int i; i > 0&&i <= \result .nbSubPredicates(); \result .predicateAt(i) instanceof FileSetPredicate);

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception