Move required parameters for image into the image builder.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / AbstractImageBuilder.java
index 533ba39..1b9e3a8 100644 (file)
@@ -18,6 +18,7 @@ package net.pterodactylus.sone.data.impl;
 
 import static com.google.common.base.Preconditions.checkState;
 
+import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.database.ImageBuilder;
 
 /**
@@ -33,6 +34,12 @@ public abstract class AbstractImageBuilder implements ImageBuilder {
 
        /** The ID of the album to create. */
        protected String id;
+       protected Sone sone;
+       protected long creationTime;
+       protected boolean createdNow;
+       protected String key;
+       protected int width;
+       protected int height;
 
        @Override
        public ImageBuilder randomId() {
@@ -46,6 +53,37 @@ public abstract class AbstractImageBuilder implements ImageBuilder {
                return this;
        }
 
+       @Override
+       public ImageBuilder by(Sone sone) {
+               this.sone = sone;
+               return this;
+       }
+
+       @Override
+       public ImageBuilder created(long creationTime) {
+               this.creationTime = creationTime;
+               return this;
+       }
+
+       @Override
+       public ImageBuilder createdNow() {
+               createdNow = true;
+               return this;
+       }
+
+       @Override
+       public ImageBuilder at(String key) {
+               this.key = key;
+               return this;
+       }
+
+       @Override
+       public ImageBuilder sized(int width, int height) {
+               this.width = width;
+               this.height = height;
+               return this;
+       }
+
        //
        // PROTECTED METHODS
        //
@@ -58,6 +96,9 @@ public abstract class AbstractImageBuilder implements ImageBuilder {
         */
        protected void validate() throws IllegalStateException {
                checkState((randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID must be set");
+               checkState(sone != null, "sone must not be null");
+               checkState((createdNow && (creationTime == 0)) || (!createdNow && (creationTime > 0)), "exactly one of created now or creation time must be set");
+               checkState((width > 0) && (height > 0), "width and height must be set");
        }
 
 }