From b91729004b50c2d56ace556ffca3bff396917b39 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 17 Aug 2016 16:01:49 +0100 Subject: [PATCH] No longer unnecessarily storing search value. --- src/main/java/musicplayer/library/JTreeLibrary.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/musicplayer/library/JTreeLibrary.java b/src/main/java/musicplayer/library/JTreeLibrary.java index 872b84c..f6b9bff 100644 --- a/src/main/java/musicplayer/library/JTreeLibrary.java +++ b/src/main/java/musicplayer/library/JTreeLibrary.java @@ -37,7 +37,6 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt private final JXTextField librarySearchField = new JXTextField(); final JTree libraryTree = new JTree(); private final Map libraryDisplayVariants = createDisplayVariantMap(); - private String filterValue = ""; /** * @return Map of display types for the library paired code to populate the library with data in the correct format. @@ -72,10 +71,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt } }); librarySearchField.setPrompt("Search... (Press Enter)"); - librarySearchField.addActionListener(e ->{ - filterValue = librarySearchField.getText(); - refreshLibrary(); - }); + librarySearchField.addActionListener(e -> refreshLibrary()); JPanel otherContainer = new JPanel(); otherContainer.setLayout(new BoxLayout(otherContainer, BoxLayout.PAGE_AXIS)); @@ -117,7 +113,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt dbQuery.ifPresent(x -> { DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode()); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot(); - List x1 = x.parallelStream().filter(song -> song.getTitle().contains(filterValue)).collect(Collectors.toList()); + List x1 = x.parallelStream().filter(song -> song.getTitle().contains(librarySearchField.getText())).collect(Collectors.toList()); Collections.sort(x1); x1.forEach(y -> addNodeToTreeModel(model, parentNode, new DefaultMutableTreeNode(y))); libraryTree.setModel(model); @@ -139,7 +135,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot(); Collections.sort(x); x.forEach(y -> { - List filteredSongs = y.getSongs().parallelStream().filter(song -> song.getTitle().contains(filterValue)).collect(Collectors.toList()); + List filteredSongs = y.getSongs().parallelStream().filter(song -> song.getTitle().contains(librarySearchField.getText())).collect(Collectors.toList()); if(!filteredSongs.isEmpty()) { DefaultMutableTreeNode outerNode = new DefaultMutableTreeNode(y); addNodeToTreeModel(model, parentNode, outerNode); @@ -241,7 +237,7 @@ public class JTreeLibrary extends JPanel implements ILibrary, LibraryCallbackInt playlist.addSong((Song) selectedItem); } else if (selectedItem instanceof HasSongs) { ((HasSongs) selectedItem).getSongs().stream().filter(song -> song.getTitle().contains - (filterValue)).forEach(playlist::addSong); + (librarySearchField.getText())).forEach(playlist::addSong); } } } catch (NullPointerException ignored) {