Switched Optional logic to ifPresent where appropriate.
This commit is contained in:
parent
75f310e140
commit
9073242390
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user