Load an artist’s groups lazily.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 19 Apr 2012 14:11:47 +0000 (16:11 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 19 Apr 2012 14:11:47 +0000 (16:11 +0200)
src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java

index 85f35fa..7e74ea9 100644 (file)
@@ -202,10 +202,31 @@ public class DataManager {
                        }
                });
 
+               private final Memoizer<Void> groupsMemoizer = new Memoizer<Void>(new Callable<Void>() {
+
+                       @Override
+                       public Void call() throws Exception {
+                               if (!hasValue("groups")) {
+                                       value("groups", Collection.class).set(getGroupsByArtist(id()));
+                               }
+                               return null;
+                       }
+
+               });
+
                public LazyArtist(String id) {
                        super(id);
                }
 
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public Collection<Group> groups() {
+                       groupsMemoizer.get();
+                       return super.groups();
+               }
+
                public Collection<Track> tracks() {
                        tracksMemoizer.get();
                        return super.tracks();