This is an automated email from the ASF dual-hosted git repository. pdallig pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new 934d4e36b1 [ZEPPELIN-6285] Refactor getNotesInfo to improve readability and immutability 934d4e36b1 is described below commit 934d4e36b14c58d93df7653123dc15ab192d3712 Author: eunhwa99 <68810660+eunhw...@users.noreply.github.com> AuthorDate: Fri Aug 22 22:47:34 2025 +0900 [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 <philipp.dal...@gmail.com> --- .../org/apache/zeppelin/notebook/Notebook.java | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index e8b92b3cc1..713cc79322 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -19,6 +19,7 @@ package org.apache.zeppelin.notebook; import java.io.IOException; import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -757,25 +758,13 @@ public class Notebook { zConf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN_HIDE); synchronized (noteManager.getNotesInfo()) { - List<NoteInfo> notesInfo = noteManager.getNotesInfo().entrySet().stream().filter(entry -> + + return noteManager.getNotesInfo().entrySet().stream().filter(entry -> func.test(entry.getKey()) && - ((!hideHomeScreenNotebookFromList) || - ((hideHomeScreenNotebookFromList) && !entry.getKey().equals(homescreenNoteId)))) + (!hideHomeScreenNotebookFromList || !entry.getKey().equals(homescreenNoteId))) .map(entry -> new NoteInfo(entry.getKey(), entry.getValue())) - .collect(Collectors.toList()); - - notesInfo.sort((note1, note2) -> { - String name1 = note1.getId(); - if (note1.getPath() != null) { - name1 = note1.getPath(); - } - String name2 = note2.getId(); - if (note2.getPath() != null) { - name2 = note2.getPath(); - } - return name1.compareTo(name2); - }); - return notesInfo; + .sorted(Comparator.comparing(note -> note.getPath() != null ? note.getPath() : note.getId())) + .collect(Collectors.toUnmodifiableList()); } }