From 442daa4c3aafcc8398ab52e7e475f3c28c5e7caa Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 19 Apr 2012 16:11:47 +0200 Subject: [PATCH] =?utf8?q?Load=20an=20artist=E2=80=99s=20groups=20lazily.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../demoscenemusic/data/DataManager.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index 85f35fa..7e74ea9 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -202,10 +202,31 @@ public class DataManager { } }); + private final Memoizer groupsMemoizer = new Memoizer(new Callable() { + + @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 groups() { + groupsMemoizer.get(); + return super.groups(); + } + public Collection tracks() { tracksMemoizer.get(); return super.tracks(); -- 2.7.4