From 3b711e4ff7898c71778dd3a8695ee3e0e3542861 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 15 Oct 2017 19:13:23 +0200 Subject: [PATCH] Return a nullable Image instead of an Optional --- src/main/java/net/pterodactylus/sone/core/Core.java | 6 +++--- .../net/pterodactylus/sone/database/memory/MemoryDatabase.java | 5 +++-- src/main/kotlin/net/pterodactylus/sone/database/ImageProvider.kt | 2 +- .../pterodactylus/sone/database/memory/MemoryDatabaseTest.java | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 508d167..63c82ed 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -576,9 +576,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, */ @Nullable public Image getImage(String imageId, boolean create) { - Optional image = database.getImage(imageId); - if (image.isPresent()) { - return image.get(); + Image image = database.getImage(imageId); + if (image != null) { + return image; } if (!create) { return null; diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 248592c..79c34d7 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -527,11 +527,12 @@ public class MemoryDatabase extends AbstractService implements Database { // IMAGEPROVIDER METHODS // + @Nullable @Override - public Optional getImage(String imageId) { + public Image getImage(@Nonnull String imageId) { lock.readLock().lock(); try { - return fromNullable(allImages.get(imageId)); + return allImages.get(imageId); } finally { lock.readLock().unlock(); } diff --git a/src/main/kotlin/net/pterodactylus/sone/database/ImageProvider.kt b/src/main/kotlin/net/pterodactylus/sone/database/ImageProvider.kt index 987c52f..c7cc75e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/database/ImageProvider.kt +++ b/src/main/kotlin/net/pterodactylus/sone/database/ImageProvider.kt @@ -26,6 +26,6 @@ import com.google.common.base.Optional */ interface ImageProvider { - fun getImage(imageId: String): Optional + fun getImage(imageId: String): Image? } diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java index daa5e4d..6e66b18 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -198,16 +198,16 @@ public class MemoryDatabaseTest { assertThat(memoryDatabase.getAlbum("album3").get(), isAlbum("album3", "album1", "album3", "album-description3")); assertThat(memoryDatabase.getAlbum("album4").isPresent(), is(false)); - assertThat(memoryDatabase.getImage("image1").get(), + assertThat(memoryDatabase.getImage("image1"), isImage("image1", 1000L, "KSK@image1", "image1", "image-description1", 16, 9)); - assertThat(memoryDatabase.getImage("image2").get(), + assertThat(memoryDatabase.getImage("image2"), isImage("image2", 2000L, "KSK@image2", "image2", "image-description2", 32, 18)); - assertThat(memoryDatabase.getImage("image3").get(), + assertThat(memoryDatabase.getImage("image3"), isImage("image3", 3000L, "KSK@image3", "image3", "image-description3", 48, 27)); - assertThat(memoryDatabase.getImage("image4").isPresent(), is(false)); + assertThat(memoryDatabase.getImage("image4"), nullValue()); } @Test -- 2.7.4