Skip to content
Draft
Show file tree
Hide file tree
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
@@ -1,7 +1,5 @@
package org.jabref.gui.preferences.entry;

import java.util.function.UnaryOperator;

import javafx.css.PseudoClass;
import javafx.fxml.FXML;
import javafx.scene.Node;
Expand All @@ -10,7 +8,6 @@
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.input.KeyCode;

import org.jabref.gui.actions.ActionFactory;
Expand Down Expand Up @@ -57,15 +54,15 @@ public void initialize() {
keywordSeparator.textProperty().bindBidirectional(viewModel.keywordSeparatorProperty());

// Use TextFormatter to limit the length of the Input of keywordSeparator to 1 character only.
UnaryOperator<TextFormatter.Change> singleCharacterFilter = change -> {
if (change.getControlNewText().length() <= 1) {
return change;
}
return null; // null means the change is rejected
};
TextFormatter<String> formatter = new TextFormatter<>(singleCharacterFilter);

keywordSeparator.setTextFormatter(formatter);
// UnaryOperator<TextFormatter.Change> singleCharacterFilter = change -> {
// if (change.getControlNewText().length() <= 1) {
// return change;
// }
// return null; // null means the change is rejected
// };
// TextFormatter<String> formatter = new TextFormatter<>(singleCharacterFilter);

// keywordSeparator.setTextFormatter(formatter);

resolveStrings.selectedProperty().bindBidirectional(viewModel.resolveStringsProperty());

Expand Down
25 changes: 25 additions & 0 deletions jablib/src/main/java/org/jabref/model/entry/KeywordList.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ public static KeywordList parse(String keywordString, Character delimiter, Chara
return keywordList;
}

public static KeywordList parseMultipleDelimiter(String keywordString, String delimiter, Character hierarchicalDelimiter) {
if (StringUtil.isBlank(keywordString)) {
return new KeywordList();
}

Objects.requireNonNull(delimiter);
Objects.requireNonNull(hierarchicalDelimiter);

KeywordList keywordList = new KeywordList();
for (char d:delimiter.toCharArray()) {
keywordString = keywordString.replace(d, ',');
}
Comment on lines +74 to +76
Copy link

Choose a reason for hiding this comment

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

String mutation in loop is inefficient. Using StringBuilder or StringJoiner would be more performant for string manipulations.

StringTokenizer tok = new StringTokenizer(keywordString, ",");
while (tok.hasMoreTokens()) {
String chain = tok.nextToken();
Keyword chainRoot = Keyword.of(chain.split(hierarchicalDelimiter.toString()));
keywordList.add(chainRoot);
}
return keywordList;
}

/**
* Parses the keyword list and uses {@link Keyword#DEFAULT_HIERARCHICAL_DELIMITER} as hierarchical delimiter.
*
Expand All @@ -73,6 +94,10 @@ public static KeywordList parse(String keywordString, Character delimiter) {
return parse(keywordString, delimiter, Keyword.DEFAULT_HIERARCHICAL_DELIMITER);
}

public static KeywordList parseMultipleDelimeter(String keywordString, String delimiter) {
Copy link

Choose a reason for hiding this comment

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

Method name contains a spelling error ('Delimeter' instead of 'Delimiter'), which violates consistent and correct naming conventions in the codebase.

return parseMultipleDelimiter(keywordString, delimiter, Keyword.DEFAULT_HIERARCHICAL_DELIMITER);
}

public static String serialize(List<Keyword> keywords, Character delimiter) {
return keywords.stream().map(Keyword::get).collect(Collectors.joining(delimiter.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ void mergeTwoDistinctKeywordsShouldReturnTheTwoKeywordsMerged() {
void mergeTwoListsOfKeywordsShouldReturnTheKeywordsMerged() {
assertEquals(new KeywordList("Figma", "Adobe", "JabRef", "Eclipse", "JetBrains"), KeywordList.merge("Figma, Adobe, JetBrains, Eclipse", "Adobe, JabRef", ','));
}

@Test
void parseMultipleDelimiter() {
assertEquals(new KeywordList("keywordOne", "keywordTwo", "keywordThree"),
KeywordList.parseMultipleDelimeter("keywordOne; keywordTwo: keywordThree", ";:"));
Copy link

Choose a reason for hiding this comment

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

Method name contains a typo ('Delimeter' instead of 'Delimiter'), which violates the requirement for correctly spelled variable and method names.

}
}
Loading