From 0fd78802d3ee78b558108d714314d0117078d105 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 12 Oct 2013 15:44:46 +0200 Subject: [PATCH] Add in-memory implementation of an image and its builder. --- .../sone/database/memory/MemoryImage.java | 53 ++++++++++++++++++++++ .../sone/database/memory/MemoryImageBuilder.java | 48 ++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/database/memory/MemoryImage.java create mode 100644 src/main/java/net/pterodactylus/sone/database/memory/MemoryImageBuilder.java diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryImage.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryImage.java new file mode 100644 index 0000000..a694720 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryImage.java @@ -0,0 +1,53 @@ +/* + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database.memory; + +import net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.data.impl.AbstractImage; + +/** + * In-memory implementation of an {@link Image}. + * + * @author David ‘Bombe’ Roden + */ +public class MemoryImage extends AbstractImage { + + private final MemoryDatabase memoryDatabase; + private final Sone sone; /* TODO - store sone ID only. */ + private final String albumId; + + public MemoryImage(MemoryDatabase memoryDatabase, String id, Sone sone, String albumId, String key, long creationTime, int width, int height) { + super(id, key, creationTime, width, height); + this.memoryDatabase = memoryDatabase; + this.sone = sone; + this.albumId = albumId; + } + + @Override + public Sone getSone() { + return sone; + } + + @Override + public Album getAlbum() { + return memoryDatabase.getAlbum(albumId).get(); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryImageBuilder.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryImageBuilder.java new file mode 100644 index 0000000..cf16416 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryImageBuilder.java @@ -0,0 +1,48 @@ +/* + * Sone - MemoryImageBuilder.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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database.memory; + +import net.pterodactylus.sone.data.Image; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.data.impl.AbstractImageBuilder; +import net.pterodactylus.sone.database.ImageBuilder; + +/** + * {@link ImageBuilder} implementation that creates {@link MemoryImage}s. + * + * @author David ‘Bombe’ Roden + */ +public class MemoryImageBuilder extends AbstractImageBuilder { + + private final MemoryDatabase memoryDatabase; + private final Sone sone; + private final String albumId; + + public MemoryImageBuilder(MemoryDatabase memoryDatabase, Sone sone, String albumId) { + this.memoryDatabase = memoryDatabase; + this.sone = sone; + this.albumId = albumId; + } + + @Override + public Image build() throws IllegalStateException { + validate(); + return new MemoryImage(memoryDatabase, getId(), sone, albumId, key, getCreationTime(), width, height); + } + +} -- 2.7.4