Skip to content

Commit dcc7bde

Browse files
eunhwa99Reamer
authored andcommitted
[ZEPPELIN-6285] Refactor getNotesInfo to improve readability and immutability
### What is this PR for? This PR refactors the getNotesInfo method in NotebookService to improve readability and enforce immutability. The functional behavior remains unchanged, but the code is now more concise and safer for multi-threaded access. - Use `Comparator.comparing` for cleaner sorting logic - Return an `unmodifiable list` to emphasize immutability - Remove redundant condition for improved readability - Refactored getNotesInfo to use inline return, eliminating intermediate variables. This change is internal-only and does not affect any runtime behavior or public APIs. ### What type of PR is it? Refactoring ### Todos * [ ] - Task ### What is the Jira issue? * [Zeppelin-6285](https://issues.apache.org/jira/browse/ZEPPELIN-6285) ### How should this be tested? * No functional changes; existing tests should pass as-is. ### Screenshots (if appropriate) ### Questions: * Does the license files need to update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Closes #5033 from eunhwa99/ZEPPELIN-6285. Signed-off-by: Philipp Dallig <[email protected]> (cherry picked from commit 934d4e3) Signed-off-by: Philipp Dallig <[email protected]>
1 parent ef00777 commit dcc7bde

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

  • zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook

zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22+
import java.util.Comparator;
2223
import java.util.Date;
2324
import java.util.HashMap;
2425
import java.util.HashSet;
@@ -757,25 +758,13 @@ public List<NoteInfo> getNotesInfo(Predicate<String> func) {
757758
zConf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN_HIDE);
758759

759760
synchronized (noteManager.getNotesInfo()) {
760-
List<NoteInfo> notesInfo = noteManager.getNotesInfo().entrySet().stream().filter(entry ->
761+
762+
return noteManager.getNotesInfo().entrySet().stream().filter(entry ->
761763
func.test(entry.getKey()) &&
762-
((!hideHomeScreenNotebookFromList) ||
763-
((hideHomeScreenNotebookFromList) && !entry.getKey().equals(homescreenNoteId))))
764+
(!hideHomeScreenNotebookFromList || !entry.getKey().equals(homescreenNoteId)))
764765
.map(entry -> new NoteInfo(entry.getKey(), entry.getValue()))
765-
.collect(Collectors.toList());
766-
767-
notesInfo.sort((note1, note2) -> {
768-
String name1 = note1.getId();
769-
if (note1.getPath() != null) {
770-
name1 = note1.getPath();
771-
}
772-
String name2 = note2.getId();
773-
if (note2.getPath() != null) {
774-
name2 = note2.getPath();
775-
}
776-
return name1.compareTo(name2);
777-
});
778-
return notesInfo;
766+
.sorted(Comparator.comparing(note -> note.getPath() != null ? note.getPath() : note.getId()))
767+
.collect(Collectors.toUnmodifiableList());
779768
}
780769
}
781770

0 commit comments

Comments
 (0)