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

Implemented title and camel key modifiers #1894

Merged
merged 9 commits into from
Sep 25, 2016
Merged

Implemented title and camel key modifiers #1894

merged 9 commits into from
Sep 25, 2016

Conversation

oscargus
Copy link
Contributor

Implemented #1506

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)


### Fixed
- Fixed NullPointerException when opening search result window for an untitled database
- Fixed #1757: Crash after saving illegal argument in entry editor
- Fixed[#1663](https://github.com/JabRef/jabref/issues/1663): Better multi-monitor support
Copy link
Member

Choose a reason for hiding this comment

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

Space after fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you hear that @stefan-kolb ;-)

Copy link
Member

Choose a reason for hiding this comment

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

What?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Siedlerchr
Copy link
Member

LGTM, just some misisng space in the changelog 👍

@Test
public void generateKeyTitleTitle() {
preferences = new BibtexKeyPatternPreferences("", "", false, true, false, pattern);
DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(pattern);
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 it makes sense to move preferences = ...; DatabaseBibtexKeyPattern bibtexKeyPattern = ... and metadata.setBibtexKeyPattern(bibtexKeyPattern); BibEntry entry = new BibEntry(); entry.setField("title",...)
to the setup method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The preferences are different for different tests. There is a standard preferences in setUp, but in this case it is not the standard preferences. Adding set methods which are only used in the tests doesn't seem worthwhile to me.

Regarding entries, yes, one could have one in the preferences with some standard content, and edit as required in the tests.

(This also holds for your similar comment in the other PR, although I noted I used the standard preferences in some test and still redefined them...)

@tobiasdiez tobiasdiez removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 31, 2016
@oscargus oscargus added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 31, 2016
@@ -16,6 +17,11 @@ public Title(String title) {
this.words.addAll(new TitleParser().parse(title));
}

public List<Word> getWordsReadOnly() {
Copy link
Member

Choose a reason for hiding this comment

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

Why not immediately replace getWords with getWordsReadOnly, i.e. just have getWords return Collections.unmodifiableList(words); and skip the introduction of getWordsReadOnly? From what I see this should not break the existing implementations.

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 think it will break it... See @tobiasdiez comment above. The thing is that forEach(Word::toUpperFirst) actually modifies the Title object, which it can't (I think) if Collections.unmodifiableList(words); is returned. On the other hand, I do not really see the use case of Title unless one is allowed to modify the content.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I get it. The real problem is that the Word objects are mutable, less that the list is.

However, that means that you can still return Collections.unmodifiableList(words) and execute forEach(Word::toUpperFirst). The unmodifiableList only ensures that the structure of the list will not change (and your lambda does not change it), the objects contained therein can still be modified (which is ugly, but anyway...). Therefore, I would ask you to implement my suggestion and skip the deprecated getter.

Copy link
Member

Choose a reason for hiding this comment

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

And please add at least a comment in Word that this class should be rewritten to be not mutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I'll add immutable getWords as default and add a comment. On the other hand it is quite convenient that Word mutable. Somehow the whole Title class depends on it as the toString() method really wouldn't make sense if you cannot change any Word in Title. You would just get the same string that you entered and there is no way to convert a stream to a new Title at the moment.

@tobiasdiez tobiasdiez removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 8, 2016
@oscargus
Copy link
Contributor Author

Added lower_case, upper_case, sentence_case, capitalize, and title_case modifiers (the two first are just additional names).

Unmodifiable return from Title.getWords() but the function of the modifier rely heavily on mutable Word.

@oscargus oscargus added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 16, 2016
@@ -46,9 +47,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Entries in the SearchResultDialog are now converted to Unicode
- Suggestions in the autocomplete (search) are now in Unicode
- Fixed NullPointerException when opening search result window for an untitled database
- Fixed entry table traversal with Tab (no column traversal thus no double jump)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops...

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

Just some small remarks about the code. Can be merged afterwards.

resultingLabel = resultingLabel.toLowerCase(Locale.ENGLISH);
} else if ("upper".equals(modifier)) {
resultingLabel = resultingLabel.toUpperCase(Locale.ENGLISH);
if ("lower".equals(modifier) || lowerCaseFormatter.getKey().equals(modifier)) {
Copy link
Member

Choose a reason for hiding this comment

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

Please refactor the code a bit: first convert the modifier to the corresponding formatter Formatter getFormatterForModifier(string modifier) and then apply it to the label.


@Test
public void generateKeyTitleCapitalize() {
DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(pattern);
Copy link
Member

Choose a reason for hiding this comment

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

The lines DatabaseBibtexKeyPattern bibtexKeyPattern = ... and metadata.setBibtexKeyPattern(bibtexKeyPattern); can be extracted to the setup method.

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

koppor commented Sep 21, 2016

@oscargus Could you follow up so that we can merge?

@tobiasdiez
Copy link
Member

tobiasdiez commented Sep 23, 2016

@koppor / @oscargus pls also move metadata.setBibtexKeyPattern(bibtexKeyPattern); to the setup method

# Conflicts:
#	src/test/java/net/sf/jabref/logic/bibtexkeypattern/MakeLabelWithDatabaseTest.java
...and also all DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(pattern);
@koppor
Copy link
Member

koppor commented Sep 25, 2016

@tobiasdiez Sorry for overlooking your second move comment. I also created Formatters.getFormatterForModifier. Hope, this is good to go now.

The tests are locally OK. The failing test is unrelated to the update.

@tobiasdiez
Copy link
Member

Yes, looks good now. Thanks @koppor for finishing this PR 😄

@tobiasdiez tobiasdiez merged commit adf226f into master Sep 25, 2016
@tobiasdiez tobiasdiez deleted the implement1506 branch September 25, 2016 08:31
Siedlerchr added a commit that referenced this pull request Sep 25, 2016
* upstream/master:
  Implemented Integrity NoBibtexFieldChecker (#2059)
  Implemented title and camel key modifiers (#1894)
  Fix localization task hints (#2031)
  Result of syncLang.py update
  Result of syncLang.py update (with manual correction of captial_letters, and The_BibTeX_entry...)
  Fix "large capitals" to "capital letters"
  Updated Menu_tr.properties (#2057)
  Updated jabref_tr.properties (#2056)
  fix ignore version (#2055)
  Towards hierarchical keywords (#1950)
  Fix failing test, replace \uxxx encoded chars with proper UTF8 chars.
  Import Italian patch
zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
* Implemented title and camel key modifiers

* Fixed comments

* Added more modifiers

* Move bibtexKeyPattern to constructor

* Move metadata.setBibtexKeyPattern(bibtexKeyPattern); to @before

...and also all DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(pattern);

* Introduce Formatters.getFormatterForModifier(String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants