Package com.deltawalker.script
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 Summary
Modifier and TypeMethodDescriptionaddAlignFilter(String expression1, String expression2, boolean regexType, boolean caseSensitive, String applyToFolders, String description) Creates anAlignFilterand adds it to this collection.addAttributeFilter(boolean exclude, Resource.Attribute attrib, FolderFilter.Target target, String description) Creates anAttributeFilterand adds it to this collection.addPathFilter(boolean exclude, FolderFilter.Target target, String expression, boolean regexType, boolean caseSensitive, String description) Creates aPathFilterand adds it to this collection.addSizeFilter(boolean exclude, boolean larger, long size, SizeUnit unit, String description) Creates aSizeFilterand adds it to this collection.addTextFilter(String expression, boolean forLines, String description) Creates aTextFilterand adds it to this collection.addTimeFilter(boolean exclude, FolderFilter.Target target, boolean older, long time, boolean absolute, String description) Creates aTimeFilterand adds it to this collection.get(int index) Returns the filter at the specified 0-based index.Filter[]getAll()Returns all filters in this collection, in order.intgetCount()Returns the number of filters in this collection.intmoveUpDown(Filter filter, boolean moveUp) Moves the specified filter one position up or down in this collection.voidremove(int index) Removes the filter at the specified index from this collection.voidRemoves the specified filter from this collection.
-
Method Details
-
addAlignFilter
AlignFilter addAlignFilter(String expression1, String expression2, boolean regexType, boolean caseSensitive, String applyToFolders, String description) throws PatternSyntaxException Creates anAlignFilterand 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 benullor emptyexpression2- the secondary regular or shell expression, which can refer to groups of the primary one; cannot benullor emptyregexType-truewhenexpression1andexpression2are regular expressions,falsewhen they are shell expressionscaseSensitive-truefor case-sensitive matching,falsefor case-insensitive matchingapplyToFolders- 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; whennullor empty the filter applies to all folders.description- an optional description of the filter; can benull- Returns:
- the new align filter
- Throws:
PatternSyntaxException- ifexpression1orexpression2is not a valid patternNullPointerException- ifexpression1orexpression2isnullIllegalArgumentException- ifexpression1orexpression2is empty- Since:
- 2.0
-
addAttributeFilter
AttributeFilter addAttributeFilter(boolean exclude, Resource.Attribute attrib, FolderFilter.Target target, String description) Creates anAttributeFilterand adds it to this collection. The new filter is applied immediately.- Parameters:
exclude-trueto exclude the resources matched by this filter,falseto include themattrib- theResource.Attributeto match resources by; cannot benulltarget- whether the filter applies to files, folders, or both; cannot benulldescription- an optional description of the filter; can benull- Returns:
- the new attribute filter
- Throws:
NullPointerException- ifattribortargetisnull- Since:
- 2.0
-
addPathFilter
PathFilter addPathFilter(boolean exclude, FolderFilter.Target target, String expression, boolean regexType, boolean caseSensitive, String description) Creates aPathFilterand 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-trueto exclude the resources matched by this filter,falseto include themtarget- whether the filter applies to files, folders, or both; cannot benullexpression- a regular or shell expression; cannot benullor empty. An expression without a path separator is matched against names, one with a separator against paths.regexType-truewhenexpressionis a regular expression,falsewhen it is a shell expressioncaseSensitive-truefor case-sensitive matching,falsefor case-insensitive matchingdescription- an optional description of the filter; can benull- Returns:
- the new path filter
- Throws:
NullPointerException- iftargetorexpressionisnullIllegalArgumentException- ifexpressionis empty- Since:
- 2.0
-
addSizeFilter
SizeFilter addSizeFilter(boolean exclude, boolean larger, long size, SizeUnit unit, String description) Creates aSizeFilterand 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-trueto exclude the files matched by this filter,falseto include themlarger-trueto match files larger thansize,falseto match files that are not largersize- the size to compare files with, inunitsunit- the unit ofsize; cannot benulldescription- an optional description of the filter; can benull- Returns:
- the new size filter
- Throws:
NullPointerException- ifunitisnull- Since:
- 2.0
- See Also:
-
addTextFilter
Creates aTextFilterand 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 benullforLines-trueto treat a whole line as the same when any part of it matchesexpression;falseto ignore only the matching charactersdescription- an optional description of the filter; can benull- Returns:
- the new text filter
- Throws:
NullPointerException- ifexpressionisnullPatternSyntaxException- ifexpressionis 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 aTimeFilterand 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-trueto exclude the resources matched by this filter,falseto include themtarget- whether the filter applies to files, folders, or both; cannot benullolder-trueto match resources modified at or before the time given bytime,falseto match resources modified after ittime- a time in milliseconds, interpreted according toabsoluteabsolute- howtimeis interpreted: whentrue,timeis a point in time, in milliseconds since January 1, 1970, 00:00:00 GMT; whenfalse,timeis a number of milliseconds before the moment the filter is applied. For instance, withabsolutefalseandtime60 * 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 benull- Returns:
- the new time filter
- Throws:
NullPointerException- iftargetisnull- Since:
- 2.0
-
get
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- ifindexis 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
Moves the specified filter one position up or down in this collection.- Parameters:
filter- theFilterto move; cannot benullmoveUp-trueto move up,falseto move down- Returns:
- the new index of the filter, or -1 if its position did not change
- Since:
- 2.0
-
remove
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- ifindexis out of range (index < 0 || index >= getCount())- Since:
- 2.0
-