Move image implementation to better package.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 22 Nov 2014 12:53:17 +0000 (13:53 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 22 Nov 2014 12:58:43 +0000 (13:58 +0100)
src/main/java/net/pterodactylus/sone/data/ImageImpl.java [deleted file]
src/main/java/net/pterodactylus/sone/data/impl/ImageBuilderImpl.java
src/main/java/net/pterodactylus/sone/data/impl/ImageImpl.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/UploadImagePage.java
src/test/java/net/pterodactylus/sone/core/FreenetInterfaceTest.java
src/test/java/net/pterodactylus/sone/data/ImageImplTest.java [deleted file]
src/test/java/net/pterodactylus/sone/data/impl/ImageImplTest.java [new file with mode: 0644]

diff --git a/src/main/java/net/pterodactylus/sone/data/ImageImpl.java b/src/main/java/net/pterodactylus/sone/data/ImageImpl.java
deleted file mode 100644 (file)
index df901b0..0000000
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * Sone - ImageImpl.java - Copyright © 2011–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 <http://www.gnu.org/licenses/>.
- */
-package net.pterodactylus.sone.data;
-
-import static com.google.common.base.Optional.absent;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Optional.of;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-
-import java.util.UUID;
-
-import com.google.common.base.Optional;
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-
-/**
- * Container for image metadata.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class ImageImpl implements Image {
-
-       /** The ID of the image. */
-       private final String id;
-
-       /** The Sone the image belongs to. */
-       private Sone sone;
-
-       /** The album this image belongs to. */
-       private Album album;
-
-       /** The request key of the image. */
-       private String key;
-
-       /** The creation time of the image. */
-       private long creationTime;
-
-       /** The width of the image. */
-       private int width;
-
-       /** The height of the image. */
-       private int height;
-
-       /** The title of the image. */
-       private String title;
-
-       /** The description of the image. */
-       private String description;
-
-       /** Creates a new image with a random ID. */
-       public ImageImpl() {
-               this(UUID.randomUUID().toString());
-               this.creationTime = System.currentTimeMillis();
-       }
-
-       /**
-        * Creates a new image.
-        *
-        * @param id
-        *              The ID of the image
-        */
-       public ImageImpl(String id) {
-               this.id = checkNotNull(id, "id must not be null");
-       }
-
-       //
-       // ACCESSORS
-       //
-
-       @Override
-       public String getId() {
-               return id;
-       }
-
-       @Override
-       public Sone getSone() {
-               return sone;
-       }
-
-       @Override
-       public Album getAlbum() {
-               return album;
-       }
-
-       @Override
-       public Image setAlbum(Album album) {
-               checkNotNull(album, "album must not be null");
-               checkNotNull(album.getSone().equals(getSone()), "album must belong to the same Sone as this image");
-               this.album = album;
-               return this;
-       }
-
-       @Override
-       public String getKey() {
-               return key;
-       }
-
-       @Override
-       public boolean isInserted() {
-               return key != null;
-       }
-
-       @Override
-       public long getCreationTime() {
-               return creationTime;
-       }
-
-       @Override
-       public int getWidth() {
-               return width;
-       }
-
-       @Override
-       public int getHeight() {
-               return height;
-       }
-
-       @Override
-       public String getTitle() {
-               return title;
-       }
-
-       @Override
-       public String getDescription() {
-               return description;
-       }
-
-       public Modifier modify() throws IllegalStateException {
-               // TODO: reenable check for local images
-               return new Modifier() {
-                       private Optional<Sone> sone = absent();
-
-                       private Optional<Long> creationTime = absent();
-
-                       private Optional<String> key = absent();
-
-                       private Optional<String> title = absent();
-
-                       private Optional<String> description = absent();
-
-                       private Optional<Integer> width = absent();
-
-                       private Optional<Integer> height = absent();
-
-                       @Override
-                       public Modifier setSone(Sone sone) {
-                               this.sone = fromNullable(sone);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setCreationTime(long creationTime) {
-                               this.creationTime = of(creationTime);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setKey(String key) {
-                               this.key = fromNullable(key);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setTitle(String title) {
-                               this.title = fromNullable(title);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setDescription(String description) {
-                               this.description = fromNullable(description);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setWidth(int width) {
-                               this.width = of(width);
-                               return this;
-                       }
-
-                       @Override
-                       public Modifier setHeight(int height) {
-                               this.height = of(height);
-                               return this;
-                       }
-
-                       @Override
-                       public Image update() throws IllegalStateException {
-                               checkState(!sone.isPresent() || (ImageImpl.this.sone == null) || sone.get().equals(ImageImpl.this.sone), "can not change Sone once set");
-                               checkState(!creationTime.isPresent() || ((ImageImpl.this.creationTime == 0) || (ImageImpl.this.creationTime == creationTime.get())), "can not change creation time once set");
-                               checkState(!key.isPresent() || (ImageImpl.this.key == null) || key.get().equals(ImageImpl.this.key), "can not change key once set");
-                               if (title.isPresent() && title.get().trim().isEmpty()) {
-                                       throw new ImageTitleMustNotBeEmpty();
-                               }
-                               checkState(!width.isPresent() || (ImageImpl.this.width == 0) || width.get().equals(ImageImpl.this.width), "can not change width once set");
-                               checkState(!height.isPresent() || (ImageImpl.this.height == 0) || height.get().equals(ImageImpl.this.height), "can not change height once set");
-
-                               if (sone.isPresent()) {
-                                       ImageImpl.this.sone = sone.get();
-                               }
-                               if (creationTime.isPresent()) {
-                                       ImageImpl.this.creationTime = creationTime.get();
-                               }
-                               if (key.isPresent()) {
-                                       ImageImpl.this.key = key.get();
-                               }
-                               if (title.isPresent()) {
-                                       ImageImpl.this.title = title.get();
-                               }
-                               if (description.isPresent()) {
-                                       ImageImpl.this.description = description.get();
-                               }
-                               if (width.isPresent()) {
-                                       ImageImpl.this.width = width.get();
-                               }
-                               if (height.isPresent()) {
-                                       ImageImpl.this.height = height.get();
-                               }
-
-                               return ImageImpl.this;
-                       }
-               };
-       }
-
-       public static class ImageTitleMustNotBeEmpty extends IllegalStateException { }
-
-       //
-       // FINGERPRINTABLE METHODS
-       //
-
-       @Override
-       public String getFingerprint() {
-               Hasher hash = Hashing.sha256().newHasher();
-               hash.putString("Image(");
-               hash.putString("ID(").putString(id).putString(")");
-               hash.putString("Title(").putString(title).putString(")");
-               hash.putString("Description(").putString(description).putString(")");
-               hash.putString(")");
-               return hash.hash().toString();
-       }
-
-       //
-       // OBJECT METHODS
-       //
-
-       /** {@inheritDoc} */
-       @Override
-       public int hashCode() {
-               return id.hashCode();
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       public boolean equals(Object object) {
-               if (!(object instanceof ImageImpl)) {
-                       return false;
-               }
-               return ((ImageImpl) object).id.equals(id);
-       }
-
-}
index 870b5d7..ba7d75f 100644 (file)
@@ -18,7 +18,6 @@
 package net.pterodactylus.sone.data.impl;
 
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.ImageImpl;
 import net.pterodactylus.sone.database.ImageBuilder;
 
 /**
diff --git a/src/main/java/net/pterodactylus/sone/data/impl/ImageImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/ImageImpl.java
new file mode 100644 (file)
index 0000000..e9c8fa9
--- /dev/null
@@ -0,0 +1,280 @@
+/*
+ * Sone - ImageImpl.java - Copyright © 2011–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 <http://www.gnu.org/licenses/>.
+ */
+package net.pterodactylus.sone.data.impl;
+
+import static com.google.common.base.Optional.absent;
+import static com.google.common.base.Optional.fromNullable;
+import static com.google.common.base.Optional.of;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.UUID;
+
+import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.Sone;
+
+import com.google.common.base.Optional;
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+
+/**
+ * Container for image metadata.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ImageImpl implements Image {
+
+       /** The ID of the image. */
+       private final String id;
+
+       /** The Sone the image belongs to. */
+       private Sone sone;
+
+       /** The album this image belongs to. */
+       private Album album;
+
+       /** The request key of the image. */
+       private String key;
+
+       /** The creation time of the image. */
+       private long creationTime;
+
+       /** The width of the image. */
+       private int width;
+
+       /** The height of the image. */
+       private int height;
+
+       /** The title of the image. */
+       private String title;
+
+       /** The description of the image. */
+       private String description;
+
+       /** Creates a new image with a random ID. */
+       public ImageImpl() {
+               this(UUID.randomUUID().toString());
+               this.creationTime = System.currentTimeMillis();
+       }
+
+       /**
+        * Creates a new image.
+        *
+        * @param id
+        *              The ID of the image
+        */
+       public ImageImpl(String id) {
+               this.id = checkNotNull(id, "id must not be null");
+       }
+
+       //
+       // ACCESSORS
+       //
+
+       @Override
+       public String getId() {
+               return id;
+       }
+
+       @Override
+       public Sone getSone() {
+               return sone;
+       }
+
+       @Override
+       public Album getAlbum() {
+               return album;
+       }
+
+       @Override
+       public Image setAlbum(Album album) {
+               checkNotNull(album, "album must not be null");
+               checkNotNull(album.getSone().equals(getSone()), "album must belong to the same Sone as this image");
+               this.album = album;
+               return this;
+       }
+
+       @Override
+       public String getKey() {
+               return key;
+       }
+
+       @Override
+       public boolean isInserted() {
+               return key != null;
+       }
+
+       @Override
+       public long getCreationTime() {
+               return creationTime;
+       }
+
+       @Override
+       public int getWidth() {
+               return width;
+       }
+
+       @Override
+       public int getHeight() {
+               return height;
+       }
+
+       @Override
+       public String getTitle() {
+               return title;
+       }
+
+       @Override
+       public String getDescription() {
+               return description;
+       }
+
+       public Modifier modify() throws IllegalStateException {
+               // TODO: reenable check for local images
+               return new Modifier() {
+                       private Optional<Sone> sone = absent();
+
+                       private Optional<Long> creationTime = absent();
+
+                       private Optional<String> key = absent();
+
+                       private Optional<String> title = absent();
+
+                       private Optional<String> description = absent();
+
+                       private Optional<Integer> width = absent();
+
+                       private Optional<Integer> height = absent();
+
+                       @Override
+                       public Modifier setSone(Sone sone) {
+                               this.sone = fromNullable(sone);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setCreationTime(long creationTime) {
+                               this.creationTime = of(creationTime);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setKey(String key) {
+                               this.key = fromNullable(key);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setTitle(String title) {
+                               this.title = fromNullable(title);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setDescription(String description) {
+                               this.description = fromNullable(description);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setWidth(int width) {
+                               this.width = of(width);
+                               return this;
+                       }
+
+                       @Override
+                       public Modifier setHeight(int height) {
+                               this.height = of(height);
+                               return this;
+                       }
+
+                       @Override
+                       public Image update() throws IllegalStateException {
+                               checkState(!sone.isPresent() || (ImageImpl.this.sone == null) || sone.get().equals(ImageImpl.this.sone), "can not change Sone once set");
+                               checkState(!creationTime.isPresent() || ((ImageImpl.this.creationTime == 0) || (ImageImpl.this.creationTime == creationTime.get())), "can not change creation time once set");
+                               checkState(!key.isPresent() || (ImageImpl.this.key == null) || key.get().equals(ImageImpl.this.key), "can not change key once set");
+                               if (title.isPresent() && title.get().trim().isEmpty()) {
+                                       throw new ImageTitleMustNotBeEmpty();
+                               }
+                               checkState(!width.isPresent() || (ImageImpl.this.width == 0) || width.get().equals(ImageImpl.this.width), "can not change width once set");
+                               checkState(!height.isPresent() || (ImageImpl.this.height == 0) || height.get().equals(ImageImpl.this.height), "can not change height once set");
+
+                               if (sone.isPresent()) {
+                                       ImageImpl.this.sone = sone.get();
+                               }
+                               if (creationTime.isPresent()) {
+                                       ImageImpl.this.creationTime = creationTime.get();
+                               }
+                               if (key.isPresent()) {
+                                       ImageImpl.this.key = key.get();
+                               }
+                               if (title.isPresent()) {
+                                       ImageImpl.this.title = title.get();
+                               }
+                               if (description.isPresent()) {
+                                       ImageImpl.this.description = description.get();
+                               }
+                               if (width.isPresent()) {
+                                       ImageImpl.this.width = width.get();
+                               }
+                               if (height.isPresent()) {
+                                       ImageImpl.this.height = height.get();
+                               }
+
+                               return ImageImpl.this;
+                       }
+               };
+       }
+
+       public static class ImageTitleMustNotBeEmpty extends IllegalStateException { }
+
+       //
+       // FINGERPRINTABLE METHODS
+       //
+
+       @Override
+       public String getFingerprint() {
+               Hasher hash = Hashing.sha256().newHasher();
+               hash.putString("Image(");
+               hash.putString("ID(").putString(id).putString(")");
+               hash.putString("Title(").putString(title).putString(")");
+               hash.putString("Description(").putString(description).putString(")");
+               hash.putString(")");
+               return hash.hash().toString();
+       }
+
+       //
+       // OBJECT METHODS
+       //
+
+       /** {@inheritDoc} */
+       @Override
+       public int hashCode() {
+               return id.hashCode();
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       public boolean equals(Object object) {
+               if (!(object instanceof ImageImpl)) {
+                       return false;
+               }
+               return ((ImageImpl) object).id.equals(id);
+       }
+
+}
index 8aab02e..5812af5 100644 (file)
@@ -33,7 +33,7 @@ import javax.imageio.ImageReader;
 import javax.imageio.stream.ImageInputStream;
 
 import net.pterodactylus.sone.data.Album;
-import net.pterodactylus.sone.data.ImageImpl.ImageTitleMustNotBeEmpty;
+import net.pterodactylus.sone.data.impl.ImageImpl.ImageTitleMustNotBeEmpty;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.sone.text.TextFilter;
index 60c8344..c753740 100644 (file)
@@ -38,7 +38,7 @@ import net.pterodactylus.sone.core.event.ImageInsertFailedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertStartedEvent;
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.ImageImpl;
+import net.pterodactylus.sone.data.impl.ImageImpl;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.sone.freenet.StringBucket;
diff --git a/src/test/java/net/pterodactylus/sone/data/ImageImplTest.java b/src/test/java/net/pterodactylus/sone/data/ImageImplTest.java
deleted file mode 100644 (file)
index 5a096a4..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-package net.pterodactylus.sone.data;
-
-import net.pterodactylus.sone.data.ImageImpl.ImageTitleMustNotBeEmpty;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link ImageImpl}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class ImageImplTest {
-
-       private final Image image = new ImageImpl();
-
-       @Test(expected = ImageTitleMustNotBeEmpty.class)
-       public void modifierDoesNotAllowTitleDoBeEmpty() {
-               image.modify().setTitle("").update();
-       }
-
-}
diff --git a/src/test/java/net/pterodactylus/sone/data/impl/ImageImplTest.java b/src/test/java/net/pterodactylus/sone/data/impl/ImageImplTest.java
new file mode 100644 (file)
index 0000000..0875284
--- /dev/null
@@ -0,0 +1,23 @@
+package net.pterodactylus.sone.data.impl;
+
+import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.impl.ImageImpl;
+import net.pterodactylus.sone.data.impl.ImageImpl.ImageTitleMustNotBeEmpty;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link ImageImpl}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ImageImplTest {
+
+       private final Image image = new ImageImpl();
+
+       @Test(expected = ImageTitleMustNotBeEmpty.class)
+       public void modifierDoesNotAllowTitleDoBeEmpty() {
+               image.modify().setTitle("").update();
+       }
+
+}