From 9073242390d34873a5ff213b4bb4a39d39787456 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 24 Feb 2016 14:13:46 +0000 Subject: [PATCH] Switched Optional logic to ifPresent where appropriate. --- .../musicplayer/LibraryTreeCellRenderer.java | 17 +++++++---------- src/main/java/musicplayer/LibraryUtils.java | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/musicplayer/LibraryTreeCellRenderer.java b/src/main/java/musicplayer/LibraryTreeCellRenderer.java index 74310d4..381ebb3 100644 --- a/src/main/java/musicplayer/LibraryTreeCellRenderer.java +++ b/src/main/java/musicplayer/LibraryTreeCellRenderer.java @@ -18,17 +18,14 @@ public class LibraryTreeCellRenderer implements TreeCellRenderer { @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Object o = ((DefaultMutableTreeNode) value).getUserObject(); - if (o instanceof Album) { - Album album = (Album) o; - if (album.getAlbumArt().isPresent()) - label.setIcon(new ImageIcon(album.getAlbumArt().get())); - else { - label.setIcon(null); - } - } else - label.setIcon(null); - if (o != null) + label.setIcon(null); + if (o != null) { label.setText(o.toString()); + if (o instanceof Album) { + Album album = (Album) o; + album.getAlbumArt().ifPresent(x -> label.setIcon(new ImageIcon(x))); + } + } return label; } } diff --git a/src/main/java/musicplayer/LibraryUtils.java b/src/main/java/musicplayer/LibraryUtils.java index 7e4ccdd..5028959 100644 --- a/src/main/java/musicplayer/LibraryUtils.java +++ b/src/main/java/musicplayer/LibraryUtils.java @@ -57,7 +57,7 @@ public final class LibraryUtils { public static void processSongs(Path rootDirectory) throws IOException { Files.walk(rootDirectory) .filter(f -> f.toString().matches(musicFileExtensionRegex)) - .map(LibraryUtils::autoParse).filter(Optional::isPresent).map(Optional::get).forEach(Gateway::addSong); + .map(LibraryUtils::autoParse).forEach(x -> x.ifPresent(Gateway::addSong)); } /**