From 72b624fa52cc839f22e8133288d858bc5c2e2196 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:55:01 +0200 Subject: [PATCH] Add lazy track implementation and creator. --- .../demoscenemusic/data/DataManager.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java index e595121..5523bbe 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/data/DataManager.java @@ -50,6 +50,7 @@ public class DataManager { private final ObjectCreator artistCreator = new ArtistCreator(); private final ObjectCreator groupCreator = new GroupCreator(); + private final ObjectCreator trackCreator = new TrackCreator(); private final Database database; @@ -285,4 +286,57 @@ public class DataManager { } + private class LazyTrack extends DefaultTrack { + + private final Memoizer artistsMemoizer = new Memoizer(new Callable() { + + @Override + public Void call() throws Exception { + if (!hasValue("artists")) { + value("artists", List.class).set(getArtistsByTrack(id())); + } + return null; + } + + }); + + /** + * @param id + */ + public LazyTrack(String id) { + super(id); + } + + /** + * {@inheritDoc} + */ + @Override + public List artists() { + artistsMemoizer.get(); + return super.artists(); + } + + /** + * {@inheritDoc} + */ + @Override + public Collection