Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3994 Duplicate unmodifiable list for sorting #3996

Merged
merged 1 commit into from
Apr 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@
import org.slf4j.LoggerFactory;

public class ExportToClipboardAction extends AbstractWorker {

private static final Logger LOGGER = LoggerFactory.getLogger(ExportToClipboardAction.class);

private final JabRefFrame frame;

/**
* written by run() and read by update()
*/
// written by run() and read by update()
private String message;


public ExportToClipboardAction(JabRefFrame frame) {
this.frame = Objects.requireNonNull(frame);
}
Expand All @@ -55,9 +51,8 @@ public void run() {
return;
}

List<Exporter> exporters = Globals.exportFactory.getExporters();
exporters.sort(Comparator.comparing(Exporter::getDisplayName));
List<String> exportFormatDisplayNames = exporters.stream().map(Exporter::getDisplayName).collect(Collectors.toList());
List<Exporter> sortedExporters = Globals.exportFactory.getExporters().stream().sorted(Comparator.comparing(Exporter::getDisplayName)).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can improve this a bit, if you return here only the stream, and reuse it for the displayName. Is more efficent then adding it to a list and iterating that list again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the list in line 70?! Once the Stream is terminated I cannot reuse it.

List<String> exportFormatDisplayNames = sortedExporters.stream().map(Exporter::getDisplayName).collect(Collectors.toList());

JList<String> list = new JList<>(exportFormatDisplayNames.toArray(new String[exportFormatDisplayNames.size()]));
list.setBorder(BorderFactory.createEtchedBorder());
Expand All @@ -72,7 +67,7 @@ public void run() {
return;
}

Exporter exporter = exporters.get(list.getSelectedIndex());
Exporter exporter = sortedExporters.get(list.getSelectedIndex());

// Set the global variable for this database's file directory before exporting,
// so formatters can resolve linked files correctly.
Expand Down