🚚 Rename Album helper file
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 18 Feb 2020 15:57:00 +0000 (16:57 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 18 Feb 2020 15:57:18 +0000 (16:57 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
src/main/java/net/pterodactylus/sone/data/impl/SoneImpl.java
src/main/kotlin/net/pterodactylus/sone/data/Album.kt [new file with mode: 0644]
src/main/kotlin/net/pterodactylus/sone/data/Albums.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/data/AlbumTest.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt [deleted file]

index e186e6f..c4cc9cf 100644 (file)
@@ -24,7 +24,7 @@ import static com.google.common.primitives.Longs.tryParse;
 import static java.lang.String.format;
 import static java.util.logging.Level.WARNING;
 import static java.util.logging.Logger.getLogger;
-import static net.pterodactylus.sone.data.AlbumsKt.getAllImages;
+import static net.pterodactylus.sone.data.AlbumKt.getAllImages;
 
 import java.util.ArrayList;
 import java.util.Collection;
index e74c98d..651b62e 100644 (file)
@@ -40,7 +40,7 @@ import net.pterodactylus.sone.core.event.InsertionDelayChangedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertingEvent;
-import net.pterodactylus.sone.data.AlbumsKt;
+import net.pterodactylus.sone.data.AlbumKt;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
@@ -312,7 +312,7 @@ public class SoneInserter extends AbstractService {
                        soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies()));
                        soneProperties.put("likedPostIds", new HashSet<>(sone.getLikedPostIds()));
                        soneProperties.put("likedReplyIds", new HashSet<>(sone.getLikedReplyIds()));
-                       soneProperties.put("albums", SoneKt.getAllAlbums(sone).stream().filter(AlbumsKt.notEmpty()::invoke).collect(toList()));
+                       soneProperties.put("albums", SoneKt.getAllAlbums(sone).stream().filter(AlbumKt.notEmpty()::invoke).collect(toList()));
                        manifestCreator = new ManifestCreator(core, soneProperties);
                }
 
index 87bd7a6..8f5a50f 100644 (file)
@@ -37,7 +37,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.data.AlbumsKt;
+import net.pterodactylus.sone.data.AlbumKt;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
@@ -650,7 +650,7 @@ public class SoneImpl implements Sone {
 
                hash.putString("Albums(", UTF_8);
                for (Album album : rootAlbum.getAlbums()) {
-                       if (!AlbumsKt.notEmpty().invoke(album)) {
+                       if (!AlbumKt.notEmpty().invoke(album)) {
                                continue;
                        }
                        hash.putString(album.getFingerprint(), UTF_8);
diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Album.kt b/src/main/kotlin/net/pterodactylus/sone/data/Album.kt
new file mode 100644 (file)
index 0000000..991c0ec
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Sone - Album.kt - Copyright Â© 2019–2020 David â€˜Bombe’ 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.data
+
+/** Returns all images contained in this album and all its albums. */
+val Album.allImages: Collection<Image>
+       get() =
+               images + albums.flatMap(Album::allImages)
+
+/**
+ *  Returns this album and all albums contained in this album (recursively).
+ * A child album is always listed after its parent.
+ */
+val Album.allAlbums: List<Album>
+       get() =
+               listOf(this) + albums.flatMap(Album::allAlbums)
+
+@get:JvmName("notEmpty")
+val notEmpty: (Album) -> Boolean = { album ->
+       album.allImages.let { images ->
+               images.isNotEmpty() && images.any(Image::isInserted)
+       }
+}
diff --git a/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt b/src/main/kotlin/net/pterodactylus/sone/data/Albums.kt
deleted file mode 100644 (file)
index a38e9dd..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Sone - Albums.kt - Copyright Â© 2019–2020 David â€˜Bombe’ 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data
-
-/** Returns all images contained in this album and all its albums. */
-val Album.allImages: Collection<Image>
-       get() =
-               images + albums.flatMap(Album::allImages)
-
-/**
- *  Returns this album and all albums contained in this album (recursively).
- * A child album is always listed after its parent.
- */
-val Album.allAlbums: List<Album>
-       get() =
-               listOf(this) + albums.flatMap(Album::allAlbums)
-
-@get:JvmName("notEmpty")
-val notEmpty: (Album) -> Boolean = { album ->
-       album.allImages.let { images ->
-               images.isNotEmpty() && images.any(Image::isInserted)
-       }
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/data/AlbumTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/AlbumTest.kt
new file mode 100644 (file)
index 0000000..fe11c2c
--- /dev/null
@@ -0,0 +1,136 @@
+/**
+ * Sone - AlbumTest.kt - Copyright Â© 2019–2020 David â€˜Bombe’ 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.data
+
+import net.pterodactylus.sone.data.impl.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import kotlin.test.*
+
+/**
+ * Unit test for various helper method in `Album.kt`.
+ */
+class AlbumTest {
+
+       @Test
+       fun `recursive list of all images for album is returned correctly`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               val firstNestedAlbum = AlbumImpl(sone)
+               val secondNestedAlbum = AlbumImpl(sone)
+               firstNestedAlbum.addImage(createImage(sone, "image-1"))
+               firstNestedAlbum.addImage(createImage(sone, "image-2"))
+               secondNestedAlbum.addImage(createImage(sone, "image-3"))
+               album.addImage(createImage(sone, "image-4"))
+               album.addAlbum(firstNestedAlbum)
+               album.addAlbum(secondNestedAlbum)
+               val images = album.allImages
+               assertThat(images.map(Image::id), containsInAnyOrder("image-1", "image-2", "image-3", "image-4"))
+       }
+
+       private fun createImage(sone: IdOnlySone, id: String, key: String? = null) = ImageImpl(id).modify().setSone(sone).setKey(key).update()
+
+       @Test
+       fun `allAlbums returns itself and all its subalbums`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               val firstNestedAlbum = AlbumImpl(sone)
+               val secondNestedAlbum = AlbumImpl(sone)
+               val albumNestedInFirst = AlbumImpl(sone)
+               album.addAlbum(firstNestedAlbum)
+               album.addAlbum(secondNestedAlbum)
+               firstNestedAlbum.addAlbum(albumNestedInFirst)
+               val albums = album.allAlbums
+               assertThat(albums, containsInAnyOrder<Album>(album, firstNestedAlbum, secondNestedAlbum, albumNestedInFirst))
+               assertThat(albums.indexOf(firstNestedAlbum), greaterThan(albums.indexOf(album)))
+               assertThat(albums.indexOf(secondNestedAlbum), greaterThan(albums.indexOf(album)))
+               assertThat(albums.indexOf(albumNestedInFirst), greaterThan(albums.indexOf(firstNestedAlbum)))
+       }
+
+       @Test
+       fun `notEmpty finds album without images is empty`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               assertThat(notEmpty(album), equalTo(false))
+       }
+
+       @Test
+       fun `notEmpty finds album with one inserted image is not empty`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               album.addImage(createImage(sone, "1", "key"))
+               assertThat(notEmpty(album), equalTo(true))
+       }
+
+       @Test
+       fun `notEmpty finds album with one not-inserted image is empty`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               album.addImage(createImage(sone, "1"))
+               assertThat(notEmpty(album), equalTo(false))
+       }
+
+       @Test
+       fun `notEmpty finds album with empty subalbums is empty`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               val firstNestedAlbum = AlbumImpl(sone)
+               album.addAlbum(firstNestedAlbum)
+               assertThat(notEmpty(album), equalTo(false))
+       }
+
+       @Test
+       fun `notEmpty finds album with subalbum with not inserted image is empty`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               val firstNestedAlbum = AlbumImpl(sone)
+               firstNestedAlbum.addImage(createImage(sone, "1"))
+               album.addAlbum(firstNestedAlbum)
+               assertThat(notEmpty(album), equalTo(false))
+       }
+
+       @Test
+       fun `notEmpty finds album with subalbum with inserted image is not empty`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               val firstNestedAlbum = AlbumImpl(sone)
+               firstNestedAlbum.addImage(createImage(sone, "1", "key"))
+               album.addAlbum(firstNestedAlbum)
+               assertThat(notEmpty(album), equalTo(true))
+       }
+
+       @Test
+       fun `allImages returns images from album`() {
+               val sone = IdOnlySone("sone")
+               val album = AlbumImpl(sone)
+               val image1 = createImage(sone, "1").also(album::addImage)
+               val image2 = createImage(sone, "2").also(album::addImage)
+               assertThat(album.allImages, contains(image1, image2))
+       }
+
+       @Test
+       fun `allImages returns images from subalbum`() {
+               val sone = IdOnlySone("sone")
+               val album1 = AlbumImpl(sone)
+               val album2 = AlbumImpl(sone).also(album1::addAlbum)
+               val image1 = createImage(sone, "1").also(album1::addImage)
+               val image2 = createImage(sone, "2").also(album2::addImage)
+               assertThat(album1.allImages, contains(image1, image2))
+       }
+
+}
diff --git a/src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt b/src/test/kotlin/net/pterodactylus/sone/data/AlbumsTest.kt
deleted file mode 100644 (file)
index 6821a24..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * Sone - AlbumsTest.kt - Copyright Â© 2019–2020 David â€˜Bombe’ 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data
-
-import net.pterodactylus.sone.data.impl.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import kotlin.test.*
-
-/**
- * Unit test for various helper method in `Albums.kt`.
- */
-class AlbumsTest {
-
-       @Test
-       fun `recursive list of all images for album is returned correctly`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               val firstNestedAlbum = AlbumImpl(sone)
-               val secondNestedAlbum = AlbumImpl(sone)
-               firstNestedAlbum.addImage(createImage(sone, "image-1"))
-               firstNestedAlbum.addImage(createImage(sone, "image-2"))
-               secondNestedAlbum.addImage(createImage(sone, "image-3"))
-               album.addImage(createImage(sone, "image-4"))
-               album.addAlbum(firstNestedAlbum)
-               album.addAlbum(secondNestedAlbum)
-               val images = album.allImages
-               assertThat(images.map(Image::id), containsInAnyOrder("image-1", "image-2", "image-3", "image-4"))
-       }
-
-       private fun createImage(sone: IdOnlySone, id: String, key: String? = null) = ImageImpl(id).modify().setSone(sone).setKey(key).update()
-
-       @Test
-       fun `allAlbums returns itself and all its subalbums`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               val firstNestedAlbum = AlbumImpl(sone)
-               val secondNestedAlbum = AlbumImpl(sone)
-               val albumNestedInFirst = AlbumImpl(sone)
-               album.addAlbum(firstNestedAlbum)
-               album.addAlbum(secondNestedAlbum)
-               firstNestedAlbum.addAlbum(albumNestedInFirst)
-               val albums = album.allAlbums
-               assertThat(albums, containsInAnyOrder<Album>(album, firstNestedAlbum, secondNestedAlbum, albumNestedInFirst))
-               assertThat(albums.indexOf(firstNestedAlbum), greaterThan(albums.indexOf(album)))
-               assertThat(albums.indexOf(secondNestedAlbum), greaterThan(albums.indexOf(album)))
-               assertThat(albums.indexOf(albumNestedInFirst), greaterThan(albums.indexOf(firstNestedAlbum)))
-       }
-
-       @Test
-       fun `notEmpty finds album without images is empty`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               assertThat(notEmpty(album), equalTo(false))
-       }
-
-       @Test
-       fun `notEmpty finds album with one inserted image is not empty`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               album.addImage(createImage(sone, "1", "key"))
-               assertThat(notEmpty(album), equalTo(true))
-       }
-
-       @Test
-       fun `notEmpty finds album with one not-inserted image is empty`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               album.addImage(createImage(sone, "1"))
-               assertThat(notEmpty(album), equalTo(false))
-       }
-
-       @Test
-       fun `notEmpty finds album with empty subalbums is empty`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               val firstNestedAlbum = AlbumImpl(sone)
-               album.addAlbum(firstNestedAlbum)
-               assertThat(notEmpty(album), equalTo(false))
-       }
-
-       @Test
-       fun `notEmpty finds album with subalbum with not inserted image is empty`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               val firstNestedAlbum = AlbumImpl(sone)
-               firstNestedAlbum.addImage(createImage(sone, "1"))
-               album.addAlbum(firstNestedAlbum)
-               assertThat(notEmpty(album), equalTo(false))
-       }
-
-       @Test
-       fun `notEmpty finds album with subalbum with inserted image is not empty`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               val firstNestedAlbum = AlbumImpl(sone)
-               firstNestedAlbum.addImage(createImage(sone, "1", "key"))
-               album.addAlbum(firstNestedAlbum)
-               assertThat(notEmpty(album), equalTo(true))
-       }
-
-       @Test
-       fun `allImages returns images from album`() {
-               val sone = IdOnlySone("sone")
-               val album = AlbumImpl(sone)
-               val image1 = createImage(sone, "1").also(album::addImage)
-               val image2 = createImage(sone, "2").also(album::addImage)
-               assertThat(album.allImages, contains(image1, image2))
-       }
-
-       @Test
-       fun `allImages returns images from subalbum`() {
-               val sone = IdOnlySone("sone")
-               val album1 = AlbumImpl(sone)
-               val album2 = AlbumImpl(sone).also(album1::addAlbum)
-               val image1 = createImage(sone, "1").also(album1::addImage)
-               val image2 = createImage(sone, "2").also(album2::addImage)
-               assertThat(album1.allImages, contains(image1, image2))
-       }
-
-}