/*
- * Sone - DefaultImage.java - Copyright © 2013 David Roden
+ * Sone - MemoryImage.java - Copyright © 2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.Database;
/**
- * Dumb, store-everything-in-memory implementation of an {@link Image}.
+ * {@link Image} implementation that uses a {@link Database}.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public class DefaultImage extends AbstractImage {
- private final Sone sone;
- private final DefaultAlbum album;
+ private final Database database;
+ private final Sone sone; /* TODO - store sone ID only. */
+ private final String albumId;
- public DefaultImage(String id, Sone sone, DefaultAlbum album, String key, long creationTime, int width, int height) {
+ public DefaultImage(Database database, String id, Sone sone, String albumId, String key, long creationTime, int width, int height) {
super(id, key, creationTime, width, height);
+ this.database = database;
this.sone = sone;
- this.album = album;
+ this.albumId = albumId;
}
@Override
@Override
public Album getAlbum() {
- return album;
+ return database.getAlbum(albumId).get();
+ }
+
+ @Override
+ public void moveUp() throws IllegalStateException {
+ database.moveUp(this);
+ }
+
+ @Override
+ public void moveDown() throws IllegalStateException {
+ database.moveDown(this);
+ }
+
+ @Override
+ public void remove() throws IllegalStateException {
+ database.removeImage(this);
}
}