-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat:Allowed multiple delimiter in keyword separator field. #13706
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
base: main
Are you sure you want to change the base?
Changes from all commits
27f97b5
88fe7f7
729e2dc
37bd7e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, ','); | ||
} | ||
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. | ||
* | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", ";:")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} |
There was a problem hiding this comment.
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.