Interface Filters


public interface Filters
An ordered collection of Filters, obtained with Settings.filters(Comparison.Type). The filters of a comparison's settings apply to that comparison only; the filters of the application settings, App.getSettings(), are the defaults for new comparisons.

Folder comparisons use path, attribute, size, time and align filters; text comparisons use text filters. The add...Filter() methods create an enabled filter, add it at the end of the collection unless an equal filter is already present, and apply it immediately.


 const Comparison = Java.type('com.deltawalker.script.Comparison');
 const FolderFilter = Java.type('com.deltawalker.script.FolderFilter');

 await comp.compare();
 const filters = comp.getSettings().filters(Comparison.Type.FOLDER);
 const filter = filters.addPathFilter(true, FolderFilter.Target.FILES, '*.js',
         false, false, 'Exclude all JavaScript files');
 console.log('Nodes after filtering: ' + comp.getDeltaCount());
 filters.remove(filter);
 
  • Method Details

    • addAlignFilter

      AlignFilter addAlignFilter(String expression1, String expression2, boolean regexType, boolean caseSensitive, String applyToFolders, String description) throws PatternSyntaxException
      Creates an AlignFilter and adds it to this collection. An align filter lets a folder comparison match files and folders whose names differ, using a primary and a secondary expression. The new filter is applied immediately.
      Parameters:
      expression1 - the primary regular or shell expression; cannot be null or empty
      expression2 - the secondary regular or shell expression, which can refer to groups of the primary one; cannot be null or empty
      regexType - true when expression1 and expression2 are regular expressions, false when they are shell expressions
      caseSensitive - true for case-sensitive matching, false for case-insensitive matching
      applyToFolders - the folders this filter applies to, as shell expressions separated by the platform path separator - ':' on macOS and Linux, ';' on Windows. Align filters can be CPU-intensive, so it is good practice to limit them to the folders that need them. Optional; when null or empty the filter applies to all folders.
      description - an optional description of the filter; can be null
      Returns:
      the new align filter
      Throws:
      PatternSyntaxException - if expression1 or expression2 is not a valid pattern
      NullPointerException - if expression1 or expression2 is null
      IllegalArgumentException - if expression1 or expression2 is empty
      Since:
      2.0
    • addAttributeFilter

      AttributeFilter addAttributeFilter(boolean exclude, Resource.Attribute attrib, FolderFilter.Target target, String description)
      Creates an AttributeFilter and adds it to this collection. The new filter is applied immediately.
      Parameters:
      exclude - true to exclude the resources matched by this filter, false to include them
      attrib - the Resource.Attribute to match resources by; cannot be null
      target - whether the filter applies to files, folders, or both; cannot be null
      description - an optional description of the filter; can be null
      Returns:
      the new attribute filter
      Throws:
      NullPointerException - if attrib or target is null
      Since:
      2.0
    • addPathFilter

      PathFilter addPathFilter(boolean exclude, FolderFilter.Target target, String expression, boolean regexType, boolean caseSensitive, String description)
      Creates a PathFilter and adds it to this collection. A path filter matches files and folders by name or path. The new filter is applied immediately.
      
       // Exclude all .log files
       filters.addPathFilter(true, FolderFilter.Target.FILES, '*.log', false, false, null);
       
      Parameters:
      exclude - true to exclude the resources matched by this filter, false to include them
      target - whether the filter applies to files, folders, or both; cannot be null
      expression - a regular or shell expression; cannot be null or empty. An expression without a path separator is matched against names, one with a separator against paths.
      regexType - true when expression is a regular expression, false when it is a shell expression
      caseSensitive - true for case-sensitive matching, false for case-insensitive matching
      description - an optional description of the filter; can be null
      Returns:
      the new path filter
      Throws:
      NullPointerException - if target or expression is null
      IllegalArgumentException - if expression is empty
      Since:
      2.0
    • addSizeFilter

      SizeFilter addSizeFilter(boolean exclude, boolean larger, long size, SizeUnit unit, String description)
      Creates a SizeFilter and adds it to this collection. Size filters apply to files only. The new filter is applied immediately.
      
       const SizeUnit = Java.type('com.deltawalker.script.SizeUnit');
      
       // Exclude files larger than 100 MB
       filters.addSizeFilter(true, true, 100, SizeUnit.MBYTES, null);
       
      Parameters:
      exclude - true to exclude the files matched by this filter, false to include them
      larger - true to match files larger than size, false to match files that are not larger
      size - the size to compare files with, in units
      unit - the unit of size; cannot be null
      description - an optional description of the filter; can be null
      Returns:
      the new size filter
      Throws:
      NullPointerException - if unit is null
      Since:
      2.0
      See Also:
    • addTextFilter

      TextFilter addTextFilter(String expression, boolean forLines, String description)
      Creates a TextFilter and adds it to this collection. A text filter makes a text comparison ignore the text matched by a regular expression. The new filter is applied immediately.
      
       // Ignore lines that start with '#'
       const filters = comp.getSettings().filters(Comparison.Type.TEXT);
       filters.addTextFilter('^#.*', true, 'Ignore comment lines');
       
      Parameters:
      expression - a regular expression; cannot be null
      forLines - true to treat a whole line as the same when any part of it matches expression; false to ignore only the matching characters
      description - an optional description of the filter; can be null
      Returns:
      the new text filter
      Throws:
      NullPointerException - if expression is null
      PatternSyntaxException - if expression is not a valid regular expression
      Since:
      2.0
    • addTimeFilter

      TimeFilter addTimeFilter(boolean exclude, FolderFilter.Target target, boolean older, long time, boolean absolute, String description)
      Creates a TimeFilter and adds it to this collection. A time filter matches files and folders by their last-modified time. The new filter is applied immediately.
      
       // Exclude files modified more than 7 days ago
       filters.addTimeFilter(true, FolderFilter.Target.FILES, true,
               7 * 24 * 60 * 60 * 1000, false, null);
       
      Parameters:
      exclude - true to exclude the resources matched by this filter, false to include them
      target - whether the filter applies to files, folders, or both; cannot be null
      older - true to match resources modified at or before the time given by time, false to match resources modified after it
      time - a time in milliseconds, interpreted according to absolute
      absolute - how time is interpreted: when true, time is a point in time, in milliseconds since January 1, 1970, 00:00:00 GMT; when false, time is a number of milliseconds before the moment the filter is applied. For instance, with absolute false and time 60 * 60 * 1000 (1 hour), the filter matches resources modified more, or less, than an hour before it is applied.
      description - an optional description of the filter; can be null
      Returns:
      the new time filter
      Throws:
      NullPointerException - if target is null
      Since:
      2.0
    • get

      Filter get(int index) throws IndexOutOfBoundsException
      Returns the filter at the specified 0-based index.
      Parameters:
      index - the 0-based index of the filter
      Returns:
      the filter at the specified index
      Throws:
      IndexOutOfBoundsException - if index is out of range
      Since:
      2.0
    • getAll

      Filter[] getAll()
      Returns all filters in this collection, in order.
      Returns:
      an array of zero or more filters; never null
      Since:
      2.0
    • getCount

      int getCount()
      Returns the number of filters in this collection.
      Returns:
      the number of filters
      Since:
      2.0
    • moveUpDown

      int moveUpDown(Filter filter, boolean moveUp)
      Moves the specified filter one position up or down in this collection.
      Parameters:
      filter - the Filter to move; cannot be null
      moveUp - true to move up, false to move down
      Returns:
      the new index of the filter, or -1 if its position did not change
      Since:
      2.0
    • remove

      void remove(Filter filter)
      Removes the specified filter from this collection. Has no effect if the filter is not in the collection.
      Parameters:
      filter - the filter to remove
      Since:
      2.0
    • remove

      void remove(int index)
      Removes the filter at the specified index from this collection.
      Parameters:
      index - the 0-based index of the filter to remove
      Throws:
      IndexOutOfBoundsException - if index is out of range (index < 0 || index >= getCount())
      Since:
      2.0