X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FDefaultImage.java;h=445fa6bc861616590a9ef32179ee09172c9bee0a;hb=7fb49938b9198110c34bcc600c545bfa91acf6f2;hp=26f635522ba1181de5013ed45f1e91a9d60b4781;hpb=31a732a2e18008ea65a31a4e8180c337458b2df9;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultImage.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultImage.java index 26f6355..445fa6b 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultImage.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultImage.java @@ -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 @@ -17,26 +17,27 @@ package net.pterodactylus.sone.data.impl; -import static com.google.common.collect.FluentIterable.from; - 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 David ‘Bombe’ Roden */ 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 @@ -46,32 +47,22 @@ public class DefaultImage extends AbstractImage { @Override public Album getAlbum() { - return album; + return database.getAlbum(albumId).get(); } @Override public void moveUp() throws IllegalStateException { - int oldIndex = album.imageIds.indexOf(getId()); - album.imageIds.remove(getId()); - album.imageIds.add(Math.max(0, oldIndex - 1), getId()); + database.moveUp(this); } @Override public void moveDown() throws IllegalStateException { - int oldIndex = album.imageIds.indexOf(getId()); - album.imageIds.remove(getId()); - album.imageIds.add(Math.min(album.imageIds.size(), oldIndex + 1), getId()); + database.moveDown(this); } @Override public void remove() throws IllegalStateException { - synchronized (album) { - album.images.remove(getId()); - album.imageIds.remove(getId()); - if (getId().equals(album.albumImage)) { - album.albumImage = from(album.images.values()).transform(GET_ID).first().orNull(); - } - } + database.removeImage(this); } }