Remove copy method from post builder.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / DefaultImage.java
index 54e6495..445fa6b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -20,21 +20,24 @@ package net.pterodactylus.sone.data.impl;
 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
@@ -44,7 +47,22 @@ public class DefaultImage extends AbstractImage {
 
        @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);
        }
 
 }