Interface Comparison
- All Superinterfaces:
HistoryEntry
- All Known Subinterfaces:
FileComparison,FolderComparison,ImageComparison,TextComparison
Comparisons are created with Comparisons.create(Comparison.Type, String[], ComparisonListener). Each comparison opens in its own DeltaWalker
window or view; the actual comparison runs when compare() is
called. The object returned by create() is a
FolderComparison, a TextComparison or an
ImageComparison, depending on the requested Comparison.Type, so the
methods of those types can be called on it directly.
const Comparison = Java.type('com.deltawalker.script.Comparison');
const IN = App.getProperty('user.home') + '/test/samples';
const comp = App.getComparisons().create(Comparison.Type.FOLDER,
[IN + '/f0', IN + '/f1'], null);
await comp.compare();
if (comp.hasDifferences()) {
console.log('Nodes: ' + comp.getDeltaCount());
}
comp.close();
A comparison runs one long-running operation (compare, merge, sync, report or print) at a time. Starting another one while an operation is still pending on the same comparison fails with a rejected operation.
- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe individual comparison methods - by size, date, attributes, as text, and byte by byte.static enumThe states reported to aComparisonListenerthroughComparisonEvent.getState().static enumThe supported types of comparison. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ComparisonListener listener) Adds aComparisonListenerthat is notified of theComparisonEvents of this comparison.voidclose()Closes the window or view showing this comparison, without saving changes.compare()Compares the resources this comparison was created with, and returns a promise that settles when the comparison completes.booleanAnswers whether the lastcompare()found any differences between the resources of this comparison.booleanisClosed()Answers whether this comparison has been closed, by the user or byclose(), and aComparison.State.CLOSEDevent delivered.print()Prints this comparison to a printer or a PDF file using the application'sPrinterSettingsandPageSettings, and returns a promise that settles when printing completes.voidremoveListener(ComparisonListener listener) Removes a listener previously added withaddListener(ComparisonListener).Methods inherited from interface com.deltawalker.script.HistoryEntry
getCreationTime, getDisplayCreationTime, getName, getPaths, getRoles, getSettings, getType, getUriInfos, setName
-
Method Details
-
addListener
Adds aComparisonListenerthat is notified of theComparisonEvents of this comparison.Listeners are a legacy mechanism; new scripts should
awaitthe operation they are interested in instead.Adding the same, or an equal, listener more than once has no effect. To remove a listener use
removeListener(ComparisonListener).- Parameters:
listener- the listener to add; cannot benull- Throws:
NullPointerException- iflistenerisnull- Since:
- 2.0
- See Also:
-
close
void close()Closes the window or view showing this comparison, without saving changes. Comparisons hold system resources - the bigger they are, the more - so it is good practice to close comparisons that are no longer needed.The window is closed asynchronously. Once it is closed,
isClosed()returnstrue, any pending operation is cancelled, and the comparison should no longer be used.- Since:
- 2.0
-
compare
Compares the resources this comparison was created with, and returns a promise that settles when the comparison completes. The work starts immediately;awaitthe result before reading comparison results.const op = comp.compare(); console.log('Comparison running...'); await op; console.log('Differences found: ' + comp.hasDifferences());The returned promise is a native JavaScript
Promise: it can be awaited more than once and used inPromise.all(). It is rejected if another operation is already pending on this comparison, and cancelled (seeScriptCancellationError) if the comparison is closed before it completes.- Returns:
- a promise that resolves when the comparison completes
- Throws:
IOException- declared for compatibility; failures are reported by rejecting the returned promise- Since:
- 2.0
-
hasDifferences
boolean hasDifferences()Answers whether the lastcompare()found any differences between the resources of this comparison.To analyze the differences use
TextComparison.getAllDeltas()orFolderComparison.getAllDeltas(). For image comparisons this method currently always returnsfalse.- Returns:
trueif the resources are different,falseif they are the same- Since:
- 2.0
- See Also:
-
print
Object print()Prints this comparison to a printer or a PDF file using the application'sPrinterSettingsandPageSettings, and returns a promise that settles when printing completes.const PageOrientation = Java.type('com.deltawalker.script.PageOrientation'); const settings = App.getSettings(); settings.getPage().setOrientation(PageOrientation.LANDSCAPE); // Printing to a PDF file is available on macOS only settings.getPrinter().setPrintToFile(true); settings.getPrinter().setFilePath(App.getProperty('user.home') + '/comparison.pdf'); await comp.print();Like the promise returned by
compare(), the returned promise is a native JavaScriptPromisethat can be awaited more than once.- Returns:
- a promise that resolves when printing completes
- Since:
- 2.0
-
isClosed
boolean isClosed()Answers whether this comparison has been closed, by the user or byclose(), and aComparison.State.CLOSEDevent delivered.A closed comparison cannot run further operations such as compare, merge, sync, report or print. Once this method returns
trueit never returnsfalseagain.- Returns:
trueif this comparison has been closed,falseotherwise- Since:
- 3.0
-
removeListener
Removes a listener previously added withaddListener(ComparisonListener). Has no effect if the listener is not registered.- Parameters:
listener- the listener to remove; cannot benull- Throws:
NullPointerException- iflistenerisnull- Since:
- 2.0
-