org.entityfs.util.filter.regexp
Class EntityLocationGlobFilter

java.lang.Object
  extended by org.entityfs.support.filter.AbstractConvenientFilter<EntityView>
      extended by org.entityfs.util.filter.regexp.EntityLocationGlobFilter
All Implemented Interfaces:
Cloneable, EntityFilter, ConvenientFilter<EntityView>, Filter<EntityView>

public class EntityLocationGlobFilter
extends AbstractConvenientFilter<EntityView>
implements EntityFilter

This is a filter that matches an entity's location relative to a base directory against a glob pattern, for instance doc\/*\/*.xml.

This can be used together with EntityNameGlobFilter:s to construct filters matching specific files in a file hierarchy. (Compare this with Apache Ant's include and exclude patterns.) The example below shows an iterator that will return all XML files in all doc catalogs in all non-test projects in an Eclipse workspace.

\/\/ wosRoot is a Directory for the workspace's root directory.
Iterator itr = new FilteringIterator(
  Directories.getDepthLastIterator(
    wosRoot,
    new EntityNameGlobFilter("*_test").and(
      new EntityParentFilter(wosRoot)).not()),
  new EntityLocationGlobFilter(wosRoot,"*\/doc").and(
    new EFileNameExtensionFilter("xml"));
This filter is not very suitable for using as a selection filter in a recursive iterator. It is easier to use it for filtering the results from a recursive iterator in a FilteringIterator instead.

Since:
1.0
Author:
Karl Gustafsson
See Also:
EntityNameGlobFilter
In_jar:
entityfs-util

Constructor Summary
EntityLocationGlobFilter(DirectoryView baseDir, String pattern)
          Create a location glob filter that will compare locations relative to the given base directory.
EntityLocationGlobFilter(DirectoryView baseDir, String pattern, boolean caseSensitive)
          Create a location glob filter that will compare locations relative to the given base directory.
 
Method Summary
 boolean equals(Object o)
           
 int hashCode()
           
 boolean matches(EntityView ev)
          Does the filter match the object?
 String toString()
           
 
Methods inherited from class org.entityfs.support.filter.AbstractConvenientFilter
and, bitwiseNegate, isCase, not, or, xor
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EntityLocationGlobFilter

public EntityLocationGlobFilter(DirectoryView baseDir,
                                String pattern)
                         throws PatternSyntaxException
Create a location glob filter that will compare locations relative to the given base directory. The filter is case sensitive.

Parameters:
baseDir - The base directory
pattern - The glob pattern. Patterns for the different path segments are separated with slashes. See the example above.
Throws:
PatternSyntaxException - On syntax errors in the glob patterns.

EntityLocationGlobFilter

public EntityLocationGlobFilter(DirectoryView baseDir,
                                String pattern,
                                boolean caseSensitive)
                         throws PatternSyntaxException
Create a location glob filter that will compare locations relative to the given base directory.

Parameters:
baseDir - The base directory
pattern - The glob pattern. Patterns for the different path segments are separated with slashes. See the example above.
caseSensitive - Will the filter be case sensitive?
Throws:
PatternSyntaxException - On syntax errors in the glob patterns.
Method Detail

matches

public boolean matches(EntityView ev)
Description copied from interface: Filter
Does the filter match the object?

Specified by:
matches in interface Filter<EntityView>
Parameters:
ev - The object to match.
Returns:
true if the filter matches the object.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object