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

improve find entry #1915

Merged
merged 4 commits into from
Sep 5, 2016
Merged

improve find entry #1915

merged 4 commits into from
Sep 5, 2016

Conversation

chriba
Copy link
Contributor

@chriba chriba commented Sep 3, 2016

I imroved the findEntry-method some more. Now it always finds the correct Entry (by searching it with the id and not with the canonical representation.

Steps to reproduce a situation in which the problem occurs

  • have multiple duplicates in a database
  • search them and open the results in the extra window
  • select one of the duplicates in the extra window but the first
  • in the main window always the first of the duplicates is selected


public int findLastEntry(BibEntry entry) {
return model.getTableRows().lastIndexOf(entry);
EventList<BibEntry> tableRows = model.getTableRows();
Copy link
Member

@Siedlerchr Siedlerchr Sep 3, 2016

Choose a reason for hiding this comment

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

This can be replaced a combination of stream,filter and findFirst
sth like : tableRows.stream().filter(bibEntry->bibEntry.getId().equals(entry.getId()).findFirst()

And it has the advantage to return an optional which is way better to return a -1 value. Returning 1 comes from the old times of programming where everything >0 was indicating succes and negative things like -1 indicated errors. (Unfortunately I just can't find a source explaining it, but it is not considered good practice returning -1 nowadays if no element is found or error happend)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to find the position of the given entry in the model.
With the statement you described you would get an Optional of an Entry.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, you are right. Currently there is no real good solution to return the index. :(

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in this particular case it is fine to use an "old school" for loop. But please rename i to row.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -19,6 +19,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- [#1897](https://github.com/JabRef/jabref/issues/1897) Implemented integrity check for `year` field: Last four nonpunctuation characters should be numerals

### Fixed
- Fixed selecting an entry out of multiple duplicates
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add it at the end of the section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I try not to do that b/c then I have to rebase after nearly each merged PR.

@boceckts
Copy link
Contributor

boceckts commented Sep 4, 2016

Very small comments by my side, otherwise it looks good to me 👍

EventList<BibEntry> tableRows = model.getTableRows();
for (int row = 0; row < tableRows.size(); row++) {
BibEntry bibEntry = tableRows.get(row);
if (entry.getId().equals(bibEntry.getId())) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that the ID is used to compare the entries (because I hope that we can get rid of the ID completely at some point). Does if (entry == bibentry) work?

Copy link
Contributor Author

@chriba chriba Sep 4, 2016

Choose a reason for hiding this comment

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

works & done

@boceckts boceckts added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 4, 2016
@koppor
Copy link
Member

koppor commented Sep 5, 2016

LGTM

@koppor koppor merged commit 5dcc05a into JabRef:master Sep 5, 2016
@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 5, 2016
@chriba chriba deleted the improveFindEntry branch September 5, 2016 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants