Interface Comparisons
App.getComparisons().
const Comparison = Java.type('com.deltawalker.script.Comparison');
const comps = App.getComparisons();
const IN = App.getProperty('user.home') + '/test/samples';
// Two-way folder comparison
const folders = comps.create(Comparison.Type.FOLDER, [IN + '/f0', IN + '/f1'], null);
// Three-way text comparison; the last path is the common base (Role.REF)
const texts = comps.create(Comparison.Type.TEXT,
[IN + '/q1.txt', IN + '/q2.txt', IN + '/q0.txt'], null);
await Promise.all([folders.compare(), texts.compare()]);
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptioncreate(Comparison.Type type, String[] paths, ComparisonListener listener) Creates a comparison of the specifiedComparison.Typefor the specified paths and opens it in a DeltaWalker window or view.createEx(Comparison.Type type, UriInfo[] uriInfos, ComparisonListener listener) Likecreate(Comparison.Type, String[], ComparisonListener), but takesUriInfoobjects instead of plain paths.createFromHistory(Object id, ComparisonListener listener) Creates a comparison from the comparison history: a comparison of the same type and over the same resources as the history entry with the specified ID.createFromReport(String path, ComparisonListener listener) Opens a comparison from aReportKind.JSONsnapshot file, as created byFolderComparison.report(String, ReportKind, PatchFormat, Role[]).Looks up a comparison by its ID and opens it.getAll()Returns all comparisons that are currently open in DeltaWalker, whether they were created by a script or in the UI.intgetCount()Returns the number of comparisons known to DeltaWalker, including history entries that are not currently open.Returns the comparison history: an entry for every comparison known to DeltaWalker, open or not.booleanRemoves the comparison with the specified ID from the comparison history.
-
Method Details
-
create
Creates a comparison of the specifiedComparison.Typefor the specified paths and opens it in a DeltaWalker window or view. The comparison itself runs whenComparison.compare()is called.The number of paths determines whether this is a two-way or a three-way comparison, and their order determines the
Roleof each resource:- Two paths:
paths[0]isRole.REFandpaths[1]isRole.ONE. - Three paths:
paths[0]isRole.ONE,paths[1]isRole.TWOandpaths[2], the common base, isRole.REF. - One path: the path is
Role.REF; the other side is left empty.
The returned object is a
FolderComparison,TextComparisonorImageComparison, depending ontype. Comparisons hold system resources, so close them withComparison.close()when they are no longer needed.const comp = App.getComparisons().create(Comparison.Type.TEXT, ['/path/to/file-a.txt', '/path/to/file-b.txt'], null); await comp.compare();- Parameters:
type- the type of comparison to create; cannot benullpaths- the paths of the resources to compare, at most three. Whennullor empty, an empty comparison of the specifiedtypeis created.listener- an optional, legacyComparisonListenerto register on the new comparison; new scripts passnulland useawaitinstead- Returns:
- the newly created comparison; never
null - Throws:
NullPointerException- iftypeisnullIllegalArgumentException- ifpathshas more than 3 elements- Since:
- 2.0
- Two paths:
-
createEx
Likecreate(Comparison.Type, String[], ComparisonListener), but takesUriInfoobjects instead of plain paths.A
UriInfocarries additional information about a resource, such as the user name and password of a remote (S)FTP(S) server, or the character encoding and line ending of a text file. The order of the elements determines theirRoles exactly as increate(). The following is based onfolder-compare-remote.js, one of the samples that ship with DeltaWalker:const Comparison = Java.type('com.deltawalker.script.Comparison'); const UriInfo = Java.type('com.deltawalker.script.UriInfo'); // A folder on an FTP server and a local folder const remote = new UriInfo('ftp://speedtest.tele2.net/'); const local = new UriInfo(App.getProperty('user.home') + '/test/samples/f0'); // For SFTP: new UriInfo('sftp://host', {username: 'user', password: 'pass'}) const comp = App.getComparisons().createEx(Comparison.Type.FOLDER, [remote, local], null); await comp.compare();- Parameters:
type- the type of comparison to create; cannot benulluriInfos- the resources to compare. Only the first three elements are used; any further elements are ignored. Whennullor empty, an empty comparison of the specifiedtypeis created.listener- an optional, legacyComparisonListenerto register on the new comparison; new scripts passnulland useawaitinstead- Returns:
- the newly created comparison; never
null - Throws:
NullPointerException- iftypeisnullIllegalArgumentException- if aUriInfohas a property name that is not supported- Since:
- 2.0
-
createFromHistory
Creates a comparison from the comparison history: a comparison of the same type and over the same resources as the history entry with the specified ID. Seeget(Object)for how the ID is matched.- Parameters:
id- the ID - creation time or name - of theHistoryEntryto create the comparison fromlistener- an optional, legacyComparisonListenerto register on the new comparison; can benull- Returns:
- the newly created comparison, or
nullif no history entry matchesid - Throws:
NullPointerException- ifidisnullIllegalArgumentException- ifidis an empty string- Since:
- 2.0
-
createFromReport
Opens a comparison from aReportKind.JSONsnapshot file, as created byFolderComparison.report(String, ReportKind, PatchFormat, Role[]). Only JSON snapshots are supported.- Parameters:
path- the full path of the snapshot filelistener- ignored; passnull- Returns:
- the comparison opened from the snapshot, or
nullif the snapshot could not be opened - Since:
- 2.1.0
-
get
Looks up a comparison by its ID and opens it. The ID is either a creation time or a name:- a number is matched against the creation time in milliseconds since
January 1, 1970, 00:00:00 GMT (see
HistoryEntry.getCreationTime()); - a string is first matched against the creation time as shown in the
UI (see
HistoryEntry.getDisplayCreationTime()) and then against the comparison name (seeHistoryEntry.getName()).
All comparisons known to DeltaWalker are searched, including history entries that are not currently open. The matching entry is opened as a comparison of the same type over the same resources, and that comparison is returned; it is not necessarily the same object as the one originally created. To enumerate the comparisons that are currently open, use
getAll().- Parameters:
id- the ID - creation time or name - of the comparison to get- Returns:
- the matching comparison, or
nullif no comparison matchesid - Throws:
NullPointerException- ifidisnullIllegalArgumentException- ifidis an empty string- Since:
- 2.0
- See Also:
- a number is matched against the creation time in milliseconds since
January 1, 1970, 00:00:00 GMT (see
-
getAll
Comparison[] getAll()Returns all comparisons that are currently open in DeltaWalker, whether they were created by a script or in the UI.- Returns:
- an array with zero or more comparisons; never
null - Since:
- 2.0
-
getCount
int getCount()Returns the number of comparisons known to DeltaWalker, including history entries that are not currently open. The result can therefore be larger than the length ofgetAll().- Returns:
- the number of comparisons
- Since:
- 2.0
-
getHistory
HistoryEntry[] getHistory()Returns the comparison history: an entry for every comparison known to DeltaWalker, open or not.- Returns:
- an array with zero or more history entries; never
null - See Also:
-
removeFromHistory
Removes the comparison with the specified ID from the comparison history. Seeget(Object)for how the ID is matched.- Parameters:
id- the ID - creation time or name - of the comparison to remove- Returns:
trueif a comparison with the specified ID was found and removed,falseotherwise- Throws:
NullPointerException- ifidisnullIllegalArgumentException- ifidis an empty string- Since:
- 2.0
- See Also:
-