Switched Optional logic to ifPresent where appropriate.

This commit is contained in:
neviyn 2016-02-24 14:13:46 +00:00
parent 75f310e140
commit 9073242390
2 changed files with 8 additions and 11 deletions

View File

@ -18,17 +18,14 @@ public class LibraryTreeCellRenderer implements TreeCellRenderer {
@Override @Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Object o = ((DefaultMutableTreeNode) value).getUserObject(); Object o = ((DefaultMutableTreeNode) value).getUserObject();
label.setIcon(null);
if (o != null) {
label.setText(o.toString());
if (o instanceof Album) { if (o instanceof Album) {
Album album = (Album) o; Album album = (Album) o;
if (album.getAlbumArt().isPresent()) album.getAlbumArt().ifPresent(x -> label.setIcon(new ImageIcon(x)));
label.setIcon(new ImageIcon(album.getAlbumArt().get())); }
else {
label.setIcon(null);
} }
} else
label.setIcon(null);
if (o != null)
label.setText(o.toString());
return label; return label;
} }
} }

View File

@ -57,7 +57,7 @@ public final class LibraryUtils {
public static void processSongs(Path rootDirectory) throws IOException { public static void processSongs(Path rootDirectory) throws IOException {
Files.walk(rootDirectory) Files.walk(rootDirectory)
.filter(f -> f.toString().matches(musicFileExtensionRegex)) .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));
} }
/** /**