Adding limit to comparison.
This commit is contained in:
parent
087df7535e
commit
8ea6990dd5
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package io.github.applecommander.acx.command;
|
package io.github.applecommander.acx.command;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import com.webcodepro.applecommander.storage.Disk;
|
import com.webcodepro.applecommander.storage.Disk;
|
||||||
|
@ -39,6 +40,9 @@ public class CompareCommand extends ReadOnlyDiskImageCommandOptions {
|
||||||
|
|
||||||
@ArgGroup(heading = "%nComparison Strategy Selection:%n")
|
@ArgGroup(heading = "%nComparison Strategy Selection:%n")
|
||||||
private StrategySelection strategySelection = new StrategySelection();
|
private StrategySelection strategySelection = new StrategySelection();
|
||||||
|
|
||||||
|
@Option(names = { "-l", "--limit" }, description = "Set limit to messages displayed.")
|
||||||
|
private Optional<Integer> limit = Optional.empty();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int handleCommand() throws Exception {
|
public int handleCommand() throws Exception {
|
||||||
|
@ -51,8 +55,12 @@ public class CompareCommand extends ReadOnlyDiskImageCommandOptions {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println("The disks do not match.");
|
System.out.println("The disks do not match.");
|
||||||
result.getErrors().forEach(System.out::println);
|
limit.map(result::getLimitedMessages)
|
||||||
result.getWarnings().forEach(System.out::println);
|
.orElseGet(result::getAllMessages)
|
||||||
|
.forEach(System.out::println);
|
||||||
|
if (result.getDifferenceCount() > limit.orElse(Integer.MAX_VALUE)) {
|
||||||
|
System.out.printf("There are %d more messages.\n", result.getDifferenceCount() - limit.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -33,6 +33,17 @@ public class ComparisonResult {
|
||||||
return errors.size() + warnings.size();
|
return errors.size() + warnings.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getAllMessages() {
|
||||||
|
List<String> messages = new ArrayList<>();
|
||||||
|
messages.addAll(errors);
|
||||||
|
messages.addAll(warnings);
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
public List<String> getLimitedMessages(int limit) {
|
||||||
|
List<String> messages = getAllMessages();
|
||||||
|
return messages.subList(0, Math.min(messages.size(), limit));
|
||||||
|
}
|
||||||
|
|
||||||
public void addError(Exception ex) {
|
public void addError(Exception ex) {
|
||||||
errors.add(ex.getMessage());
|
errors.add(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ public abstract class Wizard {
|
||||||
RowData rowData = new RowData();
|
RowData rowData = new RowData();
|
||||||
rowData.width = logo.getImageData().width;
|
rowData.width = logo.getImageData().width;
|
||||||
rowData.height = logo.getImageData().height;
|
rowData.height = logo.getImageData().height;
|
||||||
|
System.out.println(rowData.toString());
|
||||||
imageCanvas = new ImageCanvas(dialog, SWT.BORDER, logo, rowData);
|
imageCanvas = new ImageCanvas(dialog, SWT.BORDER, logo, rowData);
|
||||||
|
|
||||||
// Starting pane
|
// Starting pane
|
||||||
|
|
|
@ -117,8 +117,7 @@ public class CompareDisksResultsPane extends WizardPane {
|
||||||
}
|
}
|
||||||
if (disk1 != null && disk2 != null) {
|
if (disk1 != null && disk2 != null) {
|
||||||
ComparisonResult result = DiskDiff.compare(disk1, disk2);
|
ComparisonResult result = DiskDiff.compare(disk1, disk2);
|
||||||
errorMessages.addAll(result.getErrors());
|
errorMessages.addAll(result.getLimitedMessages(wizard.getMessageLimit()));
|
||||||
errorMessages.addAll(result.getWarnings());
|
|
||||||
}
|
}
|
||||||
if (errorMessages.size() == 0) {
|
if (errorMessages.size() == 0) {
|
||||||
return textBundle.get("CompareDisksResultsPane.DisksMatch"); //$NON-NLS-1$
|
return textBundle.get("CompareDisksResultsPane.DisksMatch"); //$NON-NLS-1$
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.eclipse.swt.events.ModifyEvent;
|
||||||
import org.eclipse.swt.events.ModifyListener;
|
import org.eclipse.swt.events.ModifyListener;
|
||||||
import org.eclipse.swt.events.SelectionAdapter;
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
import org.eclipse.swt.events.SelectionEvent;
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
import org.eclipse.swt.graphics.Color;
|
|
||||||
import org.eclipse.swt.layout.RowData;
|
import org.eclipse.swt.layout.RowData;
|
||||||
import org.eclipse.swt.layout.RowLayout;
|
import org.eclipse.swt.layout.RowLayout;
|
||||||
import org.eclipse.swt.widgets.Button;
|
import org.eclipse.swt.widgets.Button;
|
||||||
|
@ -50,6 +49,7 @@ public class CompareDisksStartPane extends WizardPane {
|
||||||
private CompareDisksWizard wizard;
|
private CompareDisksWizard wizard;
|
||||||
private Text diskname1Text;
|
private Text diskname1Text;
|
||||||
private Text diskname2Text;
|
private Text diskname2Text;
|
||||||
|
private Text limitText;
|
||||||
/**
|
/**
|
||||||
* Constructor for CompareDisksStartPane.
|
* Constructor for CompareDisksStartPane.
|
||||||
*/
|
*/
|
||||||
|
@ -75,6 +75,7 @@ public class CompareDisksStartPane extends WizardPane {
|
||||||
layout.marginTop = 5;
|
layout.marginTop = 5;
|
||||||
layout.spacing = 3;
|
layout.spacing = 3;
|
||||||
control.setLayout(layout);
|
control.setLayout(layout);
|
||||||
|
|
||||||
Label label = new Label(control, SWT.WRAP);
|
Label label = new Label(control, SWT.WRAP);
|
||||||
label.setText(textBundle.get("CompareDisksStartPane.Description")); //$NON-NLS-1$
|
label.setText(textBundle.get("CompareDisksStartPane.Description")); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -84,7 +85,6 @@ public class CompareDisksStartPane extends WizardPane {
|
||||||
diskname1Text = new Text(control, SWT.WRAP | SWT.BORDER);
|
diskname1Text = new Text(control, SWT.WRAP | SWT.BORDER);
|
||||||
if (wizard.getDiskname1() != null) diskname1Text.setText(wizard.getDiskname1());
|
if (wizard.getDiskname1() != null) diskname1Text.setText(wizard.getDiskname1());
|
||||||
diskname1Text.setLayoutData(new RowData(300, -1));
|
diskname1Text.setLayoutData(new RowData(300, -1));
|
||||||
diskname1Text.setBackground(new Color(control.getDisplay(), 255,255,255));
|
|
||||||
diskname1Text.setFocus();
|
diskname1Text.setFocus();
|
||||||
diskname1Text.addModifyListener(new ModifyListener() {
|
diskname1Text.addModifyListener(new ModifyListener() {
|
||||||
public void modifyText(ModifyEvent event) {
|
public void modifyText(ModifyEvent event) {
|
||||||
|
@ -113,7 +113,6 @@ public class CompareDisksStartPane extends WizardPane {
|
||||||
diskname2Text = new Text(control, SWT.WRAP | SWT.BORDER);
|
diskname2Text = new Text(control, SWT.WRAP | SWT.BORDER);
|
||||||
if (wizard.getDiskname2() != null) diskname2Text.setText(wizard.getDiskname2());
|
if (wizard.getDiskname2() != null) diskname2Text.setText(wizard.getDiskname2());
|
||||||
diskname2Text.setLayoutData(new RowData(300, -1));
|
diskname2Text.setLayoutData(new RowData(300, -1));
|
||||||
diskname2Text.setBackground(new Color(control.getDisplay(), 255,255,255));
|
|
||||||
diskname2Text.addModifyListener(new ModifyListener() {
|
diskname2Text.addModifyListener(new ModifyListener() {
|
||||||
public void modifyText(ModifyEvent event) {
|
public void modifyText(ModifyEvent event) {
|
||||||
Text text = (Text) event.getSource();
|
Text text = (Text) event.getSource();
|
||||||
|
@ -134,6 +133,16 @@ public class CompareDisksStartPane extends WizardPane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
label = new Label(control, SWT.WRAP);
|
||||||
|
label.setText("Set limit on messages displayed:");
|
||||||
|
|
||||||
|
limitText = new Text(control, SWT.WRAP | SWT.BORDER);
|
||||||
|
limitText.setText(Integer.toString(wizard.getMessageLimit()));
|
||||||
|
limitText.setLayoutData(new RowData(200, -1));
|
||||||
|
limitText.addModifyListener(this::limitTextModifyListener);
|
||||||
|
|
||||||
|
parent.pack();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the next pane. A null return indicates the end of the wizard.
|
* Get the next pane. A null return indicates the end of the wizard.
|
||||||
|
@ -166,4 +175,12 @@ public class CompareDisksStartPane extends WizardPane {
|
||||||
return textBundle.format("CompareDisksStartPane.DiskNLabel", //$NON-NLS-1$
|
return textBundle.format("CompareDisksStartPane.DiskNLabel", //$NON-NLS-1$
|
||||||
diskNumber);
|
diskNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void limitTextModifyListener(ModifyEvent event) {
|
||||||
|
try {
|
||||||
|
wizard.setMessageLimit(Integer.parseInt(limitText.getText()));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
limitText.setText(Integer.toString(wizard.getMessageLimit()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import com.webcodepro.applecommander.ui.swt.wizard.WizardPane;
|
||||||
public class CompareDisksWizard extends Wizard {
|
public class CompareDisksWizard extends Wizard {
|
||||||
private String diskname1;
|
private String diskname1;
|
||||||
private String diskname2;
|
private String diskname2;
|
||||||
|
private int messageLimit = 10;
|
||||||
/**
|
/**
|
||||||
* Constructor for ExportWizard.
|
* Constructor for ExportWizard.
|
||||||
*/
|
*/
|
||||||
|
@ -54,11 +55,16 @@ public class CompareDisksWizard extends Wizard {
|
||||||
public String getDiskname2() {
|
public String getDiskname2() {
|
||||||
return diskname2;
|
return diskname2;
|
||||||
}
|
}
|
||||||
|
public int getMessageLimit() {
|
||||||
|
return messageLimit;
|
||||||
|
}
|
||||||
public void setDiskname1(String string) {
|
public void setDiskname1(String string) {
|
||||||
diskname1 = string;
|
diskname1 = string;
|
||||||
}
|
}
|
||||||
public void setDiskname2(String string) {
|
public void setDiskname2(String string) {
|
||||||
diskname2 = string;
|
diskname2 = string;
|
||||||
}
|
}
|
||||||
|
public void setMessageLimit(int messageLimit) {
|
||||||
|
this.messageLimit = messageLimit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue