From: David ‘Bombe’ Roden Date: Thu, 19 Apr 2012 14:55:01 +0000 (+0200) Subject: Add lazy track implementation and creator. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=72b624fa52cc839f22e8133288d858bc5c2e2196;p=demoscenemusic.git Add lazy track implementation and creator. --- 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